SPI PeripheralDriver
Description
SPI Peripheral Interface driver.
Flexible SPI Peripheral driver implementation for use in an NCP scenario.
This driver will support both blocking and non-blocking operation, with LDMA backing the background transfers to support nonblocking.
Functions |
|
void | spi_peripheral_init (void) |
void | spi_peripheral_deinit (void) |
int32_t | spi_peripheral_sendBuffer (uint8_t *buffer, size_t length) |
int32_t | spi_peripheral_sendByte (uint8_t byte) |
size_t | spi_peripheral_getTxBytesLeft (void) |
void | spi_peripheral_enableTransmitter (bool enable) |
void | spi_peripheral_enableReceiver (bool enable) |
size_t | spi_peripheral_getRxAvailableBytes (void) |
int32_t | spi_peripheral_receiveBuffer (uint8_t *buffer, size_t requestedLength, size_t *receivedLength, bool blocking, uint32_t timeout) |
int32_t | spi_peripheral_receiveByte (uint8_t *byte) |
void | spi_peripheral_flush (bool flushTx, bool flushRx) |
Function Documentation
void spi_peripheral_init | ( | void |
|
) |
Initialize the configured USART peripheral for the SPI peripheral operation. Also sets up GPIO settings for MOSI, MISO, SCLK and SS. After initialization, the SPI peripheral will have RX enabled.
- Returns
- BOOTLOADER_OK if successful, error code otherwise
void spi_peripheral_deinit | ( | void |
|
) |
Disable the configured USART peripheral for the SPI operation.
int32_t spi_peripheral_sendBuffer | ( | uint8_t * |
buffer,
|
size_t |
length
|
||
) |
Write a data buffer to the controller next time the controller starts clocking SCLK. This transfer will be non-blocking and its progress can be tracked through spi_peripheral_getTxBytesLeft .
- Parameters
-
[in] buffer
The data buffer to send [in] length
Number of bytes in the buffer to send
- Returns
- BOOTLOADER_OK if successful, error code otherwise
int32_t spi_peripheral_sendByte | ( | uint8_t |
byte
|
) |
Write one byte to the controller in a blocking fashion.
- Warning
- If the controller goes down, this will block forever.
- Parameters
-
[in] byte
The byte to send
- Returns
- BOOTLOADER_OK if successful, error code otherwise
size_t spi_peripheral_getTxBytesLeft | ( | void |
|
) |
Get the amount of bytes left in the TX data buffer.
- Returns
- Number of bytes in the transmit buffer still needing to go out
void spi_peripheral_enableTransmitter | ( | bool |
enable
|
) |
Enable/disable MISO output.
- Parameters
-
[in] enable
True to enable the transmitter, false to disable
void spi_peripheral_enableReceiver | ( | bool |
enable
|
) |
Enable/disable receiving bytes from the controller into the internal buffer. This function makes it possible to avoid filling up the buffer with 0xFF while a controller is polling for new data.
- Parameters
-
[in] enable
True to enable the receiver, false to disable
size_t spi_peripheral_getRxAvailableBytes | ( | void |
|
) |
Get the amount of bytes ready for reading.
- Returns
- Number of bytes in the receive buffer available for reading with spi_peripheral_receiveBuffer
int32_t spi_peripheral_receiveBuffer | ( | uint8_t * |
buffer,
|
size_t |
requestedLength,
|
||
size_t * |
receivedLength,
|
||
bool |
blocking,
|
||
uint32_t |
timeout
|
||
) |
Read from the RX buffer into a local buffer.
- Parameters
-
[out] buffer
The data buffer to receive into [in] requestedLength
Number of bytes we'd like to read [out] receivedLength
Number of bytes read [in] blocking
Indicate whether we should wait for requestedLength bytes to be available and read before returning, or we can read out whatever is currently in the buffer and return. [in] timeout
Number of milliseconds to wait for data in blocking mode
- Returns
- BOOTLOADER_OK if successful, error code otherwise
int32_t spi_peripheral_receiveByte | ( | uint8_t * |
byte
|
) |
Get one byte from the SPI peripheral in a blocking fashion.
- Warning
- If the controller never clocks in a byte, this function will block forever.
- Parameters
-
[out] byte
Pointer to where to put the received byte
- Returns
- BOOTLOADER_OK if successful, error code otherwise
void spi_peripheral_flush | ( | bool |
flushTx,
|
bool |
flushRx
|
||
) |
Flush one or both buffers.
- Parameters
-
[in] flushTx
Flush the transmit buffer when true [in] flushRx
Flush the receive buffer when true