From 6a9973cf19bcee8870af311151239610fb146a34 Mon Sep 17 00:00:00 2001 From: Siwei Xu Date: Fri, 7 Jul 2023 21:11:14 +0800 Subject: [PATCH] [bsp][Infineon] Add I2C4 config for psoc6-evaluationkit --- bsp/Infineon/libraries/HAL_Drivers/SConscript | 2 +- bsp/Infineon/libraries/HAL_Drivers/drv_i2c.c | 29 ++++++++++++++----- .../psoc6-evaluationkit-062S2/board/Kconfig | 14 +++++++++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/bsp/Infineon/libraries/HAL_Drivers/SConscript b/bsp/Infineon/libraries/HAL_Drivers/SConscript index e62120048c..4219799884 100644 --- a/bsp/Infineon/libraries/HAL_Drivers/SConscript +++ b/bsp/Infineon/libraries/HAL_Drivers/SConscript @@ -23,7 +23,7 @@ if GetDepend(['RT_USING_I2C', 'RT_USING_I2C_BITOPS']): src += ['drv_soft_i2c.c'] if GetDepend(['RT_USING_I2C']): - if GetDepend('BSP_USING_HW_I2C3') or GetDepend('BSP_USING_HW_I2C6'): + if GetDepend('BSP_USING_HW_I2C3') or GetDepend('BSP_USING_HW_I2C4') or GetDepend('BSP_USING_HW_I2C6'): src += ['drv_i2c.c'] if GetDepend(['BSP_USING_SDIO1']): diff --git a/bsp/Infineon/libraries/HAL_Drivers/drv_i2c.c b/bsp/Infineon/libraries/HAL_Drivers/drv_i2c.c index 5a91a99cf4..079d4b16de 100644 --- a/bsp/Infineon/libraries/HAL_Drivers/drv_i2c.c +++ b/bsp/Infineon/libraries/HAL_Drivers/drv_i2c.c @@ -11,7 +11,7 @@ #include "board.h" #if defined(RT_USING_I2C) -#if defined(BSP_USING_HW_I2C3) || defined(BSP_USING_HW_I2C6) +#if defined(BSP_USING_HW_I2C3) || defined(BSP_USING_HW_I2C4) || defined(BSP_USING_HW_I2C6) #include #ifndef I2C3_CONFIG @@ -22,7 +22,16 @@ .sda_pin = BSP_I2C3_SDA_PIN, \ } #endif /* I2C3_CONFIG */ -#endif + +#ifndef I2C4_CONFIG +#define I2C4_CONFIG \ + { \ + .name = "i2c4", \ + .scl_pin = BSP_I2C4_SCL_PIN, \ + .sda_pin = BSP_I2C4_SDA_PIN, \ + } +#endif /* I2C4_CONFIG */ + #ifndef I2C6_CONFIG #define I2C6_CONFIG \ { \ @@ -32,11 +41,16 @@ } #endif /* I2C6_CONFIG */ +#endif /* defined(BSP_USING_I2C1) || defined(BSP_USING_I2C2) */ + enum { #ifdef BSP_USING_HW_I2C3 I2C3_INDEX, #endif +#ifdef BSP_USING_HW_I2C4 + I2C4_INDEX, +#endif #ifdef BSP_USING_HW_I2C6 I2C6_INDEX, #endif @@ -63,6 +77,10 @@ static struct ifx_i2c_config i2c_config[] = I2C3_CONFIG, #endif +#ifdef BSP_USING_HW_I2C4 + I2C4_CONFIG, +#endif + #ifdef BSP_USING_HW_I2C6 I2C6_CONFIG, #endif @@ -145,8 +163,7 @@ void HAL_I2C_Init(struct ifx_i2c *obj) int rt_hw_i2c_init(void) { - rt_err_t result; - cyhal_i2c_t mI2C; + rt_err_t result = RT_EOK; for (int i = 0; i < sizeof(i2c_config) / sizeof(i2c_config[0]); i++) { @@ -157,8 +174,6 @@ int rt_hw_i2c_init(void) i2c_objs[i].mI2C_cfg.address = 0; i2c_objs[i].mI2C_cfg.frequencyhal_hz = (400000UL); - i2c_objs[i].mI2C = mI2C; - i2c_objs[i].i2c_bus.ops = &i2c_ops; HAL_I2C_Init(&i2c_objs[i]); @@ -171,4 +186,4 @@ int rt_hw_i2c_init(void) } INIT_DEVICE_EXPORT(rt_hw_i2c_init); -#endif /* defined(BSP_USING_I2C1) || defined(BSP_USING_I2C2) */ +#endif /* RT_USING_I2C */ diff --git a/bsp/Infineon/psoc6-evaluationkit-062S2/board/Kconfig b/bsp/Infineon/psoc6-evaluationkit-062S2/board/Kconfig index ed5d4d7945..84005737f6 100644 --- a/bsp/Infineon/psoc6-evaluationkit-062S2/board/Kconfig +++ b/bsp/Infineon/psoc6-evaluationkit-062S2/board/Kconfig @@ -155,6 +155,20 @@ menu "On-chip Peripheral Drivers" range 1 113 default 49 endif + config BSP_USING_HW_I2C4 + bool "Enable I2C4 Bus (Arduino I2C)" + default n + if BSP_USING_HW_I2C4 + comment "Notice: P8_0 --> 64; P8_1 --> 65" + config BSP_I2C4_SCL_PIN + int "i2c4 SCL pin number" + range 1 113 + default 64 + config BSP_I2C4_SDA_PIN + int "i2c4 SDA pin number" + range 1 113 + default 65 + endif config BSP_USING_HW_I2C6 bool "Enable I2C6 Bus (User I2C)" default n