This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new d5e7ef99243 boards/xtensa: heltec_wifi_lora_32: Add userleds support
d5e7ef99243 is described below
commit d5e7ef992438b822b6c0b17b0184e1944a0121d4
Author: Shriyans S Sahoo <[email protected]>
AuthorDate: Fri Jun 5 21:45:57 2026 +0530
boards/xtensa: heltec_wifi_lora_32: Add userleds 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 S Sahoo <[email protected]>
---
.../esp32/heltec_wifi_lora32/include/board.h | 1 +
.../xtensa/esp32/heltec_wifi_lora32/src/Make.defs | 3 +
.../esp32/heltec_wifi_lora32/src/esp32_bringup.c | 14 +++-
.../src/{esp32_bringup.c => esp32_userleds.c} | 98 +++++++++-------------
.../heltec_wifi_lora32/src/heltec_wifi_lora32.h | 7 --
5 files changed, 55 insertions(+), 68 deletions(-)
diff --git a/boards/xtensa/esp32/heltec_wifi_lora32/include/board.h
b/boards/xtensa/esp32/heltec_wifi_lora32/include/board.h
index a1621b7f1bf..a3dc52cb66b 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 5fb022e2e28..ff0b47d7bf6 100644
--- a/boards/xtensa/esp32/heltec_wifi_lora32/src/Make.defs
+++ b/boards/xtensa/esp32/heltec_wifi_lora32/src/Make.defs
@@ -30,3 +30,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 10dfae80071..75a241ce02e 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 <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/types.h>
-#include <nuttx/debug.h>
#include <errno.h>
+#include <nuttx/debug.h>
#include <nuttx/board.h>
+#ifdef CONFIG_USERLED
+# include <nuttx/leds/userled.h>
+#endif
+
#include "esp32_start.h"
#ifdef CONFIG_ESPRESSIF_HR_TIMER
@@ -107,6 +111,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_bringup.c
b/boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_userleds.c
similarity index 50%
copy from boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_bringup.c
copy to boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_userleds.c
index 10dfae80071..005bf202df0 100644
--- a/boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_bringup.c
+++ b/boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_userleds.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_bringup.c
+ * boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_userleds.c
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -26,87 +26,65 @@
#include <nuttx/config.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <nuttx/debug.h>
-#include <errno.h>
+#include <stdbool.h>
+
#include <nuttx/board.h>
+#include <arch/board/board.h>
-#include "esp32_start.h"
+#include "espressif/esp_gpio.h"
+#include "heltec_wifi_lora32.h"
-#ifdef CONFIG_ESPRESSIF_HR_TIMER
-# include "espressif/esp_hr_timer.h"
-#endif
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
-#include "heltec_wifi_lora32.h"
+static const uint32_t g_ledcfg[BOARD_NLEDS] =
+{
+ GPIO_LED1,
+};
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
- * Name: esp32_bringup
- *
- * Description:
- * Perform architecture-specific initialization
- *
- * CONFIG_BOARD_LATE_INITIALIZE=y :
- * Called from board_late_initialize().
- *
+ * Name: board_userled_initialize
****************************************************************************/
-int esp32_bringup(void)
+uint32_t board_userled_initialize(void)
{
- int ret;
+ int i;
-#ifdef CONFIG_FS_PROCFS
- /* Mount the procfs file system */
-
- ret = nx_mount(NULL, "/proc", "procfs", 0, NULL);
- if (ret < 0)
+ for (i = 0; i < BOARD_NLEDS; i++)
{
- syslog(LOG_ERR, "ERROR: Failed to mount procfs at /proc: %d\n", ret);
+ esp_configgpio(g_ledcfg[i], OUTPUT);
}
-#endif
-#ifdef CONFIG_FS_TMPFS
- /* Mount the tmpfs file system */
+ return BOARD_NLEDS;
+}
- ret = nx_mount(NULL, CONFIG_LIBC_TMPDIR, "tmpfs", 0, NULL);
- if (ret < 0)
- {
- syslog(LOG_ERR, "ERROR: Failed to mount tmpfs at %s: %d\n",
- CONFIG_LIBC_TMPDIR, ret);
- }
-#endif
+/****************************************************************************
+ * Name: board_userled
+ ****************************************************************************/
-#ifdef CONFIG_LPWAN_SX127X
- ret = esp32_lpwaninitialize();
- if (ret < 0)
+void board_userled(int led, bool ledon)
+{
+ if ((unsigned int)led < BOARD_NLEDS)
{
- syslog(LOG_ERR,
- "ERROR: Failed to initialize wireless driver: %d\n",
- ret);
+ esp_gpiowrite(g_ledcfg[led], ledon);
}
-#endif /* CONFIG_LPWAN_SX127X */
+}
-#ifdef CONFIG_ESPRESSIF_HR_TIMER
- ret = esp_hr_timer_init();
- if (ret < 0)
- {
- syslog(LOG_ERR, "ERROR: esp_hr_timer_init() failed: %d\n", ret);
- }
-#endif
+/****************************************************************************
+ * Name: board_userled_all
+ ****************************************************************************/
- /* If we got here then perhaps not all initialization was successful, but
- * at least enough succeeded to bring-up NSH with perhaps reduced
- * capabilities.
- */
+void board_userled_all(uint32_t ledset)
+{
+ int i;
- UNUSED(ret);
- return OK;
+ 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 86335c75a55..a553559db7c 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,13 +46,6 @@
#define BUTTON_BOOT 0
-/* LED
- *
- * This is an externally connected LED used for testing.
- */
-
-#define GPIO_LED1 2
-
/* PCNT Quadrature Encoder IDs */
#define PCNT_QE0_ID 0