From 07139eb85404815fdec7fd741e5e217624410a57 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/heltec_wifi_lora32: Add LED support 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/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 +++++++++++++++++++ .../src/heltec_wifi_lora32.h | 6 -- 5 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_userleds.c 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); + } +} diff --git a/boards/xtensa/esp32/heltec_wifi_lora32/src/heltec_wifi_lora32.h b/boards/xtensa/esp32/heltec_wifi_lora32/src/heltec_wifi_lora32.h index 4fcec67960999..c818cb34f37d8 100644 --- a/boards/xtensa/esp32/heltec_wifi_lora32/src/heltec_wifi_lora32.h +++ b/boards/xtensa/esp32/heltec_wifi_lora32/src/heltec_wifi_lora32.h @@ -46,12 +46,6 @@ #define BUTTON_BOOT 0 -/* LED - * - * This is an externally connected LED used for testing. - */ - -#define GPIO_LED1 2 /* PCNT Quadrature Encoder IDs */