Skip to content

Commit b8a2cc4

Browse files
committed
feat(extension/fs): add littlefs, windows, arduino sd filesystem backend support
1 parent 6e04c96 commit b8a2cc4

14 files changed

Lines changed: 958 additions & 15 deletions

File tree

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ if(CONFIG_CTSHELL_USE_FS)
4848
list(APPEND ctshell_srcs "${CMAKE_CURRENT_SOURCE_DIR}/extension/fs/ctshell_fs_posix.c")
4949
list(APPEND CTSHELL_DEFINITIONS "CONFIG_CTSHELL_USE_FS_POSIX=1")
5050
endif()
51+
if(CONFIG_CTSHELL_USE_FS_LITTLEFS)
52+
list(APPEND ctshell_srcs "${CMAKE_CURRENT_SOURCE_DIR}/extension/fs/ctshell_fs_littlefs.c")
53+
list(APPEND CTSHELL_DEFINITIONS "CONFIG_CTSHELL_USE_FS_LITTLEFS=1")
54+
endif()
55+
if(CONFIG_CTSHELL_USE_FS_WINDOWS)
56+
list(APPEND ctshell_srcs "${CMAKE_CURRENT_SOURCE_DIR}/extension/fs/ctshell_fs_windows.c")
57+
list(APPEND CTSHELL_DEFINITIONS "CONFIG_CTSHELL_USE_FS_WINDOWS=1")
58+
endif()
59+
if(CONFIG_CTSHELL_USE_FS_ARDUINO_SD)
60+
list(APPEND ctshell_srcs "${CMAKE_CURRENT_SOURCE_DIR}/extension/fs/ctshell_fs_arduino_sd.cpp")
61+
list(APPEND CTSHELL_DEFINITIONS "CONFIG_CTSHELL_USE_FS_ARDUINO_SD=1")
62+
endif()
5163
endif()
5264

5365
if(CONFIG_CTSHELL_USE_DOUBLE)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Ctshell is a low-overhead shell designed specifically for resource-constrained e
1414
* Signal Handling (SIGINT): Implements setjmp/longjmp logic to abort long-running commands via `Ctrl+C`.
1515
* Built-in Argument Parser: Includes a strictly-typed argument parser to easily handle flags (bool), integers, strings, and verbs within custom commands.
1616
* ANSI Escape Sequence Support: Handles standard VT100/ANSI escape codes for arrow keys and screen control.
17-
* Filesystem Support: Out-of-box for `FatFS` now, other fs native support will come soon.
17+
* Filesystem Support: Out-of-box for FatFS, POSIX, Windows, littlefs, and Arduino SD.
1818
* Command Hierarchy Framework: Supports hierarchical command management.
1919

2020
## Porting

ctshell.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,15 @@ extern void ctshell_fs_fatfs_init(ctshell_ctx_t *ctx);
305305
#ifdef CONFIG_CTSHELL_USE_FS_POSIX
306306
extern void ctshell_fs_posix_init(ctshell_ctx_t *ctx);
307307
#endif
308+
#ifdef CONFIG_CTSHELL_USE_FS_LITTLEFS
309+
extern void ctshell_fs_littlefs_init(ctshell_ctx_t *ctx, lfs_t *lfs);
310+
#endif
311+
#ifdef CONFIG_CTSHELL_USE_FS_WINDOWS
312+
extern void ctshell_fs_windows_init(ctshell_ctx_t *ctx);
313+
#endif
314+
#ifdef CONFIG_CTSHELL_USE_FS_ARDUINO_SD
315+
extern void ctshell_fs_arduino_sd_init(ctshell_ctx_t *ctx);
316+
#endif
308317
#endif
309318

310319
#ifdef __cplusplus

ctshell_config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
//#define CONFIG_CTSHELL_USE_FS
1414
//#define CONFIG_CTSHELL_USE_FS_FATFS
1515
//#define CONFIG_CTSHELL_USE_FS_POSIX
16+
//#define CONFIG_CTSHELL_USE_FS_LITTLEFS
17+
//#define CONFIG_CTSHELL_USE_FS_WINDOWS
18+
//#define CONFIG_CTSHELL_USE_FS_ARDUINO_SD
1619

1720
/* ================= Resource Limits ================= */
1821
#define CONFIG_CTSHELL_CMD_NAME_MAX_LEN 16

docs/en/api/api.rst

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,61 @@ Check if a termination signal (Ctrl+C) has been received.
196196
Filesystem API
197197
-------
198198

199-
ctshell_fatfs_init
199+
ctshell_fs_fatfs_init
200200
^^^^^^
201-
Initialize ctshell support for the FatFS file system. This should be called after ctshell initialization.
201+
Initialize ctshell support for the ``FatFS`` file system. This should be called after ctshell initialization.
202202

203203
.. code-block:: c
204204
205-
void ctshell_fatfs_init(ctshell_ctx_t *ctx, ctshell_fs_t *fs);
205+
void ctshell_fs_fatfs_init(ctshell_ctx_t *ctx);
206+
207+
:Parameters:
208+
* ``ctx``: A pointer to the Shell context.
209+
210+
ctshell_fs_posix_init
211+
^^^^^^
212+
Initialize ctshell support for the ``POSIX`` file system. This should be called after ctshell initialization.
213+
214+
.. code-block:: c
215+
216+
void ctshell_fs_posix_init(ctshell_ctx_t *ctx);
217+
218+
:Parameters:
219+
* ``ctx``: A pointer to the Shell context.
220+
221+
ctshell_fs_windows_init
222+
^^^^^^
223+
Initialize ctshell support for the ``Win32`` file system. This should be called after ctshell initialization.
224+
225+
.. code-block:: c
226+
227+
void ctshell_fs_windows_init(ctshell_ctx_t *ctx);
228+
229+
:Parameters:
230+
* ``ctx``: A pointer to the Shell context.
231+
232+
ctshell_fs_littlefs_init
233+
^^^^^^
234+
Initialize ctshell support for the ``littlefs`` file system. This should be called after ctshell initialization.
235+
236+
.. code-block:: c
237+
238+
void ctshell_fs_littlefs_init(ctshell_ctx_t *ctx, lfs_t *lfs);
239+
240+
:Parameters:
241+
* ``ctx``: A pointer to the Shell context.
242+
* ``lfs``: A pointer to the LittleFS instance.
243+
244+
ctshell_fs_arduino_sd_init
245+
^^^^^^
246+
Initialize ctshell support for the ``Arduino SD`` file system. This should be called after ctshell initialization.
247+
248+
.. code-block:: c
249+
250+
void ctshell_fs_arduino_sd_init(ctshell_ctx_t *ctx);
206251
207252
:Parameters:
208253
* ``ctx``: A pointer to the Shell context.
209-
* ``fs``: A pointer to the file system interface structure.
210254

211255
Command Register API
212256
-------

docs/en/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Highlights
1818
* Signal Handling (SIGINT): Implements setjmp/longjmp logic to abort long-running commands via ``Ctrl+C``.
1919
* Built-in Argument Parser: Includes a strictly-typed argument parser to easily handle flags (bool), integers, strings, and verbs within custom commands.
2020
* ANSI Escape Sequence Support: Handles standard VT100/ANSI escape codes for arrow keys and screen control.
21-
* Filesystem Support: Out-of-box for ``FatFS`` now, other fs native support will come soon.
21+
* Filesystem Support: Out-of-box for FatFS, POSIX, Windows, littlefs, and Arduino SD.
2222
* Command Hierarchy Framework: Supports hierarchical command management.
2323

2424
Porting

docs/en/quickstart/porting.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Bare Metal Environment: Initialize the Shell after initializing the UART in the
7070
HAL_Init();
7171
MX_USART1_UART_Init();
7272
73-
ctshell_stm32_init(&ctx, &huart1);
73+
ctshell_port_stm32_init(&ctx, &huart1);
7474
7575
while (1) {
7676
ctshell_poll(&ctx);
@@ -82,7 +82,7 @@ RTOS Environment: It is recommended to create a dedicated task to run the Shell.
8282
.. code-block:: c
8383
8484
void shell_task(void *argument) {
85-
ctshell_stm32_init(&ctx, &huart1);
85+
ctshell_port_stm32_init(&ctx, &huart1);
8686
8787
while (1) {
8888
ctshell_poll(&ctx);

docs/zh/api/api.rst

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,61 @@ ctshell_check_abort
196196
文件系统 API
197197
-------
198198

199-
ctshell_fatfs_init
199+
ctshell_fs_fatfs_init
200200
^^^^^^
201201
初始化 ctshell 对 ``FatFS`` 文件系统的支持。应当在ctshell初始化完成之后调用。
202202

203203
.. code-block:: c
204204
205-
void ctshell_fatfs_init(ctshell_ctx_t *ctx, ctshell_fs_t *fs);
205+
void ctshell_fs_fatfs_init(ctshell_ctx_t *ctx);
206+
207+
:参数:
208+
* ``ctx``: Shell 上下文指针。
209+
210+
ctshell_fs_posix_init
211+
^^^^^^
212+
初始化 ctshell 对 ``POSIX`` 文件系统的支持。应当在ctshell初始化完成之后调用。
213+
214+
.. code-block:: c
215+
216+
void ctshell_fs_posix_init(ctshell_ctx_t *ctx);
217+
218+
:参数:
219+
* ``ctx``: Shell 上下文指针。
220+
221+
ctshell_fs_windows_init
222+
^^^^^^
223+
初始化 ctshell 对 ``Win32`` 文件系统的支持。应当在ctshell初始化完成之后调用。
224+
225+
.. code-block:: c
226+
227+
void ctshell_fs_windows_init(ctshell_ctx_t *ctx);
228+
229+
:参数:
230+
* ``ctx``: Shell 上下文指针。
231+
232+
ctshell_fs_littlefs_init
233+
^^^^^^
234+
初始化 ctshell 对 ``littlefs`` 文件系统的支持。应当在ctshell初始化完成之后调用。
235+
236+
.. code-block:: c
237+
238+
void ctshell_fs_littlefs_init(ctshell_ctx_t *ctx, lfs_t *lfs);
239+
240+
:参数:
241+
* ``ctx``: Shell 上下文指针。
242+
* ``lfs``: LittleFS 上下文指针。
243+
244+
ctshell_fs_arduino_sd_init
245+
^^^^^^
246+
初始化 ctshell 对 ``Arduino SD`` 文件系统的支持。应当在ctshell初始化完成之后调用。
247+
248+
.. code-block:: c
249+
250+
void ctshell_fs_arduino_sd_init(ctshell_ctx_t *ctx);
206251
207252
:参数:
208253
* ``ctx``: Shell 上下文指针。
209-
* ``fs``: 文件系统接口结构体指针。
210254

211255
命令注册 API
212256
-------

docs/zh/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Ctshell 是一款小而美的、低开销的shell,专为资源受限的嵌入
1818
* 信号处理 (SIGINT):实现 setjmp/longjmp 逻辑,可通过 Ctrl+C 中断长时间运行的命令。
1919
* 内置参数解析器:包含一个强类型参数解析器,可轻松处理自定义命令中的标志(布尔值)、整数、字符串和子命令。
2020
* ANSI 转义序列支持:处理用于箭头键和屏幕控制的标准 VT100/ANSI 转义码。
21-
* 文件系统支持:目前已原生支持 FatFS,其他文件系统的原生支持也将很快推出
21+
* 文件系统支持:目前已原生支持 FatFS、POSIX、Windows、littlefs、Arduino SD
2222
* 命令层级框架:支持层级式命令管理。
2323

2424
移植

docs/zh/quickstart/porting.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ stm32 使用中断接收示例:
7070
HAL_Init();
7171
MX_USART1_UART_Init();
7272
73-
ctshell_stm32_init(&ctx, &huart1);
73+
ctshell_port_stm32_init(&ctx, &huart1);
7474
7575
while (1) {
7676
ctshell_poll(&ctx);
@@ -82,7 +82,7 @@ RTOS 环境: 建议创建一个独立的任务来运行 Shell。
8282
.. code-block:: c
8383
8484
void shell_task(void *argument) {
85-
ctshell_stm32_init(&ctx, &huart1);
85+
ctshell_port_stm32_init(&ctx, &huart1);
8686
8787
while (1) {
8888
ctshell_poll(&ctx);

0 commit comments

Comments
 (0)