diff --git a/boards/xtensa/esp32/esp32-wrover-kit/include/board.h b/boards/xtensa/esp32/esp32-wrover-kit/include/board.h index 78a0c480d1..85c5e07b68 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/include/board.h +++ b/boards/xtensa/esp32/esp32-wrover-kit/include/board.h @@ -76,7 +76,33 @@ /* Define how many LEDs this board has (needed by userleds) */ -#define BOARD_NLEDS 1 -#define GPIO_LED1 2 +#define BOARD_LED1 0 +#define BOARD_LED2 1 +#define BOARD_LED3 2 +#define BOARD_NLEDS 3 + +#define BOARD_LED_RED BOARD_LED1 +#define BOARD_LED_GREEN BOARD_LED2 +#define BOARD_LED_BLUE BOARD_LED3 + +/* LED bits for use with autoleds */ + +#define BOARD_LED1_BIT (1 << BOARD_LED1) +#define BOARD_LED2_BIT (1 << BOARD_LED2) +#define BOARD_LED3_BIT (1 << BOARD_LED3) + +/* If CONFIG_ARCH_LEDs is defined, then NuttX will control the 3 LEDs on + * board the ESP-WROVER-KIT. The following definitions describe how + * NuttX controls the LEDs: + */ + +#define LED_STARTED 0 /* LED2 */ +#define LED_HEAPALLOCATE 1 /* LED3 */ +#define LED_IRQSENABLED 2 /* LED3 + LED2 */ +#define LED_STACKCREATED 3 /* LED3 */ +#define LED_INIRQ 4 /* LED1 + LED3 */ +#define LED_SIGNAL 5 /* LED2 + LED3 */ +#define LED_ASSERTION 6 /* LED1 + LED2 + LED3 */ +#define LED_PANIC 7 /* LED1 + N/C + N/C */ #endif /* __BOARDS_XTENSA_ESP32_ESP32_WROVER_KIT_INCLUDE_BOARD_H */ diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs b/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs index 2b5f8b2769..9ec3df22b2 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs +++ b/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs @@ -26,6 +26,12 @@ CONFIGFILE = $(TOPDIR)$(DELIM)include$(DELIM)nuttx$(DELIM)config.h CSRCS = esp32_boot.c esp32_bringup.c +ifeq ($(CONFIG_ARCH_LEDS),y) +CSRCS += esp32_autoleds.c +else +CSRCS += esp32_userleds.c +endif + ifeq ($(CONFIG_LIB_BOARDCTL),y) CSRCS += esp32_appinit.c ifeq ($(CONFIG_BOARDCTL_RESET),y) @@ -45,10 +51,6 @@ ifeq ($(CONFIG_ESP32_SPIFLASH),y) CSRCS += esp32_spiflash.c 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-wrover-kit/src/esp32-wrover-kit.h b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32-wrover-kit.h index 943247aea3..de618bd1bc 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32-wrover-kit.h +++ b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32-wrover-kit.h @@ -33,6 +33,14 @@ * Pre-processor Definitions ****************************************************************************/ +/* ESP-WROVER-KIT GPIOs *****************************************************/ + +/* LEDs */ + +#define GPIO_LED1 0 +#define GPIO_LED2 2 +#define GPIO_LED3 4 + /**************************************************************************** * Public Types ****************************************************************************/ @@ -68,6 +76,7 @@ int esp32_bringup(void); * * Description: * Initialize SPI-based SD card and card detect thread. + * ****************************************************************************/ int esp32_mmcsd_initialize(int minor); diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_autoleds.c b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_autoleds.c new file mode 100644 index 0000000000..eeedc32bc5 --- /dev/null +++ b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_autoleds.c @@ -0,0 +1,147 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-wrover-kit/src/esp32_autoleds.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 + +#include "esp32_gpio.h" +#include "esp32-wrover-kit.h" + +#ifdef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* The following definitions map the encoded LED setting to GPIO settings */ + +#define LED_STARTED_BITS (BOARD_LED2_BIT) +#define LED_HEAPALLOCATE_BITS (BOARD_LED3_BIT) +#define LED_IRQSENABLED_BITS (BOARD_LED3_BIT | BOARD_LED2_BIT) +#define LED_STACKCREATED_BITS (BOARD_LED3_BIT) +#define LED_INIRQ_BITS (BOARD_LED1_BIT | BOARD_LED3_BIT) +#define LED_SIGNAL_BITS (BOARD_LED2_BIT | BOARD_LED3_BIT) +#define LED_ASSERTION_BITS (BOARD_LED1_BIT | BOARD_LED2_BIT |\ + BOARD_LED3_BIT) +#define LED_PANIC_BITS (BOARD_LED1_BIT) + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const unsigned int g_ledbits[8] = +{ + LED_STARTED_BITS, + LED_HEAPALLOCATE_BITS, + LED_IRQSENABLED_BITS, + LED_STACKCREATED_BITS, + LED_INIRQ_BITS, + LED_SIGNAL_BITS, + LED_ASSERTION_BITS, + LED_PANIC_BITS +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static inline void led_clrbits(unsigned int clrbits) +{ + if ((clrbits & BOARD_LED1_BIT) != 0) + { + esp32_gpiowrite(GPIO_LED1, false); + } + + if ((clrbits & BOARD_LED2_BIT) != 0) + { + esp32_gpiowrite(GPIO_LED2, false); + } + + if ((clrbits & BOARD_LED3_BIT) != 0) + { + esp32_gpiowrite(GPIO_LED3, false); + } +} + +static inline void led_setbits(unsigned int setbits) +{ + if ((setbits & BOARD_LED1_BIT) != 0) + { + esp32_gpiowrite(GPIO_LED1, true); + } + + if ((setbits & BOARD_LED2_BIT) != 0) + { + esp32_gpiowrite(GPIO_LED2, true); + } + + if ((setbits & BOARD_LED3_BIT) != 0) + { + esp32_gpiowrite(GPIO_LED3, true); + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_autoled_initialize + ****************************************************************************/ + +void board_autoled_initialize(void) +{ + /* Configure LED1-4 GPIOs for output */ + + esp32_configgpio(GPIO_LED1, OUTPUT); + esp32_configgpio(GPIO_LED2, OUTPUT); + esp32_configgpio(GPIO_LED3, OUTPUT); +} + +/**************************************************************************** + * Name: board_autoled_on + ****************************************************************************/ + +void board_autoled_on(int led) +{ + led_clrbits(BOARD_LED1_BIT | BOARD_LED2_BIT | BOARD_LED3_BIT); + led_setbits(g_ledbits[led]); +} + +/**************************************************************************** + * Name: board_autoled_off + ****************************************************************************/ + +void board_autoled_off(int led) +{ + led_clrbits(g_ledbits[led]); +} + +#endif /* CONFIG_ARCH_LEDS */ diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_boot.c b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_boot.c index 9b60456391..bf05463e85 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_boot.c +++ b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_boot.c @@ -56,6 +56,11 @@ void esp32_board_initialize(void) { + /* Configure on-board LEDs if LED support has been selected. */ + +#ifdef CONFIG_ARCH_LEDS + board_autoled_initialize(); +#endif } /**************************************************************************** diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_userleds.c b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_userleds.c index b861ff296e..d0b9c58974 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_userleds.c +++ b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_userleds.c @@ -27,9 +27,11 @@ #include #include #include -#include -#include "esp32_gpio.h" +#include +#include + +#include "esp32_gpio.h" #include "esp32-wrover-kit.h" /**************************************************************************** @@ -40,7 +42,7 @@ static const uint32_t g_ledcfg[BOARD_NLEDS] = { - GPIO_LED1, + GPIO_LED1, GPIO_LED2, GPIO_LED3 }; /**************************************************************************** @@ -55,6 +57,8 @@ uint32_t board_userled_initialize(void) { uint8_t i; + /* Configure the LEDs GPIOs as outputs */ + for (i = 0; i < BOARD_NLEDS; i++) { esp32_configgpio(g_ledcfg[i], OUTPUT); @@ -83,8 +87,6 @@ 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);