Midnight Sun Firmware
Loading...
Searching...
No Matches
I2C

I2C library. More...

Classes

struct  I2CSettings
 I2C settings struct. More...
 

Macros

#define I2C_TIMEOUT_MS   100U
 Maximum time permitted for an I2C transaction.
 
#define I2C_MAX_NUM_DATA   32U
 None of our I2C transactions should need to be longer than 32 bytes.
 

Typedefs

typedef uint8_t I2CAddress
 I2C address type.
 

Enumerations

enum  I2CPort { I2C_PORT_1 = 0 , I2C_PORT_2 , NUM_I2C_PORTS }
 I2C Port selection. More...
 
enum  I2CSpeed { I2C_SPEED_STANDARD = 0 , I2C_SPEED_FAST , NUM_I2C_SPEEDS }
 I2C speed type. More...
 

Functions

StatusCode i2c_init (I2CPort i2c, const I2CSettings *settings)
 Initialize I2C instance. More...
 
StatusCode i2c_read (I2CPort i2c, I2CAddress addr, uint8_t *rx_data, size_t rx_len)
 Reads data using the I2C port from the specified address. More...
 
StatusCode i2c_write (I2CPort i2c, I2CAddress addr, uint8_t *tx_data, size_t tx_len)
 Writes data using the I2C port to the specified address. More...
 
StatusCode i2c_read_reg (I2CPort i2c, I2CAddress addr, uint8_t reg, uint8_t *rx_data, size_t rx_len)
 Reads data using the I2C port from the specified address and register. More...
 
StatusCode i2c_write_reg (I2CPort i2c, I2CAddress addr, uint8_t reg, uint8_t *tx_data, size_t tx_len)
 Writes data using the I2C port to the specified address and register. More...
 

Detailed Description

I2C library.

Enumeration Type Documentation

◆ I2CPort

enum I2CPort

I2C Port selection.

Enumerator
I2C_PORT_1 

SCL: PA9 and SDA: PA10

I2C_PORT_2 

SCL: PB10 and SDA: PB11

NUM_I2C_PORTS 

Number of I2C Ports

◆ I2CSpeed

enum I2CSpeed

I2C speed type.

Enumerator
I2C_SPEED_STANDARD 

100kHz

I2C_SPEED_FAST 

400 kHz

NUM_I2C_SPEEDS 

Number of I2C Speeds

Function Documentation

◆ i2c_init()

StatusCode i2c_init ( I2CPort  i2c,
const I2CSettings settings 
)

Initialize I2C instance.

Parameters
i2cSpecifies which I2C port to initialize
settingsPointer to I2C initialization settings
Returns
STATUS_CODE_OK if initialization succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect STATUS_CODE_INTERNAL_ERROR if HAL initialization fails STATUS_CODE_RESOURCE_EXHAUSTED if already initialized

◆ i2c_read()

StatusCode i2c_read ( I2CPort  i2c,
I2CAddress  addr,
uint8_t *  rx_data,
size_t  rx_len 
)

Reads data using the I2C port from the specified address.

Parameters
i2cSpecifies which I2C port to read with
addrThe I2C address to read from
rx_dataPointer to a buffer to receive data
rx_lenLength of data to receive
Returns
STATUS_CODE_OK if reading succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect STATUS_CODE_INTERNAL_ERROR if HAL transmission fails STATUS_CODE_TIMEOUT if transmission takes too long

◆ i2c_read_reg()

StatusCode i2c_read_reg ( I2CPort  i2c,
I2CAddress  addr,
uint8_t  reg,
uint8_t *  rx_data,
size_t  rx_len 
)

Reads data using the I2C port from the specified address and register.

Parameters
i2cSpecifies which I2C port to read with
addrSpecifies the I2C address to read from
regSpecifies the register to read from
rx_dataPointer to a buffer to receive data
rx_lenLength of the data to receive
Returns
STATUS_CODE_OK if reading succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect STATUS_CODE_INTERNAL_ERROR if HAL transmission fails STATUS_CODE_TIMEOUT if transmission takes too long

◆ i2c_write()

StatusCode i2c_write ( I2CPort  i2c,
I2CAddress  addr,
uint8_t *  tx_data,
size_t  tx_len 
)

Writes data using the I2C port to the specified address.

Parameters
i2cSpecifies which I2C port to write with
addrSpecifies the I2C address to write to
tx_dataPointer to a buffer to transmit data
tx_lenLength of the data to transmit
Returns
STATUS_CODE_OK if writing succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect STATUS_CODE_INTERNAL_ERROR if HAL transmission fails STATUS_CODE_TIMEOUT if transmission takes too long

◆ i2c_write_reg()

StatusCode i2c_write_reg ( I2CPort  i2c,
I2CAddress  addr,
uint8_t  reg,
uint8_t *  tx_data,
size_t  tx_len 
)

Writes data using the I2C port to the specified address and register.

Parameters
i2cSpecifies which I2C port to write with
addrSpecifies the I2C address to write to
regSpecifies the register to write to
tx_dataPointer to a buffer to transmit data
tx_lenLength of the data to transmit
Returns
STATUS_CODE_OK if writing succeeded STATUS_CODE_INVALID_ARGS if one of the parameters are incorrect STATUS_CODE_INTERNAL_ERROR if HAL transmission fails STATUS_CODE_TIMEOUT if transmission takes too long