41
41
42
42
#define USBD_STACK_SIZE 4096
43
43
#else
44
+
44
45
#include "FreeRTOS.h"
45
46
#include "semphr.h"
46
47
#include "queue.h"
54
55
#define CDC_STACK_SZIE configMINIMAL_STACK_SIZE
55
56
56
57
//--------------------------------------------------------------------+
57
- // MACRO CONSTANT TYPEDEF PROTYPES
58
+ // MACRO CONSTANT TYPEDEF PROTOTYPES
58
59
//--------------------------------------------------------------------+
59
60
60
61
/* Blink pattern
61
62
* - 250 ms : device not mounted
62
63
* - 1000 ms : device mounted
63
64
* - 2500 ms : device is suspended
64
65
*/
65
- enum {
66
+ enum {
66
67
BLINK_NOT_MOUNTED = 250 ,
67
68
BLINK_MOUNTED = 1000 ,
68
69
BLINK_SUSPENDED = 2500 ,
@@ -81,16 +82,15 @@ StaticTask_t cdc_taskdef;
81
82
82
83
TimerHandle_t blinky_tm ;
83
84
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 );
87
88
88
89
//--------------------------------------------------------------------+
89
90
// Main
90
91
//--------------------------------------------------------------------+
91
92
92
- int main (void )
93
- {
93
+ int main (void ) {
94
94
board_init ();
95
95
96
96
#if configSUPPORT_STATIC_ALLOCATION
@@ -104,8 +104,8 @@ int main(void)
104
104
xTaskCreateStatic (cdc_task , "cdc" , CDC_STACK_SZIE , NULL , configMAX_PRIORITIES - 2 , cdc_stack , & cdc_taskdef );
105
105
#else
106
106
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 );
109
109
#endif
110
110
111
111
xTimerStart (blinky_tm , 0 );
@@ -119,16 +119,14 @@ int main(void)
119
119
}
120
120
121
121
#if TU_CHECK_MCU (OPT_MCU_ESP32S2 , OPT_MCU_ESP32S3 )
122
- void app_main (void )
123
- {
122
+ void app_main (void ) {
124
123
main ();
125
124
}
126
125
#endif
127
126
128
127
// USB Device Driver task
129
128
// 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 ) {
132
130
(void ) param ;
133
131
134
132
// init device stack on configured roothub port
@@ -141,8 +139,7 @@ void usb_device_task(void* param)
141
139
}
142
140
143
141
// RTOS forever loop
144
- while (1 )
145
- {
142
+ while (1 ) {
146
143
// put this thread to waiting state until there is new events
147
144
tud_task ();
148
145
@@ -156,56 +153,46 @@ void usb_device_task(void* param)
156
153
//--------------------------------------------------------------------+
157
154
158
155
// Invoked when device is mounted
159
- void tud_mount_cb (void )
160
- {
156
+ void tud_mount_cb (void ) {
161
157
xTimerChangePeriod (blinky_tm , pdMS_TO_TICKS (BLINK_MOUNTED ), 0 );
162
158
}
163
159
164
160
// Invoked when device is unmounted
165
- void tud_umount_cb (void )
166
- {
161
+ void tud_umount_cb (void ) {
167
162
xTimerChangePeriod (blinky_tm , pdMS_TO_TICKS (BLINK_NOT_MOUNTED ), 0 );
168
163
}
169
164
170
165
// Invoked when usb bus is suspended
171
166
// remote_wakeup_en : if host allow us to perform remote wakeup
172
167
// 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 ) {
175
169
(void ) remote_wakeup_en ;
176
170
xTimerChangePeriod (blinky_tm , pdMS_TO_TICKS (BLINK_SUSPENDED ), 0 );
177
171
}
178
172
179
173
// 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 ()) {
184
176
xTimerChangePeriod (blinky_tm , pdMS_TO_TICKS (BLINK_MOUNTED ), 0 );
185
- }
186
- else
187
- {
177
+ } else {
188
178
xTimerChangePeriod (blinky_tm , pdMS_TO_TICKS (BLINK_NOT_MOUNTED ), 0 );
189
179
}
190
180
}
191
181
192
182
//--------------------------------------------------------------------+
193
183
// USB CDC
194
184
//--------------------------------------------------------------------+
195
- void cdc_task (void * params )
196
- {
185
+ void cdc_task (void * params ) {
197
186
(void ) params ;
198
187
199
188
// RTOS forever loop
200
- while ( 1 )
201
- {
189
+ while (1 ) {
202
190
// connected() check for DTR bit
203
191
// Most but not all terminal client set this when making connection
204
192
// if ( tud_cdc_connected() )
205
193
{
206
194
// There are data available
207
- while ( tud_cdc_available () )
208
- {
195
+ while (tud_cdc_available ()) {
209
196
uint8_t buf [64 ];
210
197
211
198
// read and echo back
@@ -228,32 +215,27 @@ void cdc_task(void* params)
228
215
}
229
216
230
217
// 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 ) {
233
219
(void ) itf ;
234
220
(void ) rts ;
235
221
236
222
// TODO set some indicator
237
- if ( dtr )
238
- {
223
+ if (dtr ) {
239
224
// Terminal connected
240
- }else
241
- {
225
+ } else {
242
226
// Terminal disconnected
243
227
}
244
228
}
245
229
246
230
// 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 ) {
249
232
(void ) itf ;
250
233
}
251
234
252
235
//--------------------------------------------------------------------+
253
236
// BLINKING TASK
254
237
//--------------------------------------------------------------------+
255
- void led_blinky_cb (TimerHandle_t xTimer )
256
- {
238
+ static void led_blinky_cb (TimerHandle_t xTimer ) {
257
239
(void ) xTimer ;
258
240
static bool led_state = false;
259
241
0 commit comments