Skip to content

Commit a7c136c

Browse files
committed
adding host/cdc_msc_hid_freertos example
1 parent 81cd995 commit a7c136c

File tree

20 files changed

+622
-111
lines changed

20 files changed

+622
-111
lines changed

.idea/cmake.xml

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/device/cdc_msc_freertos/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ INC += \
1010
src/FreeRTOSConfig \
1111
$(TOP)/hw \
1212
$(TOP)/$(FREERTOS_SRC)/include \
13-
$(TOP)/$(FREERTOS_PORTABLE_SRC)
13+
$(TOP)/$(FREERTOS_PORTABLE_SRC) \
1414

1515
# Example source
1616
EXAMPLE_SOURCE = \

examples/device/cdc_msc_freertos/src/main.c

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
#define USBD_STACK_SIZE 4096
4343
#else
44+
4445
#include "FreeRTOS.h"
4546
#include "semphr.h"
4647
#include "queue.h"
@@ -54,15 +55,15 @@
5455
#define CDC_STACK_SZIE configMINIMAL_STACK_SIZE
5556

5657
//--------------------------------------------------------------------+
57-
// MACRO CONSTANT TYPEDEF PROTYPES
58+
// MACRO CONSTANT TYPEDEF PROTOTYPES
5859
//--------------------------------------------------------------------+
5960

6061
/* Blink pattern
6162
* - 250 ms : device not mounted
6263
* - 1000 ms : device mounted
6364
* - 2500 ms : device is suspended
6465
*/
65-
enum {
66+
enum {
6667
BLINK_NOT_MOUNTED = 250,
6768
BLINK_MOUNTED = 1000,
6869
BLINK_SUSPENDED = 2500,
@@ -81,16 +82,15 @@ StaticTask_t cdc_taskdef;
8182

8283
TimerHandle_t blinky_tm;
8384

84-
void led_blinky_cb(TimerHandle_t xTimer);
85-
void usb_device_task(void* param);
86-
void cdc_task(void* params);
85+
static void led_blinky_cb(TimerHandle_t xTimer);
86+
static void usb_device_task(void *param);
87+
void cdc_task(void *params);
8788

8889
//--------------------------------------------------------------------+
8990
// Main
9091
//--------------------------------------------------------------------+
9192

92-
int main(void)
93-
{
93+
int main(void) {
9494
board_init();
9595

9696
#if configSUPPORT_STATIC_ALLOCATION
@@ -104,8 +104,8 @@ int main(void)
104104
xTaskCreateStatic(cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, cdc_stack, &cdc_taskdef);
105105
#else
106106
blinky_tm = xTimerCreate(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb);
107-
xTaskCreate( usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, NULL);
108-
xTaskCreate( cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, NULL);
107+
xTaskCreate(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
108+
xTaskCreate(cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES - 2, NULL);
109109
#endif
110110

111111
xTimerStart(blinky_tm, 0);
@@ -119,16 +119,14 @@ int main(void)
119119
}
120120

121121
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
122-
void app_main(void)
123-
{
122+
void app_main(void) {
124123
main();
125124
}
126125
#endif
127126

128127
// USB Device Driver task
129128
// This top level thread process all usb events and invoke callbacks
130-
void usb_device_task(void* param)
131-
{
129+
static void usb_device_task(void *param) {
132130
(void) param;
133131

134132
// init device stack on configured roothub port
@@ -141,8 +139,7 @@ void usb_device_task(void* param)
141139
}
142140

143141
// RTOS forever loop
144-
while (1)
145-
{
142+
while (1) {
146143
// put this thread to waiting state until there is new events
147144
tud_task();
148145

@@ -156,56 +153,46 @@ void usb_device_task(void* param)
156153
//--------------------------------------------------------------------+
157154

158155
// Invoked when device is mounted
159-
void tud_mount_cb(void)
160-
{
156+
void tud_mount_cb(void) {
161157
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
162158
}
163159

164160
// Invoked when device is unmounted
165-
void tud_umount_cb(void)
166-
{
161+
void tud_umount_cb(void) {
167162
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), 0);
168163
}
169164

170165
// Invoked when usb bus is suspended
171166
// remote_wakeup_en : if host allow us to perform remote wakeup
172167
// Within 7ms, device must draw an average of current less than 2.5 mA from bus
173-
void tud_suspend_cb(bool remote_wakeup_en)
174-
{
168+
void tud_suspend_cb(bool remote_wakeup_en) {
175169
(void) remote_wakeup_en;
176170
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_SUSPENDED), 0);
177171
}
178172

179173
// Invoked when usb bus is resumed
180-
void tud_resume_cb(void)
181-
{
182-
if (tud_mounted())
183-
{
174+
void tud_resume_cb(void) {
175+
if (tud_mounted()) {
184176
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
185-
}
186-
else
187-
{
177+
} else {
188178
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), 0);
189179
}
190180
}
191181

192182
//--------------------------------------------------------------------+
193183
// USB CDC
194184
//--------------------------------------------------------------------+
195-
void cdc_task(void* params)
196-
{
185+
void cdc_task(void *params) {
197186
(void) params;
198187

199188
// RTOS forever loop
200-
while ( 1 )
201-
{
189+
while (1) {
202190
// connected() check for DTR bit
203191
// Most but not all terminal client set this when making connection
204192
// if ( tud_cdc_connected() )
205193
{
206194
// There are data available
207-
while ( tud_cdc_available() )
208-
{
195+
while (tud_cdc_available()) {
209196
uint8_t buf[64];
210197

211198
// read and echo back
@@ -228,32 +215,27 @@ void cdc_task(void* params)
228215
}
229216

230217
// Invoked when cdc when line state changed e.g connected/disconnected
231-
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
232-
{
218+
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
233219
(void) itf;
234220
(void) rts;
235221

236222
// TODO set some indicator
237-
if ( dtr )
238-
{
223+
if (dtr) {
239224
// Terminal connected
240-
}else
241-
{
225+
} else {
242226
// Terminal disconnected
243227
}
244228
}
245229

246230
// Invoked when CDC interface received data from host
247-
void tud_cdc_rx_cb(uint8_t itf)
248-
{
231+
void tud_cdc_rx_cb(uint8_t itf) {
249232
(void) itf;
250233
}
251234

252235
//--------------------------------------------------------------------+
253236
// BLINKING TASK
254237
//--------------------------------------------------------------------+
255-
void led_blinky_cb(TimerHandle_t xTimer)
256-
{
238+
static void led_blinky_cb(TimerHandle_t xTimer) {
257239
(void) xTimer;
258240
static bool led_state = false;
259241

examples/host/bare_api/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ project(${PROJECT} C CXX ASM)
1010
# Checks this example is valid for the family and initializes the project
1111
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
1212

13+
# Espressif has its own cmake build system
14+
if(FAMILY STREQUAL "espressif")
15+
return()
16+
endif()
17+
1318
add_executable(${PROJECT})
1419

1520
# Example source

examples/host/cdc_msc_hid/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ project(${PROJECT} C CXX ASM)
1010
# Checks this example is valid for the family and initializes the project
1111
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
1212

13+
# Espressif has its own cmake build system
14+
if(FAMILY STREQUAL "espressif")
15+
return()
16+
endif()
17+
1318
add_executable(${PROJECT})
1419

1520
# Example source
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
cmake_minimum_required(VERSION 3.17)
2+
3+
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)
4+
5+
# gets PROJECT name for the example (e.g. <BOARD>-<DIR_NAME>)
6+
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
7+
8+
project(${PROJECT} C CXX ASM)
9+
10+
# Checks this example is valid for the family and initializes the project
11+
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
12+
13+
# Espressif has its own cmake build system
14+
if(FAMILY STREQUAL "espressif")
15+
return()
16+
endif()
17+
18+
add_executable(${PROJECT})
19+
20+
# Example source
21+
target_sources(${PROJECT} PUBLIC
22+
${CMAKE_CURRENT_SOURCE_DIR}/src/cdc_app.c
23+
${CMAKE_CURRENT_SOURCE_DIR}/src/freertos_hook.c
24+
${CMAKE_CURRENT_SOURCE_DIR}/src/hid_app.c
25+
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
26+
${CMAKE_CURRENT_SOURCE_DIR}/src/msc_app.c
27+
)
28+
29+
# Example include
30+
target_include_directories(${PROJECT} PUBLIC
31+
${CMAKE_CURRENT_SOURCE_DIR}/src
32+
)
33+
34+
# Configure compilation flags and libraries for the example without RTOS.
35+
# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
36+
family_configure_host_example(${PROJECT} freertos)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This file is for ESP-IDF only
2+
idf_component_register(SRCS "hid_app.c" "main.c"
3+
INCLUDE_DIRS "."
4+
REQUIRES boards tinyusb_src)

0 commit comments

Comments
 (0)