Skip to content

Commit 2fbefa9

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 2fbefa9

7 files changed

Lines changed: 124 additions & 42 deletions

File tree

boards/xtensa/esp32/esp32-devkitc/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 2 /* Typical On-board LED is on GPIO 2 */
5152

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

boards/xtensa/esp32/esp32-devkitc/src/esp32_userleds.c

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,10 @@
2323
/****************************************************************************
2424
* Included Files
2525
****************************************************************************/
26-
2726
#include <nuttx/config.h>
28-
29-
#include <stdint.h>
3027
#include <stdbool.h>
31-
#include <nuttx/debug.h>
32-
3328
#include <nuttx/board.h>
3429
#include <arch/board/board.h>
35-
3630
#include "espressif/esp_gpio.h"
3731
#include "esp32-devkitc.h"
3832

@@ -42,11 +36,7 @@
4236

4337
/* This array maps an LED number to GPIO pin configuration */
4438

45-
static const uint32_t g_ledcfg[BOARD_NLEDS] =
46-
{
47-
GPIO_LED1,
48-
};
49-
39+
static const uint32_t g_ledcfg[BOARD_NLEDS] = { GPIO_LED1 };
5040
/****************************************************************************
5141
* Public Functions
5242
****************************************************************************/
@@ -55,42 +45,28 @@ static const uint32_t g_ledcfg[BOARD_NLEDS] =
5545
* Name: board_userled_initialize
5646
****************************************************************************/
5747

58-
uint32_t board_userled_initialize(void)
59-
{
60-
uint8_t i;
61-
62-
for (i = 0; i < BOARD_NLEDS; i++)
63-
{
64-
esp_configgpio(g_ledcfg[i], OUTPUT);
65-
}
66-
48+
uint32_t board_userled_initialize(void) {
49+
for (int i = 0; i < BOARD_NLEDS; i++) {
50+
esp_configgpio(g_ledcfg[i], OUTPUT);
51+
}
6752
return BOARD_NLEDS;
6853
}
69-
7054
/****************************************************************************
7155
* Name: board_userled
7256
****************************************************************************/
7357

74-
void board_userled(int led, bool ledon)
75-
{
76-
if ((unsigned)led < BOARD_NLEDS)
77-
{
78-
esp_gpiowrite(g_ledcfg[led], ledon);
79-
}
80-
}
8158

59+
void board_userled(int led, bool ledon) {
60+
if ((unsigned)led < BOARD_NLEDS) {
61+
esp_gpiowrite(g_ledcfg[led], ledon);
62+
}
63+
}
8264
/****************************************************************************
8365
* Name: board_userled_all
8466
****************************************************************************/
8567

86-
void board_userled_all(uint32_t ledset)
87-
{
88-
uint8_t i;
89-
90-
/* Configure LED1-8 GPIOs for output */
91-
92-
for (i = 0; i < BOARD_NLEDS; i++)
93-
{
94-
esp_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
95-
}
96-
}
68+
void board_userled_all(uint32_t ledset) {
69+
for (int i = 0; i < BOARD_NLEDS; i++) {
70+
esp_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
71+
}
72+
}

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ 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+
ifeq ($(CONFIG_USERLED),y)
38+
CSRCS += esp32_userleds.c
39+
endif

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@
3232
#include <sys/stat.h>
3333
#include <sys/ioctl.h>
3434
#include <sys/types.h>
35-
#include <nuttx/debug.h>
3635
#include <errno.h>
36+
#include <nuttx/debug.h>
3737
#include <nuttx/board.h>
3838

39+
#ifdef CONFIG_USERLED
40+
# include <nuttx/leds/userled.h>
41+
#endif
42+
3943
#include "esp32_start.h"
4044

4145
#ifdef CONFIG_ESPRESSIF_HR_TIMER
@@ -110,6 +114,14 @@ int esp32_bringup(void)
110114
* capabilities.
111115
*/
112116

117+
#ifdef CONFIG_USERLED
118+
ret = userled_lower_initialize("/dev/userleds");
119+
if (ret < 0)
120+
{
121+
syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret);
122+
}
123+
#endif
124+
113125
UNUSED(ret);
114126
return OK;
115127
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <nuttx/config.h>
28+
29+
#include <stdbool.h>
30+
31+
#include <nuttx/board.h>
32+
#include <arch/board/board.h>
33+
34+
#include "espressif/esp_gpio.h"
35+
#include "heltec_wifi_lora32.h"
36+
37+
/****************************************************************************
38+
* Private Data
39+
****************************************************************************/
40+
41+
static const uint32_t g_ledcfg[BOARD_NLEDS] =
42+
{
43+
GPIO_LED1,
44+
};
45+
46+
/****************************************************************************
47+
* Public Functions
48+
****************************************************************************/
49+
50+
/****************************************************************************
51+
* Name: board_userled_initialize
52+
****************************************************************************/
53+
54+
uint32_t board_userled_initialize(void)
55+
{
56+
int i;
57+
58+
for (i = 0; i < BOARD_NLEDS; i++)
59+
{
60+
esp_configgpio(g_ledcfg[i], OUTPUT);
61+
}
62+
63+
return BOARD_NLEDS;
64+
}
65+
66+
/****************************************************************************
67+
* Name: board_userled
68+
****************************************************************************/
69+
70+
void board_userled(int led, bool ledon)
71+
{
72+
if ((unsigned int)led < BOARD_NLEDS)
73+
{
74+
esp_gpiowrite(g_ledcfg[led], ledon);
75+
}
76+
}
77+
78+
/****************************************************************************
79+
* Name: board_userled_all
80+
****************************************************************************/
81+
82+
void board_userled_all(uint32_t ledset)
83+
{
84+
int i;
85+
86+
for (i = 0; i < BOARD_NLEDS; i++)
87+
{
88+
esp_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
89+
}
90+
}

boards/xtensa/esp32/heltec_wifi_lora32/src/heltec_wifi_lora32.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@
4949
/* LED
5050
*
5151
* This is an externally connected LED used for testing.
52+
* (Moved to include/board.h)
5253
*/
5354

54-
#define GPIO_LED1 2
55-
5655
/* PCNT Quadrature Encoder IDs */
5756

5857
#define PCNT_QE0_ID 0

0 commit comments

Comments
 (0)