34 #include "mcu_periph/i2c_arch.h"
45 #if USE_I2C1 || USE_I2C2 || USE_I2C3
60 static const systime_t tmo = TIME_US2I(10000000 / PERIODIC_FREQUENCY);
89 memcpy(i->dma_buf, (
void *)t->
buf, (
size_t)(t->
len_w));
90 status = i2cMasterTransmitTimeout(
96 memcpy((
void *)t->
buf, i->dma_buf, (
size_t)(t->
len_r));
98 status = i2cMasterTransmitTimeout(
108 memcpy(i->dma_buf, (
void *)t->
buf, (
size_t)(t->
len_w));
109 status = i2cMasterReceiveTimeout(
114 memcpy((
void *)t->
buf, i->dma_buf, (
size_t)(t->
len_r));
116 status = i2cMasterReceiveTimeout(
143 i2cStart((I2CDriver *)p->
reg_addr, i->cfg);
149 i2cflags_t errors = i2cGetErrors((I2CDriver *)p->
reg_addr);
150 if (errors & I2C_BUS_ERROR) {
153 if (errors & I2C_ARBITRATION_LOST) {
156 if (errors & I2C_ACK_FAILURE) {
159 if (errors & I2C_OVERRUN) {
162 if (errors & I2C_PEC_ERROR) {
168 if (errors & I2C_SMB_ALERT) {
186 static struct i2c_init i2c1_init_s = {
189 .dma_buf = i2c1_dma_buf
192 static struct i2c_init i2c1_init_s = {
200 static __attribute__((noreturn)) void thd_i2c1(
void *arg);
206 void i2c1_hw_init(
void)
208 i2cStart(&I2CD1, &i2cfg1);
209 i2c1.reg_addr = &I2CD1;
210 i2c1.errors = &i2c1_errors;
211 i2c1.init_struct = &i2c1_init_s;
213 chThdCreateStatic(wa_thd_i2c1,
sizeof(wa_thd_i2c1),
214 NORMALPRIO + 1, thd_i2c1, NULL);
221 static void thd_i2c1(
void *arg)
224 chRegSetThreadName(
"i2c1");
227 handle_i2c_thd(&i2c1);
240 static struct i2c_init i2c2_init_s = {
243 .dma_buf = i2c2_dma_buf
246 static struct i2c_init i2c2_init_s = {
254 static __attribute__((noreturn)) void thd_i2c2(
void *arg);
260 void i2c2_hw_init(
void)
262 i2cStart(&I2CD2, &i2cfg2);
263 i2c2.reg_addr = &I2CD2;
264 i2c2.errors = &i2c2_errors;
265 i2c2.init_struct = &i2c2_init_s;
267 chThdCreateStatic(wa_thd_i2c2,
sizeof(wa_thd_i2c2),
268 NORMALPRIO + 1, thd_i2c2, NULL);
275 static void thd_i2c2(
void *arg)
278 chRegSetThreadName(
"i2c2");
281 handle_i2c_thd(&i2c2);
288 PRINT_CONFIG_VAR(I2C3_CLOCK_SPEED)
290 static I2CConfig i2cfg3 = I2C3_CFG_DEF;
294 static struct i2c_init i2c3_init_s = {
297 .dma_buf = i2c3_dma_buf
300 static struct i2c_init i2c3_init_s = {
308 static __attribute__((noreturn)) void thd_i2c3(
void *arg);
314 void i2c3_hw_init(
void)
316 i2cStart(&I2CD3, &i2cfg3);
317 i2c3.reg_addr = &I2CD3;
318 i2c3.init_struct = NULL;
319 i2c3.errors = &i2c3_errors;
320 i2c3.init_struct = &i2c3_init_s;
322 chThdCreateStatic(wa_thd_i2c3,
sizeof(wa_thd_i2c3),
323 NORMALPRIO + 1, thd_i2c3, NULL);
330 static void thd_i2c3(
void *arg)
333 chRegSetThreadName(
"i2c3");
336 handle_i2c_thd(&i2c3);
376 #if USE_I2C1 || USE_I2C2 || USE_I2C3
Specific RAM section for DMA usage on F7.
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
static THD_WORKING_AREA(wa_thd_spi1, 256)
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.
#define IN_DMA_SECTION(var)
#define I2C_BUF_LEN
I2C buffer length.
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
volatile uint16_t ack_fail_cnt
volatile uint16_t timeout_tlow_cnt
Architecture independent I2C (Inter-Integrated Circuit Bus) API.