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 5fb022e2e28a4..ff0b47d7bf691 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 10dfae800718f..75a241ce02e93 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 @@ -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_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 86335c75a55b1..7bc54179d96b6 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 */