diff options
| author | CYFS <[email protected]> | 2026-07-15 17:54:33 +0800 |
|---|---|---|
| committer | Rbb666 <[email protected]> | 2026-07-16 13:19:57 +0800 |
| commit | 414ff7f3710168dbf99a398e18b2a4ff8448b005 (patch) | |
| tree | 4d29ff0dadc5cb4aa74941deb4e28bb46ff5ad6d /bsp/Infineon/libraries | |
| parent | 997de9433af42aacb1988489ccb08b6688f440cc (diff) | |
[bsp][drivers][soft_i2c] unify the software I2C driver
Diffstat (limited to 'bsp/Infineon/libraries')
5 files changed, 38 insertions, 260 deletions
diff --git a/bsp/Infineon/libraries/HAL_Drivers/SConscript b/bsp/Infineon/libraries/HAL_Drivers/SConscript index 017b3cb4d7..280ee05b70 100644 --- a/bsp/Infineon/libraries/HAL_Drivers/SConscript +++ b/bsp/Infineon/libraries/HAL_Drivers/SConscript @@ -18,10 +18,6 @@ if GetDepend(['RT_USING_SERIAL']): else: src += ['drv_uart.c'] -if GetDepend(['RT_USING_I2C', 'RT_USING_I2C_BITOPS']): - if GetDepend('BSP_USING_I2C1'): - src += ['drv_soft_i2c.c'] - if GetDepend(['RT_USING_I2C']): if GetDepend('BSP_USING_HW_I2C1') or GetDepend('BSP_USING_HW_I2C3') or GetDepend('BSP_USING_HW_I2C4') or GetDepend('BSP_USING_HW_I2C6'): src += ['drv_i2c.c'] diff --git a/bsp/Infineon/libraries/HAL_Drivers/drv_soft_i2c.c b/bsp/Infineon/libraries/HAL_Drivers/drv_soft_i2c.c deleted file mode 100644 index 9c20a54ca1..0000000000 --- a/bsp/Infineon/libraries/HAL_Drivers/drv_soft_i2c.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2006-2024 RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2022-07-20 Rbb666 first version - */ - -#include <board.h> -#include "drv_soft_i2c.h" - -#ifdef RT_USING_I2C - -/*#define DRV_DEBUG*/ -#define LOG_TAG "drv.i2c" -#include <drv_log.h> - -#if !defined(BSP_USING_I2C1) - #error "Please define at least one BSP_USING_I2Cx" - /* this driver can be disabled at menuconfig -> RT-Thread Components -> Device Drivers */ -#endif - -static const struct ifx_soft_i2c_config soft_i2c_config[] = -{ - #ifdef BSP_USING_I2C1 - I2C1_BUS_CONFIG, - #endif -}; - -static struct ifx_i2c i2c_obj[sizeof(soft_i2c_config) / sizeof(soft_i2c_config[0])]; - -/** - * This function initializes the i2c pin. - * - * @param ifx i2c dirver class. - */ -static void ifx_i2c_gpio_init(struct ifx_i2c *i2c) -{ - struct ifx_soft_i2c_config *cfg = (struct ifx_soft_i2c_config *)i2c->ops.data; - - rt_pin_mode(cfg->scl, PIN_MODE_OUTPUT_OD); - rt_pin_mode(cfg->sda, PIN_MODE_OUTPUT_OD); - - rt_pin_write(cfg->scl, PIN_HIGH); - rt_pin_write(cfg->sda, PIN_HIGH); -} - -static void ifx_i2c_pin_init(void) -{ - rt_size_t obj_num = sizeof(i2c_obj) / sizeof(struct ifx_i2c); - - for(rt_size_t i = 0; i < obj_num; i++) - { - ifx_i2c_gpio_init(&i2c_obj[i]); - } -} - -/** - * This function sets the sda pin. - * - * @param ifx config class. - * @param The sda pin state. - */ -static void ifx_set_sda(void *data, rt_int32_t state) -{ - struct ifx_soft_i2c_config *cfg = (struct ifx_soft_i2c_config *)data; - - if (state) - { - rt_pin_write(cfg->sda, PIN_HIGH); - } - else - { - rt_pin_write(cfg->sda, PIN_LOW); - } -} - -/** - * This function sets the scl pin. - * - * @param ifx config class. - * @param The scl pin state. - */ -static void ifx_set_scl(void *data, rt_int32_t state) -{ - struct ifx_soft_i2c_config *cfg = (struct ifx_soft_i2c_config *)data; - - if (state) - { - rt_pin_write(cfg->scl, PIN_HIGH); - } - else - { - rt_pin_write(cfg->scl, PIN_LOW); - } -} - -/** - * This function gets the sda pin state. - * - * @param The sda pin state. - */ -static rt_int32_t ifx_get_sda(void *data) -{ - struct ifx_soft_i2c_config *cfg = (struct ifx_soft_i2c_config *)data; - return rt_pin_read(cfg->sda); -} - -/** - * This function gets the scl pin state. - * - * @param The scl pin state. - */ -static rt_int32_t ifx_get_scl(void *data) -{ - struct ifx_soft_i2c_config *cfg = (struct ifx_soft_i2c_config *)data; - return rt_pin_read(cfg->scl); -} - -static const struct rt_i2c_bit_ops ifx_bit_ops_default = -{ - .data = RT_NULL, - .pin_init = ifx_i2c_pin_init, - .set_sda = ifx_set_sda, - .set_scl = ifx_set_scl, - .get_sda = ifx_get_sda, - .get_scl = ifx_get_scl, - .udelay = rt_hw_us_delay, - .delay_us = 1, - .timeout = 100, - .i2c_pin_init_flag = RT_FALSE -}; - -/** - * if i2c is locked, this function will unlock it - * - * @param ifx config class - * - * @return RT_EOK indicates successful unlock. - */ -static rt_err_t ifx_i2c_bus_unlock(const struct ifx_soft_i2c_config *cfg) -{ - rt_int32_t i = 0; - - if (PIN_LOW == rt_pin_read(cfg->sda)) - { - while (i++ < 9) - { - rt_pin_write(cfg->scl, PIN_HIGH); - rt_hw_us_delay(100); - rt_pin_write(cfg->scl, PIN_LOW); - rt_hw_us_delay(100); - } - } - - if (PIN_LOW == rt_pin_read(cfg->sda)) - { - return -RT_ERROR; - } - - return RT_EOK; -} - -/* I2C initialization function */ -int rt_hw_i2c_init(void) -{ - rt_size_t obj_num = sizeof(i2c_obj) / sizeof(struct ifx_i2c); - rt_err_t result; - - for (int i = 0; i < obj_num; i++) - { - i2c_obj[i].ops = ifx_bit_ops_default; - i2c_obj[i].ops.data = (void *)&soft_i2c_config[i]; - i2c_obj[i].i2c_bus.priv = &i2c_obj[i].ops; - - result = rt_i2c_bit_add_bus(&i2c_obj[i].i2c_bus, soft_i2c_config[i].bus_name); - RT_ASSERT(result == RT_EOK); - ifx_i2c_bus_unlock(&soft_i2c_config[i]); - - LOG_D("software simulation %s init done, pin scl: %d, pin sda %d", - soft_i2c_config[i].bus_name, - soft_i2c_config[i].scl, - soft_i2c_config[i].sda); - } - - return RT_EOK; -} -INIT_BOARD_EXPORT(rt_hw_i2c_init); - -#endif /* RT_USING_I2C */ diff --git a/bsp/Infineon/libraries/HAL_Drivers/drv_soft_i2c.h b/bsp/Infineon/libraries/HAL_Drivers/drv_soft_i2c.h deleted file mode 100644 index 2e49a62c2f..0000000000 --- a/bsp/Infineon/libraries/HAL_Drivers/drv_soft_i2c.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2006-2024 RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2022-07-20 Rbb666 first version - */ - -#ifndef __DRV_I2C__ -#define __DRV_I2C__ - -#include <rtthread.h> -#include <rthw.h> -#include <rtdevice.h> - -/* ifx config class */ -struct ifx_soft_i2c_config -{ - rt_uint8_t scl; - rt_uint8_t sda; - const char *bus_name; -}; -/* ifx i2c dirver class */ -struct ifx_i2c -{ - struct rt_i2c_bit_ops ops; - struct rt_i2c_bus_device i2c_bus; -}; - -#ifdef BSP_USING_I2C1 -#define I2C1_BUS_CONFIG \ - { \ - .scl = BSP_I2C1_SCL_PIN, \ - .sda = BSP_I2C1_SDA_PIN, \ - .bus_name = "i2c1", \ - } -#endif - -int rt_hw_i2c_init(void); - -#endif diff --git a/bsp/Infineon/libraries/templates/PSOC62/.ci/attachconfig/ci.attachconfig.yml b/bsp/Infineon/libraries/templates/PSOC62/.ci/attachconfig/ci.attachconfig.yml new file mode 100644 index 0000000000..6cbc2bc3c3 --- /dev/null +++ b/bsp/Infineon/libraries/templates/PSOC62/.ci/attachconfig/ci.attachconfig.yml @@ -0,0 +1,8 @@ +devices.soft_i2c: + kconfig: + - CONFIG_RT_USING_I2C=y + - CONFIG_RT_USING_SOFT_I2C=y + - CONFIG_RT_USING_SOFT_I2C1=y + - CONFIG_RT_SOFT_I2C1_SCL_PIN=105 + - CONFIG_RT_SOFT_I2C1_SDA_PIN=106 + - CONFIG_RT_SOFT_I2C1_BUS_NAME="swi2c1" diff --git a/bsp/Infineon/libraries/templates/PSOC62/board/Kconfig b/bsp/Infineon/libraries/templates/PSOC62/board/Kconfig index 07a230d796..5a771696dd 100644 --- a/bsp/Infineon/libraries/templates/PSOC62/board/Kconfig +++ b/bsp/Infineon/libraries/templates/PSOC62/board/Kconfig @@ -173,29 +173,26 @@ menu "On-chip Peripheral Drivers" default 105 endif endif - - menuconfig BSP_USING_I2C - bool "Enable Software I2C Bus" + menuconfig BSP_USING_SOFT_I2C + bool "Enable software I2C (swi2c)" default n select RT_USING_I2C - select RT_USING_I2C_BITOPS - select RT_USING_PIN - if BSP_USING_I2C - config BSP_USING_I2C1 - bool "Enable I2C1 Bus (User I2C)" - default n - if BSP_USING_I2C1 - comment "Notice: P13_1 --> 105; P13_2 --> 106" - config BSP_I2C1_SCL_PIN - int "i2c1 SCL pin number" - range 1 113 - default 105 - config BSP_I2C1_SDA_PIN - int "i2c1 SDA pin number" - range 1 113 - default 106 - endif - endif + select RT_USING_SOFT_I2C + if BSP_USING_SOFT_I2C + menuconfig BSP_USING_SOFT_I2C1 + bool "Enable software I2C1 Bus (swi2c1)" + default n + select RT_USING_SOFT_I2C1 + if BSP_USING_SOFT_I2C1 + config RT_SOFT_I2C1_SCL_PIN + int "swi2c1 SCL pin number" + default 105 + config RT_SOFT_I2C1_SDA_PIN + int "swi2c1 SDA pin number" + default 106 + endif + endif + menuconfig BSP_USING_RTC bool "Enable RTC" @@ -250,4 +247,16 @@ menu "On-chip Peripheral Drivers" endif endmenu + config RT_SOFT_I2C1_HAS_PIN_DEFAULT + bool + default y if RT_USING_SOFT_I2C1 + + config RT_SOFT_I2C1_SCL_PIN_DEFAULT + int + default 105 if RT_USING_SOFT_I2C1 + + config RT_SOFT_I2C1_SDA_PIN_DEFAULT + int + default 106 if RT_USING_SOFT_I2C1 + endmenu |
