mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-02-07 09:52:08 +08:00
[bsp][stm32] add hardware i2c driver
This commit is contained in:
@@ -35,6 +35,10 @@ if GetDepend('RT_USING_SPI_BITOPS'):
|
||||
if GetDepend(['RT_USING_I2C', 'RT_USING_I2C_BITOPS']):
|
||||
if GetDepend('BSP_USING_I2C1') or GetDepend('BSP_USING_I2C2') or GetDepend('BSP_USING_I2C3') or GetDepend('BSP_USING_I2C4'):
|
||||
src += ['drv_soft_i2c.c']
|
||||
|
||||
if GetDepend(['RT_USING_I2C']):
|
||||
if GetDepend('BSP_USING_HARD_I2C1') or GetDepend('BSP_USING_HARD_I2C2') or GetDepend('BSP_USING_HARD_I2C3') or GetDepend('BSP_USING_HARD_I2C4'):
|
||||
src += ['drv_hard_i2c.c']
|
||||
|
||||
if GetDepend(['BSP_USING_ETH', 'RT_USING_LWIP']):
|
||||
src += ['drv_eth.c']
|
||||
|
||||
726
bsp/stm32/libraries/HAL_Drivers/drivers/drv_hard_i2c.c
Normal file
726
bsp/stm32/libraries/HAL_Drivers/drivers/drv_hard_i2c.c
Normal file
File diff suppressed because it is too large
Load Diff
66
bsp/stm32/libraries/HAL_Drivers/drivers/drv_hard_i2c.h
Normal file
66
bsp/stm32/libraries/HAL_Drivers/drivers/drv_hard_i2c.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2024-02-17 Dyyt587 first version
|
||||
*/
|
||||
|
||||
#ifndef __DRV_HARD_I2C_H__
|
||||
#define __DRV_HARD_I2C_H__
|
||||
|
||||
#include "drv_config.h"
|
||||
#include <rtthread.h>
|
||||
#include "rtdevice.h"
|
||||
#include <rthw.h>
|
||||
#include <drv_common.h>
|
||||
#include "drv_dma.h"
|
||||
#include <ipc/completion.h>
|
||||
#ifdef (RT_USING_I2C && BSP_USING_I2C)
|
||||
|
||||
/* C binding of definitions if building with C++ compiler */
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#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, *dma_tx;
|
||||
};
|
||||
|
||||
struct stm32_i2c
|
||||
{
|
||||
I2C_HandleTypeDef handle;
|
||||
struct
|
||||
{
|
||||
DMA_HandleTypeDef handle_rx;
|
||||
DMA_HandleTypeDef handle_tx;
|
||||
} dma;
|
||||
struct stm32_i2c_config *config;
|
||||
struct rt_i2c_bus_device i2c_bus;
|
||||
rt_uint8_t i2c_dma_flag;
|
||||
struct rt_completion completion;
|
||||
|
||||
};
|
||||
|
||||
#define I2C_USING_TX_DMA_FLAG (1U)
|
||||
#define I2C_USING_RX_DMA_FLAG (1U << 1)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* BSP_USING_I2C */
|
||||
|
||||
#endif /* __DRV_I2C_H__ */
|
||||
137
bsp/stm32/libraries/HAL_Drivers/drivers/i2c_hard_config.h
Normal file
137
bsp/stm32/libraries/HAL_Drivers/drivers/i2c_hard_config.h
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2024-02-06 Dyyt587 first version
|
||||
*/
|
||||
#ifndef __I2C_HARD_CONFIG_H__
|
||||
#define __I2C_HARD_CONFIG_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_HARD_I2C1
|
||||
#ifndef I2C1_BUS_CONFIG
|
||||
#define I2C1_BUS_CONFIG \
|
||||
{ \
|
||||
.Instance = I2C1, \
|
||||
.timing=0x10707DBC, \
|
||||
.timeout=0x1000, \
|
||||
.name = "i2c1", \
|
||||
.evirq_type = I2C1_EV_IRQn, \
|
||||
.erirq_type = I2C1_ER_IRQn, \
|
||||
}
|
||||
#endif /* I2C1_BUS_CONFIG */
|
||||
#endif /* BSP_USING_HARD_I2C1 */
|
||||
|
||||
#ifdef BSP_I2C1_TX_USING_DMA
|
||||
#ifndef I2C1_TX_DMA_CONFIG
|
||||
#define I2C1_TX_DMA_CONFIG \
|
||||
{ \
|
||||
.dma_rcc = I2C1_TX_DMA_RCC, \
|
||||
.Instance = I2C1_TX_DMA_INSTANCE, \
|
||||
.dma_irq = I2C1_TX_DMA_IRQ, \
|
||||
.request = DMA_REQUEST_I2C1_TX \
|
||||
}
|
||||
#endif /* I2C1_TX_DMA_CONFIG */
|
||||
#endif /* BSP_I2C1_TX_USING_DMA */
|
||||
|
||||
#ifdef BSP_I2C1_RX_USING_DMA
|
||||
#ifndef I2C1_RX_DMA_CONFIG
|
||||
#define I2C1_RX_DMA_CONFIG \
|
||||
{ \
|
||||
.dma_rcc = I2C1_RX_DMA_RCC, \
|
||||
.Instance = I2C1_RX_DMA_INSTANCE, \
|
||||
.dma_irq = I2C1_RX_DMA_IRQ, \
|
||||
.request = DMA_REQUEST_I2C1_RX \
|
||||
}
|
||||
#endif /* I2C1_RX_DMA_CONFIG */
|
||||
#endif /* BSP_I2C1_RX_USING_DMA */
|
||||
|
||||
#ifdef BSP_USING_HARD_I2C2
|
||||
#ifndef I2C2_BUS_CONFIG
|
||||
#define I2C2_BUS_CONFIG \
|
||||
{ \
|
||||
.Instance = I2C2, \
|
||||
.timing=0x10707DBC, \
|
||||
.timeout=0x1000, \
|
||||
.name = "i2c2", \
|
||||
.evirq_type = I2C2_EV_IRQn, \
|
||||
.erirq_type = I2C2_ER_IRQn, \
|
||||
}
|
||||
#endif /* I2C2_BUS_CONFIG */
|
||||
#endif /* BSP_USING_HARD_I2C2 */
|
||||
|
||||
#ifdef BSP_I2C2_TX_USING_DMA
|
||||
#ifndef I2C2_TX_DMA_CONFIG
|
||||
#define I2C2_TX_DMA_CONFIG \
|
||||
{ \
|
||||
.dma_rcc = I2C2_TX_DMA_RCC, \
|
||||
.Instance = I2C2_TX_DMA_INSTANCE, \
|
||||
.dma_irq = I2C2_TX_DMA_IRQ, \
|
||||
.request = DMA_REQUEST_I2C2_TX \
|
||||
}
|
||||
#endif /* I2C2_TX_DMA_CONFIG */
|
||||
#endif /* BSP_I2C2_TX_USING_DMA */
|
||||
|
||||
#ifdef BSP_I2C2_RX_USING_DMA
|
||||
#ifndef I2C2_RX_DMA_CONFIG
|
||||
#define I2C2_RX_DMA_CONFIG \
|
||||
{ \
|
||||
.dma_rcc = I2C2_RX_DMA_RCC, \
|
||||
.Instance = I2C2_RX_DMA_INSTANCE, \
|
||||
.dma_irq = I2C2_RX_DMA_IRQ, \
|
||||
.request = DMA_REQUEST_I2C2_RX \
|
||||
}
|
||||
#endif /* I2C2_RX_DMA_CONFIG */
|
||||
#endif /* BSP_I2C2_RX_USING_DMA */
|
||||
|
||||
#ifdef BSP_USING_HARD_I2C3
|
||||
#ifndef I2C3_BUS_CONFIG
|
||||
#define I2C3_BUS_CONFIG \
|
||||
{ \
|
||||
.Instance = I2C3, \
|
||||
.timing=0x10707DBC, \
|
||||
.timeout=0x1000, \
|
||||
.name = "i2c3", \
|
||||
.evirq_type = I2C3_EV_IRQn, \
|
||||
.erirq_type = I2C3_ER_IRQn, \
|
||||
}
|
||||
#endif /* I2C3_BUS_CONFIG */
|
||||
#endif /* BSP_USING_HARD_I2C3 */
|
||||
|
||||
#ifdef BSP_I2C3_TX_USING_DMA
|
||||
#ifndef I2C3_TX_DMA_CONFIG
|
||||
#define I2C3_TX_DMA_CONFIG \
|
||||
{ \
|
||||
.dma_rcc = I2C3_TX_DMA_RCC, \
|
||||
.Instance = I2C3_TX_DMA_INSTANCE, \
|
||||
.dma_irq = I2C3_TX_DMA_IRQ, \
|
||||
.request = DMA_REQUEST_I2C3_TX \
|
||||
}
|
||||
#endif /* I2C3_TX_DMA_CONFIG */
|
||||
#endif /* BSP_I2C3_TX_USING_DMA */
|
||||
|
||||
#ifdef BSP_I2C3_RX_USING_DMA
|
||||
#ifndef I2C3_RX_DMA_CONFIG
|
||||
#define I2C3_RX_DMA_CONFIG \
|
||||
{ \
|
||||
.dma_rcc = I2C3_RX_DMA_RCC, \
|
||||
.Instance = I2C3_RX_DMA_INSTANCE, \
|
||||
.dma_irq = I2C3_RX_DMA_IRQ, \
|
||||
.request = DMA_REQUEST_I2C3_RX \
|
||||
}
|
||||
#endif /* I2C3_RX_DMA_CONFIG */
|
||||
#endif /* BSP_I2C3_RX_USING_DMA */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*__I2C_CONFIG_H__ */
|
||||
Reference in New Issue
Block a user