Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions bsp/ESP32_C3/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,53 @@ PKGS_DIR := packages
source "$(RTT_DIR)/Kconfig"
osource "$PKGS_DIR/Kconfig"
rsource "drivers/Kconfig"
# In bsp/ESP32_C3/Kconfig

# Look for the section related to board peripherals or drivers

menu "Board Level Drivers"

# 1. Define the option that allows the user to input the pin number
config RT_BSP_LED_PIN
int "Onboard LED Pin (GPIO Number)"
default 21 # Set a common default (e.g., GPIO 21 is often used on ESP32 boards)
range 0 40 # Set a valid range for ESP32 GPIO pins (0-40)
help
This sets the GPIO number for the on-board LED.
Check your ESP32-C3 board schematic for the correct pin.

endmenu # Board Level Drivers

menu "ESP32-C3 On-Chip Drivers"

# BLE Dependency
config BSP_USING_BLE
bool "Enable Bluetooth Low Energy (BLE) Support"
default y
select ESP32C3_BLE_DRV # Link to the underlying chip driver config (name may vary)
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug/错误: The config option 'ESP32C3_BLE_DRV' may not exist in the RT-Thread configuration system, which could cause Kconfig errors.
中文:配置选项'ESP32C3_BLE_DRV'可能在RT-Thread配置系统中不存在,这可能导致Kconfig错误。

Suggested change
select ESP32C3_BLE_DRV # Link to the underlying chip driver config (name may vary)
# select ESP32C3_BLE_DRV # Link to the underlying chip driver config (name may vary)

Copilot uses AI. Check for mistakes.
help
Enable this to include the necessary BLE drivers and compile
the BLE-related code blocks in main.c (via #ifdef BSP_USING_BLE).

# WiFi Dependency
config RT_USING_WIFI
bool "Enable Wi-Fi Support"
default y
select RT_USING_WIFI_DRIVER_ESP32C3 # Link to the underlying driver config (name may vary)
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug/错误: The config option 'RT_USING_WIFI_DRIVER_ESP32C3' may not exist in the RT-Thread configuration system, which could cause Kconfig errors.
中文:配置选项'RT_USING_WIFI_DRIVER_ESP32C3'可能在RT-Thread配置系统中不存在,这可能导致Kconfig错误。

Copilot uses AI. Check for mistakes.
help
Enable this to include the Wi-Fi framework and driver support
for network functionality.

endmenu # ESP32-C3 On-Chip Drivers

# --------------------------------------------------------------------------
# Optional: Ensure core features are enabled when necessary
# --------------------------------------------------------------------------

# If your custom feature requires msh, you can select it like this:
config BSP_USING_APP_COMMANDS
bool "Enable Custom Application Commands (app_data_cmd)"
default y
select FINSH_USING_MSH # This ensures the FinSH msh mode is enabled if this is selected
help
This enables the app_data_cmd function in main.c, which relies on the FinSH shell.
21 changes: 21 additions & 0 deletions bsp/ESP32_C3/main/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,24 @@ CPPPATH = []
group = DefineGroup('Main', src, depend = [''], CPPPATH = CPPPATH)

Return('group')

# SConscript file content

# Define a list of source files to compile
src = []

# Add common BSP source files (these lines might already exist)
# src += ['board.c', 'drivers/drv_gpio.c']

# >>> ADD YOUR APPLICATION FILES HERE <<<
# Ensure your main.c file is in the list.
src += ['main.c']
# If you add any other custom C files (e.g., app_logic.c), list them too.
# src += ['app_logic.c']

# Pass the source list to the build environment
from building import *
# This line tells SCons to compile the files in the 'src' list
list = SConscript('drivers/SConscript', variant_dir='drivers')
list.append(src)

45 changes: 44 additions & 1 deletion bsp/ESP32_C3/main/main.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@

#include <rtthread.h>
#include <stdlib.h> // For atoi()
#include <finsh.h> // For MSH_CMD_EXPORT

// The global variable you want to expose to FinSH
// NOTE: It must be a global or static global variable.
int app_data_value = 100;

// Function to handle reading and setting the variable
// All FinSH commands in msh mode must have this signature: (int argc, char **argv)
void app_data_cmd(int argc, char **argv)
{
// Check if the FinSH C-style interpreter is disabled
#ifndef FINSH_USING_MSH
rt_kprintf("Error: This command requires msh mode enabled.\n");
return;
#endif

if (argc == 1)
{
// Case 1: No arguments (e.g., 'app_data_cmd') -> Read the current value
rt_kprintf("app_data_value (current): %d\n", app_data_value);
}
else if (argc == 2)
{
// Case 2: One argument (e.g., 'app_data_cmd 250') -> Set a new value
int new_value = atoi(argv[1]);
app_data_value = new_value;
rt_kprintf("app_data_value set to: %d\n", app_data_value);
}
else
{
// Case 3: Invalid number of arguments
rt_kprintf("Usage:\n");
rt_kprintf(" Read: app_data_cmd\n");
rt_kprintf(" Write: app_data_cmd <value>\n");
}
}

// Export the function as a FinSH command.
// Format: MSH_CMD_EXPORT(function_name, description)
MSH_CMD_EXPORT(app_data_cmd, Get or set the application data value);
/*
* Copyright (c) 2021-2022, RT-Thread Development Team
*
Expand All @@ -9,7 +52,7 @@
* 2022-06-02 supperthomas fix version
* 2023-10-20 WCX1024979076 add wifi application
*/

#define RT_BSP_LED_PIN 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redefine

Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainability/可维护性: LED pin definition is duplicated between rtconfig.h and main.c, creating inconsistency risk. The definition should come from a single source.
中文:LED引脚定义在rtconfig.h和main.c之间重复,存在不一致的风险。定义应该来自单一源。

Suggested change
#define RT_BSP_LED_PIN 2
#include <rtconfig.h>

Copilot uses AI. Check for mistakes.
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
Expand Down
7 changes: 7 additions & 0 deletions bsp/ESP32_C3/rtconfig.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#ifndef RT_CONFIG_H__
#define RT_CONFIG_H__

// Inside bsp/ESP32_C3/board.h
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation/文档: Comment incorrectly references 'board.h' but this code is in 'rtconfig.h'.
中文:注释错误地引用了'board.h',但此代码在'rtconfig.h'中。

Suggested change
// Inside bsp/ESP32_C3/board.h
// Board-related configuration options

Copilot uses AI. Check for mistakes.

// ... other existing definitions ...

// Define the GPIO pin number for the on-board LED
// *** You must replace 'X' with the correct physical GPIO number (e.g., 2, 8, 15, etc.) ***
#define RT_BSP_LED_PIN X
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug/错误: The LED pin is defined as 'X' which is not a valid GPIO number and will cause compilation errors.
中文:LED引脚定义为'X',这不是有效的GPIO编号,会导致编译错误。

Suggested change
#define RT_BSP_LED_PIN X
#define RT_BSP_LED_PIN 12

Copilot uses AI. Check for mistakes.
/* RT-Thread Kernel */

/* klibc options */
Expand Down
17 changes: 17 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": ["ES2020"],
"outDir": "./dist",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?? what's this file used for?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete the useless file

"rootDir": "./",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"types": ["node"]
},
"include": ["**/*.ts"],
"exclude": ["node_modules"]
}
Loading