summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-08-15 23:11:34 +0800
committerruki <[email protected]>2026-08-15 23:11:34 +0800
commit3c40bc1cbd5515256c36ab7ea6a45c0d4bc203e3 (patch)
tree3adb2b6b224a43018f5909e38dd47684c2aa446b
parent2f9993a333a820006b4cf6a18f6dd753cfe48eec (diff)
add blink test
-rw-r--r--tests/projects/embed/esp32/blink/boards/esp32c3/board.h7
-rw-r--r--tests/projects/embed/esp32/blink/boards/esp32s3/board.h8
-rw-r--r--tests/projects/embed/esp32/blink/src/main.c26
-rw-r--r--tests/projects/embed/esp32/blink/xmake-addons.lua2
-rw-r--r--tests/projects/embed/esp32/blink/xmake.lua15
5 files changed, 58 insertions, 0 deletions
diff --git a/tests/projects/embed/esp32/blink/boards/esp32c3/board.h b/tests/projects/embed/esp32/blink/boards/esp32c3/board.h
new file mode 100644
index 000000000..126f2c2c3
--- /dev/null
+++ b/tests/projects/embed/esp32/blink/boards/esp32c3/board.h
@@ -0,0 +1,7 @@
+// the board configuration of esp32c3, it's selected by the `board` option
+//
+// @note gpio12-17 are the spi flash of the esp32c3, do not use them
+//
+#pragma once
+
+#define LED_GPIO 8
diff --git a/tests/projects/embed/esp32/blink/boards/esp32s3/board.h b/tests/projects/embed/esp32/blink/boards/esp32s3/board.h
new file mode 100644
index 000000000..91e7617cc
--- /dev/null
+++ b/tests/projects/embed/esp32/blink/boards/esp32s3/board.h
@@ -0,0 +1,8 @@
+// the board configuration of esp32s3, it's selected by the `board` option
+//
+// @note it's the addressable rgb led (ws2812) on the devkit, a plain gpio toggle
+// does not light it up, set it to a real led pin of your board
+//
+#pragma once
+
+#define LED_GPIO 48
diff --git a/tests/projects/embed/esp32/blink/src/main.c b/tests/projects/embed/esp32/blink/src/main.c
new file mode 100644
index 000000000..5f384985e
--- /dev/null
+++ b/tests/projects/embed/esp32/blink/src/main.c
@@ -0,0 +1,26 @@
+// blink the led of the board and print a heartbeat
+//
+// the led pin comes from `boards/<board>/board.h`, it's selected by the board option,
+// e.g. xmake f --board=esp32s3
+//
+// @note the entry is the esp-idf native `void app_main(void)`, and we print with
+// `esp_rom_printf`, it writes to the rom console, which is the usb port on the
+// boards booting over the native usb (usb-serial-jtag), e.g. xmake monitor
+//
+#include "board.h"
+#include "driver/gpio.h"
+#include "esp_rom_sys.h"
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+
+void app_main(void)
+{
+ esp_rom_printf("blink: toggle gpio %d every 500ms\n", LED_GPIO);
+ gpio_reset_pin(LED_GPIO);
+ gpio_set_direction(LED_GPIO, GPIO_MODE_OUTPUT);
+ for (int count = 0; ; count++) {
+ gpio_set_level(LED_GPIO, count & 1);
+ esp_rom_printf("blink: tick %d\n", count);
+ vTaskDelay(pdMS_TO_TICKS(500));
+ }
+}
diff --git a/tests/projects/embed/esp32/blink/xmake-addons.lua b/tests/projects/embed/esp32/blink/xmake-addons.lua
new file mode 100644
index 000000000..aea4ad480
--- /dev/null
+++ b/tests/projects/embed/esp32/blink/xmake-addons.lua
@@ -0,0 +1,2 @@
+-- the addon is installed automatically when we load this project
+add_addons("esp32-devel")
diff --git a/tests/projects/embed/esp32/blink/xmake.lua b/tests/projects/embed/esp32/blink/xmake.lua
new file mode 100644
index 000000000..3fea2dd12
--- /dev/null
+++ b/tests/projects/embed/esp32/blink/xmake.lua
@@ -0,0 +1,15 @@
+-- the esp32 blink example, it needs the esp32-devel addon
+--
+-- $ xmake f --board=esp32c3
+-- $ xmake
+-- $ xmake install -- flash the image to the board
+-- $ xmake run -- flash it and monitor the serial output
+--
+includes("@addon/esp32-devel/board")
+
+target("blink")
+ add_rules("@addon/esp32-devel/app")
+ add_files("src/*.c")
+
+ -- the led pin of the board, @see boards/<board>/board.h
+ add_includedirs("boards/" .. (get_config("board") or "esp32c3"))