Skyward boardcore
Loading...
Searching...
No Matches
SPITransaction.h
Go to the documentation of this file.
1/* Copyright (c) 2020 Skyward Experimental Rocketry
2 * Author: Luca Erbetta
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include "SPIBusInterface.h"
26
27namespace Boardcore
28{
29
57{
58public:
65 explicit SPITransaction(const SPISlave& slave);
66
67 // /**
68 // * @brief Instantiates a new SPITransaction, configuring the bus with the
69 // * provided parameters.
70 // *
71 // * @param bus Bus to communicate on.
72 // * @param cs Chip select of the slave to communicate to.
73 // * @param config Configuration of the bus for the selected slave.
74 // */
75 // SPITransaction(SPIBusInterface &bus, GpioType cs, SPIBusConfig config);
76
82
89
90 // Read, write and transfer operations
91
97 uint8_t read();
98
104 uint16_t read16();
105
111 virtual uint32_t read24();
112
118 virtual uint32_t read32();
119
126 void read(uint8_t* data, size_t size);
127
134 void read16(uint16_t* data, size_t size);
135
141 void write(uint8_t data);
142
148 void write16(uint16_t data);
149
155 virtual void write24(uint32_t data);
156
162 virtual void write32(uint32_t data);
163
170 void write(uint8_t* data, size_t size);
171
178 void write16(uint16_t* data, size_t size);
179
186 uint8_t transfer(uint8_t data);
187
194 uint16_t transfer16(uint16_t data);
195
202 virtual uint32_t transfer24(uint32_t data);
203
210 virtual uint32_t transfer32(uint32_t data);
211
218 void transfer(uint8_t* data, size_t size);
219
226 void transfer16(uint16_t* data, size_t size);
227
228 // Read, write and transfer operations with registers
229
235 uint8_t readRegister(uint8_t reg);
236
242 uint16_t readRegister16(uint8_t reg);
243
249 uint32_t readRegister24(uint8_t reg);
250
256 uint32_t readRegister32(uint8_t reg);
257
264 void readRegisters(uint8_t reg, uint8_t* data, size_t size);
265
272 void writeRegister(uint8_t reg, uint8_t data);
273
280 void writeRegister16(uint8_t reg, uint16_t data);
281
288 void writeRegister24(uint8_t reg, uint32_t data);
289
296 void writeRegister32(uint8_t reg, uint32_t data);
297
305 void writeRegisters(uint8_t reg, uint8_t* data, size_t size);
306
307private:
308 const SPISlave& slave;
309};
310
311} // namespace Boardcore
Interface for low level access of a SPI bus as a master.
Provides high-level access to the SPI Bus for a single transaction.
virtual uint32_t read32()
Reads 32 bits from the bus.
void write16(uint16_t data)
Writes a single half word to the bus.
SPITransaction(SPITransaction &&)=delete
void write(uint8_t data)
Writes a single byte to the bus.
SPITransaction & operator=(const SPITransaction &)=delete
uint8_t readRegister(uint8_t reg)
Reads an 8 bit register.
void writeRegister32(uint8_t reg, uint32_t data)
Writes a 32 bit register.
uint8_t read()
Reads a single byte from the bus.
void writeRegisters(uint8_t reg, uint8_t *data, size_t size)
Writes multiple bytes starting from the specified register.
virtual void write32(uint32_t data)
Writes 32 bits to the bus.
uint16_t transfer16(uint16_t data)
Full duplex transmission of one half word on the bus.
virtual uint32_t read24()
Reads 24 bits from the bus.
void writeRegister24(uint8_t reg, uint32_t data)
Writes a 24 bit register.
uint32_t readRegister32(uint8_t reg)
Reads a 32 bit register.
void readRegisters(uint8_t reg, uint8_t *data, size_t size)
Reads multiple bytes starting from the specified register.
SPITransaction & operator=(SPITransaction &&)=delete
void writeRegister(uint8_t reg, uint8_t data)
Writes an 8 bit register.
SPIBusInterface & getBus()
Returns the underlying bus for low level access.
virtual void write24(uint32_t data)
Writes 24 bits to the bus.
SPITransaction(const SPITransaction &)=delete
< Delete copy/move constructors/operators.
SPITransaction(const SPISlave &slave)
Instantiates a new SPITransaction, configuring the bus with the provided parameters.
virtual uint32_t transfer24(uint32_t data)
Full duplex transmission of 24 bits on the bus.
uint32_t readRegister24(uint8_t reg)
Reads a 24 bit register.
void writeRegister16(uint8_t reg, uint16_t data)
Writes a 16 bit register.
uint8_t transfer(uint8_t data)
Full duplex transmission of one byte on the bus.
uint16_t readRegister16(uint8_t reg)
Reads a 16 bit register.
virtual uint32_t transfer32(uint32_t data)
Full duplex transmission of 32 bits on the bus.
uint16_t read16()
Reads a single half word from the bus.
This file includes all the types the logdecoder script will decode.
Contains information about a single SPI slave device.