This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 456aaa8c1c1dcc76f99235eed2b09d0f9575c552
Author: Alan Carvalho de Assis <acas...@gmail.com>
AuthorDate: Mon Aug 22 18:23:19 2022 -0300

    esp32c3-devkit-rust-1: Add ARCH LED support
---
 boards/Kconfig                                     |   2 +
 .../esp32c3/esp32c3-devkit-rust-1/include/board.h  |  12 +++
 .../esp32c3/esp32c3-devkit-rust-1/src/Makefile     |   3 +
 .../src/{esp32c3_boot.c => esp32c3_autoleds.c}     | 102 ++++++++++++++-------
 .../esp32c3-devkit-rust-1/src/esp32c3_boot.c       |   1 +
 5 files changed, 86 insertions(+), 34 deletions(-)

diff --git a/boards/Kconfig b/boards/Kconfig
index 92e9f95fed..3cecc628b6 100644
--- a/boards/Kconfig
+++ b/boards/Kconfig
@@ -308,6 +308,8 @@ config ARCH_BOARD_ESP32C3_DEVKIT
 config ARCH_BOARD_ESP32C3_DEVKIT_RUST1
        bool "Espressif ESP32-C3-RUST-1 board"
        depends on ARCH_CHIP_ESP32C3MINI1
+       select ARCH_HAVE_LEDS
+       select ARCH_HAVE_BUTTONS
        ---help---
                The ESP32-C3-DevKit-RUST-1 features the ESP32-C3 CPU with a 
RISC-V core.
                This board includes the ESP32-C3-MINI-1 module, a 6DoF IMU, a 
temperature
diff --git a/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/include/board.h 
b/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/include/board.h
index 7f440e7c28..a0a65c219c 100644
--- a/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/include/board.h
+++ b/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/include/board.h
@@ -25,6 +25,18 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+#define NUM_BUTTONS       1
+
+#define LED_STARTED       0  /* ON */
+#define LED_HEAPALLOCATE  1  /* ON */
+#define LED_IRQSENABLED   2  /* N/A */
+#define LED_STACKCREATED  3  /* N/A */
+#define LED_INIRQ         4  /* N/A */
+#define LED_SIGNAL        5  /* N/A */
+#define LED_ASSERTION     6  /* N/A */
+#define LED_PANIC         7  /* Blinking */
+#define LED_CPU           8  /* N/A */
+
 /* Clocking *****************************************************************/
 
 #define BOARD_XTAL_FREQUENCY  40000000
diff --git a/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/Makefile 
b/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/Makefile
index 170aa4e962..2b6fe94ba7 100644
--- a/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/Makefile
+++ b/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/Makefile
@@ -31,7 +31,10 @@ CSRCS += esp32c3_appinit.c
 ifeq ($(CONFIG_BOARDCTL_RESET),y)
 CSRCS += esp32c3_reset.c
 endif
+endif
 
+ifeq ($(CONFIG_ARCH_LEDS),y)
+CSRCS += esp32c3_autoleds.c
 endif
 
 ifeq ($(CONFIG_BOARDCTL_IOCTL),y)
diff --git a/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/esp32c3_boot.c 
b/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/esp32c3_autoleds.c
similarity index 55%
copy from boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/esp32c3_boot.c
copy to boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/esp32c3_autoleds.c
index 7d1605329e..55c0c8e86e 100644
--- a/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/esp32c3_boot.c
+++ b/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/esp32c3_autoleds.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/esp32c3_boot.c
+ * boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/esp32c3_autoleds.c
  *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -24,63 +24,97 @@
 
 #include <nuttx/config.h>
 
-#include "riscv_internal.h"
+#include <debug.h>
+
+#include <arch/board/board.h>
+
+#include "esp32c3_gpio.h"
+#include "hardware/esp32c3_gpio_sigmap.h"
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* IO7 is connected to LED D2 */
+
+#define GPIO_LED   7
+
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
 
+static inline void set_led(bool v)
+{
+  ledinfo("Turn LED %s\n", v ? "on":"off");
+  esp32c3_gpiowrite(GPIO_LED, v);
+}
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: esp32c3_board_initialize
- *
- * Description:
- *   All ESP32-C3 architectures must provide the following entry point.
- *   This entry point is called early in the initialization -- after all
- *   memory has been configured and mapped but before any devices have been
- *   initialized.
- *
+ * Name: board_autoled_initialize
  ****************************************************************************/
 
-void esp32c3_board_initialize(void)
+void board_autoled_initialize(void)
 {
-#ifdef CONFIG_SCHED_CRITMONITOR
-  up_perf_init(NULL);
-#endif
+  /* Configure the LED's pin to be used as output */
+
+  esp32c3_gpio_matrix_out(GPIO_LED, SIG_GPIO_OUT_IDX, 0, 0);
+  esp32c3_configgpio(GPIO_LED, OUTPUT_FUNCTION_1 | INPUT_FUNCTION_1);
+}
 
-  /* Configure on-board LEDs if LED support has been selected. */
+/****************************************************************************
+ * Name: board_autoled_on
+ ****************************************************************************/
 
-#ifdef CONFIG_ARCH_LEDS
-  board_autoled_initialize();
-#endif
+void board_autoled_on(int led)
+{
+  ledinfo("board_autoled_on(%d)\n", led);
+
+  switch (led)
+    {
+      case LED_STARTED:
+      case LED_HEAPALLOCATE:
+
+        /* As the board provides only one soft controllable LED, we simply
+         * turn it on when the board boots.
+         */
+
+        set_led(true);
+        break;
+
+      case LED_PANIC:
+
+        /* For panic state, the LED is blinking */
+
+        set_led(true);
+        break;
+
+      default:
+        ledinfo("Not handled LED state: %d\n", led);
+        break;
+    }
 }
 
 /****************************************************************************
- * Name: board_late_initialize
- *
- * Description:
- *   If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional
- *   initialization call will be performed in the boot-up sequence to a
- *   function called board_late_initialize().  board_late_initialize() will
- *   be called immediately after up_initialize() is called and just before
- *   the initial application is started.  This additional initialization
- *   phase may be used, for example, to initialize board-specific device
- *   drivers.
- *
+ * Name: board_autoled_off
  ****************************************************************************/
 
-#ifdef CONFIG_BOARD_LATE_INITIALIZE
-void board_late_initialize(void)
+void board_autoled_off(int led)
 {
-  /* Perform board-specific initialization */
+  switch (led)
+    {
+      case LED_PANIC:
+
+        /* For panic state, the LED is blinking */
+
+        set_led(false);
+        break;
 
-  esp32c3_bringup();
+      default:
+        ledinfo("Not handled LED state: %d\n", led);
+        break;
+    }
 }
-#endif
diff --git a/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/esp32c3_boot.c 
b/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/esp32c3_boot.c
index 7d1605329e..812e49b371 100644
--- a/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/esp32c3_boot.c
+++ b/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/esp32c3_boot.c
@@ -23,6 +23,7 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
+#include <nuttx/board.h>
 
 #include "riscv_internal.h"
 

Reply via email to