![]() |
RT-Thread RTOS
An open source embedded real-time operating system
|
Collaboration diagram for SPI:Data Structures | |
| struct | rt_spi_message |
| struct | rt_spi_configuration |
| struct | rt_spi_bus |
| struct | rt_spi_ops |
| struct | rt_spi_device |
| struct | rt_qspi_message |
| struct | rt_qspi_configuration |
| struct | rt_qspi_device |
Macros | |
| #define | RT_SPI_CPHA (1<<0) |
| #define | RT_SPI_CPOL (1<<1) |
| #define | RT_SPI_LSB (0<<2) |
| #define | RT_SPI_MSB (1<<2) |
| #define | RT_SPI_MASTER (0<<3) |
| #define | RT_SPI_SLAVE (1<<3) |
| #define | RT_SPI_CS_HIGH (1<<4) |
| #define | RT_SPI_NO_CS (1<<5) |
| #define | RT_SPI_3WIRE (1<<6) |
| #define | RT_SPI_READY (1<<7) |
| #define | RT_SPI_MODE_0 (0 | 0) |
| #define | RT_SPI_MODE_1 (0 | RT_SPI_CPHA) |
| #define | RT_SPI_MODE_2 (RT_SPI_CPOL | 0) |
| #define | RT_SPI_MODE_3 (RT_SPI_CPOL | RT_SPI_CPHA) |
Functions | |
| rt_err_t | rt_spi_bus_register (struct rt_spi_bus *bus, const char *name, const struct rt_spi_ops *ops) |
| rt_err_t | rt_spi_bus_attach_device (struct rt_spi_device *device, const char *name, const char *bus_name, void *user_data) |
| rt_err_t | rt_spi_bus_attach_device_cspin (struct rt_spi_device *device, const char *name, const char *bus_name, rt_base_t cs_pin, void *user_data) |
| rt_err_t | rt_spi_bus_configure (struct rt_spi_device *device) |
| rt_err_t | rt_spi_take_bus (struct rt_spi_device *device) |
| rt_err_t | rt_spi_release_bus (struct rt_spi_device *device) |
| rt_err_t | rt_spi_take (struct rt_spi_device *device) |
| rt_err_t | rt_spi_release (struct rt_spi_device *device) |
| rt_err_t | rt_spi_configure (struct rt_spi_device *device, struct rt_spi_configuration *cfg) |
| rt_err_t | rt_spi_send_then_recv (struct rt_spi_device *device, const void *send_buf, rt_size_t send_length, void *recv_buf, rt_size_t recv_length) |
| rt_err_t | rt_spi_send_then_send (struct rt_spi_device *device, const void *send_buf1, rt_size_t send_length1, const void *send_buf2, rt_size_t send_length2) |
| rt_ssize_t | rt_spi_transfer (struct rt_spi_device *device, const void *send_buf, void *recv_buf, rt_size_t length) |
| rt_err_t | rt_spi_sendrecv8 (struct rt_spi_device *device, rt_uint8_t senddata, rt_uint8_t *recvdata) |
| rt_err_t | rt_spi_sendrecv16 (struct rt_spi_device *device, rt_uint16_t senddata, rt_uint16_t *recvdata) |
| struct rt_spi_message * | rt_spi_transfer_message (struct rt_spi_device *device, struct rt_spi_message *message) |
| rt_inline rt_size_t | rt_spi_recv (struct rt_spi_device *device, void *recv_buf, rt_size_t length) |
| rt_inline rt_size_t | rt_spi_send (struct rt_spi_device *device, const void *send_buf, rt_size_t length) |
| rt_inline void | rt_spi_message_append (struct rt_spi_message *list, struct rt_spi_message *message) |
| rt_err_t | rt_qspi_configure (struct rt_qspi_device *device, struct rt_qspi_configuration *cfg) |
| rt_err_t | rt_qspi_bus_register (struct rt_spi_bus *bus, const char *name, const struct rt_spi_ops *ops) |
| rt_size_t | rt_qspi_transfer_message (struct rt_qspi_device *device, struct rt_qspi_message *message) |
| rt_err_t | rt_qspi_send_then_recv (struct rt_qspi_device *device, const void *send_buf, rt_size_t send_length, void *recv_buf, rt_size_t recv_length) |
| rt_err_t | rt_qspi_send (struct rt_qspi_device *device, const void *send_buf, rt_size_t length) |
SPI driver api.
Example
| #define RT_SPI_CPHA (1<<0) |
At CPOL=0 the base value of the clock is zero
| #define RT_SPI_CPOL (1<<1) |
bit[1]:CPOL, clock polarity
| #define RT_SPI_LSB (0<<2) |
bit[2]: 0-LSB
| #define RT_SPI_MSB (1<<2) |
bit[2]: 1-MSB
| #define RT_SPI_MASTER (0<<3) |
SPI master device
| #define RT_SPI_SLAVE (1<<3) |
SPI slave device
| #define RT_SPI_CS_HIGH (1<<4) |
Chipselect active high
| #define RT_SPI_NO_CS (1<<5) |
No chipselect
| #define RT_SPI_3WIRE (1<<6) |
SI/SO pin shared
| #define RT_SPI_READY (1<<7) |
Slave pulls low to pause
| #define RT_SPI_MODE_0 (0 | 0) |
CPOL = 0, CPHA = 0
| #define RT_SPI_MODE_1 (0 | RT_SPI_CPHA) |
CPOL = 0, CPHA = 1
| #define RT_SPI_MODE_2 (RT_SPI_CPOL | 0) |
CPOL = 1, CPHA = 0
| #define RT_SPI_MODE_3 (RT_SPI_CPOL | RT_SPI_CPHA) |
CPOL = 1, CPHA = 1
| rt_err_t rt_spi_bus_register | ( | struct rt_spi_bus * | bus, |
| const char * | name, | ||
| const struct rt_spi_ops * | ops ) |
register a SPI bus
| bus | the SPI bus |
| name | the name of SPI bus |
| ops | the operations of SPI bus |
| rt_err_t rt_spi_bus_attach_device | ( | struct rt_spi_device * | device, |
| const char * | name, | ||
| const char * | bus_name, | ||
| void * | user_data ) |
attach a device on SPI bus
| device | the SPI device |
| name | the name of SPI device |
| bus_name | the name of SPI bus |
| user_data | the user data of SPI device |
| rt_err_t rt_spi_bus_attach_device_cspin | ( | struct rt_spi_device * | device, |
| const char * | name, | ||
| const char * | bus_name, | ||
| rt_base_t | cs_pin, | ||
| void * | user_data ) |
attach a device on SPI bus with CS pin
| device | the SPI device |
| name | the name of SPI device |
| bus_name | the name of SPI bus |
| cs_pin | the CS pin of SPI device |
| user_data | the user data of SPI device |
| rt_err_t rt_spi_bus_configure | ( | struct rt_spi_device * | device | ) |
Reconfigure the SPI bus for the specified device.
| device | Pointer to the SPI device attached to the SPI bus. |
| RT_EOK | if the SPI device was successfully released and the bus was configured. RT_EBUSY if the SPI bus is currently in use; the new configuration will take effect once the device releases the bus. Other return values indicate failure to configure the SPI bus due to various reasons. |
| rt_err_t rt_spi_take_bus | ( | struct rt_spi_device * | device | ) |
This function takes SPI bus.
| device | the SPI device attached to SPI bus |
| rt_err_t rt_spi_release_bus | ( | struct rt_spi_device * | device | ) |
This function releases SPI bus.
| device | the SPI device attached to SPI bus |
| rt_err_t rt_spi_take | ( | struct rt_spi_device * | device | ) |
This function take SPI device (takes CS of SPI device).
| device | the SPI device attached to SPI bus |
| rt_err_t rt_spi_release | ( | struct rt_spi_device * | device | ) |
This function releases SPI device (releases CS of SPI device).
| device | the SPI device attached to SPI bus |
| rt_err_t rt_spi_configure | ( | struct rt_spi_device * | device, |
| struct rt_spi_configuration * | cfg ) |
This function can set configuration on SPI device.
| device | the SPI device attached to SPI bus |
| cfg | the configuration pointer. |
| RT_EOK | on release SPI device successfully. RT_EBUSY is not an error condition and the configuration will take effect once the device has the bus others on taken SPI bus failed. |
| rt_err_t rt_spi_send_then_recv | ( | struct rt_spi_device * | device, |
| const void * | send_buf, | ||
| rt_size_t | send_length, | ||
| void * | recv_buf, | ||
| rt_size_t | recv_length ) |
This function can send data then receive data from SPI device.
| device | the SPI device attached to SPI bus |
| send_buf | the buffer to be transmitted to SPI device. |
| send_length | the number of data to be transmitted. |
| recv_buf | the buffer to be recivied from SPI device. |
| recv_length | the data to be recivied. |
| rt_err_t rt_spi_send_then_send | ( | struct rt_spi_device * | device, |
| const void * | send_buf1, | ||
| rt_size_t | send_length1, | ||
| const void * | send_buf2, | ||
| rt_size_t | send_length2 ) |
This function can send data then send data from SPI device.
| device | the SPI device attached to SPI bus |
| send_buf1 | the buffer to be transmitted to SPI device. |
| send_length1 | the number of data to be transmitted. |
| send_buf2 | the buffer to be transmitted to SPI device. |
| send_length2 | the number of data to be transmitted. |
| rt_ssize_t rt_spi_transfer | ( | struct rt_spi_device * | device, |
| const void * | send_buf, | ||
| void * | recv_buf, | ||
| rt_size_t | length ) |
This function transmits data to SPI device.
| device | the SPI device attached to SPI bus |
| send_buf | the buffer to be transmitted to SPI device. |
| recv_buf | the buffer to save received data from SPI device. |
| length | the length of transmitted data. |
| rt_err_t rt_spi_sendrecv8 | ( | struct rt_spi_device * | device, |
| rt_uint8_t | senddata, | ||
| rt_uint8_t * | recvdata ) |
The SPI device transmits 8 bytes of data.
| device | the SPI device attached to SPI bus |
| senddata | send data buffer |
| recvdata | receive data buffer |
| rt_err_t rt_spi_sendrecv16 | ( | struct rt_spi_device * | device, |
| rt_uint16_t | senddata, | ||
| rt_uint16_t * | recvdata ) |
The SPI device transmits 16 bytes of data.
| device | the SPI device attached to SPI bus |
| senddata | send data buffer |
| recvdata | receive data buffer |
| struct rt_spi_message * rt_spi_transfer_message | ( | struct rt_spi_device * | device, |
| struct rt_spi_message * | message ) |
This function transfers a message list to the SPI device.
| device | the SPI device attached to SPI bus |
| message | the message list to be transmitted to SPI device |
| rt_inline rt_size_t rt_spi_recv | ( | struct rt_spi_device * | device, |
| void * | recv_buf, | ||
| rt_size_t | length ) |
This function receives data from SPI device.
| device | the SPI device attached to SPI bus |
| recv_buf | the buffer to be recivied from SPI device. |
| length | the data to be recivied. |
| rt_inline rt_size_t rt_spi_send | ( | struct rt_spi_device * | device, |
| const void * | send_buf, | ||
| rt_size_t | length ) |
This function sends data to SPI device.
| device | the SPI device attached to SPI bus |
| send_buf | the buffer to be transmitted to SPI device. |
| length | the number of data to be transmitted. |
| rt_inline void rt_spi_message_append | ( | struct rt_spi_message * | list, |
| struct rt_spi_message * | message ) |
This function appends a message to the SPI message list.
| list | the SPI message list header. |
| message | the message pointer to be appended to the message list. |
| rt_err_t rt_qspi_configure | ( | struct rt_qspi_device * | device, |
| struct rt_qspi_configuration * | cfg ) |
This function can set configuration on QSPI device.
| device | the QSPI device attached to QSPI bus. |
| cfg | the configuration pointer. |
| rt_err_t rt_qspi_bus_register | ( | struct rt_spi_bus * | bus, |
| const char * | name, | ||
| const struct rt_spi_ops * | ops ) |
This function can register a SPI bus for QSPI mode.
| bus | the SPI bus for QSPI mode. |
| name | The name of the spi bus. |
| ops | the SPI bus instance to be registered. |
| rt_size_t rt_qspi_transfer_message | ( | struct rt_qspi_device * | device, |
| struct rt_qspi_message * | message ) |
This function transmits data to QSPI device.
| device | the QSPI device attached to QSPI bus. |
| message | the message pointer. |
| rt_err_t rt_qspi_send_then_recv | ( | struct rt_qspi_device * | device, |
| const void * | send_buf, | ||
| rt_size_t | send_length, | ||
| void * | recv_buf, | ||
| rt_size_t | recv_length ) |
This function can send data then receive data from QSPI device.
| device | the QSPI device attached to QSPI bus. |
| send_buf | the buffer to be transmitted to QSPI device. |
| send_length | the number of data to be transmitted. |
| recv_buf | the buffer to be recivied from QSPI device. |
| recv_length | the data to be recivied. |
| rt_err_t rt_qspi_send | ( | struct rt_qspi_device * | device, |
| const void * | send_buf, | ||
| rt_size_t | length ) |
This function can send data to QSPI device.
| device | the QSPI device attached to QSPI bus. |
| send_buf | the buffer to be transmitted to QSPI device. |
| length | the number of data to be transmitted. |