This is an automated email from the ASF dual-hosted git repository. pkarashchenko pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 01b3ddd22f50ee865009d0eb0f624fb7e1b1a6d0 Author: Gustavo Henrique Nihei <[email protected]> AuthorDate: Wed Jun 15 15:49:35 2022 -0300 esp32s2-saola-1: Add support for I2C chardev driver Signed-off-by: Gustavo Henrique Nihei <[email protected]> --- .../esp32s2/esp32s2-saola-1/configs/i2c/defconfig | 60 ++++++++++++++ .../xtensa/esp32s2/esp32s2-saola-1/src/Make.defs | 4 + .../esp32s2/esp32s2-saola-1/src/esp32s2-saola-1.h | 16 ++++ .../esp32s2-saola-1/src/esp32s2_board_i2c.c | 93 ++++++++++++++++++++++ .../esp32s2/esp32s2-saola-1/src/esp32s2_bringup.c | 10 +++ 5 files changed, 183 insertions(+) diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/i2c/defconfig b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/i2c/defconfig new file mode 100644 index 0000000000..66de620ab0 --- /dev/null +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/i2c/defconfig @@ -0,0 +1,60 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_ARCH_LEDS is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +# CONFIG_NSH_CMDPARMS is not set +CONFIG_ARCH="xtensa" +CONFIG_ARCH_BOARD="esp32s2-saola-1" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32S2_SAOLA_1=y +CONFIG_ARCH_CHIP="esp32s2" +CONFIG_ARCH_CHIP_ESP32S2=y +CONFIG_ARCH_CHIP_ESP32S2WROVER=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH_XTENSA=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_DEBUG_ASSERTIONS=y +CONFIG_DEBUG_ERROR=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_I2C=y +CONFIG_DEBUG_I2C_ERROR=y +CONFIG_DEBUG_I2C_INFO=y +CONFIG_DEBUG_I2C_WARN=y +CONFIG_DEBUG_INFO=y +CONFIG_DEBUG_WARN=y +CONFIG_ESP32S2_I2C0=y +CONFIG_ESP32S2_I2C1=y +CONFIG_ESP32S2_UART0=y +CONFIG_FS_PROCFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_I2CTOOL_DEFFREQ=100000 +CONFIG_I2CTOOL_MAXBUS=1 +CONFIG_I2C_RESET=y +CONFIG_I2C_TRACE=y +CONFIG_IDLETHREAD_STACKSIZE=3072 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INTELHEX_BINARY=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=114688 +CONFIG_RAM_START=0x20000000 +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_START_DAY=28 +CONFIG_START_MONTH=6 +CONFIG_START_YEAR=2022 +CONFIG_SYSTEM_I2CTOOL=y +CONFIG_SYSTEM_NSH=y +CONFIG_UART0_SERIAL_CONSOLE=y diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/src/Make.defs b/boards/xtensa/esp32s2/esp32s2-saola-1/src/Make.defs index 23737b3157..43ce38abba 100644 --- a/boards/xtensa/esp32s2/esp32s2-saola-1/src/Make.defs +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/src/Make.defs @@ -41,6 +41,10 @@ ifeq ($(CONFIG_ONESHOT),y) CSRCS += esp32s2_oneshot.c endif +ifeq ($(CONFIG_I2C_DRIVER),y) +CSRCS += esp32s2_board_i2c.c +endif + SCRIPTIN = $(SCRIPTDIR)$(DELIM)esp32s2.template.ld SCRIPTOUT = $(SCRIPTDIR)$(DELIM)esp32s2_out.ld diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2-saola-1.h b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2-saola-1.h index 35bb4e25bc..89f5263a28 100644 --- a/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2-saola-1.h +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2-saola-1.h @@ -117,5 +117,21 @@ int esp32s2_gpio_init(void); int board_oneshot_init(int timer, uint16_t resolution); #endif +/**************************************************************************** + * Name: board_i2c_init + * + * Description: + * Configure the I2C driver. + * + * Returned Value: + * Zero (OK) is returned on success; A negated errno value is returned + * to indicate the nature of any failure. + * + ****************************************************************************/ + +#ifdef CONFIG_I2C_DRIVER +int board_i2c_init(void); +#endif + #endif /* __ASSEMBLY__ */ #endif /* __BOARDS_XTENSA_ESP32S2_ESP32S2_SAOLA_1_SRC_ESP32S2_SAOLA_1_H */ diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_board_i2c.c b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_board_i2c.c new file mode 100644 index 0000000000..8b6f4f73c6 --- /dev/null +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_board_i2c.c @@ -0,0 +1,93 @@ +/**************************************************************************** + * boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_board_i2c.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 <nuttx/config.h> + +#include <debug.h> +#include <errno.h> +#include <sys/types.h> + +#include <nuttx/i2c/i2c_master.h> + +#include "esp32s2_i2c.h" +#include "esp32s2-saola-1.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static int i2c_driver_init(int bus) +{ + struct i2c_master_s *i2c; + int ret; + + i2c = esp32s2_i2cbus_initialize(bus); + 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); + esp32s2_i2cbus_uninitialize(i2c); + } + + return ret; +} + +/**************************************************************************** + * Name: board_i2c_init + * + * Description: + * Configure the I2C driver. + * + * Returned Value: + * Zero (OK) is returned on success; A negated errno value is returned + * to indicate the nature of any failure. + * + ****************************************************************************/ + +int board_i2c_init(void) +{ + int ret = OK; + +#ifdef CONFIG_ESP32S2_I2C0 + ret = i2c_driver_init(ESP32S2_I2C0); + if (ret != OK) + { + goto done; + } +#endif + +#ifdef CONFIG_ESP32S2_I2C1 + ret = i2c_driver_init(ESP32S2_I2C1); +#endif + +done: + return ret; +} + diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bringup.c b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bringup.c index 198ca5c767..7835f1bf40 100644 --- a/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bringup.c +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bringup.c @@ -192,6 +192,16 @@ int esp32s2_bringup(void) #endif /* CONFIG_ONESHOT */ +#ifdef CONFIG_I2C_DRIVER + /* Configure I2C peripheral interfaces */ + + ret = board_i2c_init(); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize I2C driver: %d\n", ret); + } +#endif + /* If we got here then perhaps not all initialization was successful, but * at least enough succeeded to bring-up NSH with perhaps reduced * capabilities.
