32 #include <sys/ioctl.h>
33 #include <linux/i2c.h>
34 #include <linux/i2c-dev.h>
50 #pragma GCC diagnostic push
51 #pragma GCC diagnostic ignored "-Wcast-qual"
57 struct i2c_rdwr_ioctl_data trx_data = {
66 ioctl(file,
I2C_SLAVE, t->slave_addr >> 1);
67 if (write(file, (
uint8_t *)t->buf, t->len_w) < 0) {
69 p->errors->queue_full_cnt++;
77 ioctl(file,
I2C_SLAVE, t->slave_addr >> 1);
78 if (read(file, (
uint8_t *)t->buf, t->len_r) < 0) {
80 p->errors->ack_fail_cnt++;
87 trx_msgs[0].addr = t->slave_addr >> 1;
88 trx_msgs[0].flags = 0;
89 trx_msgs[0].len = t->len_w;
90 trx_msgs[0].buf = (
void*) t->buf;
91 trx_msgs[1].addr = t->slave_addr >> 1;
93 trx_msgs[1].len = t->len_r;
94 trx_msgs[1].buf = (
void*) t->buf;
95 if (ioctl(file,
I2C_RDWR, &trx_data) < 0) {
97 p->errors->miss_start_stop_cnt++;
110 #pragma GCC diagnostic pop
116 void i2c0_hw_init(
void)
118 i2c0.reg_addr = (
void *)open(
"/dev/i2c-0", O_RDWR);
119 i2c0.errors = &i2c0_errors;
129 void i2c1_hw_init(
void)
131 i2c1.reg_addr = (
void *)open(
"/dev/i2c-1", O_RDWR);
132 i2c1.errors = &i2c1_errors;
142 void i2c2_hw_init(
void)
144 i2c2.reg_addr = (
void *)open(
"/dev/i2c-2", O_RDWR);
145 i2c2.errors = &i2c2_errors;
155 void i2c3_hw_init(
void)
157 i2c3.reg_addr = (
void *)open(
"/dev/i2c-3", O_RDWR);
158 i2c3.errors = &i2c3_errors;
transaction successfully finished by I2C driver
transmit and receive transaction
bool i2c_idle(struct i2c_periph *p)
i2c_idle() function
void i2c_setbitrate(struct i2c_periph *p, int bitrate)
i2c_setbitrate() function
#define ZEROS_ERR_COUNTER(_i2c_err)
bool i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
i2c_submit() function
I2C transaction structure.
I2C peripheral structure.
transmit only transaction
void i2c_event(void)
i2c_event() function
Architecture independent I2C (Inter-Integrated Circuit Bus) API.