19#include <drivers/core/driver.h>
111#define RT_SPI_CPHA (1<<0)
112#define RT_SPI_CPOL (1<<1)
114#define RT_SPI_LSB (0<<2)
115#define RT_SPI_MSB (1<<2)
117#define RT_SPI_MASTER (0<<3)
118#define RT_SPI_SLAVE (1<<3)
120#define RT_SPI_CS_HIGH (1<<4)
121#define RT_SPI_NO_CS (1<<5)
122#define RT_SPI_3WIRE (1<<6)
123#define RT_SPI_READY (1<<7)
125#define RT_SPI_MODE_MASK (RT_SPI_CPHA | RT_SPI_CPOL | RT_SPI_MSB | RT_SPI_SLAVE | RT_SPI_CS_HIGH | RT_SPI_NO_CS | RT_SPI_3WIRE | RT_SPI_READY)
127#define RT_SPI_MODE_0 (0 | 0)
128#define RT_SPI_MODE_1 (0 | RT_SPI_CPHA)
129#define RT_SPI_MODE_2 (RT_SPI_CPOL | 0)
130#define RT_SPI_MODE_3 (RT_SPI_CPOL | RT_SPI_CPHA)
132#define RT_SPI_BUS_MODE_SPI (1<<0)
133#define RT_SPI_BUS_MODE_QSPI (1<<1)
202#define RT_SPI_DELAY_UNIT_USECS 0
203#define RT_SPI_DELAY_UNIT_NSECS 1
204#define RT_SPI_DELAY_UNIT_SCK 2
220 const struct rt_spi_device_id *id;
224 struct rt_spi_delay cs_setup;
225 struct rt_spi_delay cs_hold;
226 struct rt_spi_delay cs_inactive;
291#define SPI_DEVICE(dev) ((struct rt_spi_device *)(dev))
294struct rt_spi_device_id
302 struct rt_driver parent;
304 const struct rt_spi_device_id *ids;
305 const struct rt_ofw_node_id *ofw_ids;
307 rt_err_t (*probe)(
struct rt_spi_device *device);
308 rt_err_t (*remove)(
struct rt_spi_device *device);
309 rt_err_t (*shutdown)(
struct rt_spi_device *device);
312rt_err_t rt_spi_driver_register(
struct rt_spi_driver *driver);
315#define RT_SPI_DRIVER_EXPORT(driver) RT_DRIVER_EXPORT(driver, spi, BUILIN)
344 const char *bus_name,
361 const char *bus_name,
443 const void *send_buf,
460 const void *send_buf1,
462 const void *send_buf2,
476 const void *send_buf,
568 list->
next = message;
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
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.
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.
rt_err_t rt_spi_take_bus(struct rt_spi_device *device)
This function takes 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
rt_size_t rt_qspi_transfer_message(struct rt_qspi_device *device, struct rt_qspi_message *message)
This function transmits data to QSPI device.
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.
rt_err_t rt_spi_configure(struct rt_spi_device *device, struct rt_spi_configuration *cfg)
This function can set configuration on SPI device.
rt_err_t rt_qspi_configure(struct rt_qspi_device *device, struct rt_qspi_configuration *cfg)
This function can set configuration on QSPI device.
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
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
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.
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
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
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.
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
rt_err_t rt_spi_release_bus(struct rt_spi_device *device)
This function releases SPI bus.
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.
rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
Reconfigure the SPI bus for the specified device.
rt_err_t rt_spi_release(struct rt_spi_device *device)
This function releases SPI device (releases CS of SPI device).
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.
rt_err_t rt_spi_take(struct rt_spi_device *device)
This function take SPI device (takes CS of 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.
unsigned short rt_uint16_t
QSPI configuration structure
struct rt_spi_configuration parent
struct rt_spi_device parent
void(* exit_qspi_mode)(struct rt_qspi_device *device)
void(* enter_qspi_mode)(struct rt_qspi_device *device)
struct rt_qspi_configuration config
struct rt_qspi_message::@255176026317266043011237255203006261277256257132 instruction
rt_uint8_t qspi_data_lines
struct rt_qspi_message::@003110057025021075065161337153040327357177277157 alternate_bytes
struct rt_spi_message parent
struct rt_qspi_message::@003110057025021075065161337153040327357177277157 address
struct rt_spi_device * owner
const struct rt_spi_ops * ops
SPI configuration structure
SPI Virtual BUS, one device must connected to a virtual BUS
struct rt_spi_configuration config
struct rt_spi_message * next
rt_err_t(* configure)(struct rt_spi_device *device, struct rt_spi_configuration *configuration)
rt_ssize_t(* xfer)(struct rt_spi_device *device, struct rt_spi_message *message)