feat[stm32][i2c]: support poll/int/dma transfer paths and i2c4

This commit is contained in:
wdfk-prog
2026-03-14 15:08:57 +08:00
committed by Rbb666
parent e3cfde245d
commit 41ea75839d
2 changed files with 444 additions and 136 deletions
File diff suppressed because it is too large Load Diff
@@ -1,11 +1,12 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2024-02-17 Dyyt587 first version
* 2024-02-17 Dyyt587 first version
* 2024-06-23 wdfk-prog Add mode selection scaffolding
*/
#ifndef __DRV_HARD_I2C_H__
@@ -22,35 +23,118 @@ extern "C"
{
#endif
/* hardware bus */
#if defined(BSP_USING_HARD_I2C1) \
|| defined(BSP_USING_HARD_I2C2) \
|| defined(BSP_USING_HARD_I2C3) \
|| defined(BSP_USING_HARD_I2C4)
#define BSP_HARDWARE_I2C
#endif
/* poll */
#if defined(BSP_I2C1_TX_USING_POLL) \
|| defined(BSP_I2C2_TX_USING_POLL) \
|| defined(BSP_I2C3_TX_USING_POLL) \
|| defined(BSP_I2C4_TX_USING_POLL)
#define BSP_I2C_TX_USING_POLL
#endif
#if defined(BSP_I2C1_RX_USING_POLL) \
|| defined(BSP_I2C2_RX_USING_POLL) \
|| defined(BSP_I2C3_RX_USING_POLL) \
|| defined(BSP_I2C4_RX_USING_POLL)
#define BSP_I2C_RX_USING_POLL
#endif
#if defined (BSP_I2C_TX_USING_POLL) \
|| defined (BSP_I2C_RX_USING_POLL)
#define BSP_I2C_USING_POLL
#endif
/* DMA */
#if defined(BSP_I2C1_TX_USING_DMA) \
|| defined(BSP_I2C2_TX_USING_DMA) \
|| defined(BSP_I2C3_TX_USING_DMA) \
|| defined(BSP_I2C4_TX_USING_DMA)
#define BSP_I2C_TX_USING_DMA
#endif
#if defined(BSP_I2C1_RX_USING_DMA) \
|| defined(BSP_I2C2_RX_USING_DMA) \
|| defined(BSP_I2C3_RX_USING_DMA) \
|| defined(BSP_I2C4_RX_USING_DMA)
#define BSP_I2C_RX_USING_DMA
#endif
#if defined (BSP_I2C_TX_USING_DMA) \
|| defined (BSP_I2C_RX_USING_DMA)
#define BSP_I2C_USING_DMA
#endif
/* INT */
#if defined(BSP_I2C1_TX_USING_INT) \
|| defined(BSP_I2C2_TX_USING_INT) \
|| defined(BSP_I2C3_TX_USING_INT) \
|| defined(BSP_I2C4_TX_USING_INT)
#define BSP_I2C_TX_USING_INT
#endif
#if defined(BSP_I2C1_RX_USING_INT) \
|| defined(BSP_I2C2_RX_USING_INT) \
|| defined(BSP_I2C3_RX_USING_INT) \
|| defined(BSP_I2C4_RX_USING_INT)
#define BSP_I2C_RX_USING_INT
#endif
#if defined (BSP_I2C_TX_USING_INT) \
|| defined (BSP_I2C_RX_USING_INT)
#define BSP_I2C_USING_INT
#endif
/* IRQ */
#if defined (BSP_I2C_USING_DMA) \
|| defined (BSP_I2C_USING_INT)
#define BSP_I2C_USING_IRQ
#endif
struct stm32_i2c_config
{
const char *name;
I2C_TypeDef *Instance;
rt_uint32_t timing;
rt_uint32_t timeout;
IRQn_Type evirq_type;
IRQn_Type erirq_type;
struct dma_config *dma_rx;
struct dma_config *dma_tx;
const char *name;
I2C_TypeDef *Instance;
rt_uint32_t timing;
rt_uint32_t timeout;
IRQn_Type evirq_type;
IRQn_Type erirq_type;
#ifdef BSP_I2C_RX_USING_DMA
struct dma_config *dma_rx;
#endif /* BSP_I2C_RX_USING_DMA */
#ifdef BSP_I2C_TX_USING_DMA
struct dma_config *dma_tx;
#endif /* BSP_I2C_TX_USING_DMA */
};
struct stm32_i2c
{
I2C_HandleTypeDef handle;
struct stm32_i2c_config *config;
I2C_HandleTypeDef handle;
struct stm32_i2c_config *config;
struct rt_i2c_bus_device i2c_bus;
rt_uint16_t i2c_dma_flag;
#ifdef BSP_I2C_USING_IRQ
struct rt_completion completion;
#endif /* BSP_I2C_USING_IRQ */
#ifdef BSP_I2C_USING_DMA
struct
{
DMA_HandleTypeDef handle_rx;
DMA_HandleTypeDef handle_tx;
#ifdef BSP_I2C_RX_USING_DMA
DMA_HandleTypeDef handle_rx;
#endif /* BSP_I2C_RX_USING_DMA */
#ifdef BSP_I2C_TX_USING_DMA
DMA_HandleTypeDef handle_tx;
#endif /* BSP_I2C_TX_USING_DMA */
} dma;
rt_uint8_t i2c_dma_flag;
struct rt_i2c_bus_device i2c_bus;
struct rt_completion completion;
#endif /* BSP_I2C_USING_DMA */
};
#define I2C_USING_TX_DMA_FLAG (1U)
#define I2C_USING_RX_DMA_FLAG (1U << 1)
#ifdef __cplusplus
}
#endif