Skip to content

Commit 24ee5d1

Browse files
committed
bsp/esp32c3: Add LED blink, FinSH command
1 parent 1aef0db commit 24ee5d1

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

bsp/ESP32_C3/main/main.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
1+
#include <rtthread.h>
2+
#include <stdlib.h> // For atoi()
3+
#include <finsh.h> // For MSH_CMD_EXPORT
4+
5+
// The global variable you want to expose to FinSH
6+
// NOTE: It must be a global or static global variable.
7+
int app_data_value = 100;
8+
9+
// Function to handle reading and setting the variable
10+
// All FinSH commands in msh mode must have this signature: (int argc, char **argv)
11+
void app_data_cmd(int argc, char **argv)
12+
{
13+
// Check if the FinSH C-style interpreter is disabled
14+
#ifndef FINSH_USING_MSH
15+
rt_kprintf("Error: This command requires msh mode enabled.\n");
16+
return;
17+
#endif
18+
19+
if (argc == 1)
20+
{
21+
// Case 1: No arguments (e.g., 'app_data_cmd') -> Read the current value
22+
rt_kprintf("app_data_value (current): %d\n", app_data_value);
23+
}
24+
else if (argc == 2)
25+
{
26+
// Case 2: One argument (e.g., 'app_data_cmd 250') -> Set a new value
27+
int new_value = atoi(argv[1]);
28+
app_data_value = new_value;
29+
rt_kprintf("app_data_value set to: %d\n", app_data_value);
30+
}
31+
else
32+
{
33+
// Case 3: Invalid number of arguments
34+
rt_kprintf("Usage:\n");
35+
rt_kprintf(" Read: app_data_cmd\n");
36+
rt_kprintf(" Write: app_data_cmd <value>\n");
37+
}
38+
}
39+
40+
// Export the function as a FinSH command.
41+
// Format: MSH_CMD_EXPORT(function_name, description)
42+
MSH_CMD_EXPORT(app_data_cmd, Get or set the application data value);
143
/*
244
* Copyright (c) 2021-2022, RT-Thread Development Team
345
*
@@ -9,7 +51,7 @@
951
* 2022-06-02 supperthomas fix version
1052
* 2023-10-20 WCX1024979076 add wifi application
1153
*/
12-
54+
#define RT_BSP_LED_PIN 2
1355
#include <rtthread.h>
1456
#include <rtdevice.h>
1557
#include <board.h>

0 commit comments

Comments
 (0)