46 __attribute__((always_inline)) static inline
void I2cSendAck(
void *reg)
54 p->trans_extract_idx++;
56 p->trans_extract_idx = 0;
59 if (p->trans_extract_idx == p->trans_insert_idx) {
88 __attribute__((always_inline)) static inline
void I2cReceive(
void *reg,
bool ack)
94 __attribute__((always_inline)) static inline
void I2cClearStart(
void *reg)
99 __attribute__((always_inline)) static inline
void I2cClearIT(
void *reg)
111 switch (trans->
type) {
127 if (p->idx_buf < trans->
len_r) {
128 trans->
buf[p->idx_buf] = ((
i2cRegs_t *)(p->reg_addr))->dat;
137 if (p->idx_buf < trans->
len_r) {
138 trans->
buf[p->idx_buf] = ((
i2cRegs_t *)(p->reg_addr))->dat;
153 if (p->idx_buf < trans->
len_w) {
180 #define I2C0_SCLL 200
184 #define I2C0_SCLH 200
189 #if (PCLK == 15000000)
190 #define I2C0_SCLL_D I2C0_SCLL
191 #define I2C0_SCLH_D I2C0_SCLH
194 #if (PCLK == 30000000)
195 #define I2C0_SCLL_D (2*I2C0_SCLL)
196 #define I2C0_SCLH_D (2*I2C0_SCLH)
199 #if (PCLK == 60000000)
200 #define I2C0_SCLL_D (4*I2C0_SCLL)
201 #define I2C0_SCLH_D (4*I2C0_SCLH)
204 #error unknown PCLK frequency
209 #ifndef I2C0_VIC_SLOT
210 #define I2C0_VIC_SLOT 8
214 void i2c0_ISR(
void) __attribute__((naked));
232 void i2c0_hw_init(
void)
235 i2c0.reg_addr =
I2C0;
237 i2c0.init_struct = (
void *)(&i2c0_vic_channel);
265 #define I2C1_SCLL 200
269 #define I2C1_SCLH 200
274 #if (PCLK == 15000000)
275 #define I2C1_SCLL_D I2C1_SCLL
276 #define I2C1_SCLH_D I2C1_SCLH
279 #if (PCLK == 30000000)
280 #define I2C1_SCLL_D (2*I2C1_SCLL)
281 #define I2C1_SCLH_D (2*I2C1_SCLH)
284 #if (PCLK == 60000000)
285 #define I2C1_SCLL_D (4*I2C1_SCLL)
286 #define I2C1_SCLH_D (4*I2C1_SCLH)
289 #error unknown PCLK frequency
294 #ifndef I2C1_VIC_SLOT
295 #define I2C1_VIC_SLOT 9
299 void i2c1_ISR(
void) __attribute__((naked));
317 void i2c1_hw_init(
void)
320 i2c1.reg_addr =
I2C1;
322 i2c1.init_struct = (
void *)(&i2c1_vic_channel);
388 int period = 15000000 / 2 / bitrate;
398 #if (PCLK == 30000000)
402 #if (PCLK == 60000000)
#define I2C_TRANSACTION_QUEUE_LEN
I2C transaction queue length.
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
uint16_t len_r
Number of bytes to read/receive.
static void I2cClearIT(void *reg)
static void I2cClearStart(void *reg)
static void I2cSendAck(void *reg)
transaction successfully finished by I2C driver
transmit and receive transaction
uint8_t trans_extract_idx
bool i2c_idle(struct i2c_periph *p)
i2c_idle() function
volatile uint16_t queue_full_cnt
void i2c_setbitrate(struct i2c_periph *p, int bitrate)
i2c_setbitrate() function
static void I2cEndOfTransaction(struct i2c_periph *p)
struct i2c_errors * errors
static void I2cSendStop(struct i2c_periph *p, struct i2c_transaction *t)
uint8_t len_w
Number of bytes to write/transmit.
static void I2cAutomaton(int32_t state, struct i2c_periph *p)
struct i2c_transaction * trans[I2C_TRANSACTION_QUEUE_LEN]
bool i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
i2c_submit() function
static void I2cFail(struct i2c_periph *p, struct i2c_transaction *t)
I2C transaction structure.
enum I2CTransactionStatus status
Transaction status.
static void I2cSendStart(struct i2c_periph *p)
uint8_t slave_addr
Slave address.
I2C peripheral structure.
unsigned disableIRQ(void)
static void I2cReceive(void *reg, bool ack)
transmit only transaction
static void I2cSendByte(void *reg, uint8_t b)
void i2c_event(void)
i2c_event() function
enum I2CTransactionType type
Transaction type.
transaction is pending in queue
Architecture independent I2C (Inter-Integrated Circuit Bus) API.