Bouffalo SDK  1.0
Bouffalolab Software Development Kit
bflb_spi.h
Go to the documentation of this file.
1 #ifndef _BFLB_SPI_H
2 #define _BFLB_SPI_H
3 
4 #include "bflb_core.h"
5 
14 #if defined(BL602) || defined(BL702)
15 #define SPI_FIFO_WORD_NUM_MAX 4
16 #define SPI_FIFO_WIDTH_VARIABLE_SUPPORT 0
17 #elif defined(BL606P) || defined(BL808)
18 #define SPI_FIFO_BYTE_NUM_MAX 32
19 #define SPI_FIFO_WIDTH_VARIABLE_SUPPORT 1
20 #elif defined(BL616) || defined(BL628)
21 #define SPI_FIFO_BYTE_NUM_MAX 32
22 #define SPI_FIFO_WIDTH_VARIABLE_SUPPORT 1
23 #elif defined(BL702L)
24 #define SPI_FIFO_BYTE_NUM_MAX 16
25 #define SPI_FIFO_WIDTH_VARIABLE_SUPPORT 1
26 #else
27 #error "unknown device"
28 #endif
29 
33 #define SPI_ROLE_MASTER 0
34 #define SPI_ROLE_SLAVE 1
35 
42 #define SPI_MODE0 0 /* CPOL=0 CHPHA=0 */
43 #define SPI_MODE1 1 /* CPOL=0 CHPHA=1 */
44 #define SPI_MODE2 2 /* CPOL=1 CHPHA=0 */
45 #define SPI_MODE3 3 /* CPOL=1 CHPHA=1 */
46 
53 #define SPI_DATA_WIDTH_8BIT 1
54 #define SPI_DATA_WIDTH_16BIT 2
55 #define SPI_DATA_WIDTH_24BIT 3
56 #define SPI_DATA_WIDTH_32BIT 4
57 
64 #define SPI_BIT_LSB 1
65 #define SPI_BIT_MSB 0
66 
73 #define SPI_BYTE_LSB 0
74 #if !defined(BL602) && !defined(BL702)
75 #define SPI_BYTE_MSB 1
76 #endif
77 
84 #define SPI_INTSTS_TC (1 << 0)
85 #define SPI_INTSTS_TX_FIFO (1 << 1)
86 #define SPI_INTSTS_RX_FIFO (1 << 2)
87 #define SPI_INTSTS_SLAVE_TIMEOUT (1 << 3)
88 #define SPI_INTSTS_SLAVE_TX_UNDERRUN (1 << 4)
89 #define SPI_INTSTS_FIFO_ERR (1 << 5)
90 
97 #define SPI_INTCLR_TC (1 << 16)
98 #define SPI_INTCLR_SLAVE_TIMEOUT (1 << 19)
99 #define SPI_INTCLR_SLAVE_TX_UNDERRUN (1 << 20)
100 
107 #define SPI_CMD_SET_DATA_WIDTH (0x01)
108 #define SPI_CMD_GET_DATA_WIDTH (0x02)
109 #define SPI_CMD_CLEAR_TX_FIFO (0x03)
110 #define SPI_CMD_CLEAR_RX_FIFO (0x04)
111 #define SPI_CMD_SET_CS_INTERVAL (0x05)
112 #define SPI_CMD_RX_IGNORE (0x06)
113 #define SPI_CMD_SET_MODE (0x07)
114 #define SPI_CMD_GET_MODE (0x08)
115 #define SPI_CMD_SET_FREQ (0x09)
116 #define SPI_CMD_GET_FREQ (0x0A)
117 #define SPI_CMD_SET_BIT_ORDER (0x0B)
118 #define SPI_CMD_GET_BIT_ORDER (0x0C)
119 #define SPI_CMD_SET_BYTE_ORDER (0x0E)
120 #define SPI_CMD_GET_BYTE_ORDER (0x0F)
121 
139  uint32_t freq;
140  uint8_t role;
141  uint8_t mode;
142  uint8_t data_width;
143  uint8_t bit_order;
144  uint8_t byte_order;
147 };
148 
149 #ifdef __cplusplus
150 extern "C" {
151 #endif
152 
159 void bflb_spi_init(struct bflb_device_s *dev, const struct bflb_spi_config_s *config);
160 
166 void bflb_spi_deinit(struct bflb_device_s *dev);
167 
174 void bflb_spi_link_txdma(struct bflb_device_s *dev, bool enable);
175 
182 void bflb_spi_link_rxdma(struct bflb_device_s *dev, bool enable);
183 
191 uint32_t bflb_spi_poll_send(struct bflb_device_s *dev, uint32_t data);
192 
202 int bflb_spi_poll_exchange(struct bflb_device_s *dev, const void *txbuffer, void *rxbuffer, size_t nbytes);
203 
210 bool bflb_spi_isbusy(struct bflb_device_s *dev);
211 
218 void bflb_spi_txint_mask(struct bflb_device_s *dev, bool mask);
219 
226 void bflb_spi_rxint_mask(struct bflb_device_s *dev, bool mask);
227 
234 void bflb_spi_tcint_mask(struct bflb_device_s *dev, bool mask);
235 
242 void bflb_spi_errint_mask(struct bflb_device_s *dev, bool mask);
243 
250 uint32_t bflb_spi_get_intstatus(struct bflb_device_s *dev);
251 
258 void bflb_spi_int_clear(struct bflb_device_s *dev, uint32_t int_clear);
259 
268 int bflb_spi_feature_control(struct bflb_device_s *dev, int cmd, size_t arg);
269 
270 #ifdef __cplusplus
271 }
272 #endif
273 
282 #endif
void bflb_spi_rxint_mask(struct bflb_device_s *dev, bool mask)
Enable or disable spi rx fifo threhold interrupt.
void bflb_spi_tcint_mask(struct bflb_device_s *dev, bool mask)
Enable or disable spi transfer done interrupt.
uint32_t bflb_spi_get_intstatus(struct bflb_device_s *dev)
Get spi interrupt status.
int bflb_spi_poll_exchange(struct bflb_device_s *dev, const void *txbuffer, void *rxbuffer, size_t nbytes)
Send and receive a block of data on spi.
void bflb_spi_link_rxdma(struct bflb_device_s *dev, bool enable)
Enable spi rx dma.
uint8_t rx_fifo_threshold
Definition: bflb_spi.h:146
void bflb_spi_init(struct bflb_device_s *dev, const struct bflb_spi_config_s *config)
Initialize spi.
SPI configuration structure.
Definition: bflb_spi.h:138
uint8_t bit_order
Definition: bflb_spi.h:143
uint8_t tx_fifo_threshold
Definition: bflb_spi.h:145
uint32_t bflb_spi_poll_send(struct bflb_device_s *dev, uint32_t data)
Send and receive one data on spi.
void bflb_spi_txint_mask(struct bflb_device_s *dev, bool mask)
Enable or disable spi rx fifo threhold interrupt.
void bflb_spi_errint_mask(struct bflb_device_s *dev, bool mask)
Enable or disable spi error interrupt.
uint8_t data_width
Definition: bflb_spi.h:142
uint8_t byte_order
Definition: bflb_spi.h:144
void bflb_spi_deinit(struct bflb_device_s *dev)
Deinitialize spi.
void bflb_spi_link_txdma(struct bflb_device_s *dev, bool enable)
Enable spi tx dma.
bool bflb_spi_isbusy(struct bflb_device_s *dev)
Check if spi is busy.
int bflb_spi_feature_control(struct bflb_device_s *dev, int cmd, size_t arg)
Control spi feature.
void bflb_spi_int_clear(struct bflb_device_s *dev, uint32_t int_clear)
Clear spi interrupt status.
uint32_t freq
Definition: bflb_spi.h:139