hal
Hardware Abstraction Layer
hal_i2c_txn_t Struct Reference

The main data structure for interacting with the I2C module. More...

#include <i2c.h>

Public Attributes

uint8_t target_addr
 
hal_i2c_op_t i2c_op
 
uint8_t tx_data [TX_MESSAGE_MAX_LENGTH]
 
size_t expected_bytes_to_tx
 
size_t expected_bytes_to_rx
 
hal_i2c_txn_state_t processing_state
 
hal_i2c_txn_result_t transaction_result
 
size_t actual_bytes_received
 
size_t actual_bytes_transmitted
 
uint8_t rx_data [RX_MESSAGE_MAX_LENGTH]
 

Detailed Description

The main data structure for interacting with the I2C module.

All interactions with the I2C driver involve using this data structure. In it is defined everything needed to initiate and complete a single I2C transaction with a target device, including the device address, the operation mode, the data to send (if any), and the expected data to receive (if any). It also includes status information used to track progress and check for success or failure.

The use of this transaction struct involves initializing the proper inputs, polling the the processing_state, and reading the outputs once the state is complete.

Note
When submitting a transaction for processing, the client must maintain the memory for the transaction. Only a reference is passed to the driver. If the memory for the transaction is erased (i.e. declared in a function followed by the function's return) then the I2C driver will operate on a reference to invalid memory.

Member Data Documentation

◆ actual_bytes_received

size_t hal_i2c_txn_t::actual_bytes_received

The actual number of bytes that got read during the transaction. Init to 0.

◆ actual_bytes_transmitted

size_t hal_i2c_txn_t::actual_bytes_transmitted

The actual number of bytes that got transmitted during the transaction. Init to 0.

◆ expected_bytes_to_rx

size_t hal_i2c_txn_t::expected_bytes_to_rx

The desired number of bytes to read from the device during this transaction. Only set for READ or WRITE-READ.

◆ expected_bytes_to_tx

size_t hal_i2c_txn_t::expected_bytes_to_tx

The num of bytes to send the device. Include the reg addr in the count.

◆ i2c_op

hal_i2c_op_t hal_i2c_txn_t::i2c_op

The type of transaction. i.e. READ, WRITE, or WRITE-READ.

◆ processing_state

hal_i2c_txn_state_t hal_i2c_txn_t::processing_state

Submit transaction with CREATED. When processing_state == COMPLETED then client can collect results. Safe to check periodically. Poll to determine when transaction has been completed.

◆ rx_data

uint8_t hal_i2c_txn_t::rx_data[RX_MESSAGE_MAX_LENGTH]

Data read from device will be stored here. Only valid after processing_state == COMPLETED. Init rx_data to zeros when creating the transaction struct.

◆ target_addr

uint8_t hal_i2c_txn_t::target_addr

The I2C address of the target device.

◆ transaction_result

hal_i2c_txn_result_t hal_i2c_txn_t::transaction_result

Only valid once processing_state == COMPLETED. Contains the result of the transaction (success, fail, etc). Init to NONE.

◆ tx_data

uint8_t hal_i2c_txn_t::tx_data[TX_MESSAGE_MAX_LENGTH]

The data to send. Put the register addr in the first slot.


The documentation for this struct was generated from the following file: