diff --git a/boards/Kconfig b/boards/Kconfig index 92e9f95fed4..3cecc628b6c 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 7f440e7c283..a0a65c219cb 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 170aa4e9628..2b6fe94ba76 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_autoleds.c b/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/esp32c3_autoleds.c new file mode 100644 index 00000000000..55c0c8e86ea --- /dev/null +++ b/boards/risc-v/esp32c3/esp32c3-devkit-rust-1/src/esp32c3_autoleds.c @@ -0,0 +1,120 @@ +/**************************************************************************** + * 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 + * 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 "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: board_autoled_initialize + ****************************************************************************/ + +void board_autoled_initialize(void) +{ + /* 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); +} + +/**************************************************************************** + * Name: board_autoled_on + ****************************************************************************/ + +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_autoled_off + ****************************************************************************/ + +void board_autoled_off(int led) +{ + switch (led) + { + case LED_PANIC: + + /* For panic state, the LED is blinking */ + + set_led(false); + break; + + default: + ledinfo("Not handled LED state: %d\n", led); + break; + } +} 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 7d1605329e7..812e49b3711 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 +#include #include "riscv_internal.h"