Midnight Sun Firmware
|
SPI library. More...
Classes | |
struct | SpiSettings |
SPI settings struct. More... | |
Macros | |
#define | SPI_TIMEOUT_MS 100U |
Maximum time permitted for a SPI transaction. | |
#define | SPI_MAX_NUM_DATA 32U |
None of our SPI transactions should need to be longer than 32 bytes. | |
#define | spi_tx(spi, tx_data, tx_len) spi_exchange(spi, tx_data, tx_len, NULL, 0U) |
Transmit data from the SPI port. More... | |
#define | spi_rx(spi, rx_data, rx_len) spi_exchange(spi, NULL, 0U, rx_data, rx_len) |
Receive data from the SPI port. More... | |
Enumerations | |
enum | SpiPort { SPI_PORT_1 = 0 , SPI_PORT_2 , SPI_PORT_3 , NUM_SPI_PORTS } |
SPI Port selection. More... | |
enum | SpiMode { SPI_MODE_0 = 0 , SPI_MODE_1 , SPI_MODE_2 , SPI_MODE_3 , NUM_SPI_MODES } |
SPI Mode selection. More... | |
Functions | |
StatusCode | spi_init (SpiPort spi, const SpiSettings *settings) |
Initialize SPI instance. More... | |
StatusCode | spi_exchange (SpiPort spi, uint8_t *tx_data, size_t tx_len, uint8_t *rx_data, size_t rx_len) |
Performs a SPI data exchange. More... | |
SPI library.
#define spi_rx | ( | spi, | |
rx_data, | |||
rx_len | |||
) | spi_exchange(spi, NULL, 0U, rx_data, rx_len) |
Receive data from the SPI port.
This method will only receive data, and will not send any data
spi | Specifies which SPI port performs the receive |
rx_data | Pointer to a buffer to receive data |
rx_len | Length of the data to receive |
#define spi_tx | ( | spi, | |
tx_data, | |||
tx_len | |||
) | spi_exchange(spi, tx_data, tx_len, NULL, 0U) |
Transmit data from the SPI port.
This method will only send data, and will discard the response bytes
spi | Specifies which SPI port performs the transmit |
tx_data | Pointer to a buffer to transmit data |
tx_len | Length of the data to transmit |
enum SpiMode |
SPI Mode selection.
enum SpiPort |
StatusCode spi_exchange | ( | SpiPort | spi, |
uint8_t * | tx_data, | ||
size_t | tx_len, | ||
uint8_t * | rx_data, | ||
size_t | rx_len | ||
) |
Performs a SPI data exchange.
Half-duplex communication where it transmits first, then receives. It will first pull the CS low, transmit the data, then receive data, and finally pull CS high.
spi | Specifies which SPI port performs the exchange |
tx_data | Pointer to a buffer to transmit data |
tx_len | Length of the data to transmit |
rx_data | Pointer to a buffer to receive data |
rx_len | Length of the data to receive |
StatusCode spi_init | ( | SpiPort | spi, |
const SpiSettings * | settings | ||
) |
Initialize SPI instance.
Prescalers on STM32 must be a power of 2, so the actual baudrate may not be as exactly as requested.
spi | Specifies which SPI port to initialize |
settings | Pointer to SPI initialization settings |