@@ -62,10 +62,11 @@ class USBAudioConfig {
6262 int func_ep_out_size_max = 0 ; // CFG_TUD_AUDIO_EP_SZ_OUT
6363 size_t (*p_write_callback)(const uint8_t *data, size_t len,
6464 USBDeviceAudio &ref) = nullptr ;
65- size_t (*p_read_callback)(uint8_t *data, size_t len, USBDeviceAudio &ref) = nullptr ;
65+ size_t (*p_read_callback)(uint8_t *data, size_t len,
66+ USBDeviceAudio &ref) = nullptr ;
6667
67- bool is_ep_out () { return p_write_callback!= nullptr ;}
68- bool is_ep_in () {return p_read_callback!= nullptr ;};
68+ bool is_ep_out () { return p_write_callback != nullptr ; }
69+ bool is_ep_in () { return p_read_callback != nullptr ; };
6970
7071 // setup (missing) default values
7172 void begin () {
@@ -291,7 +292,7 @@ class USBDeviceAudioAPI {
291292 }
292293
293294 void audiod_init () {
294- assert (p_cb!= nullptr );
295+ if (p_cb == nullptr ) return ;
295296 _audiod_fct.resize (cfg.func_n_as_int );
296297 ctrl_buf_1.resize (cfg.func_ctl_buffer_size );
297298 alt_setting_1.resize (cfg.func_n_as_int );
@@ -340,10 +341,7 @@ class USBDeviceAudioAPI {
340341 if (cfg.enable_linear_buffer_rx ) audio->lin_buf_out = lin_buf_out_1.data ();
341342 }
342343
343- bool audiod_deinit (void ) {
344-
345- return true ;
346- }
344+ bool audiod_deinit (void ) { return true ; }
347345
348346 void audiod_reset (uint8_t rhport) {
349347 (void )rhport;
@@ -361,13 +359,16 @@ class USBDeviceAudioAPI {
361359 uint16_t audiod_open (uint8_t rhport, tusb_desc_interface_t const *itf_desc,
362360 uint16_t max_len) {
363361 (void )max_len;
364- assert (p_cb != nullptr );
362+ if (p_cb == nullptr ) return 0 ;
363+
364+ int cls_tobe = TUSB_CLASS_AUDIO;
365+ int cls_is = itf_desc->bInterfaceClass ;
365366
366- TU_VERIFY (TUSB_CLASS_AUDIO == itf_desc->bInterfaceClass &&
367- AUDIO_SUBCLASS_CONTROL == itf_desc->bInterfaceSubClass );
367+ // TU_VERIFY(TUSB_CLASS_AUDIO == itf_desc->bInterfaceClass &&
368+ // AUDIO_SUBCLASS_CONTROL == itf_desc->bInterfaceSubClass);
368369
369- // Verify version is correct - this check can be omitted
370- TU_VERIFY (itf_desc->bInterfaceProtocol == AUDIO_INT_PROTOCOL_CODE_V2);
370+ // // Verify version is correct - this check can be omitted
371+ // TU_VERIFY(itf_desc->bInterfaceProtocol == AUDIO_INT_PROTOCOL_CODE_V2);
371372
372373 // Verify interrupt control EP is enabled if demanded by descriptor
373374 TU_ASSERT (itf_desc->bNumEndpoints <= 1 ); // 0 or 1 EPs are allowed
@@ -390,40 +391,44 @@ class USBDeviceAudioAPI {
390391 _audiod_fct[i].rhport = rhport;
391392
392393#ifdef TUP_DCD_EDPT_ISO_ALLOC
393- uint8_t ep_in = 0 ;
394- uint16_t ep_in_size = 0 ;
395- uint8_t ep_out = 0 ;
396- uint16_t ep_out_size = 0 ;
397- uint8_t ep_fb = 0 ;
398- uint8_t const *p_desc = _audiod_fct[i].p_desc ;
399- uint8_t const *p_desc_end =
400- p_desc + _audiod_fct[i].desc_length - TUD_AUDIO_DESC_IAD_LEN;
401- // Condition modified from p_desc < p_desc_end to prevent gcc>=12
402- // strict-overflow warning
403- while (p_desc_end - p_desc > 0 ) {
404- if (tu_desc_type (p_desc) == TUSB_DESC_ENDPOINT) {
405- tusb_desc_endpoint_t const *desc_ep =
406- (tusb_desc_endpoint_t const *)p_desc;
407- if (desc_ep->bmAttributes .xfer == TUSB_XFER_ISOCHRONOUS) {
408- if (cfg.enable_feedback_ep ) {
409- // Explicit feedback EP
410- if (desc_ep->bmAttributes .usage == 1 ) {
411- ep_fb = desc_ep->bEndpointAddress ;
412- }
413- }
414- // Data EP
415- if (desc_ep->bmAttributes .usage == 0 ) {
416- if (tu_edpt_dir (desc_ep->bEndpointAddress ) == TUSB_DIR_IN) {
417- if (cfg.is_ep_in ()) {
418- ep_in = desc_ep->bEndpointAddress ;
419- ep_in_size =
420- TU_MAX (tu_edpt_packet_size (desc_ep), ep_in_size);
394+ {
395+ uint8_t ep_in = 0 ;
396+ uint16_t ep_in_size = 0 ;
397+
398+ uint8_t ep_out = 0 ;
399+ uint16_t ep_out_size = 0 ;
400+
401+ uint8_t ep_fb = 0 ;
402+ uint8_t const *p_desc = _audiod_fct[i].p_desc ;
403+ uint8_t const *p_desc_end =
404+ p_desc + _audiod_fct[i].desc_length - TUD_AUDIO_DESC_IAD_LEN;
405+ // Condition modified from p_desc < p_desc_end to prevent gcc>=12
406+ // strict-overflow warning
407+ while (p_desc_end - p_desc > 0 ) {
408+ if (tu_desc_type (p_desc) == TUSB_DESC_ENDPOINT) {
409+ tusb_desc_endpoint_t const *desc_ep =
410+ (tusb_desc_endpoint_t const *)p_desc;
411+ if (desc_ep->bmAttributes .xfer == TUSB_XFER_ISOCHRONOUS) {
412+ if (cfg.enable_feedback_ep ) {
413+ // Explicit feedback EP
414+ if (desc_ep->bmAttributes .usage == 1 ) {
415+ ep_fb = desc_ep->bEndpointAddress ;
421416 }
422- } else {
423- if (cfg.is_ep_out ()) {
424- ep_out = desc_ep->bEndpointAddress ;
425- ep_out_size =
426- TU_MAX (tu_edpt_packet_size (desc_ep), ep_out_size);
417+ }
418+ // Data EP
419+ if (desc_ep->bmAttributes .usage == 0 ) {
420+ if (tu_edpt_dir (desc_ep->bEndpointAddress ) == TUSB_DIR_IN) {
421+ if (cfg.is_ep_in ()) {
422+ ep_in = desc_ep->bEndpointAddress ;
423+ ep_in_size =
424+ TU_MAX (tu_edpt_packet_size (desc_ep), ep_in_size);
425+ }
426+ } else {
427+ if (cfg.is_ep_out ()) {
428+ ep_out = desc_ep->bEndpointAddress ;
429+ ep_out_size =
430+ TU_MAX (tu_edpt_packet_size (desc_ep), ep_out_size);
431+ }
427432 }
428433 }
429434 }
@@ -432,11 +437,12 @@ class USBDeviceAudioAPI {
432437 p_desc = tu_desc_next (p_desc);
433438 }
434439
435- if (ep_in) {
440+ if (cfg. is_ep_in () && ep_in) {
436441 usbd_edpt_iso_alloc (rhport, ep_in, ep_in_size);
437442 }
438443
439- if (ep_out) {
444+
445+ if (cfg.is_ep_out () && ep_out) {
440446 usbd_edpt_iso_alloc (rhport, ep_out, ep_out_size);
441447 }
442448
@@ -446,7 +452,8 @@ class USBDeviceAudioAPI {
446452 }
447453 }
448454 }
449- #endif
455+
456+ #endif // TUP_DCD_EDPT_ISO_ALLOC
450457
451458 if (cfg.is_ep_in () && cfg.enable_ep_in_flow_control ) {
452459 uint8_t const *p_desc = _audiod_fct[i].p_desc ;
@@ -475,7 +482,7 @@ class USBDeviceAudioAPI {
475482 }
476483 p_desc = tu_desc_next (p_desc);
477484 }
478- } // cfg.enable_ep_in_flow_control
485+ } // CFG_TUD_AUDIO_EP_IN_FLOW_CONTROL
479486
480487 if (cfg.enable_interrupt_ep ) {
481488 uint8_t const *p_desc = _audiod_fct[i].p_desc ;
@@ -500,22 +507,23 @@ class USBDeviceAudioAPI {
500507 p_desc = tu_desc_next (p_desc);
501508 }
502509 }
510+
511+ _audiod_fct[i].mounted = true ;
512+ break ;
503513 }
504- _audiod_fct[i].mounted = true ;
505- break ;
506-
507- // Verify we found a free one
508- TU_ASSERT (i < cfg.func_n_as_int );
509-
510- // This is all we need so far - the EPs are setup by a later
511- // set_interface request (as per UAC2 specification)
512- uint16_t drv_len =
513- _audiod_fct[i].desc_length -
514- TUD_AUDIO_DESC_IAD_LEN; // - TUD_AUDIO_DESC_IAD_LEN since tinyUSB
515- // already handles the IAD descriptor
516- return drv_len;
517514 }
518- return 0 ;
515+
516+ // Verify we found a free one
517+ TU_ASSERT (i < cfg.func_n_as_int );
518+
519+ // This is all we need so far - the EPs are setup by a later set_interface
520+ // request (as per UAC2 specification)
521+ uint16_t drv_len =
522+ _audiod_fct[i].desc_length -
523+ TUD_AUDIO_DESC_IAD_LEN; // - TUD_AUDIO_DESC_IAD_LEN since tinyUSB
524+ // already handles the IAD descriptor
525+
526+ return drv_len;
519527 }
520528
521529 // Handle class co
@@ -759,9 +767,7 @@ class USBDeviceAudioAPI {
759767 } // cfg.is_ep_out() && cfg.enable_feedback_ep
760768 }
761769
762- USBAudioConfig &config (){
763- return cfg;
764- }
770+ USBAudioConfig &config () { return cfg; }
765771
766772 protected:
767773 USBAudioCB *p_cb = nullptr ;
@@ -809,13 +815,16 @@ class USBDeviceAudioAPI {
809815 // USB driver writes into FIFO
810816
811817 struct audiod_function_t {
818+ audiod_function_t () {
819+ memset (this ,0 , sizeof (audiod_function_t ));
820+ }
812821 uint8_t n_bytes_per_sample_tx;
813822 uint8_t n_channels_tx;
814823 uint8_t format_type_tx = AUDIO_FORMAT_TYPE_I;
815824
816825 uint8_t rhport;
817826 uint8_t const
818- *p_desc; // Pointer pointing to Standard AC Interface
827+ *p_desc = nullptr ; // Pointer pointing to Standard AC Interface
819828 // Descriptor(4.7.1)
820829 // - Audio Control descriptor defining audio function
821830
@@ -1975,7 +1984,6 @@ class USBDeviceAudioAPI {
19751984 return tu_min16 (data_count, max_depth);
19761985 }
19771986 }
1978-
19791987};
19801988
19811989// TU_ATTR_FAST_FUNC void tud_audio_feedback_interval_isr(uint8_t func_id,
0 commit comments