High Level functions for SPI. More...
Functions | |
| spi_status_en | spi_transfer_blocking (spi_instance_en id, spi_xfer_config_t *xfer) |
| spi_status_en | spi_transfer_non_blocking (spi_instance_en id, spi_xfer_config_t *xfer) |
| spi_status_en | spi_transfer_abort (spi_instance_en id) |
| spi_transfer_status_en | spi_transfer_status (spi_instance_en id) |
| uint32_t | spi_transfer_elements_transferred (spi_instance_en id) |
High Level functions for SPI.
| spi_status_en spi_transfer_blocking | ( | spi_instance_en | id, |
| spi_xfer_config_t * | xfer ) |
Transfers specified number of data elements. Does not return until all data elements are transferred or timeout. This function blocks all other code from running until it completes. If tx_buff is NULL then tx_dummy is sent for each data element. If rx_buff is NULL all received data is discarded.
If receive is not important pass a NULL pointer for rx_buff If TX is not required pass a NULL pointer for tx_buff, and set tx_dummy. Setting both tx_buff and rx_buff NULL is an invalid use case.
When this function exits both the RX and TX FIFO shall be empty and all level sensitive statuses and interrupts cleared.
Note both the tx_buff and rx_buff must have equal to or greater data elements than the specified xfer_size.
| id | SPI Instance ID. |
| xfer | spi_xfer_config_t |
| spi_status_en spi_transfer_non_blocking | ( | spi_instance_en | id, |
| spi_xfer_config_t * | xfer ) |
Initiates a non-blocking SPI transfer in full-duplex or half-duplex mode.
This function sets up the hardware SPI configuration, preloads available data into the TX FIFO (if applicable), and enables relevant interrupts. Once the initial setup is complete, the function returns immediately. All remaining data transmission and reception are managed by the interrupt handler spi_transfer_non_blocking_interrupt.
If transmit data (tx_buff) is provided, data is loaded into the TX FIFO; otherwise, the tx_dummy value is used. If receive data (rx_buff) is provided, the ISR copies received words from the RX FIFO; otherwise, received data is discarded.
The caller must ensure that tx_buff and rx_buff (if used) remain valid and unmodified for the duration of the transfer. The completion callback specified in the spi_xfer_config_t structure is invoked from the interrupt context when the transfer ends.
| id | SPI Instance ID. |
| xfer | Pointer to a spi_xfer_config_t structure containing transfer details such as buffers, transfer size, dummy data, and completion callback. |
| spi_status_en spi_transfer_abort | ( | spi_instance_en | id | ) |
Stop current SPI Transfer, clears TX and RX buffers, disables SPI interrupts. Disables SPI block.
Note this could stop a data transfer in the middle of a data element.
| id | SPI Instance ID. |
| spi_transfer_status_en spi_transfer_status | ( | spi_instance_en | id | ) |
Returns current transfer status, complete and error status are cleared when reading the status.
| id | SPI Instance ID. |
| uint32_t spi_transfer_elements_transferred | ( | spi_instance_en | id | ) |
Returns how many elements have been transferred since last call to transfer_non_blocking.
| id | SPI Instance ID. |