From 7a04e7ec41950e0b3c65288600cb9967c96f581d Mon Sep 17 00:00:00 2001 From: Shriyans S Sahoo Date: Sat, 2 May 2026 10:27:59 +0530 Subject: [PATCH] boards/xtensa/esp32: Add LED support for Heltec WiFi LoRa 32 board This commit adds the User LED driver support for the Heltec WiFi LoRa 32 board. It implements the lower-half driver, maps the onboard white LED to GPIO 25, and adds the necessary build system and initialization logic. Signed-off-by: Shriyans Sahoo --- .../esp32/esp32-devkitc/include/board.h | 1 + .../esp32/esp32-devkitc/src/esp32_userleds.c | 54 ++++------- .../esp32/heltec_wifi_lora32/include/board.h | 1 + .../esp32/heltec_wifi_lora32/src/Make.defs | 3 + .../heltec_wifi_lora32/src/esp32_bringup.c | 14 ++- .../heltec_wifi_lora32/src/esp32_userleds.c | 90 +++++++++++++++++++ 6 files changed, 123 insertions(+), 40 deletions(-) create mode 100644 boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_userleds.c diff --git a/boards/xtensa/esp32/esp32-devkitc/include/board.h b/boards/xtensa/esp32/esp32-devkitc/include/board.h index bbd54b6c5b0d5..b72da194e8c50 100644 --- a/boards/xtensa/esp32/esp32-devkitc/include/board.h +++ b/boards/xtensa/esp32/esp32-devkitc/include/board.h @@ -48,6 +48,7 @@ /* Define how many LEDs this board has (needed by userleds) */ #define BOARD_NLEDS 1 +#define GPIO_LED1 2 /* Typical On-board LED is on GPIO 2 */ /* GPIO pins used by the GPIO Subsystem */ diff --git a/boards/xtensa/esp32/esp32-devkitc/src/esp32_userleds.c b/boards/xtensa/esp32/esp32-devkitc/src/esp32_userleds.c index 54ba61e386fea..7f78cfd80e009 100644 --- a/boards/xtensa/esp32/esp32-devkitc/src/esp32_userleds.c +++ b/boards/xtensa/esp32/esp32-devkitc/src/esp32_userleds.c @@ -23,16 +23,10 @@ /**************************************************************************** * Included Files ****************************************************************************/ - #include - -#include #include -#include - #include #include - #include "espressif/esp_gpio.h" #include "esp32-devkitc.h" @@ -42,11 +36,7 @@ /* This array maps an LED number to GPIO pin configuration */ -static const uint32_t g_ledcfg[BOARD_NLEDS] = -{ - GPIO_LED1, -}; - +static const uint32_t g_ledcfg[BOARD_NLEDS] = { GPIO_LED1 }; /**************************************************************************** * Public Functions ****************************************************************************/ @@ -55,42 +45,28 @@ static const uint32_t g_ledcfg[BOARD_NLEDS] = * Name: board_userled_initialize ****************************************************************************/ -uint32_t board_userled_initialize(void) -{ - uint8_t i; - - for (i = 0; i < BOARD_NLEDS; i++) - { - esp_configgpio(g_ledcfg[i], OUTPUT); - } - +uint32_t board_userled_initialize(void) { + for (int i = 0; i < BOARD_NLEDS; i++) { + esp_configgpio(g_ledcfg[i], OUTPUT); + } return BOARD_NLEDS; } - /**************************************************************************** * Name: board_userled ****************************************************************************/ -void board_userled(int led, bool ledon) -{ - if ((unsigned)led < BOARD_NLEDS) - { - esp_gpiowrite(g_ledcfg[led], ledon); - } -} +void board_userled(int led, bool ledon) { + if ((unsigned)led < BOARD_NLEDS) { + esp_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++) - { - esp_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0); - } -} +void board_userled_all(uint32_t ledset) { + for (int i = 0; i < BOARD_NLEDS; i++) { + esp_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0); + } +} \ No newline at end of file diff --git a/boards/xtensa/esp32/heltec_wifi_lora32/include/board.h b/boards/xtensa/esp32/heltec_wifi_lora32/include/board.h index a1621b7f1bfb6..a3dc52cb66b04 100644 --- a/boards/xtensa/esp32/heltec_wifi_lora32/include/board.h +++ b/boards/xtensa/esp32/heltec_wifi_lora32/include/board.h @@ -48,6 +48,7 @@ /* Define how many LEDs this board has (needed by userleds) */ #define BOARD_NLEDS 1 +#define GPIO_LED1 25 /* White LED on Heltec WiFi LoRa 32 */ /* GPIO pins used by the GPIO Subsystem */ diff --git a/boards/xtensa/esp32/heltec_wifi_lora32/src/Make.defs b/boards/xtensa/esp32/heltec_wifi_lora32/src/Make.defs index 84953ece1ac5d..6433db4e55223 100644 --- a/boards/xtensa/esp32/heltec_wifi_lora32/src/Make.defs +++ b/boards/xtensa/esp32/heltec_wifi_lora32/src/Make.defs @@ -34,3 +34,6 @@ DEPPATH += --dep-path board VPATH += :board CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board +ifeq ($(CONFIG_USERLED),y) +CSRCS += esp32_userleds.c +endif diff --git a/boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_bringup.c b/boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_bringup.c index 8be92ac40e601..69960746dbe09 100644 --- a/boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_bringup.c +++ b/boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_bringup.c @@ -32,10 +32,14 @@ #include #include #include -#include #include +#include #include +#ifdef CONFIG_USERLED +# include +#endif + #include "esp32_start.h" #ifdef CONFIG_ESPRESSIF_HR_TIMER @@ -110,6 +114,14 @@ int esp32_bringup(void) * capabilities. */ +#ifdef CONFIG_USERLED + ret = userled_lower_initialize("/dev/userleds"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret); + } +#endif + UNUSED(ret); return OK; } diff --git a/boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_userleds.c b/boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_userleds.c new file mode 100644 index 0000000000000..005bf202df0b8 --- /dev/null +++ b/boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_userleds.c @@ -0,0 +1,90 @@ +/**************************************************************************** + * boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_userleds.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 "espressif/esp_gpio.h" +#include "heltec_wifi_lora32.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const uint32_t g_ledcfg[BOARD_NLEDS] = +{ + GPIO_LED1, +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_userled_initialize + ****************************************************************************/ + +uint32_t board_userled_initialize(void) +{ + int i; + + for (i = 0; i < BOARD_NLEDS; i++) + { + esp_configgpio(g_ledcfg[i], OUTPUT); + } + + return BOARD_NLEDS; +} + +/**************************************************************************** + * Name: board_userled + ****************************************************************************/ + +void board_userled(int led, bool ledon) +{ + if ((unsigned int)led < BOARD_NLEDS) + { + esp_gpiowrite(g_ledcfg[led], ledon); + } +} + +/**************************************************************************** + * Name: board_userled_all + ****************************************************************************/ + +void board_userled_all(uint32_t ledset) +{ + int i; + + for (i = 0; i < BOARD_NLEDS; i++) + { + esp_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0); + } +}