hal
Hardware Abstraction Layer
stm32f4_i2c.c File Reference

STM32F4 I2C HAL implementation. More...

#include "stm32f4xx.h"
#include "i2c.h"
#include "i2c_transaction_queue.h"
#include "stm32f4_hal.h"
#include <string.h>
#include <stdbool.h>
Include dependency graph for stm32f4_i2c.c:

Macros

#define SYS_FREQ_MHZ   16
 
#define I2C_DIRECTION_WRITE   0
 
#define I2C_DIRECTION_READ   1
 
#define _SET_ERROR_FLAG_AND_ABORT_TRANSACTION()
 

Functions

void I2C1_EV_IRQHandler (void)
 
void I2C1_ER_IRQHandler ()
 
hal_status_t hal_i2c_init ()
 Initialize the I2C Module. Must be called prior to using the I2C Module. More...
 
hal_status_t hal_i2c_submit_transaction (hal_i2c_txn_t *txn)
 Submit a transaction to be processed by the driver. More...
 
hal_status_t hal_i2c_transaction_servicer ()
 Called periodically to manage the loading and unloading of transactions. More...
 
void _test_fixture_hal_i2c_reset_internals ()
 Just for testing. More...
 

Detailed Description

STM32F4 I2C HAL implementation.

Copyright (c) 2025 Cory McKiel. Licensed under the MIT License. See LICENSE file in the project root.

Macro Definition Documentation

◆ _SET_ERROR_FLAG_AND_ABORT_TRANSACTION

#define _SET_ERROR_FLAG_AND_ABORT_TRANSACTION ( )
Value:
_error_occurred = true; \
I2C1->CR2 &= ~I2C_CR2_ITBUFEN; \
I2C1->CR1 |= I2C_CR1_STOP; \
_tx_in_progress = false; \
_rx_in_progress = false;

Function Documentation

◆ _test_fixture_hal_i2c_reset_internals()

void _test_fixture_hal_i2c_reset_internals ( )

Just for testing.

Warning
Grave consequences if used in production code.

◆ hal_i2c_init()

hal_status_t hal_i2c_init ( )

Initialize the I2C Module. Must be called prior to using the I2C Module.

Returns
HAL_STATUS_OK on success.

◆ hal_i2c_submit_transaction()

hal_status_t hal_i2c_submit_transaction ( hal_i2c_txn_t txn)

Submit a transaction to be processed by the driver.

Parameters
txnA reference to a transaction with the appropriate fields already filled out. See hal_i2c_txn_t for details about filling out the transaction correctly, as well as information about checking progress.
Returns
HAL_STATUS_OK if transaction was submitted successfully.
Note
Successful return from this function only represents that the transaction was successfully queued.
Clients must maintain the memory of their transactions. Only a reference to the transaction is queued.

◆ hal_i2c_transaction_servicer()

hal_status_t hal_i2c_transaction_servicer ( )

Called periodically to manage the loading and unloading of transactions.

Returns
HAL_STATUS_OK on success.