From ddc0d300630d4db7a206aeb3b214fac55b820b0b Mon Sep 17 00:00:00 2001 From: Sara Souza Date: Mon, 26 Oct 2020 09:37:48 -0300 Subject: [PATCH] xtensa/esp32: Added Userled support --- boards/Kconfig | 1 + .../esp32/esp32-core/configs/leds/defconfig | 52 +++++++++++ .../esp32-core/configs/mmcsdspi/defconfig | 1 + .../esp32/esp32-core/configs/netnsh/defconfig | 1 + .../esp32/esp32-core/configs/nsh/defconfig | 1 + .../esp32/esp32-core/configs/ostest/defconfig | 1 + .../esp32/esp32-core/configs/pm/defconfig | 1 + .../esp32/esp32-core/configs/psram/defconfig | 1 + .../esp32/esp32-core/configs/random/defconfig | 1 + .../esp32/esp32-core/configs/smp/defconfig | 1 + .../esp32-core/configs/spiflash/defconfig | 1 + .../esp32/esp32-core/configs/timer/defconfig | 1 + .../esp32/esp32-core/configs/wapi/defconfig | 1 + .../xtensa/esp32/esp32-core/include/board.h | 7 ++ boards/xtensa/esp32/esp32-core/src/Makefile | 4 + .../esp32/esp32-core/src/esp32_bringup.c | 15 +++ .../esp32/esp32-core/src/esp32_userleds.c | 91 +++++++++++++++++++ 17 files changed, 181 insertions(+) create mode 100644 boards/xtensa/esp32/esp32-core/configs/leds/defconfig create mode 100644 boards/xtensa/esp32/esp32-core/src/esp32_userleds.c diff --git a/boards/Kconfig b/boards/Kconfig index 2c39f78184..d013b8bbd2 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -191,6 +191,7 @@ config ARCH_BOARD_QUICKFEATHER config ARCH_BOARD_ESP32CORE bool "Espressif ESP32 Core board V2" depends on ARCH_CHIP_ESP32 + select ARCH_HAVE_LEDS ---help--- The ESP32 is a dual-core system from Espressif with two Harvard architecture Xtensa LX6 CPUs. All embedded memory, external memory diff --git a/boards/xtensa/esp32/esp32-core/configs/leds/defconfig b/boards/xtensa/esp32/esp32-core/configs/leds/defconfig new file mode 100644 index 0000000000..bd9aa5ec10 --- /dev/null +++ b/boards/xtensa/esp32/esp32-core/configs/leds/defconfig @@ -0,0 +1,52 @@ +# +# 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="esp32-core" +CONFIG_ARCH_BOARD_ESP32CORE=y +CONFIG_ARCH_CHIP="esp32" +CONFIG_ARCH_CHIP_ESP32=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH_XTENSA=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_ESP32_UART0=y +CONFIG_EXAMPLES_LEDS=y +CONFIG_EXPERIMENTAL=y +CONFIG_FS_PROCFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_IDLETHREAD_STACKSIZE=3072 +CONFIG_INTELHEX_BINARY=y +CONFIG_MAX_TASKS=16 +CONFIG_MM_REGIONS=2 +CONFIG_NFILE_DESCRIPTORS=8 +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_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_SDCLONE_DISABLE=y +CONFIG_SPI=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSTEM_NSH=y +CONFIG_UART0_SERIAL_CONSOLE=y +CONFIG_USERLED=y +CONFIG_USERLED_LOWER=y +CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/boards/xtensa/esp32/esp32-core/configs/mmcsdspi/defconfig b/boards/xtensa/esp32/esp32-core/configs/mmcsdspi/defconfig index 368a307717..e711c8dccf 100644 --- a/boards/xtensa/esp32/esp32-core/configs/mmcsdspi/defconfig +++ b/boards/xtensa/esp32/esp32-core/configs/mmcsdspi/defconfig @@ -5,6 +5,7 @@ # You can then do "make savedefconfig" to generate a new defconfig file that includes your # modifications. # +# CONFIG_ARCH_LEDS is not set # CONFIG_ESP32_SPI2_DMA is not set # CONFIG_MMCSD_HAVE_CARDDETECT is not set # CONFIG_MMCSD_HAVE_WRITEPROTECT is not set diff --git a/boards/xtensa/esp32/esp32-core/configs/netnsh/defconfig b/boards/xtensa/esp32/esp32-core/configs/netnsh/defconfig index 00410ad835..c7b0b7d861 100644 --- a/boards/xtensa/esp32/esp32-core/configs/netnsh/defconfig +++ b/boards/xtensa/esp32/esp32-core/configs/netnsh/defconfig @@ -5,6 +5,7 @@ # 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 diff --git a/boards/xtensa/esp32/esp32-core/configs/nsh/defconfig b/boards/xtensa/esp32/esp32-core/configs/nsh/defconfig index de68aa1184..0579ffbb9e 100644 --- a/boards/xtensa/esp32/esp32-core/configs/nsh/defconfig +++ b/boards/xtensa/esp32/esp32-core/configs/nsh/defconfig @@ -5,6 +5,7 @@ # 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 diff --git a/boards/xtensa/esp32/esp32-core/configs/ostest/defconfig b/boards/xtensa/esp32/esp32-core/configs/ostest/defconfig index 6538e2e98f..4796e33983 100644 --- a/boards/xtensa/esp32/esp32-core/configs/ostest/defconfig +++ b/boards/xtensa/esp32/esp32-core/configs/ostest/defconfig @@ -5,6 +5,7 @@ # You can then do "make savedefconfig" to generate a new defconfig file that includes your # modifications. # +# CONFIG_ARCH_LEDS is not set CONFIG_ARCH="xtensa" CONFIG_ARCH_BOARD="esp32-core" CONFIG_ARCH_BOARD_ESP32CORE=y diff --git a/boards/xtensa/esp32/esp32-core/configs/pm/defconfig b/boards/xtensa/esp32/esp32-core/configs/pm/defconfig index bb5baed139..b2c89ae4bf 100644 --- a/boards/xtensa/esp32/esp32-core/configs/pm/defconfig +++ b/boards/xtensa/esp32/esp32-core/configs/pm/defconfig @@ -5,6 +5,7 @@ # 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 diff --git a/boards/xtensa/esp32/esp32-core/configs/psram/defconfig b/boards/xtensa/esp32/esp32-core/configs/psram/defconfig index 30112e74b8..a19ba54570 100644 --- a/boards/xtensa/esp32/esp32-core/configs/psram/defconfig +++ b/boards/xtensa/esp32/esp32-core/configs/psram/defconfig @@ -5,6 +5,7 @@ # 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 diff --git a/boards/xtensa/esp32/esp32-core/configs/random/defconfig b/boards/xtensa/esp32/esp32-core/configs/random/defconfig index 569d5f9031..88d0018193 100644 --- a/boards/xtensa/esp32/esp32-core/configs/random/defconfig +++ b/boards/xtensa/esp32/esp32-core/configs/random/defconfig @@ -5,6 +5,7 @@ # 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 diff --git a/boards/xtensa/esp32/esp32-core/configs/smp/defconfig b/boards/xtensa/esp32/esp32-core/configs/smp/defconfig index 5f56206d80..151dcd0742 100644 --- a/boards/xtensa/esp32/esp32-core/configs/smp/defconfig +++ b/boards/xtensa/esp32/esp32-core/configs/smp/defconfig @@ -5,6 +5,7 @@ # 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 diff --git a/boards/xtensa/esp32/esp32-core/configs/spiflash/defconfig b/boards/xtensa/esp32/esp32-core/configs/spiflash/defconfig index a93ff5c55d..fd391d3be5 100644 --- a/boards/xtensa/esp32/esp32-core/configs/spiflash/defconfig +++ b/boards/xtensa/esp32/esp32-core/configs/spiflash/defconfig @@ -5,6 +5,7 @@ # 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 diff --git a/boards/xtensa/esp32/esp32-core/configs/timer/defconfig b/boards/xtensa/esp32/esp32-core/configs/timer/defconfig index 9c63edecd5..0c3487ff34 100644 --- a/boards/xtensa/esp32/esp32-core/configs/timer/defconfig +++ b/boards/xtensa/esp32/esp32-core/configs/timer/defconfig @@ -5,6 +5,7 @@ # 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 diff --git a/boards/xtensa/esp32/esp32-core/configs/wapi/defconfig b/boards/xtensa/esp32/esp32-core/configs/wapi/defconfig index f982ac0316..ae49d45e93 100644 --- a/boards/xtensa/esp32/esp32-core/configs/wapi/defconfig +++ b/boards/xtensa/esp32/esp32-core/configs/wapi/defconfig @@ -5,6 +5,7 @@ # 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 diff --git a/boards/xtensa/esp32/esp32-core/include/board.h b/boards/xtensa/esp32/esp32-core/include/board.h index b8bcc1aede..ce904527c3 100644 --- a/boards/xtensa/esp32/esp32-core/include/board.h +++ b/boards/xtensa/esp32/esp32-core/include/board.h @@ -85,4 +85,11 @@ #endif #endif +/* LED definitions **********************************************************/ + +/* Define how many LEDs this board has (needed by userleds) */ + +#define BOARD_NLEDS 1 +#define GPIO_LED1 2 + #endif /* __BOARDS_XTENSA_ESP32_ESP32_CORE_INCLUDE_BOARD_H */ diff --git a/boards/xtensa/esp32/esp32-core/src/Makefile b/boards/xtensa/esp32/esp32-core/src/Makefile index 6c51a74c1c..4b7204fb08 100644 --- a/boards/xtensa/esp32/esp32-core/src/Makefile +++ b/boards/xtensa/esp32/esp32-core/src/Makefile @@ -66,6 +66,10 @@ CSRCS += esp32_timer.c endif endif +ifeq ($(CONFIG_USERLED),y) + CSRCS += esp32_userleds.c +endif + SCRIPTIN = $(SCRIPTDIR)$(DELIM)esp32.template.ld SCRIPTOUT = $(SCRIPTDIR)$(DELIM)esp32_out.ld diff --git a/boards/xtensa/esp32/esp32-core/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-core/src/esp32_bringup.c index c2847b6c37..9723d3ef89 100644 --- a/boards/xtensa/esp32/esp32-core/src/esp32_bringup.c +++ b/boards/xtensa/esp32/esp32-core/src/esp32_bringup.c @@ -53,6 +53,11 @@ #ifdef CONFIG_TIMER # include #endif + +#ifdef CONFIG_USERLED +# include +#endif + #include #include @@ -244,6 +249,16 @@ int esp32_bringup(void) #endif #endif +#ifdef CONFIG_USERLED + /* Register the LED driver */ + + ret = userled_lower_initialize("/dev/userleds"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %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. diff --git a/boards/xtensa/esp32/esp32-core/src/esp32_userleds.c b/boards/xtensa/esp32/esp32-core/src/esp32_userleds.c new file mode 100644 index 0000000000..3a0b7654b5 --- /dev/null +++ b/boards/xtensa/esp32/esp32-core/src/esp32_userleds.c @@ -0,0 +1,91 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-core/src/esp32_userleds.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 + +#include +#include +#include +#include +#include "esp32_gpio.h" +#include "esp32-core.h" +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* This array maps an LED number to GPIO pin configuration */ + +static const uint32_t g_ledcfg[BOARD_NLEDS] = +{ + GPIO_LED1, +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_userled_initialize + ****************************************************************************/ + +uint32_t board_userled_initialize(void) +{ + uint8_t i; + + for (i = 0; i < BOARD_NLEDS; i++) + { + esp32_configgpio(g_ledcfg[i], OUTPUT); + } + + return BOARD_NLEDS; +} + +/**************************************************************************** + * Name: board_userled + ****************************************************************************/ + +void board_userled(int led, bool ledon) +{ + if ((unsigned)led < BOARD_NLEDS) + { + esp32_gpiowrite(g_ledcfg[led], ledon); + } +} + +/**************************************************************************** + * Name: board_userled_all + ****************************************************************************/ + +void board_userled_all(uint32_t ledset) +{ + uint8_t i; + + /* Configure LED1-8 GPIOs for output */ + + for (i = 0; i < BOARD_NLEDS; i++) + { + esp32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0); + } +} +