OLE Developer Guide  Latest Git
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
SPI

Detailed Description

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.

Files

file  spi.h
 SPI Driver.
 

Typedefs

typedef void(* SPI_Callback )(SPIEventType event)
 The callback run before and after the SPI transfer begins. More...
 

Enumerations

enum  SPIEventType { SPI_BEGIN_TRANSFER, SPI_COMPLETE_TRANSFER }
 SPI Event types.
 

Functions

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.
 

Typedef Documentation

typedef void(* SPI_Callback)(SPIEventType event)

The callback run before and after the SPI transfer begins.

Parameters
eventThe type of SPI event that occurs.

Function Documentation

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
outputThe output buffer to send, may be NULL.
output_lengthThe size of the output buffer.
inputThe location to store received data, may be NULL.
input_lengthThe length of the input data buffer.
callbackThe 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).