I2C Master

Functions for using Inter-Integrated Circuit (I2C) peripheral. More...

Modules

Types
Hardware I2C data types.
Macros
Hardware I2C macros.

Functions

gos_result_t gos_i2c_stream_configure ( gos_i2c_t port, uint8_t slave_address, uint32_t clock_rate, uint16_t retries, gos_i2c_stream_flag_t flags)
Configure an I2C slave device. More...
gos_result_t gos_i2c_stream_open ( gos_handle_t *handle_ptr, uint16_t rx_buffer_size)
Open data stream with I2C slave device. More...
gos_result_t gos_i2c_stream_write ( gos_handle_t handle, const void *data, uint32_t size, gos_i2c_stream_write_flag_t flags)
Write I2C data stream. More...
gos_result_t gos_i2c_stream_read ( gos_handle_t handle, void *data, uint32_t max_size, uint32_t *bytes_read_ptr)
Read I2C data stream. More...
gos_result_t gos_i2c_stream_write_reg8 ( gos_handle_t handle, uint8_t reg_address, uint8_t value)
Write I2C device's register with 8bit value. More...
gos_result_t gos_i2c_stream_write_reg ( gos_handle_t handle, uint8_t reg_address, const uint8_t *data, uint16_t length)
Write I2C device's register with given data. More...
gos_result_t gos_i2c_stream_read_reg8 ( gos_handle_t handle, uint8_t reg_address, uint8_t *value_ptr)
Read I2C device's register's 8bit value. More...
gos_result_t gos_i2c_stream_read_reg ( gos_handle_t handle, uint8_t reg_address, uint8_t *data, uint16_t length)
Read I2C device's register(s) into given buffer. More...
gos_result_t gos_i2c_stream_close ( gos_handle_t handle)
Close I2C data stream. More...
gos_result_t gos_i2c_stream_set_slave_address ( gos_handle_t handle, uint8_t slave_address)
Set I2C data stream's slave address. More...
gos_result_t gos_i2c_init (const gos_i2c_device_t *i2c)
Initialize the I2C bus. More...
gos_result_t gos_i2c_transfer (const gos_i2c_device_t *i2c, const gos_i2c_message_t *messages, uint16_t message_count)
Transfer I2C messages. More...
gos_result_t gos_i2c_master_write_reg8 (const gos_i2c_device_t *i2c, uint8_t reg_address, uint8_t value)
Write register with 8bit value. More...
gos_result_t gos_i2c_master_write_reg (const gos_i2c_device_t *i2c, uint8_t reg_address, const uint8_t *data, uint16_t length)
Write register with given buffer. More...
gos_result_t gos_i2c_master_read_reg8 (const gos_i2c_device_t *i2c, uint8_t reg_address, uint8_t *value_ptr)
Read register's 8bit value. More...
gos_result_t gos_i2c_master_read_reg (const gos_i2c_device_t *i2c, uint8_t reg_address, uint8_t *data, uint16_t length)
Read register into given buffer. More...

Detailed Description

Functions for using Inter-Integrated Circuit (I2C) peripheral.

Function Documentation

gos_i2c_init()

gos_result_t gos_i2c_init ( const gos_i2c_device_t * i2c )

Initialize the I2C bus.

This API directly accesses the I2C driver.

Note
gos_i2c_transfer() will automatically initialize the bus, is this only needed to re-initialize the bus
Parameters
[in] i2c I2C slave device, see gos_i2c_device_t
Returns
result of API call

gos_i2c_master_read_reg()

gos_result_t gos_i2c_master_read_reg ( const gos_i2c_device_t * i2c,
uint8_t reg_address,
uint8_t * data,
uint16_t length
)

Read register into given buffer.

Note
This API directly accesses the I2C driver.
Parameters
[in] i2c I2C slave device, see gos_i2c_device_t
[in] reg_address 8bit I2C slave register address
[out] data Buffer to hold register value(s)
[in] length Number of bytes to read
Returns
result of API call

gos_i2c_master_read_reg8()

gos_result_t gos_i2c_master_read_reg8 ( const gos_i2c_device_t * i2c,
uint8_t reg_address,
uint8_t * value_ptr
)

Read register's 8bit value.

Note
This API directly accesses the I2C driver.
Parameters
[in] i2c I2C slave device, see gos_i2c_device_t
[in] reg_address 8bit I2C slave device register address
[out] value_ptr Value of register
Returns
result of API call

gos_i2c_master_write_reg()

gos_result_t gos_i2c_master_write_reg ( const gos_i2c_device_t * i2c,
uint8_t reg_address,
const uint8_t * data,
uint16_t length
)

Write register with given buffer.

Note
This API directly accesses the I2C driver.
Parameters
[in] i2c I2C slave device, see gos_i2c_device_t
[in] reg_address 8bit I2C slave device register address
[in] data Data to write to slave device's register(s)
[in] length Number of bytes to write to device
Returns
result of API call

gos_i2c_master_write_reg8()

gos_result_t gos_i2c_master_write_reg8 ( const gos_i2c_device_t * i2c,
uint8_t reg_address,
uint8_t value
)

Write register with 8bit value.

Note
This API directly accesses the I2C driver.
Parameters
[in] i2c I2C slave device, see gos_i2c_device_t
[in] reg_address 8bit I2C slave device register address
[in] value 8bit value to write to slave device's register
Returns
result of API call

gos_i2c_stream_close()

gos_result_t gos_i2c_stream_close ( gos_handle_t handle )

Close I2C data stream.

See Gecko OS Command API documentation: stream_close

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
Parameters
[in] handle Handle of I2C stream
Returns
result of API call

gos_i2c_stream_configure()

gos_result_t gos_i2c_stream_configure ( gos_i2c_t port,
uint8_t slave_address,
uint32_t clock_rate,
uint16_t retries,
gos_i2c_stream_flag_t flags
)

Configure an I2C slave device.

See Gecko OS Command API documentation: i2c_master_config .

Parameters
[in] port I2C peripheral port, see gos_i2c_t
[in] slave_address 7bit slave address of I2C device
[in] clock_rate Clock rate of I2C device
[in] retries Number of attempts to read/write a message from/to slave device
[in] flags Configuration flags
Returns
result of API call

gos_i2c_stream_open()

gos_result_t gos_i2c_stream_open ( gos_handle_t * handle_ptr,
uint16_t rx_buffer_size
)

Open data stream with I2C slave device.

See Gecko OS Command API documentation: i2c_master_open .

The device must have been previously configured with gos_i2c_stream_configure()

Once opened used a gos_i2c_stream_xxx API to read/write the device.

Parameters
[out] handle_ptr Stream handle of opened I2C slave stream
[in] rx_buffer_size Size of RX buffer in bytes
Returns
result of API call

gos_i2c_stream_read()

gos_result_t gos_i2c_stream_read ( gos_handle_t handle,
void * data,
uint32_t max_size,
uint32_t * bytes_read_ptr
)

Read I2C data stream.

See Gecko OS Command API documentation: stream_read , i2c_master_open .

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
Parameters
[in] handle Handle of I2C stream
[out] data Buffer to hold read data
[in] max_size Maximum number of bytes to read
[out] bytes_read_ptr Number of bytes actually read
Returns
result of API call

gos_i2c_stream_read_reg()

gos_result_t gos_i2c_stream_read_reg ( gos_handle_t handle,
uint8_t reg_address,
uint8_t * data,
uint16_t length
)

Read I2C device's register(s) into given buffer.

See Gecko OS Command API documentation: stream_read , i2c_master_open .

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
Parameters
[in] handle Handle of I2C stream
[in] reg_address 8bit I2C slave register address
[out] data Buffer to hold register value(s)
[in] length Number of bytes to read
Returns
result of API call

gos_i2c_stream_read_reg8()

gos_result_t gos_i2c_stream_read_reg8 ( gos_handle_t handle,
uint8_t reg_address,
uint8_t * value_ptr
)

Read I2C device's register's 8bit value.

See Gecko OS Command API documentation: stream_read , i2c_master_open .

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
Parameters
[in] handle Handle of I2C stream
[in] reg_address 8bit I2C slave register address
[out] value_ptr Value of register
Returns
result of API call

gos_i2c_stream_set_slave_address()

gos_result_t gos_i2c_stream_set_slave_address ( gos_handle_t handle,
uint8_t slave_address
)

Set I2C data stream's slave address.

Multiple I2C devices may be accessed using the same I2C stream. Each I2C device should first be configured using gos_i2c_stream_configure() . This API can then be used to switch between the I2C slave devices.

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
Parameters
[in] handle Handle of I2C stream
[in] slave_address Slave address to update given I2C stream
Returns
result of API call

gos_i2c_stream_write()

gos_result_t gos_i2c_stream_write ( gos_handle_t handle,
const void * data,
uint32_t size,
gos_i2c_stream_write_flag_t flags
)

Write I2C data stream.

See Gecko OS Command API documentation: stream_write , i2c_master_open .

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
Parameters
[in] handle Handle of I2C stream
[in] data Data to write to device
[in] size Size in bytes of data to write
[in] flags Additional write flags, see gos_i2c_stream_write_flag_t
Returns
result of API call

gos_i2c_stream_write_reg()

gos_result_t gos_i2c_stream_write_reg ( gos_handle_t handle,
uint8_t reg_address,
const uint8_t * data,
uint16_t length
)

Write I2C device's register with given data.

See Gecko OS Command API documentation: stream_write , i2c_master_open .

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
Parameters
[in] handle Handle of I2C stream
[in] reg_address 8bit I2C slave register address
[in] data Data to write
[in] length Size in bytes of data to write
Returns
result of API call

gos_i2c_stream_write_reg8()

gos_result_t gos_i2c_stream_write_reg8 ( gos_handle_t handle,
uint8_t reg_address,
uint8_t value
)

Write I2C device's register with 8bit value.

See Gecko OS Command API documentation: stream_write , i2c_master_open .

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
Parameters
[in] handle Handle of I2C stream
[in] reg_address 8bit I2C slave register address
[in] value 8bit value to write to slave
Returns
result of API call

gos_i2c_transfer()

gos_result_t gos_i2c_transfer ( const gos_i2c_device_t * i2c,
const gos_i2c_message_t * messages,
uint16_t message_count
)

Transfer I2C messages.

Transfer one or more messages to/from an I2C slave device.

Note
This API directly accesses the I2C driver.
Parameters
[in] i2c I2C slave device, see gos_i2c_device_t
[in,out] messages Array of gos_i2c_message_t to send/receive to/from I2C slave device
[in] message_count Number of messages to transfer
Returns
result of API call