34 #include "mcu_periph/i2c_arch.h"
42 #if USE_I2C1 || USE_I2C2 || USE_I2C3
54 static const systime_t tmo = US2ST(1000000/PERIODIC_FREQUENCY);
81 status = i2cMasterTransmitTimeout(
88 status = i2cMasterReceiveTimeout(
114 i2cStart((I2CDriver*)p->
reg_addr, i->cfg);
120 i2cflags_t errors = i2cGetErrors((I2CDriver*)p->
reg_addr);
121 if (errors & I2C_BUS_ERROR) {
124 if (errors & I2C_ARBITRATION_LOST) {
127 if (errors & I2C_ACK_FAILURE) {
130 if (errors & I2C_OVERRUN) {
133 if (errors & I2C_PEC_ERROR) {
139 if (errors & I2C_SMB_ALERT) {
154 static struct
i2c_init i2c1_init_s = {
161 static __attribute__((noreturn)) void thd_i2c1(
void *arg);
167 void i2c1_hw_init(
void)
169 i2cStart(&I2CD1, &i2cfg1);
170 i2c1.reg_addr = &I2CD1;
171 i2c1.errors = &i2c1_errors;
172 i2c1.init_struct = &i2c1_init_s;
174 chThdCreateStatic(wa_thd_i2c1,
sizeof(wa_thd_i2c1),
175 NORMALPRIO+1, thd_i2c1, NULL);
182 static void thd_i2c1(
void *arg)
185 chRegSetThreadName(
"i2c1");
188 handle_i2c_thd(&i2c1);
198 static struct
i2c_init i2c2_init_s = {
205 static __attribute__((noreturn)) void thd_i2c2(
void *arg);
211 void i2c2_hw_init(
void)
213 i2cStart(&I2CD2, &i2cfg2);
214 i2c2.reg_addr = &I2CD2;
215 i2c2.init_struct = NULL;
216 i2c2.errors = &i2c2_errors;
217 i2c2.init_struct = &i2c2_init_s;
219 chThdCreateStatic(wa_thd_i2c2,
sizeof(wa_thd_i2c2),
220 NORMALPRIO+1, thd_i2c2, NULL);
227 static void thd_i2c2(
void *arg)
230 chRegSetThreadName(
"i2c2");
233 handle_i2c_thd(&i2c2);
240 PRINT_CONFIG_VAR(I2C3_CLOCK_SPEED)
242 static I2CConfig i2cfg3 = I2C3_CFG_DEF;
243 static struct
i2c_init i2c3_init_s = {
250 static __attribute__((noreturn)) void thd_i2c3(
void *arg);
256 void i2c3_hw_init(
void)
258 i2cStart(&I2CD3, &i2cfg3);
259 i2c3.reg_addr = &I2CD3;
260 i2c3.init_struct = NULL;
261 i2c3.errors = &i2c3_errors;
262 i2c3.init_struct = &i2c3_init_s;
264 chThdCreateStatic(wa_thd_i2c3,
sizeof(wa_thd_i2c3),
265 NORMALPRIO+1, thd_i2c3, NULL);
272 static void thd_i2c3(
void *arg)
275 chRegSetThreadName(
"i2c3");
278 handle_i2c_thd(&i2c3);
318 #if USE_I2C1 || USE_I2C2 || USE_I2C3
volatile uint16_t arb_lost_cnt
#define I2C_TRANSACTION_QUEUE_LEN
I2C transaction queue length.
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
uint8_t trans_extract_idx
void i2c_init(struct i2c_periph *p)
Initialize I2C peripheral.
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
struct i2c_errors * errors
static SEMAPHORE_DECL(spi1_sem, 0)
Configure SPI peripherals.
uint8_t len_w
Number of bytes to write/transmit.
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)
i2c_submit() function
I2C transaction structure.
enum I2CTransactionStatus status
Transaction status.
uint8_t slave_addr
Slave address.
I2C peripheral structure.
volatile uint16_t smbus_alert_cnt
void i2c_event(void)
i2c_event() function
#define I2C1_CLOCK_SPEED
I2C defines.
volatile uint16_t pec_recep_cnt
transaction is pending in queue
static THD_WORKING_AREA(wa_thd_spi1, 1024)
volatile uint16_t ack_fail_cnt
volatile uint16_t timeout_tlow_cnt
Architecture independent I2C (Inter-Integrated Circuit Bus) API.