lib/iic/backend/i2c_stm_impl.h¶
STM32 HAL-based I2C backend private types and helpers. More...
Classes¶
| Name | |
|---|---|
| struct | CFBD_ST_I2CPrivate Backend-private state for the STM32 I2C implementation. |
Functions¶
| Name | |
|---|---|
| I2C_HandleTypeDef * | native_handle(CFBD_ST_I2CPrivate * priv) Helper to obtain the native HAL I2C handle from the private struct. |
| void | init_stm32_i2c_privates(CFBD_ST_I2CPrivate * priv, I2C_HandleTypeDef * hi2c, GPIO_TypeDef * scl_port, uint16_t scl_pin, GPIO_TypeDef * sda_port, uint16_t sda_pin) Initialize an STM32 I2C private structure. |
| void | stm32_i2c_bus_register(CFBD_I2CHandle * bus, CFBD_ST_I2CPrivate * priv) Register the STM32 private context with a [CFBD_I2CHandle](Classes/structCFBD__I2CHandle.md). |
Detailed Description¶
STM32 HAL-based I2C backend private types and helpers.
Note: This header depends on STM32 HAL types such as I2C_HandleTypeDef and GPIO_TypeDef and is only relevant when building for ST platforms.
Provides the STM32-specific private handle used by the project's CFBD I2C abstraction. The private handle contains HAL peripheral references and GPIO pin information used for optional bus recovery or low-level operations. Utility functions are provided to initialize the private structure and register it with the public [CFBD_I2CHandle](Classes/structCFBD__I2CHandle.md).
Functions Documentation¶
function native_handle¶
Helper to obtain the native HAL I2C handle from the private struct.
Parameters:
- priv Pointer to
[CFBD_ST_I2CPrivate](Classes/structCFBD__ST__I2CPrivate.md).
Return: I2C_HandleTypeDef* Native HAL handle or NULL if priv is NULL.
function init_stm32_i2c_privates¶
void init_stm32_i2c_privates(
CFBD_ST_I2CPrivate * priv,
I2C_HandleTypeDef * hi2c,
GPIO_TypeDef * scl_port,
uint16_t scl_pin,
GPIO_TypeDef * sda_port,
uint16_t sda_pin
)
Initialize an STM32 I2C private structure.
Parameters:
- priv Pointer to the
[CFBD_ST_I2CPrivate](Classes/structCFBD__ST__I2CPrivate.md)instance to initialize. - hi2c Pointer to a valid
I2C_HandleTypeDef(HAL instance). - scl_port GPIO port used for SCL (e.g. GPIOA).
- scl_pin Pin mask/number for SCL.
- sda_port GPIO port used for SDA (e.g. GPIOA).
- sda_pin Pin mask/number for SDA.
Populates the priv structure with supplied HAL handles and GPIO pins. This helper does not modify hardware state; it only prepares the private context prior to registering it with the public bus handle via [stm32_i2c_bus_register()](Files/i2c__stm__impl_8h.md#function-stm32-i2c-bus-register).
function stm32_i2c_bus_register¶
Register the STM32 private context with a [CFBD_I2CHandle](Classes/structCFBD__I2CHandle.md).
Parameters:
- bus Pointer to the public
[CFBD_I2CHandle](Classes/structCFBD__I2CHandle.md)to register. - priv Pointer to the initialized
[CFBD_ST_I2CPrivate](Classes/structCFBD__ST__I2CPrivate.md).
Associates the backend-private data with the public [CFBD_I2CHandle](Classes/structCFBD__I2CHandle.md). After registration the I2C handle's ops table should be populated by the STM32 backend implementation to provide operational functions (init, transfer, etc.).
Source code¶
#pragma once
#include "../iic.h"
typedef struct
{
I2C_HandleTypeDef* hi2c;
GPIO_TypeDef* scl_port;
uint16_t scl_pin;
GPIO_TypeDef* sda_port;
uint16_t sda_pin;
int last_err;
} CFBD_ST_I2CPrivate;
static inline I2C_HandleTypeDef* native_handle(CFBD_ST_I2CPrivate* priv)
{
return priv ? priv->hi2c : NULL;
}
void init_stm32_i2c_privates(CFBD_ST_I2CPrivate* priv,
I2C_HandleTypeDef* hi2c,
GPIO_TypeDef* scl_port,
uint16_t scl_pin,
GPIO_TypeDef* sda_port,
uint16_t sda_pin);
void stm32_i2c_bus_register(CFBD_I2CHandle* bus, CFBD_ST_I2CPrivate* priv);
Updated on 2026-02-03 at 13:21:55 +0000