Bouffalo SDK  1.0
Bouffalolab Software Development Kit
bflb_i2c.h
Go to the documentation of this file.
1 #ifndef _BFLB_I2C_H
2 #define _BFLB_I2C_H
3 
4 #include "bflb_core.h"
5 
14 /* Bit definitions for the flags field in struct bflb_i2c_msg_s
15  *
16  * START/STOP Rules:
17  *
18  * 1. The lower half I2C driver will always issue the START condition at the
19  * beginning of a message unless I2C_M_NOSTART flag is set in the
20  * message.
21  *
22  * 2. The lower half I2C driver will always issue the STOP condition at the
23  * end of the messages unless:
24  *
25  * a. The I2C_M_NOSTOP flag is set in the message, OR
26  * b. The following message has the I2C_M_NOSTART flag set (meaning
27  * that following message is simply a continuation of the transfer).
28  *
29  * A proper I2C repeated start would then have I2C_M_NOSTOP set on msg[n]
30  * and I2C_M_NOSTART *not* set on msg[n+1]. See the following table:
31  *
32  * msg[n].flags msg[n+1].flags Behavior
33  * ------------ --------------- -----------------------------------------
34  * 0 0 Two normal, separate messages with STOP
35  * on msg[n] then START on msg[n+1]
36  * 0* I2C_M_NOSTART Continuation of the same transfer (must
37  * be the same direction). See NOTE below.
38  * NO_STOP 0 No STOP on msg[n]; repeated START on
39  * msg[n+1].
40  *
41  * * NOTE: NO_STOP is implied in this case and may or not be explicitly
42  * included in the msg[n] flags
43  */
44 
45 #define I2C_M_READ 0x0001 /* Read data, from slave to master */
46 #define I2C_M_TEN 0x0002 /* Ten bit address */
47 #define I2C_M_DMA 0x0004 /* Enable dma mode */
48 #define I2C_M_NOSTOP 0x0040 /* Message should not end with a STOP */
49 #define I2C_M_NOSTART 0x0080 /* Message should not begin with a START */
50 
54 #define I2C_INTSTS_END (1 << 0) /* Transfer end interrupt */
55 #define I2C_INTSTS_TX_FIFO (1 << 1) /* TX FIFO ready interrupt */
56 #define I2C_INTSTS_RX_FIFO (1 << 2) /* RX FIFO ready interrupt */
57 #define I2C_INTSTS_NACK (1 << 3) /* NACK interrupt */
58 #define I2C_INTSTS_ARB (1 << 4) /* Arbitration lost interrupt */
59 #define I2C_INTSTS_FER (1 << 5) /* TX/RX FIFO error interrupt */
60 
67 #define I2C_INTCLR_END (1 << 0) /* Transfer end interrupt */
68 #define I2C_INTCLR_NACK (1 << 3) /* NACK interrupt */
69 #define I2C_INTCLR_ARB (1 << 4) /* Arbitration lost interrupt */
70 
77 #define I2C_INTEN_END (1 << 0) /* Transfer end interrupt */
78 #define I2C_INTEN_TX_FIFO (1 << 1) /* TX FIFO ready interrupt */
79 #define I2C_INTEN_RX_FIFO (1 << 2) /* RX FIFO ready interrupt */
80 #define I2C_INTEN_NACK (1 << 3) /* NACK interrupt */
81 #define I2C_INTEN_ARB (1 << 4) /* Arbitration lost interrupt */
82 #define I2C_INTEN_FER (1 << 5) /* TX/RX FIFO error interrupt */
83 
90 #define I2C_CMD_SET_SCL_SYNC (0x01) /* Enable or disable multi-master and clock-stretching */
91 #define I2C_CMD_SET_DEGLITCH (0x02) /* 0 for disable deglitch, others for deglitch count */
92 
106  uint16_t addr;
107  uint16_t flags;
108  uint8_t *buffer;
109  uint16_t length;
110 };
111 
112 #ifdef __cplusplus
113 extern "C" {
114 #endif
115 
122 void bflb_i2c_init(struct bflb_device_s *dev, uint32_t frequency);
123 
129 void bflb_i2c_deinit(struct bflb_device_s *dev);
130 
137 void bflb_i2c_link_txdma(struct bflb_device_s *dev, bool enable);
138 
145 void bflb_i2c_link_rxdma(struct bflb_device_s *dev, bool enable);
146 
155 int bflb_i2c_transfer(struct bflb_device_s *dev, struct bflb_i2c_msg_s *msgs, int count);
156 
164 void bflb_i2c_int_mask(struct bflb_device_s *dev, uint32_t int_type, bool mask);
165 
172 void bflb_i2c_int_clear(struct bflb_device_s *dev, uint32_t int_clear);
173 
180 uint32_t bflb_i2c_get_intstatus(struct bflb_device_s *dev);
181 
190 int bflb_i2c_feature_control(struct bflb_device_s *dev, int cmd, size_t arg);
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 
204 #endif
int bflb_i2c_feature_control(struct bflb_device_s *dev, int cmd, size_t arg)
Control i2c feature.
I2C message structure.
Definition: bflb_i2c.h:105
uint16_t length
Definition: bflb_i2c.h:109
void bflb_i2c_link_txdma(struct bflb_device_s *dev, bool enable)
Enable i2c tx dma.
void bflb_i2c_int_mask(struct bflb_device_s *dev, uint32_t int_type, bool mask)
Enable or disable i2c interrupt.
uint16_t flags
Definition: bflb_i2c.h:107
void bflb_i2c_link_rxdma(struct bflb_device_s *dev, bool enable)
Enable i2c rx dma.
void bflb_i2c_int_clear(struct bflb_device_s *dev, uint32_t int_clear)
Clear i2c interrupt status.
int bflb_i2c_transfer(struct bflb_device_s *dev, struct bflb_i2c_msg_s *msgs, int count)
Start transferring i2c message.
uint8_t * buffer
Definition: bflb_i2c.h:108
void bflb_i2c_deinit(struct bflb_device_s *dev)
Deinitialize i2c.
uint16_t addr
Definition: bflb_i2c.h:106
void bflb_i2c_init(struct bflb_device_s *dev, uint32_t frequency)
Initialize i2c.
uint32_t bflb_i2c_get_intstatus(struct bflb_device_s *dev)
Get i2c interrupt status.