30 #ifndef MCU_PERIPH_I2C_H
31 #define MCU_PERIPH_I2C_H
35 #include "mcu_periph/i2c_arch.h"
84 #define I2C_BUF_LEN 32
132 #ifndef I2C_TRANSACTION_QUEUE_LEN
133 #define I2C_TRANSACTION_QUEUE_LEN 8
181 #define ZEROS_ERR_COUNTER(_i2c_err) { \
182 _i2c_err.wd_reset_cnt = 0; \
183 _i2c_err.queue_full_cnt = 0; \
184 _i2c_err.ack_fail_cnt = 0; \
185 _i2c_err.miss_start_stop_cnt = 0; \
186 _i2c_err.arb_lost_cnt = 0; \
187 _i2c_err.over_under_cnt = 0; \
188 _i2c_err.pec_recep_cnt = 0; \
189 _i2c_err.timeout_tlow_cnt = 0; \
190 _i2c_err.smbus_alert_cnt = 0; \
191 _i2c_err.unexpected_event_cnt = 0; \
192 _i2c_err.last_unexpected_event = 0; \
193 _i2c_err.er_irq_cnt = 0; \
200 extern void i2c0_init(
void);
208 extern void i2c1_init(
void);
216 extern void i2c2_init(
void);
224 extern void i2c3_init(
void);
232 extern void i2c4_init(
void);
239 extern void softi2c0_init(
void);
245 extern void softi2c1_init(
void);
267 return p->submit(
p, t);
275 p->setbitrate(
p, bitrate);
volatile uint16_t pec_recep_cnt
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
volatile uint16_t smbus_alert_cnt
struct i2c_errors * errors
uint8_t trans_extract_idx
uint16_t len_r
Number of bytes to read/receive.
volatile uint16_t ack_fail_cnt
volatile uint16_t timeout_tlow_cnt
volatile uint16_t over_under_cnt
volatile uint16_t unexpected_event_cnt
volatile uint32_t last_unexpected_event
volatile uint32_t er_irq_cnt
i2c_setbitrate_fn_t * setbitrate
volatile uint16_t wd_reset_cnt
enum I2CTransactionType type
Transaction type.
enum I2CTransactionStatus status
Transaction status.
volatile uint16_t queue_full_cnt
struct i2c_transaction * trans[I2C_TRANSACTION_QUEUE_LEN]
volatile uint16_t miss_start_stop_cnt
volatile int16_t watchdog
uint8_t slave_addr
Slave address.
volatile uint16_t arb_lost_cnt
uint8_t len_w
Number of bytes to write/transmit.
void i2c_event(void)
i2c_event() function
bool i2c_blocking_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r)
Submit a write/read transaction and wait for it to complete.
#define I2C_TRANSACTION_QUEUE_LEN
I2C transaction queue length.
bool i2c_blocking_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Submit a read only transaction and wait for it to complete.
#define I2C_BUF_LEN
I2C buffer length.
void i2c_spin_fn_t(struct i2c_periph *p)
static bool i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
Submit a I2C transaction.
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
static bool i2c_idle(struct i2c_periph *p)
Check if I2C bus is idle.
bool i2c_submit_fn_t(struct i2c_periph *p, struct i2c_transaction *t)
void i2c_init(struct i2c_periph *p)
Initialize I2C peripheral.
I2CStatus
I2C peripheral status.
bool i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Submit a read only transaction.
I2CTransactionStatus
I2C transaction status.
bool i2c_blocking_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction and wait for it to complete.
bool i2c_idle_fn_t(struct i2c_periph *p)
void i2c_setbitrate_fn_t(struct i2c_periph *p, int bitrate)
I2CTransactionType
I2C transaction type.
static void i2c_setbitrate(struct i2c_periph *p, int bitrate)
Set I2C bitrate.
bool i2c_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r)
Submit a write/read transaction.
@ I2CTransRunning
transaction is currently ongoing
@ I2CTransSuccess
transaction successfully finished by I2C driver
@ I2CTransFailed
transaction failed
@ I2CTransDone
transaction set to done by user level
@ I2CTransPending
transaction is pending in queue
@ I2CTransRx
receive only transaction
@ I2CTransTx
transmit only transaction
@ I2CTransTxRx
transmit and receive transaction
I2C transaction structure.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.