Skip to content

Commit 83a8199

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 83a8199

5 files changed

Lines changed: 107 additions & 7 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: 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: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@
4646

4747
#define BUTTON_BOOT 0
4848

49-
/* LED
50-
*
51-
* This is an externally connected LED used for testing.
52-
*/
53-
54-
#define GPIO_LED1 2
5549

5650
/* PCNT Quadrature Encoder IDs */
5751

0 commit comments

Comments
 (0)