I2C Structures - PalouseRobosub/SUBLIBinal GitHub Wiki
I2C Structures
This page contains information about the structures used within the I2C configuration and modification. Please refer to the list below to be redirected to the appropriate documentation.
Structures
I2C_Data
Definition
typedef struct I2C_DATA {
Queue Rx_queue;
Queue Tx_queue;
boolean Tx_is_idle;
} I2C_Data;
Description
The I2C_Data
structure is used internally by the library. It is handed back by the initialization function to allow the user to view the status of the I2C bus, but it should not be modified by the user in any way.
Parameters
- Rx_queue: This parameter is the receive buffer for the I2C channel
- Tx_queue: This parameter is the transmission buffer for the I2C channel
- Tx_is_idle: This parameter specifies whether the I2C bus is currently being used
I2C_Node
Definition
typedef struct I2C_NODE {
uint8 device_id;
uint8 device_address;
uint8 sub_address;
uint8* data_buffer;
uint8 data_size;
I2C_MODE mode;
void (*callback) (struct I2C_NODE);
} I2C_Node;
Description
The I2C_Node
structure is used when setting up an I2C transaction. The user should fill out a node load it into the work queue for processing. When the I2C transaction is completed, the node will be placed in the results queue. The I2C background process will then pop the node and call the specified callback function if one is given.
Parameters
- device_id: Not used by the library, this allows the user to uniquely identify a device
- device_address: The I2C address of the device that is being communicated with
- sub_address: The internal address location of the device that should be read/written
- data_buffer: A pointer that tells the library where the data to be sent can be read from or where the data to be read can be written to. Must be at least as large as data_size
- data_size: This parameter defines how many bytes should be read or written in the transaction.
- mode: This parameter specifies whether the node is reading or writing.
I2C_Config
Definition
typedef struct I2C_CONFIG {
uint pb_clk;
I2C_Channel channel;
uint8 *rx_buffer_ptr;
uint rx_buffer_size;
uint8 *tx_buffer_ptr;
uint tx_buffer_size;
void* callback;
}I2C_Config;
Description
This structure is used for configuration of the I2C during the initialize_I2C() function. The I2C operates using data buffers for the work and result queues, and thus must be handed memory that will remain in scope for the entirety of program execution. Please declare an array either in main or globally and supply a pointer to the array for the result and work buffer pointers. These arrays should not be modified, or the I2C will malfunction.
Parameters
- pb_clk: This parameter is a speed that the peripheral bus clock is running at. This is utilized by I2C for setting proper speeds.
- channel: This parameter specifies which I2C channel to configure
- rx_buffer_ptr: This should be a pointer to an array of memory for use by the results buffer of the I2C. For efficient memory usage, it should be a multiple of
sizeof(I2C_Node)
- rx_buffer_size: This is a size (in bytes) of the data pointed to by
rx_buffer_ptr
. - tx_buffer_ptr_: This is a pointer to an array of memory for use by the work buffer of the I2C. This buffer should be different than the RX buffer, as the memory must be distinctly different. For efficient memory usage, it should be a multiple of
sizeof(I2C_Node)
- tx_buffer_size: This parameter specifies (in bytes) the size of the data pointed to by
tx_buffer_ptr
. - callback: Specifies a function to be called every time the I2C interrupt occurs. It is ok for the function to not be implemented (set callback to NULL). If used the function must accept and return
void
.