Firmware SDK
twr_i2c

Driver for I2C bus. More...

Data Structures

struct  twr_i2c_transfer_t
 I2C transfer parameters. More...
 
struct  twr_i2c_memory_transfer_t
 I2C memory transfer parameters. More...
 

Macros

#define TWR_I2C_MEMORY_ADDRESS_16_BIT   0x80000000
 This flag extends I2C memory transfer address from 8-bit to 16-bit.
 

Enumerations

enum  twr_i2c_channel_t {
  TWR_I2C_I2C0 = 0 ,
  TWR_I2C_I2C1 = 1 ,
  TWR_I2C_I2C_1W = 2
}
 I2C channels. More...
 
enum  twr_i2c_speed_t {
  TWR_I2C_SPEED_100_KHZ = 0 ,
  TWR_I2C_SPEED_400_KHZ = 1
}
 I2C communication speed. More...
 

Functions

void twr_i2c_init (twr_i2c_channel_t channel, twr_i2c_speed_t speed)
 Initialize I2C channel. More...
 
void twr_i2c_deinit (twr_i2c_channel_t channel)
 Deitialize I2C channel. More...
 
twr_i2c_speed_t twr_i2c_get_speed (twr_i2c_channel_t channel)
 Get speed I2C channel. More...
 
void twr_i2c_set_speed (twr_i2c_channel_t channel, twr_i2c_speed_t speed)
 Set I2C channel speed. More...
 
bool twr_i2c_write (twr_i2c_channel_t channel, const twr_i2c_transfer_t *transfer)
 Write to I2C channel. More...
 
bool twr_i2c_read (twr_i2c_channel_t channel, const twr_i2c_transfer_t *transfer)
 Read from I2C channel. More...
 
bool twr_i2c_memory_write (twr_i2c_channel_t channel, const twr_i2c_memory_transfer_t *transfer)
 Memory write to I2C channel. More...
 
bool twr_i2c_memory_read (twr_i2c_channel_t channel, const twr_i2c_memory_transfer_t *transfer)
 Memory read from I2C channel. More...
 
bool twr_i2c_memory_write_8b (twr_i2c_channel_t channel, uint8_t device_address, uint32_t memory_address, uint8_t data)
 Memory write 1 byte to I2C channel. More...
 
bool twr_i2c_memory_write_16b (twr_i2c_channel_t channel, uint8_t device_address, uint32_t memory_address, uint16_t data)
 Memory write 2 bytes to I2C channel. More...
 
bool twr_i2c_memory_read_8b (twr_i2c_channel_t channel, uint8_t device_address, uint32_t memory_address, uint8_t *data)
 Memory read 1 byte from I2C channel. More...
 
bool twr_i2c_memory_read_16b (twr_i2c_channel_t channel, uint8_t device_address, uint32_t memory_address, uint16_t *data)
 Memory read 2 bytes from I2C channel. More...
 

Detailed Description

Driver for I2C bus.

Enumeration Type Documentation

◆ twr_i2c_channel_t

I2C channels.

Enumerator
TWR_I2C_I2C0 

I2C channel I2C0.

TWR_I2C_I2C1 

I2C channel I2C1.

TWR_I2C_I2C_1W 

I2C channel 1wire.

Definition at line 15 of file twr_i2c.h.

◆ twr_i2c_speed_t

I2C communication speed.

Enumerator
TWR_I2C_SPEED_100_KHZ 

I2C communication speed is 100 kHz.

TWR_I2C_SPEED_400_KHZ 

I2C communication speed is 400 kHz.

Definition at line 30 of file twr_i2c.h.

Function Documentation

◆ twr_i2c_deinit()

void twr_i2c_deinit ( twr_i2c_channel_t  channel)

Deitialize I2C channel.

Parameters
[in]channelI2C channel

Definition at line 140 of file twr_i2c.c.

Referenced by twr_zssc3123_deinit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_i2c_get_speed()

twr_i2c_speed_t twr_i2c_get_speed ( twr_i2c_channel_t  channel)

Get speed I2C channel.

Parameters
[in]channelI2C channel
Returns
I2C communication speed

Definition at line 195 of file twr_i2c.c.

◆ twr_i2c_init()

void twr_i2c_init ( twr_i2c_channel_t  channel,
twr_i2c_speed_t  speed 
)

Initialize I2C channel.

Parameters
[in]channelI2C channel
[in]speedI2C communication speed

Definition at line 57 of file twr_i2c.c.

Referenced by twr_atsha204_init(), twr_cy8cmbr3102_init(), twr_ds2484_init(), twr_hdc2080_init(), twr_hts221_init(), twr_lis2dh12_init(), twr_module_infra_grid_init(), twr_mpl3115a2_init(), twr_opt3001_init(), twr_sam_m8q_init(), twr_sc16is740_init(), twr_sgp30_init(), twr_sgpc3_init(), twr_sht20_init(), twr_sht30_init(), twr_sps30_init(), twr_ssd1306_init(), twr_tag_nfc_init(), twr_tca9534a_init(), twr_tmp112_init(), and twr_zssc3123_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_i2c_memory_read()

bool twr_i2c_memory_read ( twr_i2c_channel_t  channel,
const twr_i2c_memory_transfer_t transfer 
)

Memory read from I2C channel.

Parameters
[in]channelI2C channel
[in]transferPointer to I2C memory transfer parameters instance
Returns
true On success
false On failure

Definition at line 371 of file twr_i2c.c.

Referenced by twr_i2c_memory_read_16b(), twr_i2c_memory_read_8b(), twr_module_infra_grid_read_values(), twr_sc16is740_read(), and twr_tag_nfc_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_i2c_memory_read_16b()

bool twr_i2c_memory_read_16b ( twr_i2c_channel_t  channel,
uint8_t  device_address,
uint32_t  memory_address,
uint16_t *  data 
)

Memory read 2 bytes from I2C channel.

Parameters
[in]channelI2C channel
[in]device_address7-bit I2C device address
[in]memory_address8-bit I2C memory address (it can be extended to 16-bit format if OR-ed with TWR_I2C_MEMORY_ADDRESS_16_BIT)
[out]dataOutput data which have been read (MSB first)

Definition at line 449 of file twr_i2c.c.

Referenced by twr_cy8cmbr3102_get_proximity().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_i2c_memory_read_8b()

bool twr_i2c_memory_read_8b ( twr_i2c_channel_t  channel,
uint8_t  device_address,
uint32_t  memory_address,
uint8_t *  data 
)

Memory read 1 byte from I2C channel.

Parameters
[in]channelI2C channel
[in]device_address7-bit I2C device address
[in]memory_address8-bit I2C memory address (it can be extended to 16-bit format if OR-ed with TWR_I2C_MEMORY_ADDRESS_16_BIT)
[out]dataOutput data which have been read

Definition at line 437 of file twr_i2c.c.

Referenced by twr_cy8cmbr3102_is_touch(), twr_hts221_deinit(), twr_module_infra_grid_read_thermistor(), twr_sc16is740_available(), twr_sc16is740_get_spaces_available(), twr_sc16is740_set_baudrate(), twr_tca9534a_init(), and twr_tca9534a_read_port().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_i2c_memory_write()

bool twr_i2c_memory_write ( twr_i2c_channel_t  channel,
const twr_i2c_memory_transfer_t transfer 
)

Memory write to I2C channel.

Parameters
[in]channelI2C channel
[in]transferPointer to I2C memory transfer parameters instance
Returns
true On success
false On failure

Definition at line 333 of file twr_i2c.c.

Referenced by twr_i2c_memory_write_16b(), twr_i2c_memory_write_8b(), twr_sc16is740_write(), and twr_tag_nfc_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_i2c_memory_write_16b()

bool twr_i2c_memory_write_16b ( twr_i2c_channel_t  channel,
uint8_t  device_address,
uint32_t  memory_address,
uint16_t  data 
)

Memory write 2 bytes to I2C channel.

Parameters
[in]channelI2C channel
[in]device_address7-bit I2C device address
[in]memory_address8-bit I2C memory address (it can be extended to 16-bit format if OR-ed with TWR_I2C_MEMORY_ADDRESS_16_BIT)
[in]dataInput data to be written (MSB first)

Definition at line 420 of file twr_i2c.c.

Referenced by twr_opt3001_deinit(), twr_tmp112_deinit(), twr_zssc3123_eeprom_read(), twr_zssc3123_eeprom_write(), twr_zssc3123_end_cm(), twr_zssc3123_start_cm(), and twr_zssc3123_unlock_eeprom().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_i2c_memory_write_8b()

bool twr_i2c_memory_write_8b ( twr_i2c_channel_t  channel,
uint8_t  device_address,
uint32_t  memory_address,
uint8_t  data 
)

Memory write 1 byte to I2C channel.

Parameters
[in]channelI2C channel
[in]device_address7-bit I2C device address
[in]memory_address8-bit I2C memory address (it can be extended to 16-bit format if OR-ed with TWR_I2C_MEMORY_ADDRESS_16_BIT)
[in]dataInput data to be written

Definition at line 408 of file twr_i2c.c.

Referenced by twr_hdc2080_deinit(), twr_hts221_deinit(), twr_lis2dh12_set_alarm(), twr_module_rs485_deinit(), twr_mpl3115a2_deinit(), twr_sc16is740_init(), twr_sc16is740_reset_fifo(), twr_sc16is740_set_baudrate(), twr_tca9534a_set_port_direction(), and twr_tca9534a_write_port().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_i2c_read()

bool twr_i2c_read ( twr_i2c_channel_t  channel,
const twr_i2c_transfer_t transfer 
)

Read from I2C channel.

Parameters
[in]channelI2C channel
[in]transferPointer to I2C transfer parameters instance
Returns
true On success
false On failure

Definition at line 289 of file twr_i2c.c.

Referenced by twr_zssc3123_eeprom_read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_i2c_set_speed()

void twr_i2c_set_speed ( twr_i2c_channel_t  channel,
twr_i2c_speed_t  speed 
)

Set I2C channel speed.

Parameters
[in]channelI2C channel
[in]speedI2C communication speed

Definition at line 200 of file twr_i2c.c.

Referenced by twr_i2c_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_i2c_write()

bool twr_i2c_write ( twr_i2c_channel_t  channel,
const twr_i2c_transfer_t transfer 
)

Write to I2C channel.

Parameters
[in]channelI2C channel
[in]transferPointer to I2C transfer parameters instance
Returns
true On success
false On failure

Definition at line 243 of file twr_i2c.c.

Here is the call graph for this function: