Arduino Wrapper for Wire library (for SAM, ESP8266...) 1.4
A wrapper for Wire library meant to be put in place of cI2C library on SAM, ESP8266... targets
Loading...
Searching...
No Matches
WireWrapper.cpp File Reference

Arduino Wrapper for Wire library (for SAM, ESP8266...) code. More...

#include "WireWrapper.h"
Include dependency graph for WireWrapper.cpp:

Functions

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.
 
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)
 
bool I2C_slave_set_addr (I2C_SLAVE *slave, const uint8_t sl_addr)
 Change I2C slave address.
 
bool I2C_slave_set_reg_size (I2C_SLAVE *slave, const I2C_INT_SIZE reg_sz)
 Change I2C registers map size (for access)
 
void I2C_init (const uint16_t speed)
 Enable I2c module on arduino board (including pull-ups, enabling of ACK, and setting clock frequency)
 
uint16_t I2C_set_speed (const uint16_t speed)
 Change I2C frequency.
 
uint16_t I2C_set_timeout (const uint16_t timeout)
 Change I2C ack timeout.
 
uint8_t I2C_set_retries (const uint8_t retries)
 Change I2C message retries (in case of failure)
 
bool I2C_is_busy (void)
 Get I2C busy status.
 
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.
 
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 pointer.
 

Detailed Description

Arduino Wrapper for Wire library (for SAM, ESP8266...) code.

Author
SMFSW
Warning
Don't access (r/w) last 16b internal address byte alone right after init, this would lead to hazardous result (in such case, make a dummy read of addr 0 before)

Function Documentation

◆ I2C_init()

void I2C_init ( const uint16_t speed)

Enable I2c module on arduino board (including pull-ups, enabling of ACK, and setting clock frequency)

GCC Attributes
inline
Parameters
[in]speed- I2C bus speed in KHz
Returns
nothing
Here is the call graph for this function:
Here is the caller graph for this function:

◆ I2C_is_busy()

bool I2C_is_busy ( void )

Get I2C busy status.

Returns
true if busy

◆ I2C_read()

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 pointer.

Parameters
[in,out]slave- pointer to the I2C slave structure
[in]reg_addr- register address in register map
[in,out]data- pointer to the first byte of a block of data to read
[in]bytes- indicates how many bytes of data to read
Returns
I2C_STATUS status of read attempt
Here is the caller graph for this function:

◆ I2C_set_retries()

uint8_t I2C_set_retries ( const uint8_t retries)

Change I2C message retries (in case of failure)

Parameters
[in]retries- I2C number of retries (max of 8)
Returns
Configured number of retries

◆ I2C_set_speed()

uint16_t I2C_set_speed ( const uint16_t speed)

Change I2C frequency.

Parameters
[in]speed- I2C speed in kHz (max 3.4MHz)
Returns
Configured bus speed
Here is the caller graph for this function:

◆ I2C_set_timeout()

uint16_t I2C_set_timeout ( const uint16_t timeout)

Change I2C ack timeout.

Parameters
[in]timeout- I2C ack timeout (500 ms max)
Returns
Configured timeout

◆ I2C_slave_init()

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.

Parameters
[in]slave- pointer to the I2C slave structure to init
[in]sl_addr- I2C slave address
[in]reg_sz- internal register map size
Returns
nothing
Here is the call graph for this function:
Here is the caller graph for this function:

◆ I2C_slave_set_addr()

bool I2C_slave_set_addr ( I2C_SLAVE * slave,
const uint8_t sl_addr )

Change I2C slave address.

Parameters
[in,out]slave- pointer to the I2C slave structure to init
[in]sl_addr- I2C slave address
Returns
true if new address set (false if address is >7Fh)
Here is the caller graph for this function:

◆ I2C_slave_set_reg_size()

bool I2C_slave_set_reg_size ( I2C_SLAVE * slave,
const I2C_INT_SIZE reg_sz )

Change I2C registers map size (for access)

Parameters
[in,out]slave- pointer to the I2C slave structure
[in]reg_sz- internal register map size
Returns
true if new size is correct (false otherwise and set to 16bit by default)
Here is the caller graph for this function:

◆ I2C_slave_set_rw_func()

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)

Parameters
[in]slave- pointer to the I2C slave structure to init
[in]func- pointer to read/write function to affect
[in]rw- 0 = write function, 1 = read function
Returns
nothing
Here is the caller graph for this function:

◆ I2C_write()

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.

Parameters
[in,out]slave- pointer to the I2C slave structure
[in]reg_addr- register address in register map
[in]data- pointer to the first byte of a block of data to write
[in]bytes- indicates how many bytes of data to write
Returns
I2C_STATUS status of write attempt
Here is the caller graph for this function:

Variable Documentation

◆ busy

bool busy

true if already busy (in case of interrupts implementation)

◆ [struct]

struct { ... } cfg

◆ retries

uint8_t retries

i2c message retries when fail

◆ speed

I2C_SPEED speed

i2c bus speed

◆ start_wait

uint16_t start_wait

time start waiting for acknowledge

◆ timeout

uint16_t timeout

i2c timeout (ms)