14 #define __attribute__(a)
31#define DEF_CI2C_NB_RETRIES 3
32#define DEF_CI2C_TIMEOUT 100
78typedef bool (*
ci2c_fct_ptr) (
void*,
const uint16_t, uint8_t*,
const uint16_t);
261bool I2C_wr8(
const uint8_t dat);
267uint8_t
I2C_rd8(
const bool ack);
I2C_SPEED speed
i2c bus speed
Definition ci2c.c:41
uint8_t retries
i2c message retries when fail
Definition ci2c.c:42
uint16_t timeout
i2c timeout (ms)
Definition ci2c.c:43
enum enI2C_INT_SIZE I2C_INT_SIZE
uint8_t I2C_slave_get_addr(const I2C_SLAVE *slave)
Get I2C slave address.
Definition ci2c.h:139
enum enI2C_SPEED I2C_SPEED
void I2C_reset(void)
I2C bus reset (Release SCL and SDA lines and re-enable module)
Definition ci2c.c:157
struct StructI2CSlave I2C_SLAVE
uint16_t I2C_slave_get_reg_addr(const I2C_SLAVE *slave)
Get I2C current register address (addr may passed this way in procedures if contigous accesses)
Definition ci2c.h:155
bool I2C_slave_set_reg_size(I2C_SLAVE *slave, const I2C_INT_SIZE reg_sz)
Change I2C registers map size (for access)
Definition ci2c.c:100
bool I2C_stop(void)
Send stop condition.
Definition ci2c.c:301
enI2C_SPEED
I2C bus speed.
Definition ci2c.h:49
@ I2C_HS
I2C High Speed (3.4MHz): will set speed to Fast Mode (up to 400KHz on avr)
Definition ci2c.h:53
@ I2C_FMP
I2C Fast mode + (1MHz): will set speed to Fast Mode (up to 400KHz on avr)
Definition ci2c.h:52
@ I2C_STD
I2C Standard (100KHz)
Definition ci2c.h:50
@ I2C_FM
I2C Fast Mode (400KHz)
Definition ci2c.h:51
enI2C_STATUS
I2C slave status.
Definition ci2c.h:61
@ I2C_BUSY
I2C Bus busy.
Definition ci2c.h:63
@ I2C_NACK
I2C Not Acknowledge.
Definition ci2c.h:64
@ I2C_OK
I2C OK.
Definition ci2c.h:62
void I2C_uninit()
Disable I2c module on arduino board (releasing pull-ups, and TWI control)
Definition ci2c.c:139
uint16_t I2C_set_speed(const uint16_t speed)
Change I2C frequency.
Definition ci2c.c:168
I2C_STATUS I2C_write(I2C_SLAVE *slave, const uint16_t reg_addr, uint8_t *data, const uint16_t bytes)
This function writes the provided data to the address specified.
Definition ci2c.c:251
uint8_t I2C_rd8(const bool ack)
Receive byte from bus.
Definition ci2c.c:340
void I2C_slave_set_rw_func(I2C_SLAVE *slave, const ci2c_fct_ptr func, const I2C_RW rw)
Redirect slave I2C read/write function (if needed for advanced use)
Definition ci2c.c:77
#define __attribute__(a)
GCC attribute (ignored by Doxygen)
Definition ci2c.h:14
enI2C_RW
I2C RW bit enumeration.
Definition ci2c.h:39
@ I2C_READ
I2C rw bit (read)
Definition ci2c.h:41
@ I2C_WRITE
I2C rw bit (write)
Definition ci2c.h:40
enI2C_INT_SIZE
I2C slave internal address registers size.
Definition ci2c.h:71
@ I2C_NO_REG
Internal address registers not applicable for slave.
Definition ci2c.h:72
@ I2C_8B_REG
Slave internal address registers space is 8bits wide.
Definition ci2c.h:73
@ I2C_16B_REG
Slave internal address registers space is 16bits wide.
Definition ci2c.h:74
void I2C_init(const uint16_t speed)
Enable I2c module on arduino board (including pull-ups, enabling of ACK, and setting clock frequency)
Definition ci2c.c:122
bool I2C_start(void)
Send start condition.
Definition ci2c.c:283
bool I2C_sndAddr(I2C_SLAVE *slave, const I2C_RW rw)
Send I2C address.
Definition ci2c.c:360
bool I2C_wr8(const uint8_t dat)
Send byte on bus.
Definition ci2c.c:317
bool I2C_is_busy(void)
Get I2C busy status.
Definition ci2c.c:209
bool I2C_slave_get_reg_size(const I2C_SLAVE *slave)
Get I2C register map size (for access)
Definition ci2c.h:147
uint16_t I2C_set_timeout(const uint16_t timeout)
Change I2C ack timeout.
Definition ci2c.c:188
bool I2C_slave_set_addr(I2C_SLAVE *slave, const uint8_t sl_addr)
Change I2C slave address.
Definition ci2c.c:88
I2C_STATUS I2C_read(I2C_SLAVE *slave, const uint16_t reg_addr, uint8_t *data, const uint16_t bytes)
This function reads data from the address specified and stores this data in the area provided by the ...
Definition ci2c.c:262
uint8_t I2C_set_retries(const uint8_t retries)
Change I2C message retries (in case of failure)
Definition ci2c.c:199
I2C_STATUS I2C_write_next(I2C_SLAVE *slave, uint8_t *data, const uint16_t bytes)
This inline is a wrapper to I2C_write in case of contigous operations.
Definition ci2c.h:214
enum enI2C_STATUS I2C_STATUS
void I2C_slave_init(I2C_SLAVE *slave, const uint8_t sl_addr, const I2C_INT_SIZE reg_sz)
Init an I2C slave structure for cMI2C communication.
Definition ci2c.c:61
bool(* ci2c_fct_ptr)(void *, const uint16_t, uint8_t *, const uint16_t)
i2c read/write function pointer typedef
Definition ci2c.h:78
I2C_STATUS I2C_read_next(I2C_SLAVE *slave, uint8_t *data, const uint16_t bytes)
This inline is a wrapper to I2C_read in case of contigous operations.
Definition ci2c.h:234
ci2c slave config and control parameters
Definition ci2c.h:85
I2C_INT_SIZE reg_size
Slave internal registers size.
Definition ci2c.h:91
uint16_t reg_addr
Internal current register address.
Definition ci2c.h:95
ci2c_fct_ptr rd
Slave read function pointer.
Definition ci2c.h:93
ci2c_fct_ptr wr
Slave write function pointer.
Definition ci2c.h:92
uint8_t addr
Slave address.
Definition ci2c.h:90
I2C_STATUS status
Status of the last communications.
Definition ci2c.h:96
struct StructI2CSlave::@044243043304327257271367302002014306363224227265 cfg