@@ -33,18 +33,19 @@ static TaskHandle_t s_task_handle = NULL;
3333#define CDC_IN_EP 0x81
3434#define CDC_OUT_EP 0x01
3535#define CDC_INT_EP 0x83
36-
36+ #if CDC_ACM_CHANNEL_NUM >= 2
3737#define CDC_IN_EP1 0x82
3838#define CDC_OUT_EP1 0x02
3939#define CDC_INT_EP1 0x84
40+ #endif
4041
4142#define USBD_VID 0xFFFF
4243#define USBD_PID 0xFFFF
4344#define USBD_MAX_POWER 100
4445#define USBD_LANGID_STRING 1033
4546
4647/*!< config descriptor size */
47- #define USB_CONFIG_SIZE (9 + CDC_ACM_DESCRIPTOR_LEN * 4 )
48+ #define USB_CONFIG_SIZE (9 + CDC_ACM_DESCRIPTOR_LEN * CDC_ACM_CHANNEL_NUM )
4849
4950#define CDC_FS_MAX_MPS 64
5051#define CDC_HS_MAX_MPS 512
@@ -85,7 +86,6 @@ static uint32_t s_mps = CDC_MAX_MPS;
8586static DRAM_DMA_ALIGNED_ATTR uint8_t read_buffer [CDC_ACM_CHANNEL_NUM ][READ_BUFFER_SIZE ];
8687static DRAM_DMA_ALIGNED_ATTR uint8_t write_buffer [CDC_ACM_CHANNEL_NUM ][WRITE_BUFFER_SIZE ];
8788
88- #ifdef CONFIG_USBDEV_ADVANCE_DESC
8989static const uint8_t device_descriptor [] = {
9090 USB_DEVICE_DESCRIPTOR_INIT (USB_2_0 , 0xEF , 0x02 , 0x01 , USBD_VID , USBD_PID , 0x0100 , 0x01 )
9191};
@@ -170,90 +170,8 @@ const struct usb_descriptor cdc_descriptor = {
170170 .device_quality_descriptor_callback = device_quality_descriptor_callback ,
171171 .string_descriptor_callback = string_descriptor_callback
172172};
173- #else
174- /*!< global descriptor */
175- static const uint8_t cdc_descriptor [] = {
176- USB_DEVICE_DESCRIPTOR_INIT (USB_2_0 , 0xEF , 0x02 , 0x01 , USBD_VID , USBD_PID , 0x0100 , 0x01 ),
177- USB_CONFIG_DESCRIPTOR_INIT (USB_CONFIG_SIZE , INTERFACES_NUM , 0x01 , USB_CONFIG_BUS_POWERED , USBD_MAX_POWER ),
178- CDC_ACM_DESCRIPTOR_INIT (0x00 , CDC_INT_EP , CDC_OUT_EP , CDC_IN_EP , CDC_MAX_MPS , 0x02 ),
179- #ifdef CONFIG_EXAMPLE_CHERRYUSB_CDC_ACM_TWO_CHANNEL
180- CDC_ACM_DESCRIPTOR_INIT (0x02 , CDC_INT_EP1 , CDC_OUT_EP1 , CDC_IN_EP1 , CDC_MAX_MPS , 0x02 ),
181- #endif
182- ///////////////////////////////////////
183- /// string0 descriptor
184- ///////////////////////////////////////
185- USB_LANGID_INIT (USBD_LANGID_STRING ),
186- ///////////////////////////////////////
187- /// string1 descriptor
188- ///////////////////////////////////////
189- 0x14 , /* bLength */
190- USB_DESCRIPTOR_TYPE_STRING , /* bDescriptorType */
191- 'C' , 0x00 , /* wcChar0 */
192- 'h' , 0x00 , /* wcChar1 */
193- 'e' , 0x00 , /* wcChar2 */
194- 'r' , 0x00 , /* wcChar3 */
195- 'r' , 0x00 , /* wcChar4 */
196- 'y' , 0x00 , /* wcChar5 */
197- 'U' , 0x00 , /* wcChar6 */
198- 'S' , 0x00 , /* wcChar7 */
199- 'B' , 0x00 , /* wcChar8 */
200- ///////////////////////////////////////
201- /// string2 descriptor
202- ///////////////////////////////////////
203- 0x26 , /* bLength */
204- USB_DESCRIPTOR_TYPE_STRING , /* bDescriptorType */
205- 'C' , 0x00 , /* wcChar0 */
206- 'h' , 0x00 , /* wcChar1 */
207- 'e' , 0x00 , /* wcChar2 */
208- 'r' , 0x00 , /* wcChar3 */
209- 'r' , 0x00 , /* wcChar4 */
210- 'y' , 0x00 , /* wcChar5 */
211- 'U' , 0x00 , /* wcChar6 */
212- 'S' , 0x00 , /* wcChar7 */
213- 'B' , 0x00 , /* wcChar8 */
214- ' ' , 0x00 , /* wcChar9 */
215- 'C' , 0x00 , /* wcChar10 */
216- 'D' , 0x00 , /* wcChar11 */
217- 'C' , 0x00 , /* wcChar12 */
218- ' ' , 0x00 , /* wcChar13 */
219- 'D' , 0x00 , /* wcChar14 */
220- 'E' , 0x00 , /* wcChar15 */
221- 'M' , 0x00 , /* wcChar16 */
222- 'O' , 0x00 , /* wcChar17 */
223- ///////////////////////////////////////
224- /// string3 descriptor
225- ///////////////////////////////////////
226- 0x16 , /* bLength */
227- USB_DESCRIPTOR_TYPE_STRING , /* bDescriptorType */
228- '2' , 0x00 , /* wcChar0 */
229- '0' , 0x00 , /* wcChar1 */
230- '2' , 0x00 , /* wcChar2 */
231- '5' , 0x00 , /* wcChar3 */
232- '0' , 0x00 , /* wcChar4 */
233- '6' , 0x00 , /* wcChar5 */
234- '0' , 0x00 , /* wcChar6 */
235- '5' , 0x00 , /* wcChar7 */
236- '1' , 0x00 , /* wcChar8 */
237- '8' , 0x00 , /* wcChar9 */
238- #ifdef CONFIG_USB_HS
239- ///////////////////////////////////////
240- /// device qualifier descriptor
241- ///////////////////////////////////////
242- 0x0a ,
243- USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER ,
244- 0x00 ,
245- 0x02 ,
246- 0x00 ,
247- 0x00 ,
248- 0x00 ,
249- 0x40 ,
250- 0x00 ,
251- 0x00 ,
252- #endif
253- 0x00
254- };
255- #endif
256173
174+ //Note: This callback is in the interrupt context
257175void usbd_event_handler (uint8_t busid , uint8_t event )
258176{
259177 switch (event ) {
@@ -285,6 +203,7 @@ void usbd_event_handler(uint8_t busid, uint8_t event)
285203 }
286204}
287205
206+ //Note: This callback is in the interrupt context
288207static void usbd_cdc_acm_bulk_out (uint8_t busid , uint8_t ep , uint32_t nbytes )
289208{
290209 ESP_EARLY_LOGI (TAG , "ep 0x%02X actual out len:%d" , ep , nbytes );
@@ -321,6 +240,7 @@ static void usbd_cdc_acm_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
321240 }
322241}
323242
243+ //Note: This callback is in the interrupt context
324244static void usbd_cdc_acm_bulk_in (uint8_t busid , uint8_t ep , uint32_t nbytes )
325245{
326246 BaseType_t HPTaskAwoken = pdFALSE ;
@@ -373,11 +293,8 @@ struct usbd_interface intf3;
373293
374294static void cdc_acm_init (void )
375295{
376- #ifdef CONFIG_USBDEV_ADVANCE_DESC
377296 usbd_desc_register (0 , & cdc_descriptor );
378- #else
379- usbd_desc_register (0 , cdc_descriptor );
380- #endif
297+
381298 usbd_add_interface (0 , usbd_cdc_acm_init_intf (0 , & intf0 ));
382299 usbd_add_interface (0 , usbd_cdc_acm_init_intf (0 , & intf1 ));
383300 usbd_add_endpoint (0 , & cdc_out_ep );
@@ -396,11 +313,13 @@ static void cdc_acm_init(void)
396313#endif
397314}
398315
316+ //Note: This callback is in the interrupt context
399317void usbd_cdc_acm_set_dtr (uint8_t busid , uint8_t intf , bool dtr )
400318{
401319 ESP_EARLY_LOGI (TAG , "intf:%u, dtr:%d" , intf , dtr );
402320}
403321
322+ //Note: This callback is in the interrupt context
404323void usbd_cdc_acm_set_rts (uint8_t busid , uint8_t intf , bool rts )
405324{
406325 ESP_EARLY_LOGI (TAG , "intf:%u, rts:%d" , intf , rts );
@@ -470,22 +389,22 @@ void cdc_acm_task(void *arg)
470389void app_main (void )
471390{
472391#if CONFIG_EXAMPLE_CHERRYUSB_INIT_DEINIT_LOOP
473- reinit :
392+ while ( 1 )
474393#endif
475-
476- xTaskCreatePinnedToCore (& cdc_acm_task , "cdc_acm_task" , 1024 * 3 , NULL , 10 , & s_task_handle , 0 );
394+ {
395+ xTaskCreatePinnedToCore (& cdc_acm_task , "cdc_acm_task" , 1024 * 3 , NULL , 10 , & s_task_handle , 0 );
477396
478397#if CONFIG_EXAMPLE_CHERRYUSB_INIT_DEINIT_LOOP
479- for (int i = 10 ; i >= 0 ; i -- ) {
480- ESP_LOGW (TAG , "Deinit usb after %d seconds..." , i );
481- vTaskDelay (1000 / portTICK_PERIOD_MS );
482- }
483- ESP_LOGW (TAG , "Notify deinit usb" );
484- xTaskNotify (s_task_handle , NOTIFY_EXIT_BIT , eSetBits );
485- while (s_task_handle ) {
486- vTaskDelay (100 / portTICK_PERIOD_MS );
487- }
488- goto reinit ;
398+ for (int i = 10 ; i >= 0 ; i -- ) {
399+ ESP_LOGW (TAG , "Deinit usb after %d seconds..." , i );
400+ vTaskDelay (1000 / portTICK_PERIOD_MS );
401+ }
402+ ESP_LOGW (TAG , "Notify deinit usb" );
403+ xTaskNotify (s_task_handle , NOTIFY_EXIT_BIT , eSetBits );
404+ while (s_task_handle ) {
405+ vTaskDelay (100 / portTICK_PERIOD_MS );
406+ }
489407#endif
408+ }
490409
491410}
0 commit comments