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);
volatile uint16_t arb_lost_cnt
I2CTransactionStatus
I2C transaction status.
#define I2C_TRANSACTION_QUEUE_LEN
I2C transaction queue length.
I2CTransactionType
I2C transaction type.
volatile uint16_t miss_start_stop_cnt
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.
transaction successfully finished by I2C driver
static bool i2c_idle(struct i2c_periph *p)
Check if I2C bus is idle.
transmit and receive transaction
uint8_t trans_extract_idx
void i2c_init(struct i2c_periph *p)
Initialize I2C peripheral.
volatile uint16_t queue_full_cnt
struct i2c_errors * errors
volatile uint32_t er_irq_cnt
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.
void i2c_setbitrate_fn_t(struct i2c_periph *p, int bitrate)
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.
uint8_t len_w
Number of bytes to write/transmit.
bool i2c_idle_fn_t(struct i2c_periph *p)
transaction set to done by user level
i2c_setbitrate_fn_t * setbitrate
struct i2c_transaction * trans[I2C_TRANSACTION_QUEUE_LEN]
bool i2c_submit_fn_t(struct i2c_periph *p, struct i2c_transaction *t)
volatile uint16_t over_under_cnt
void i2c_spin_fn_t(struct i2c_periph *p)
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.
I2C transaction structure.
enum I2CTransactionStatus status
Transaction status.
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
volatile uint16_t unexpected_event_cnt
uint8_t slave_addr
Slave address.
static bool i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
Submit a I2C transaction.
#define I2C_BUF_LEN
I2C buffer length.
bool i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Submit a read only transaction.
transaction is currently ongoing
transmit only transaction
volatile int16_t watchdog
volatile uint32_t last_unexpected_event
static void i2c_setbitrate(struct i2c_periph *p, int bitrate)
Set I2C bitrate.
volatile uint16_t wd_reset_cnt
volatile uint16_t smbus_alert_cnt
void i2c_event(void)
i2c_event() function
enum I2CTransactionType type
Transaction type.
volatile uint16_t pec_recep_cnt
transaction is pending in queue
I2CStatus
I2C peripheral 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.
volatile uint16_t ack_fail_cnt
volatile uint16_t timeout_tlow_cnt