@@ -62,10 +62,11 @@ class USBAudioConfig {
62
62
int func_ep_out_size_max = 0 ; // CFG_TUD_AUDIO_EP_SZ_OUT
63
63
size_t (*p_write_callback)(const uint8_t *data, size_t len,
64
64
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 ;
66
67
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 ; };
69
70
70
71
// setup (missing) default values
71
72
void begin () {
@@ -291,7 +292,7 @@ class USBDeviceAudioAPI {
291
292
}
292
293
293
294
void audiod_init () {
294
- assert (p_cb!= nullptr );
295
+ if (p_cb == nullptr ) return ;
295
296
_audiod_fct.resize (cfg.func_n_as_int );
296
297
ctrl_buf_1.resize (cfg.func_ctl_buffer_size );
297
298
alt_setting_1.resize (cfg.func_n_as_int );
@@ -340,10 +341,7 @@ class USBDeviceAudioAPI {
340
341
if (cfg.enable_linear_buffer_rx ) audio->lin_buf_out = lin_buf_out_1.data ();
341
342
}
342
343
343
- bool audiod_deinit (void ) {
344
-
345
- return true ;
346
- }
344
+ bool audiod_deinit (void ) { return true ; }
347
345
348
346
void audiod_reset (uint8_t rhport) {
349
347
(void )rhport;
@@ -361,13 +359,16 @@ class USBDeviceAudioAPI {
361
359
uint16_t audiod_open (uint8_t rhport, tusb_desc_interface_t const *itf_desc,
362
360
uint16_t max_len) {
363
361
(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 ;
365
366
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);
368
369
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);
371
372
372
373
// Verify interrupt control EP is enabled if demanded by descriptor
373
374
TU_ASSERT (itf_desc->bNumEndpoints <= 1 ); // 0 or 1 EPs are allowed
@@ -390,40 +391,44 @@ class USBDeviceAudioAPI {
390
391
_audiod_fct[i].rhport = rhport;
391
392
392
393
#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 ;
421
416
}
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
+ }
427
432
}
428
433
}
429
434
}
@@ -432,11 +437,12 @@ class USBDeviceAudioAPI {
432
437
p_desc = tu_desc_next (p_desc);
433
438
}
434
439
435
- if (ep_in) {
440
+ if (cfg. is_ep_in () && ep_in) {
436
441
usbd_edpt_iso_alloc (rhport, ep_in, ep_in_size);
437
442
}
438
443
439
- if (ep_out) {
444
+
445
+ if (cfg.is_ep_out () && ep_out) {
440
446
usbd_edpt_iso_alloc (rhport, ep_out, ep_out_size);
441
447
}
442
448
@@ -446,7 +452,8 @@ class USBDeviceAudioAPI {
446
452
}
447
453
}
448
454
}
449
- #endif
455
+
456
+ #endif // TUP_DCD_EDPT_ISO_ALLOC
450
457
451
458
if (cfg.is_ep_in () && cfg.enable_ep_in_flow_control ) {
452
459
uint8_t const *p_desc = _audiod_fct[i].p_desc ;
@@ -475,7 +482,7 @@ class USBDeviceAudioAPI {
475
482
}
476
483
p_desc = tu_desc_next (p_desc);
477
484
}
478
- } // cfg.enable_ep_in_flow_control
485
+ } // CFG_TUD_AUDIO_EP_IN_FLOW_CONTROL
479
486
480
487
if (cfg.enable_interrupt_ep ) {
481
488
uint8_t const *p_desc = _audiod_fct[i].p_desc ;
@@ -500,22 +507,23 @@ class USBDeviceAudioAPI {
500
507
p_desc = tu_desc_next (p_desc);
501
508
}
502
509
}
510
+
511
+ _audiod_fct[i].mounted = true ;
512
+ break ;
503
513
}
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;
517
514
}
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;
519
527
}
520
528
521
529
// Handle class co
@@ -759,9 +767,7 @@ class USBDeviceAudioAPI {
759
767
} // cfg.is_ep_out() && cfg.enable_feedback_ep
760
768
}
761
769
762
- USBAudioConfig &config (){
763
- return cfg;
764
- }
770
+ USBAudioConfig &config () { return cfg; }
765
771
766
772
protected:
767
773
USBAudioCB *p_cb = nullptr ;
@@ -809,13 +815,16 @@ class USBDeviceAudioAPI {
809
815
// USB driver writes into FIFO
810
816
811
817
struct audiod_function_t {
818
+ audiod_function_t () {
819
+ memset (this ,0 , sizeof (audiod_function_t ));
820
+ }
812
821
uint8_t n_bytes_per_sample_tx;
813
822
uint8_t n_channels_tx;
814
823
uint8_t format_type_tx = AUDIO_FORMAT_TYPE_I;
815
824
816
825
uint8_t rhport;
817
826
uint8_t const
818
- *p_desc; // Pointer pointing to Standard AC Interface
827
+ *p_desc = nullptr ; // Pointer pointing to Standard AC Interface
819
828
// Descriptor(4.7.1)
820
829
// - Audio Control descriptor defining audio function
821
830
@@ -1975,7 +1984,6 @@ class USBDeviceAudioAPI {
1975
1984
return tu_min16 (data_count, max_depth);
1976
1985
}
1977
1986
}
1978
-
1979
1987
};
1980
1988
1981
1989
// TU_ATTR_FAST_FUNC void tud_audio_feedback_interval_isr(uint8_t func_id,
0 commit comments