Skip to content

Commit 69d120b

Browse files
committed
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 <shriyans.s.sahoo@gmail.com>
1 parent 8e91dd6 commit 69d120b

4 files changed

Lines changed: 66 additions & 0 deletions

File tree

boards/xtensa/esp32/heltec_wifi_lora32/include/board.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
/* Define how many LEDs this board has (needed by userleds) */
4949

5050
#define BOARD_NLEDS 1
51+
#define GPIO_LED1 25 /* White LED on Heltec WiFi LoRa 32 */
5152

5253
/* GPIO pins used by the GPIO Subsystem */
5354

boards/xtensa/esp32/heltec_wifi_lora32/src/Make.defs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ DEPPATH += --dep-path board
3434
VPATH += :board
3535
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
3636

37+
38+
ifeq ($(CONFIG_USERLED),y)
39+
CSRCS += esp32_userleds.c
40+
endif
41+

boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_bringup.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838

3939
#include "esp32_start.h"
4040

41+
#ifdef CONFIG_USERLED
42+
# include <nuttx/leds/userled.h>
43+
#endif
44+
45+
46+
4147
#ifdef CONFIG_ESPRESSIF_HR_TIMER
4248
# include "espressif/esp_hr_timer.h"
4349
#endif
@@ -110,6 +116,16 @@ int esp32_bringup(void)
110116
* capabilities.
111117
*/
112118

119+
120+
#ifdef CONFIG_USERLED
121+
ret = userled_lower_initialize("/dev/userleds");
122+
if (ret < 0)
123+
{
124+
syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret);
125+
}
126+
#endif
127+
128+
113129
UNUSED(ret);
114130
return OK;
115131
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/****************************************************************************
2+
* boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_userleds.c
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership.
9+
****************************************************************************
10+
*/
11+
12+
#include <nuttx/config.h>
13+
#include <stdbool.h>
14+
#include <nuttx/board.h>
15+
#include <arch/board/board.h>
16+
#include "espressif/esp_gpio.h"
17+
#include "heltec_wifi_lora32.h"
18+
19+
static const uint32_t g_ledcfg[BOARD_NLEDS] = { GPIO_LED1 };
20+
21+
uint32_t board_userled_initialize(void)
22+
{
23+
for (int i = 0; i < BOARD_NLEDS; i++)
24+
{
25+
esp_configgpio(g_ledcfg[i], OUTPUT);
26+
}
27+
return BOARD_NLEDS;
28+
}
29+
30+
void board_userled(int led, bool ledon)
31+
{
32+
if ((unsigned)led < BOARD_NLEDS)
33+
{
34+
esp_gpiowrite(g_ledcfg[led], ledon);
35+
}
36+
}
37+
38+
void board_userled_all(uint32_t ledset)
39+
{
40+
for (int i = 0; i < BOARD_NLEDS; i++)
41+
{
42+
esp_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
43+
}
44+
}

0 commit comments

Comments
 (0)