boards/xtensa/esp32/esp32-wrover-kit: Add autoleds.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
This commit is contained in:
parent
9d74362d75
commit
bb336498e4
@ -76,7 +76,33 @@
|
||||
|
||||
/* Define how many LEDs this board has (needed by userleds) */
|
||||
|
||||
#define BOARD_NLEDS 1
|
||||
#define GPIO_LED1 2
|
||||
#define BOARD_LED1 0
|
||||
#define BOARD_LED2 1
|
||||
#define BOARD_LED3 2
|
||||
#define BOARD_NLEDS 3
|
||||
|
||||
#define BOARD_LED_RED BOARD_LED1
|
||||
#define BOARD_LED_GREEN BOARD_LED2
|
||||
#define BOARD_LED_BLUE BOARD_LED3
|
||||
|
||||
/* LED bits for use with autoleds */
|
||||
|
||||
#define BOARD_LED1_BIT (1 << BOARD_LED1)
|
||||
#define BOARD_LED2_BIT (1 << BOARD_LED2)
|
||||
#define BOARD_LED3_BIT (1 << BOARD_LED3)
|
||||
|
||||
/* If CONFIG_ARCH_LEDs is defined, then NuttX will control the 3 LEDs on
|
||||
* board the ESP-WROVER-KIT. The following definitions describe how
|
||||
* NuttX controls the LEDs:
|
||||
*/
|
||||
|
||||
#define LED_STARTED 0 /* LED2 */
|
||||
#define LED_HEAPALLOCATE 1 /* LED3 */
|
||||
#define LED_IRQSENABLED 2 /* LED3 + LED2 */
|
||||
#define LED_STACKCREATED 3 /* LED3 */
|
||||
#define LED_INIRQ 4 /* LED1 + LED3 */
|
||||
#define LED_SIGNAL 5 /* LED2 + LED3 */
|
||||
#define LED_ASSERTION 6 /* LED1 + LED2 + LED3 */
|
||||
#define LED_PANIC 7 /* LED1 + N/C + N/C */
|
||||
|
||||
#endif /* __BOARDS_XTENSA_ESP32_ESP32_WROVER_KIT_INCLUDE_BOARD_H */
|
||||
|
@ -26,6 +26,12 @@ CONFIGFILE = $(TOPDIR)$(DELIM)include$(DELIM)nuttx$(DELIM)config.h
|
||||
|
||||
CSRCS = esp32_boot.c esp32_bringup.c
|
||||
|
||||
ifeq ($(CONFIG_ARCH_LEDS),y)
|
||||
CSRCS += esp32_autoleds.c
|
||||
else
|
||||
CSRCS += esp32_userleds.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LIB_BOARDCTL),y)
|
||||
CSRCS += esp32_appinit.c
|
||||
ifeq ($(CONFIG_BOARDCTL_RESET),y)
|
||||
@ -45,10 +51,6 @@ ifeq ($(CONFIG_ESP32_SPIFLASH),y)
|
||||
CSRCS += esp32_spiflash.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USERLED),y)
|
||||
CSRCS += esp32_userleds.c
|
||||
endif
|
||||
|
||||
SCRIPTIN = $(SCRIPTDIR)$(DELIM)esp32.template.ld
|
||||
SCRIPTOUT = $(SCRIPTDIR)$(DELIM)esp32_out.ld
|
||||
|
||||
|
@ -33,6 +33,14 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* ESP-WROVER-KIT GPIOs *****************************************************/
|
||||
|
||||
/* LEDs */
|
||||
|
||||
#define GPIO_LED1 0
|
||||
#define GPIO_LED2 2
|
||||
#define GPIO_LED3 4
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
@ -68,6 +76,7 @@ int esp32_bringup(void);
|
||||
*
|
||||
* Description:
|
||||
* Initialize SPI-based SD card and card detect thread.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp32_mmcsd_initialize(int minor);
|
||||
|
147
boards/xtensa/esp32/esp32-wrover-kit/src/esp32_autoleds.c
Normal file
147
boards/xtensa/esp32/esp32-wrover-kit/src/esp32_autoleds.c
Normal file
@ -0,0 +1,147 @@
|
||||
/****************************************************************************
|
||||
* boards/xtensa/esp32/esp32-wrover-kit/src/esp32_autoleds.c
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/board.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "esp32_gpio.h"
|
||||
#include "esp32-wrover-kit.h"
|
||||
|
||||
#ifdef CONFIG_ARCH_LEDS
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* The following definitions map the encoded LED setting to GPIO settings */
|
||||
|
||||
#define LED_STARTED_BITS (BOARD_LED2_BIT)
|
||||
#define LED_HEAPALLOCATE_BITS (BOARD_LED3_BIT)
|
||||
#define LED_IRQSENABLED_BITS (BOARD_LED3_BIT | BOARD_LED2_BIT)
|
||||
#define LED_STACKCREATED_BITS (BOARD_LED3_BIT)
|
||||
#define LED_INIRQ_BITS (BOARD_LED1_BIT | BOARD_LED3_BIT)
|
||||
#define LED_SIGNAL_BITS (BOARD_LED2_BIT | BOARD_LED3_BIT)
|
||||
#define LED_ASSERTION_BITS (BOARD_LED1_BIT | BOARD_LED2_BIT |\
|
||||
BOARD_LED3_BIT)
|
||||
#define LED_PANIC_BITS (BOARD_LED1_BIT)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const unsigned int g_ledbits[8] =
|
||||
{
|
||||
LED_STARTED_BITS,
|
||||
LED_HEAPALLOCATE_BITS,
|
||||
LED_IRQSENABLED_BITS,
|
||||
LED_STACKCREATED_BITS,
|
||||
LED_INIRQ_BITS,
|
||||
LED_SIGNAL_BITS,
|
||||
LED_ASSERTION_BITS,
|
||||
LED_PANIC_BITS
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static inline void led_clrbits(unsigned int clrbits)
|
||||
{
|
||||
if ((clrbits & BOARD_LED1_BIT) != 0)
|
||||
{
|
||||
esp32_gpiowrite(GPIO_LED1, false);
|
||||
}
|
||||
|
||||
if ((clrbits & BOARD_LED2_BIT) != 0)
|
||||
{
|
||||
esp32_gpiowrite(GPIO_LED2, false);
|
||||
}
|
||||
|
||||
if ((clrbits & BOARD_LED3_BIT) != 0)
|
||||
{
|
||||
esp32_gpiowrite(GPIO_LED3, false);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void led_setbits(unsigned int setbits)
|
||||
{
|
||||
if ((setbits & BOARD_LED1_BIT) != 0)
|
||||
{
|
||||
esp32_gpiowrite(GPIO_LED1, true);
|
||||
}
|
||||
|
||||
if ((setbits & BOARD_LED2_BIT) != 0)
|
||||
{
|
||||
esp32_gpiowrite(GPIO_LED2, true);
|
||||
}
|
||||
|
||||
if ((setbits & BOARD_LED3_BIT) != 0)
|
||||
{
|
||||
esp32_gpiowrite(GPIO_LED3, true);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_autoled_initialize
|
||||
****************************************************************************/
|
||||
|
||||
void board_autoled_initialize(void)
|
||||
{
|
||||
/* Configure LED1-4 GPIOs for output */
|
||||
|
||||
esp32_configgpio(GPIO_LED1, OUTPUT);
|
||||
esp32_configgpio(GPIO_LED2, OUTPUT);
|
||||
esp32_configgpio(GPIO_LED3, OUTPUT);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_autoled_on
|
||||
****************************************************************************/
|
||||
|
||||
void board_autoled_on(int led)
|
||||
{
|
||||
led_clrbits(BOARD_LED1_BIT | BOARD_LED2_BIT | BOARD_LED3_BIT);
|
||||
led_setbits(g_ledbits[led]);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_autoled_off
|
||||
****************************************************************************/
|
||||
|
||||
void board_autoled_off(int led)
|
||||
{
|
||||
led_clrbits(g_ledbits[led]);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_ARCH_LEDS */
|
@ -56,6 +56,11 @@
|
||||
|
||||
void esp32_board_initialize(void)
|
||||
{
|
||||
/* Configure on-board LEDs if LED support has been selected. */
|
||||
|
||||
#ifdef CONFIG_ARCH_LEDS
|
||||
board_autoled_initialize();
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -27,9 +27,11 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <debug.h>
|
||||
#include <arch/board/board.h>
|
||||
#include "esp32_gpio.h"
|
||||
|
||||
#include <nuttx/board.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "esp32_gpio.h"
|
||||
#include "esp32-wrover-kit.h"
|
||||
|
||||
/****************************************************************************
|
||||
@ -40,7 +42,7 @@
|
||||
|
||||
static const uint32_t g_ledcfg[BOARD_NLEDS] =
|
||||
{
|
||||
GPIO_LED1,
|
||||
GPIO_LED1, GPIO_LED2, GPIO_LED3
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@ -55,6 +57,8 @@ uint32_t board_userled_initialize(void)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
/* Configure the LEDs GPIOs as outputs */
|
||||
|
||||
for (i = 0; i < BOARD_NLEDS; i++)
|
||||
{
|
||||
esp32_configgpio(g_ledcfg[i], OUTPUT);
|
||||
@ -83,8 +87,6 @@ void board_userled_all(uint32_t ledset)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
/* Configure LED1-8 GPIOs for output */
|
||||
|
||||
for (i = 0; i < BOARD_NLEDS; i++)
|
||||
{
|
||||
esp32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
|
||||
|
Loading…
Reference in New Issue
Block a user