SPI Driver.
This driver allows multiple clients to share the SPI bus. This assumes that all clients use the same SPI configuration. If that isn't the case we'll need to introduce client handles or something.
Clients can queue an SPI transfer with the SPI_QueueTransfer() method. The callback argument can be used to specify a callback to be run before and after the transfer is performed. This callback can be used to set the relevant chip-enable line.
|
enum | SPIEventType { SPI_BEGIN_TRANSFER,
SPI_COMPLETE_TRANSFER
} |
| SPI Event types.
|
|
|
bool | SPI_QueueTransfer (const uint8_t *output, unsigned int output_length, uint8_t *input, unsigned int input_length, SPI_Callback callback) |
| Queue an SPI transfer. More...
|
|
void | SPI_Initialize () |
| Initialize the SPI driver.
|
|
void | SPI_Tasks () |
| The tasks function, this should be called from the main event loop.
|
|
The callback run before and after the SPI transfer begins.
- Parameters
-
event | The type of SPI event that occurs. |
bool SPI_QueueTransfer |
( |
const uint8_t * |
output, |
|
|
unsigned int |
output_length, |
|
|
uint8_t * |
input, |
|
|
unsigned int |
input_length, |
|
|
SPI_Callback |
callback |
|
) |
| |
Queue an SPI transfer.
- Parameters
-
output | The output buffer to send, may be NULL. |
output_length | The size of the output buffer. |
input | The location to store received data, may be NULL. |
input_length | The length of the input data buffer. |
callback | The callback run prior and post this transfer. |
- Returns
- True if the transfer was scheduled, false if the queue was full.
This queues a write / read SPI operation. First the data in output will be sent, then input_length worth of data will be read while 0s are sent. Both stages are optional.
The total number of bytes sent will be the sum of (output_length, input_length).