hal
Hardware Abstraction Layer
i2c.h
Go to the documentation of this file.
1 
25 #ifndef _I2C_H
26 #define _I2C_H
27 
28 #include "hal_types.h"
29 
31 #define TX_MESSAGE_MAX_LENGTH 1024
33 #define RX_MESSAGE_MAX_LENGTH 1024
34 
45 typedef enum {
53 
61 typedef enum {
68 
77 typedef enum {
84 
101 typedef struct {
102  // Immutable input. Can not change once transaction has been submitted.
103  uint8_t target_addr;
105  uint8_t tx_data[TX_MESSAGE_MAX_LENGTH];
109  // Poll to determine when transaction has been completed.
113  // Results of the transaction. Only valid once processing_state == COMPLETED.
114  // Initialize to prescribed values when submitting transaction.
118  uint8_t rx_data[RX_MESSAGE_MAX_LENGTH];
120 } hal_i2c_txn_t;
121 
128 
145 
153 
154 #endif /* _I2C_H */
Common types used across HAL modules.
hal_status_t
Return type for HAL functions.
Definition: hal_types.h:17
hal_i2c_txn_result_t
Result status of a completed transaction.
Definition: i2c.h:77
@ _HAL_I2C_TXN_RESULT_MIN
Definition: i2c.h:78
@ HAL_I2C_TXN_RESULT_NONE
Definition: i2c.h:79
@ HAL_I2C_TXN_RESULT_FAIL
Definition: i2c.h:81
@ _HAL_I2C_TX_RESULT_MAX
Definition: i2c.h:82
@ HAL_I2C_TXN_RESULT_SUCCESS
Definition: i2c.h:80
#define TX_MESSAGE_MAX_LENGTH
May be set to change the size of the TX data array inside the I2C transaction data struct....
Definition: i2c.h:31
hal_i2c_op_t
The common I2C operations read, write, and write-read.
Definition: i2c.h:61
@ _HAL_I2C_OP_MIN
Definition: i2c.h:62
@ HAL_I2C_OP_WRITE
Definition: i2c.h:63
@ HAL_I2C_OP_READ
Definition: i2c.h:64
@ HAL_I2C_OP_WRITE_READ
Definition: i2c.h:65
@ _HAL_I2C_OP_MAX
Definition: i2c.h:66
hal_status_t hal_i2c_submit_transaction(hal_i2c_txn_t *txn)
Submit a transaction to be processed by the driver.
Definition: stm32f4_i2c.c:310
hal_i2c_txn_state_t
The possible states of an I2C transaction (txn).
Definition: i2c.h:45
@ _HAL_I2C_TXN_STATE_MAX
Definition: i2c.h:51
@ HAL_I2C_TXN_STATE_PROCESSING
Definition: i2c.h:49
@ _HAL_I2C_TXN_STATE_MIN
Definition: i2c.h:46
@ HAL_I2C_TXN_STATE_CREATED
Definition: i2c.h:47
@ HAL_I2C_TXN_STATE_COMPLETED
Definition: i2c.h:50
@ HAL_I2C_TXN_STATE_QUEUED
Definition: i2c.h:48
hal_status_t hal_i2c_init()
Initialize the I2C Module. Must be called prior to using the I2C Module.
Definition: stm32f4_i2c.c:301
hal_status_t hal_i2c_transaction_servicer()
Called periodically to manage the loading and unloading of transactions.
Definition: stm32f4_i2c.c:316
#define RX_MESSAGE_MAX_LENGTH
May be set to change the size of the RX data array inside the I2C transaction data struct....
Definition: i2c.h:33
The main data structure for interacting with the I2C module.
Definition: i2c.h:101
size_t expected_bytes_to_rx
Definition: i2c.h:107
size_t expected_bytes_to_tx
Definition: i2c.h:106
hal_i2c_txn_result_t transaction_result
Definition: i2c.h:115
hal_i2c_op_t i2c_op
Definition: i2c.h:104
hal_i2c_txn_state_t processing_state
Definition: i2c.h:110
size_t actual_bytes_transmitted
Definition: i2c.h:117
size_t actual_bytes_received
Definition: i2c.h:116
uint8_t target_addr
Definition: i2c.h:103