diff --git a/arch/xtensa/src/common/espressif/Kconfig b/arch/xtensa/src/common/espressif/Kconfig index bb67064159..51f44bf83f 100644 --- a/arch/xtensa/src/common/espressif/Kconfig +++ b/arch/xtensa/src/common/espressif/Kconfig @@ -23,6 +23,23 @@ config ESPRESSIF_TEMP ---help--- A built-in sensor used to measure the chip's internal temperature. +config ESPRESSIF_I2C_PERIPH + bool + depends on (ESP32S3_I2C0 || ESP32S3_I2C1) || (ESP32_I2C0 || ESP32_I2C1) || (ESP32S2_I2C0 || ESP32S2_I2C1) + default n + +config ESPRESSIF_I2C_BITBANG + bool "I2C Bitbang" + default n + select I2C_BITBANG + select ESP32S3_I2C if ARCH_CHIP_ESP32S3 + select ESP32S2_I2C if ARCH_CHIP_ESP32S2 + select ESP32_I2C if ARCH_CHIP_ESP32 + select I2C + select I2C_BITBANG + ---help--- + Software implemented I2C peripheral with GPIOs. Suggested to use if I2C peripherals are already in use. + config ESPRESSIF_SPIFLASH bool "SPI Flash" depends on ARCH_CHIP_ESP32S2 @@ -72,6 +89,21 @@ config ESPRESSIF_TEMP_THREAD_STACKSIZE endmenu # ESPRESSIF_TEMP +menu "I2C bitbang configuration" + depends on ESPRESSIF_I2C_BITBANG + +config ESPRESSIF_I2C_BITBANG_SCLPIN + int "I2C Bitbang SCL Pin" + default 0 + range 0 21 + +config ESPRESSIF_I2C_BITBANG_SDAPIN + int "I2C Bitbang SDA Pin" + default 1 + range 0 21 + +endmenu # I2C bitbang configuration + config ESPRESSIF_HAVE_OTA_PARTITION bool default n diff --git a/arch/xtensa/src/common/espressif/Make.defs b/arch/xtensa/src/common/espressif/Make.defs index 58b2a6f4b0..de328a5cf6 100644 --- a/arch/xtensa/src/common/espressif/Make.defs +++ b/arch/xtensa/src/common/espressif/Make.defs @@ -40,6 +40,10 @@ ifeq ($(CONFIG_ESPRESSIF_TEMP),y) CHIP_CSRCS += esp_temperature_sensor.c endif +ifeq ($(CONFIG_ESPRESSIF_I2C_BITBANG),y) +CHIP_CSRCS += esp_i2c_bitbang.c +endif + ifeq ($(CONFIG_ESPRESSIF_SPIFLASH),y) CHIP_CSRCS += esp_spiflash.c ifeq ($(CONFIG_ESPRESSIF_MTD),y) diff --git a/arch/xtensa/src/common/espressif/esp_i2c_bitbang.c b/arch/xtensa/src/common/espressif/esp_i2c_bitbang.c new file mode 100644 index 0000000000..5a2b851655 --- /dev/null +++ b/arch/xtensa/src/common/espressif/esp_i2c_bitbang.c @@ -0,0 +1,277 @@ +/**************************************************************************** + * arch/xtensa/src/common/espressif/esp_i2c_bitbang.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef CONFIG_ESPRESSIF_I2C_BITBANG +#include +#include +#include +#include + +#include "espressif/esp_i2c_bitbang.h" + +#if defined(CONFIG_ARCH_CHIP_ESP32S3) +#include "esp32s3_gpio.h" +#include "hardware/esp32s3_gpio_sigmap.h" +#elif defined(CONFIG_ARCH_CHIP_ESP32S2) +#include "esp32s2_gpio.h" +#include "esp32s2_gpio_sigmap.h" +#else +#include "esp32_gpio.h" +#include "esp32_gpio_sigmap.h" +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#if defined(CONFIG_ARCH_CHIP_ESP32S3) +#define CONFIG_GPIO(pin, attr) esp32s3_configgpio(pin, attr) +#define GPIO_MATRIX_OUT(pin, idx, inv, en_inv) esp32s3_gpio_matrix_out(pin, \ + idx, inv, en_inv) +#define GPIO_WRITE(pin, value) esp32s3_gpiowrite(pin, value) +#define GPIO_READ(pin) esp32s3_gpioread(pin) +#elif defined(CONFIG_ARCH_CHIP_ESP32S2) +#define CONFIG_GPIO(pin, attr) esp32s2_configgpio(pin, attr) +#define GPIO_MATRIX_OUT(pin, idx, inv, en_inv) esp32s2_gpio_matrix_out(pin, \ + idx, inv, en_inv) +#define GPIO_WRITE(pin, value) esp32s2_gpiowrite(pin, value) +#define GPIO_READ(pin) esp32s2_gpioread(pin) +#else +#define CONFIG_GPIO(pin, attr) esp32_configgpio(pin, attr) +#define GPIO_MATRIX_OUT(pin, idx, inv, en_inv) esp32_gpio_matrix_out(pin, \ + idx, inv, en_inv) +#define GPIO_WRITE(pin, value) esp32_gpiowrite(pin, value) +#define GPIO_READ(pin) esp3_gpioread(pin) +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct esp_i2c_bitbang_dev_s +{ + struct i2c_bitbang_lower_dev_s lower; + int sda_pin; + int scl_pin; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static void esp_i2c_bitbang_init(struct i2c_bitbang_lower_dev_s *lower); +static void esp_i2c_bitbang_set_scl(struct i2c_bitbang_lower_dev_s *lower, + bool value); +static void esp_i2c_bitbang_set_sda(struct i2c_bitbang_lower_dev_s *lower, + bool value); +static bool esp_i2c_bitbang_get_scl(struct i2c_bitbang_lower_dev_s *lower); +static bool esp_i2c_bitbang_get_sda(struct i2c_bitbang_lower_dev_s *lower); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* Lower-half I2C bitbang data */ + +const static struct i2c_bitbang_lower_ops_s g_ops = +{ + .initialize = esp_i2c_bitbang_init, + .set_scl = esp_i2c_bitbang_set_scl, + .set_sda = esp_i2c_bitbang_set_sda, + .get_scl = esp_i2c_bitbang_get_scl, + .get_sda = esp_i2c_bitbang_get_sda +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp_i2c_bitbang_init + * + * Description: + * Initialize the I2C bit-bang driver + * + * Input Parameters: + * lower - A pointer the publicly visible representation of + * the "lower-half" driver state structure. + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void esp_i2c_bitbang_init(struct i2c_bitbang_lower_dev_s *lower) +{ + struct esp_i2c_bitbang_dev_s *dev = lower->priv; + + GPIO_WRITE(dev->scl_pin, 1); + GPIO_WRITE(dev->sda_pin, 1); + + CONFIG_GPIO(dev->scl_pin, INPUT_PULLUP | OUTPUT_OPEN_DRAIN); + GPIO_MATRIX_OUT(dev->scl_pin, SIG_GPIO_OUT_IDX, 0, 0); + + CONFIG_GPIO(dev->sda_pin, INPUT_PULLUP | OUTPUT_OPEN_DRAIN); + GPIO_MATRIX_OUT(dev->sda_pin, SIG_GPIO_OUT_IDX, 0, 0); +} + +/**************************************************************************** + * Name: esp_i2c_bitbang_set_scl + * + * Description: + * Set SCL line value + * + * Input Parameters: + * lower - A pointer the publicly visible representation of + * the "lower-half" driver state structure. + * value - The value to be written (0 or 1). + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void esp_i2c_bitbang_set_scl(struct i2c_bitbang_lower_dev_s *lower, + bool value) +{ + struct esp_i2c_bitbang_dev_s *dev = + (struct esp_i2c_bitbang_dev_s *)lower->priv; + + GPIO_WRITE(dev->scl_pin, value); +} + +/**************************************************************************** + * Name: esp_i2c_bitbang_set_sda + * + * Description: + * Set SDA line value + * + * Input Parameters: + * lower - A pointer the publicly visible representation of + * the "lower-half" driver state structure. + * value - The value to be written (0 or 1). + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void esp_i2c_bitbang_set_sda(struct i2c_bitbang_lower_dev_s *lower, + bool value) +{ + struct esp_i2c_bitbang_dev_s *dev = + (struct esp_i2c_bitbang_dev_s *)lower->priv; + + GPIO_WRITE(dev->sda_pin, value); +} + +/**************************************************************************** + * Name: esp_i2c_bitbang_get_scl + * + * Description: + * Get value from SCL line + * + * Input Parameters: + * lower - A pointer the publicly visible representation of + * the "lower-half" driver state structure. + * + * Returned Value: + * The boolean representation of the SCL line value (true/false). + * + ****************************************************************************/ + +static bool esp_i2c_bitbang_get_scl(struct i2c_bitbang_lower_dev_s *lower) +{ + struct esp_i2c_bitbang_dev_s *dev = + (struct esp_i2c_bitbang_dev_s *)lower->priv; + + return GPIO_READ(dev->scl_pin); +} + +/**************************************************************************** + * Name: esp_i2c_bitbang_get_sda + * + * Description: + * Get value from SDA line + * + * Input Parameters: + * lower - A pointer the publicly visible representation of + * the "lower-half" driver state structure. + * + * Returned Value: + * The boolean representation of the SDA line value (true/false). + * + ****************************************************************************/ + +static bool esp_i2c_bitbang_get_sda(struct i2c_bitbang_lower_dev_s *lower) +{ + struct esp_i2c_bitbang_dev_s *dev = + (struct esp_i2c_bitbang_dev_s *)lower->priv; + + return GPIO_READ(dev->sda_pin); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp_i2cbus_bitbang_initialize + * + * Description: + * Initialize the I2C bitbang driver. And return a unique instance of + * struct struct i2c_master_s. This function may be called to obtain + * multiple instances of the interface, each of which may be set up with + * a different frequency and slave address. + * + * Input Parameters: + * None + * + * Returned Value: + * Valid I2C device structure reference on success; a NULL on failure + * + ****************************************************************************/ + +struct i2c_master_s *esp_i2cbus_bitbang_initialize(void) +{ + struct esp_i2c_bitbang_dev_s *dev = + (struct esp_i2c_bitbang_dev_s *) + kmm_malloc(sizeof(struct esp_i2c_bitbang_dev_s)); + + DEBUGASSERT(dev); + + dev->lower.ops = &g_ops; + dev->lower.priv = dev; + dev->scl_pin = CONFIG_ESPRESSIF_I2C_BITBANG_SCLPIN; + dev->sda_pin = CONFIG_ESPRESSIF_I2C_BITBANG_SDAPIN; + + return i2c_bitbang_initialize(&dev->lower); +} +#endif /* CONFIG_ESPRESSIF_I2C_BITBANG */ diff --git a/arch/xtensa/src/common/espressif/esp_i2c_bitbang.h b/arch/xtensa/src/common/espressif/esp_i2c_bitbang.h new file mode 100644 index 0000000000..6b3b6aed85 --- /dev/null +++ b/arch/xtensa/src/common/espressif/esp_i2c_bitbang.h @@ -0,0 +1,89 @@ +/**************************************************************************** + * arch/xtensa/src/common/espressif/esp_i2c_bitbang.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_XTENSA_SRC_COMMON_ESPRESSIF_ESP_I2C_BITBANG_H +#define __ARCH_XTENSA_SRC_COMMON_ESPRESSIF_ESP_I2C_BITBANG_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_ESPRESSIF_I2C_BITBANG +# define ESPRESSIF_I2C_BITBANG 3 +#endif + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef CONFIG_ESPRESSIF_I2C_BITBANG +/**************************************************************************** + * Name: esp_i2cbus_bitbang_initialize + * + * Description: + * Initialize the I2C bitbang driver. And return a unique instance of + * struct struct i2c_master_s. This function may be called to obtain + * multiple instances of the interface, each of which may be set up with + * a different frequency and slave address. + * + * Input Parameters: + * None + * + * Returned Value: + * Valid I2C device structure reference on success; a NULL on failure + * + ****************************************************************************/ + +struct i2c_master_s *esp_i2cbus_bitbang_initialize(void); +#endif + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __ARCH_XTENSA_SRC_COMMON_ESPRESSIF_ESP_I2C_BITBANG_H */ diff --git a/arch/xtensa/src/esp32/Kconfig b/arch/xtensa/src/esp32/Kconfig index 66390e6284..68c7a68ace 100644 --- a/arch/xtensa/src/esp32/Kconfig +++ b/arch/xtensa/src/esp32/Kconfig @@ -760,11 +760,13 @@ config ESP32_I2C0 bool "I2C 0" default n select ESP32_I2C + select ESPRESSIF_I2C_PERIPH config ESP32_I2C1 bool "I2C 1" default n select ESP32_I2C + select ESPRESSIF_I2C_PERIPH config ESP32_TWAI0 bool "TWAI (CAN) 0" @@ -1135,10 +1137,12 @@ endif # ESP32_I2C1 config ESP32_I2CTIMEOSEC int "Timeout seconds" default 0 + depends on ESPRESSIF_I2C_PERIPH config ESP32_I2CTIMEOMS int "Timeout milliseconds" default 500 + depends on ESPRESSIF_I2C_PERIPH endmenu # I2C configuration diff --git a/arch/xtensa/src/esp32/Make.defs b/arch/xtensa/src/esp32/Make.defs index 2980a85737..ad4f9112c9 100644 --- a/arch/xtensa/src/esp32/Make.defs +++ b/arch/xtensa/src/esp32/Make.defs @@ -75,8 +75,10 @@ CHIP_CSRCS += esp32_ledc.c endif ifeq ($(CONFIG_ESP32_I2C),y) +ifeq ($(CONFIG_ESPRESSIF_I2C_PERIPH),y) CHIP_CSRCS += esp32_i2c.c endif +endif ifeq ($(CONFIG_ESP32_I2S),y) CHIP_CSRCS += esp32_i2s.c diff --git a/arch/xtensa/src/esp32/esp32_i2c.c b/arch/xtensa/src/esp32/esp32_i2c.c index 8fc3b581f5..211081c8fe 100644 --- a/arch/xtensa/src/esp32/esp32_i2c.c +++ b/arch/xtensa/src/esp32/esp32_i2c.c @@ -24,7 +24,7 @@ #include -#ifdef CONFIG_ESP32_I2C +#ifdef CONFIG_ESPRESSIF_I2C_PERIPH #include #include @@ -1569,4 +1569,4 @@ int esp32_i2cbus_uninitialize(struct i2c_master_s *dev) return OK; } -#endif /* CONFIG_ESP32_I2C */ +#endif /* CONFIG_ESPRESSIF_I2C_PERIPH */ diff --git a/arch/xtensa/src/esp32/esp32_i2c.h b/arch/xtensa/src/esp32/esp32_i2c.h index 38078fab9e..32687318ef 100644 --- a/arch/xtensa/src/esp32/esp32_i2c.h +++ b/arch/xtensa/src/esp32/esp32_i2c.h @@ -55,6 +55,7 @@ extern "C" * Public Function Prototypes ****************************************************************************/ +#ifdef CONFIG_ESPRESSIF_I2C_PERIPH /**************************************************************************** * Name: esp32_i2cbus_initialize * @@ -90,6 +91,7 @@ struct i2c_master_s *esp32_i2cbus_initialize(int port); ****************************************************************************/ int esp32_i2cbus_uninitialize(struct i2c_master_s *dev); +#endif /* CONFIG_ESPRESSIF_I2C_PERIPH */ #ifdef __cplusplus } diff --git a/arch/xtensa/src/esp32s2/Kconfig b/arch/xtensa/src/esp32s2/Kconfig index 0afe64c8b2..a6a257d3a7 100644 --- a/arch/xtensa/src/esp32s2/Kconfig +++ b/arch/xtensa/src/esp32s2/Kconfig @@ -471,12 +471,14 @@ config ESP32S2_I2C0 default n select ESP32S2_I2C select I2C + select ESPRESSIF_I2C_PERIPH config ESP32S2_I2C1 bool "I2C 1" default n select ESP32S2_I2C select I2C + select ESPRESSIF_I2C_PERIPH config ESP32S2_TWAI bool "TWAI (CAN)" @@ -791,10 +793,12 @@ endif # ESP32S2_I2C1 config ESP32S2_I2CTIMEOSEC int "Timeout seconds" default 0 + depends on ESPRESSIF_I2C_PERIPH config ESP32S2_I2CTIMEOMS int "Timeout milliseconds" default 500 + depends on ESPRESSIF_I2C_PERIPH endmenu # I2C Configuration diff --git a/arch/xtensa/src/esp32s2/Make.defs b/arch/xtensa/src/esp32s2/Make.defs index 5328d62dec..fffbc8a12a 100644 --- a/arch/xtensa/src/esp32s2/Make.defs +++ b/arch/xtensa/src/esp32s2/Make.defs @@ -54,8 +54,10 @@ CHIP_CSRCS += esp32s2_rng.c endif ifeq ($(CONFIG_ESP32S2_I2C),y) +ifeq ($(CONFIG_ESPRESSIF_I2C_PERIPH),y) CHIP_CSRCS += esp32s2_i2c.c endif +endif ifeq ($(CONFIG_ESP32S2_I2S),y) CHIP_CSRCS += esp32s2_i2s.c diff --git a/arch/xtensa/src/esp32s2/esp32s2_i2c.c b/arch/xtensa/src/esp32s2/esp32s2_i2c.c index 6a0d290449..d0c4f323ce 100644 --- a/arch/xtensa/src/esp32s2/esp32s2_i2c.c +++ b/arch/xtensa/src/esp32s2/esp32s2_i2c.c @@ -24,7 +24,7 @@ #include -#ifdef CONFIG_ESP32S2_I2C +#ifdef CONFIG_ESPRESSIF_I2C_PERIPH #include #include @@ -1613,4 +1613,4 @@ int esp32s2_i2cbus_uninitialize(struct i2c_master_s *dev) return OK; } -#endif /* CONFIG_ESP32S2_I2C */ +#endif /* CONFIG_ESPRESSIF_I2C_PERIPH */ diff --git a/arch/xtensa/src/esp32s2/esp32s2_i2c.h b/arch/xtensa/src/esp32s2/esp32s2_i2c.h index 51df9472f6..1e480a9ad5 100644 --- a/arch/xtensa/src/esp32s2/esp32s2_i2c.h +++ b/arch/xtensa/src/esp32s2/esp32s2_i2c.h @@ -51,6 +51,7 @@ * Public Function Prototypes ****************************************************************************/ +#ifdef CONFIG_ESPRESSIF_I2C_PERIPH /**************************************************************************** * Name: esp32s2_i2cbus_initialize * @@ -86,6 +87,7 @@ struct i2c_master_s *esp32s2_i2cbus_initialize(int port); ****************************************************************************/ int esp32s2_i2cbus_uninitialize(struct i2c_master_s *dev); +#endif /* CONFIG_ESPRESSIF_I2C_PERIPH */ #endif /* __ASSEMBLY__ */ #endif /* __ARCH_XTENSA_SRC_ESP32S2_ESP32S2_I2C_H */ diff --git a/arch/xtensa/src/esp32s3/Kconfig b/arch/xtensa/src/esp32s3/Kconfig index f76bbdd9f3..18b888c5da 100644 --- a/arch/xtensa/src/esp32s3/Kconfig +++ b/arch/xtensa/src/esp32s3/Kconfig @@ -683,12 +683,14 @@ config ESP32S3_I2C0 default n select ESP32S3_I2C select I2C + select ESPRESSIF_I2C_PERIPH config ESP32S3_I2C1 bool "I2C 1" default n select ESP32S3_I2C select I2C + select ESPRESSIF_I2C_PERIPH config ESP32S3_TWAI bool "TWAI (CAN)" @@ -1430,10 +1432,12 @@ endif # ESP32S3_I2C1 config ESP32S3_I2CTIMEOSEC int "Timeout seconds" default 0 + depends on ESPRESSIF_I2C_PERIPH config ESP32S3_I2CTIMEOMS int "Timeout milliseconds" default 500 + depends on ESPRESSIF_I2C_PERIPH endmenu # I2C Configuration diff --git a/arch/xtensa/src/esp32s3/Make.defs b/arch/xtensa/src/esp32s3/Make.defs index 4a9c9d3420..358be60518 100644 --- a/arch/xtensa/src/esp32s3/Make.defs +++ b/arch/xtensa/src/esp32s3/Make.defs @@ -114,8 +114,10 @@ CHIP_CSRCS += esp32s3_adc.c endif ifeq ($(CONFIG_ESP32S3_I2C),y) +ifeq ($(CONFIG_ESPRESSIF_I2C_PERIPH),y) CHIP_CSRCS += esp32s3_i2c.c endif +endif ifeq ($(CONFIG_ESP32S3_I2S),y) CHIP_CSRCS += esp32s3_i2s.c diff --git a/arch/xtensa/src/esp32s3/esp32s3_i2c.c b/arch/xtensa/src/esp32s3/esp32s3_i2c.c index 25526ab21c..f78532181b 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_i2c.c +++ b/arch/xtensa/src/esp32s3/esp32s3_i2c.c @@ -24,7 +24,7 @@ #include -#ifdef CONFIG_ESP32S3_I2C +#ifdef CONFIG_ESPRESSIF_I2C_PERIPH #include #include @@ -1647,4 +1647,4 @@ int esp32s3_i2cbus_uninitialize(struct i2c_master_s *dev) return OK; } -#endif /* CONFIG_ESP32S3_I2C */ +#endif /* CONFIG_ESPRESSIF_I2C_PERIPH */ diff --git a/arch/xtensa/src/esp32s3/esp32s3_i2c.h b/arch/xtensa/src/esp32s3/esp32s3_i2c.h index 3787b07ccf..e4edaeca87 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_i2c.h +++ b/arch/xtensa/src/esp32s3/esp32s3_i2c.h @@ -51,6 +51,7 @@ * Public Function Prototypes ****************************************************************************/ +#ifdef CONFIG_ESPRESSIF_I2C_PERIPH /**************************************************************************** * Name: esp32s3_i2cbus_initialize * @@ -86,6 +87,7 @@ struct i2c_master_s *esp32s3_i2cbus_initialize(int port); ****************************************************************************/ int esp32s3_i2cbus_uninitialize(struct i2c_master_s *dev); +#endif /* CONFIG_ESPRESSIF_I2C_PERIPH */ #endif /* __ASSEMBLY__ */ #endif /* __ARCH_XTENSA_SRC_ESP32S3_ESP32S3_I2C_H */ diff --git a/boards/xtensa/esp32s3/common/src/esp32s3_board_i2c.c b/boards/xtensa/esp32s3/common/src/esp32s3_board_i2c.c index 30f7c3b66b..d842ce3b81 100644 --- a/boards/xtensa/esp32s3/common/src/esp32s3_board_i2c.c +++ b/boards/xtensa/esp32s3/common/src/esp32s3_board_i2c.c @@ -30,12 +30,41 @@ #include +#ifdef CONFIG_ESPRESSIF_I2C_BITBANG +#include "espressif/esp_i2c_bitbang.h" +#endif +#ifdef CONFIG_ESPRESSIF_I2C_PERIPH #include "esp32s3_i2c.h" +#endif /**************************************************************************** * Public Functions ****************************************************************************/ +#ifdef CONFIG_ESPRESSIF_I2C_BITBANG +static int i2c_bitbang_driver_init(int bus) +{ + struct i2c_master_s *i2c; + int ret; + + i2c = esp_i2cbus_bitbang_initialize(); + if (i2c == NULL) + { + i2cerr("Failed to get I2C%d interface\n", bus); + return -ENODEV; + } + + ret = i2c_register(i2c, bus); + if (ret < 0) + { + i2cerr("Failed to register I2C%d driver: %d\n", bus, ret); + } + + return ret; +} +#endif + +#ifdef CONFIG_ESPRESSIF_I2C_PERIPH static int i2c_driver_init(int bus) { struct i2c_master_s *i2c; @@ -57,6 +86,7 @@ static int i2c_driver_init(int bus) return ret; } +#endif /**************************************************************************** * Name: board_i2c_init @@ -86,6 +116,10 @@ int board_i2c_init(void) ret = i2c_driver_init(ESP32S3_I2C1); #endif +#ifdef CONFIG_ESPRESSIF_I2C_BITBANG + ret = i2c_bitbang_driver_init(ESPRESSIF_I2C_BITBANG); +#endif + #ifdef CONFIG_ESP32S3_I2C0 done: #endif