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
170 #define ZEROS_ERR_COUNTER(_i2c_err) { \
171 _i2c_err.wd_reset_cnt = 0; \
172 _i2c_err.queue_full_cnt = 0; \
173 _i2c_err.ack_fail_cnt = 0; \
174 _i2c_err.miss_start_stop_cnt = 0; \
175 _i2c_err.arb_lost_cnt = 0; \
176 _i2c_err.over_under_cnt = 0; \
177 _i2c_err.pec_recep_cnt = 0; \
178 _i2c_err.timeout_tlow_cnt = 0; \
179 _i2c_err.smbus_alert_cnt = 0; \
180 _i2c_err.unexpected_event_cnt = 0; \
181 _i2c_err.last_unexpected_event = 0; \
182 _i2c_err.er_irq_cnt = 0; \
189 extern void i2c0_init(
void);
197 extern void i2c1_init(
void);
205 extern void i2c2_init(
void);
213 extern void i2c3_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
transmit and receive transaction
uint8_t trans_extract_idx
void i2c_init(struct i2c_periph *p)
Initialize I2C peripheral.
bool i2c_idle(struct i2c_periph *p)
Check if I2C bus is idle.
volatile uint16_t queue_full_cnt
void i2c_setbitrate(struct i2c_periph *p, int bitrate)
Set I2C bitrate.
struct i2c_errors * errors
volatile uint32_t er_irq_cnt
uint8_t len_w
Number of bytes to write/transmit.
transaction set to done by user level
struct i2c_transaction * trans[I2C_TRANSACTION_QUEUE_LEN]
volatile uint16_t over_under_cnt
bool i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
Submit a I2C transaction.
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.
I2C peripheral structure.
#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
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.
volatile uint16_t ack_fail_cnt
volatile uint16_t timeout_tlow_cnt