Skip to content

Commit 926cb92

Browse files
committed
zephyr: add shell implementation over USB CDC ACM
1 parent d48b865 commit 926cb92

File tree

9 files changed

+562
-1
lines changed

9 files changed

+562
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.19)
22

33
project(c2usb
4-
LANGUAGES CXX
4+
LANGUAGES C CXX
55
)
66

77
if(DEFINED ENV{ZEPHYR_BASE})

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ The additional transport layers supported are:
4242
* BLE (HID over GATT Protocol)
4343
* I2C
4444

45+
#### CDC-ACM - Serial Port
46+
47+
The Abstract Control Model of Communications Device Class is fully implemented.
48+
Notably the notification endpoint can be marked as unused, skipping any hardware resource allocation,
49+
but keeping compatibility with all hosts.
50+
4551
### Platforms
4652

4753
* NXP MCUs supported via `mcux_mac` (see [c2usb/port/nxp](c2usb/port/nxp))

c2usb/port/zephyr/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ target_sources_ifdef(CONFIG_C2USB_BLUETOOTH ${PROJECT_NAME}
1919
PRIVATE
2020
hid.cpp
2121
)
22+
target_sources_ifdef(CONFIG_SHELL_BACKEND_C2USB ${PROJECT_NAME}
23+
PUBLIC
24+
usb_shell.hpp
25+
PRIVATE
26+
usb_shell.c
27+
usb_shell.cpp
28+
)

c2usb/port/zephyr/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ config C2USB_UDC_MAC_BUF_POOL_RESERVE
3434

3535
endif # C2USB_UDC_MAC
3636

37+
rsource "Kconfig.shell"
38+
3739
endmenu
3840

3941
choice STD_CPP

c2usb/port/zephyr/Kconfig.shell

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
menuconfig SHELL_BACKEND_C2USB
3+
bool "c2usb shell backend"
4+
help
5+
Build c2usb shell backend.
6+
7+
if SHELL_BACKEND_C2USB
8+
9+
config SHELL_PROMPT_C2USB
10+
string "Displayed prompt name"
11+
default "c2usb:~$ "
12+
help
13+
Displayed prompt name for c2usb backend. If prompt is set, the shell will
14+
send two newlines during initialization.
15+
16+
config SHELL_BACKEND_C2USB_TX_BUFFER_SIZE
17+
int "c2usb shell TX double buffer overall size"
18+
range 128 256
19+
default 256
20+
21+
config SHELL_BACKEND_C2USB_RX_BUFFER_SIZE
22+
int "c2usb shell RX double buffer overall size"
23+
range 32 128
24+
default 128
25+
26+
module = SHELL_BACKEND_C2USB
27+
default-timeout = 100
28+
source "subsys/shell/Kconfig.template.shell_log_queue_timeout"
29+
30+
default-size = 512
31+
source "subsys/shell/Kconfig.template.shell_log_queue_size"
32+
33+
choice
34+
prompt "Initial log level limit"
35+
default SHELL_BACKEND_C2USB_LOG_LEVEL_DEFAULT
36+
37+
config SHELL_BACKEND_C2USB_LOG_LEVEL_DEFAULT
38+
bool "System limit (LOG_MAX_LEVEL)"
39+
40+
config SHELL_BACKEND_C2USB_LOG_LEVEL_DBG
41+
bool "Debug"
42+
43+
config SHELL_BACKEND_C2USB_LOG_LEVEL_INF
44+
bool "Info"
45+
46+
config SHELL_BACKEND_C2USB_LOG_LEVEL_WRN
47+
bool "Warning"
48+
49+
config SHELL_BACKEND_C2USB_LOG_LEVEL_ERR
50+
bool "Error"
51+
52+
config SHELL_BACKEND_C2USB_LOG_LEVEL_NONE
53+
bool "None"
54+
55+
endchoice
56+
57+
config SHELL_BACKEND_C2USB_LOG_LEVEL
58+
int
59+
default 0 if SHELL_BACKEND_C2USB_LOG_LEVEL_NONE
60+
default 1 if SHELL_BACKEND_C2USB_LOG_LEVEL_ERR
61+
default 2 if SHELL_BACKEND_C2USB_LOG_LEVEL_WRN
62+
default 3 if SHELL_BACKEND_C2USB_LOG_LEVEL_INF
63+
default 4 if SHELL_BACKEND_C2USB_LOG_LEVEL_DBG
64+
default 5 if SHELL_BACKEND_C2USB_LOG_LEVEL_DEFAULT
65+
66+
endif # SHELL_BACKEND_C2USB

c2usb/port/zephyr/usb_shell.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#if ((__has_include("zephyr/shell/shell.h")) && CONFIG_SHELL_BACKEND_C2USB)
2+
#include <zephyr/shell/shell.h>
3+
#include <zephyr/sys/atomic.h>
4+
5+
struct shell_transport c2usb_shell_transport = {
6+
.api = NULL,
7+
.ctx = NULL,
8+
};
9+
10+
SHELL_DEFINE(shell_c2usb, CONFIG_SHELL_PROMPT_C2USB, &c2usb_shell_transport,
11+
CONFIG_SHELL_BACKEND_C2USB_LOG_MESSAGE_QUEUE_SIZE,
12+
CONFIG_SHELL_BACKEND_C2USB_LOG_MESSAGE_QUEUE_TIMEOUT, SHELL_FLAG_OLF_CRLF);
13+
14+
const struct shell* c2usb_shell_handle()
15+
{
16+
return &shell_c2usb;
17+
}
18+
#endif

0 commit comments

Comments
 (0)