@@ -304,19 +304,6 @@ typedef struct
304
304
305
305
uint16_t desc_length ; // Length of audio function descriptor
306
306
307
- // Buffer for control requests
308
- uint8_t * ctrl_buf ;
309
- uint8_t ctrl_buf_sz ;
310
-
311
- // Current active alternate settings
312
- uint8_t * alt_setting ; // We need to save the current alternate setting this way, because it is possible that there are AS interfaces which do not have an EP!
313
-
314
- // EP Transfer buffers and FIFOs
315
- #if CFG_TUD_AUDIO_ENABLE_EP_OUT
316
- #if !CFG_TUD_AUDIO_ENABLE_DECODING
317
- tu_fifo_t ep_out_ff ;
318
- #endif
319
-
320
307
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
321
308
struct {
322
309
CFG_TUSB_MEM_ALIGN uint32_t value ; // Feedback value for asynchronous mode (in 16.16 format).
@@ -346,17 +333,6 @@ typedef struct
346
333
} feedback ;
347
334
#endif // CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
348
335
349
- #endif // CFG_TUD_AUDIO_ENABLE_EP_OUT
350
-
351
- #if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
352
- tu_fifo_t ep_in_ff ;
353
- #endif
354
-
355
- // Audio control interrupt buffer - no FIFO - 6 Bytes according to UAC 2 specification (p. 74)
356
- #if CFG_TUD_AUDIO_ENABLE_INTERRUPT_EP
357
- CFG_TUSB_MEM_ALIGN uint8_t ep_int_buf [6 ];
358
- #endif
359
-
360
336
// Decoding parameters - parameters are set when alternate AS interface is set by host
361
337
// Coding is currently only supported for EP. Software coding corresponding to AS interfaces without EPs are not supported currently.
362
338
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
@@ -365,8 +341,7 @@ typedef struct
365
341
366
342
#if CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
367
343
audio_data_format_type_I_t format_type_I_rx ;
368
- uint8_t n_bytes_per_sampe_rx ;
369
- uint8_t n_channels_per_ff_rx ;
344
+ uint8_t n_bytes_per_sample_rx ;
370
345
uint8_t n_ff_used_rx ;
371
346
#endif
372
347
#endif
@@ -382,26 +357,57 @@ typedef struct
382
357
#if CFG_TUD_AUDIO_ENABLE_EP_IN && (CFG_TUD_AUDIO_ENABLE_ENCODING || CFG_TUD_AUDIO_EP_IN_FLOW_CONTROL )
383
358
audio_format_type_t format_type_tx ;
384
359
uint8_t n_channels_tx ;
385
- uint8_t n_bytes_per_sampe_tx ;
360
+ uint8_t n_bytes_per_sample_tx ;
386
361
387
362
#if CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
388
363
audio_data_format_type_I_t format_type_I_tx ;
389
- uint8_t n_channels_per_ff_tx ;
390
364
uint8_t n_ff_used_tx ;
391
365
#endif
392
366
#endif
393
367
368
+ // Buffer for control requests
369
+ uint8_t * ctrl_buf ;
370
+ uint8_t ctrl_buf_sz ;
371
+
372
+ // Current active alternate settings
373
+ uint8_t * alt_setting ; // We need to save the current alternate setting this way, because it is possible that there are AS interfaces which do not have an EP!
374
+
375
+ // EP Transfer buffers and FIFOs
376
+ #if CFG_TUD_AUDIO_ENABLE_EP_OUT
377
+ #if !CFG_TUD_AUDIO_ENABLE_DECODING
378
+ tu_fifo_t ep_out_ff ;
379
+ #endif
380
+
381
+
382
+ #endif // CFG_TUD_AUDIO_ENABLE_EP_OUT
383
+
384
+ #if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
385
+ tu_fifo_t ep_in_ff ;
386
+ #endif
387
+
388
+ // Audio control interrupt buffer - no FIFO - 6 Bytes according to UAC 2 specification (p. 74)
389
+ #if CFG_TUD_AUDIO_ENABLE_INTERRUPT_EP
390
+ CFG_TUSB_MEM_ALIGN uint8_t ep_int_buf [6 ];
391
+ #endif
392
+
393
+
394
394
// Support FIFOs for software encoding and decoding
395
395
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
396
396
tu_fifo_t * rx_supp_ff ;
397
397
uint8_t n_rx_supp_ff ;
398
398
uint16_t rx_supp_ff_sz_max ;
399
+ #if CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
400
+ uint8_t n_channels_per_ff_rx ;
401
+ #endif
399
402
#endif
400
403
401
404
#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
402
405
tu_fifo_t * tx_supp_ff ;
403
406
uint8_t n_tx_supp_ff ;
404
407
uint16_t tx_supp_ff_sz_max ;
408
+ #if CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
409
+ uint8_t n_channels_per_ff_tx ;
410
+ #endif
405
411
#endif
406
412
407
413
// Linear buffer in case target MCU is not capable of handling a ring buffer FIFO e.g. no hardware buffer is available or driver is would need to be changed dramatically OR the support FIFOs are used
@@ -707,16 +713,16 @@ static bool audiod_decode_type_I_pcm(uint8_t rhport, audiod_function_t* audio, u
707
713
if (info .len_lin != 0 )
708
714
{
709
715
info .len_lin = tu_min16 (nBytesPerFFToRead , info .len_lin );
710
- src = & audio -> lin_buf_out [cnt_ff * audio -> n_channels_per_ff_rx * audio -> n_bytes_per_sampe_rx ];
716
+ src = & audio -> lin_buf_out [cnt_ff * audio -> n_channels_per_ff_rx * audio -> n_bytes_per_sample_rx ];
711
717
dst_end = info .ptr_lin + info .len_lin ;
712
- src = audiod_interleaved_copy_bytes_fast_decode (audio -> n_bytes_per_sampe_rx , info .ptr_lin , dst_end , src , n_ff_used );
718
+ src = audiod_interleaved_copy_bytes_fast_decode (audio -> n_bytes_per_sample_rx , info .ptr_lin , dst_end , src , n_ff_used );
713
719
714
720
// Handle wrapped part of FIFO
715
721
info .len_wrap = tu_min16 (nBytesPerFFToRead - info .len_lin , info .len_wrap );
716
722
if (info .len_wrap != 0 )
717
723
{
718
724
dst_end = info .ptr_wrap + info .len_wrap ;
719
- audiod_interleaved_copy_bytes_fast_decode (audio -> n_bytes_per_sampe_rx , info .ptr_wrap , dst_end , src , n_ff_used );
725
+ audiod_interleaved_copy_bytes_fast_decode (audio -> n_bytes_per_sample_rx , info .ptr_wrap , dst_end , src , n_ff_used );
720
726
}
721
727
tu_fifo_advance_write_pointer (& audio -> rx_supp_ff [cnt_ff ], info .len_lin + info .len_wrap );
722
728
}
@@ -1024,7 +1030,7 @@ static uint16_t audiod_encode_type_I_pcm(uint8_t rhport, audiod_function_t* audi
1024
1030
// Limit to maximum sample number - THIS IS A POSSIBLE ERROR SOURCE IF TOO MANY SAMPLE WOULD NEED TO BE SENT BUT CAN NOT!
1025
1031
nBytesPerFFToSend = tu_min16 (nBytesPerFFToSend , audio -> ep_in_sz / n_ff_used );
1026
1032
// Round to full number of samples (flooring)
1027
- uint16_t const nSlotSize = audio -> n_channels_per_ff_tx * audio -> n_bytes_per_sampe_tx ;
1033
+ uint16_t const nSlotSize = audio -> n_channels_per_ff_tx * audio -> n_bytes_per_sample_tx ;
1028
1034
nBytesPerFFToSend = (nBytesPerFFToSend / nSlotSize ) * nSlotSize ;
1029
1035
#endif
1030
1036
@@ -1036,15 +1042,15 @@ static uint16_t audiod_encode_type_I_pcm(uint8_t rhport, audiod_function_t* audi
1036
1042
1037
1043
for (cnt_ff = 0 ; cnt_ff < n_ff_used ; cnt_ff ++ )
1038
1044
{
1039
- dst = & audio -> lin_buf_in [cnt_ff * audio -> n_channels_per_ff_tx * audio -> n_bytes_per_sampe_tx ];
1045
+ dst = & audio -> lin_buf_in [cnt_ff * audio -> n_channels_per_ff_tx * audio -> n_bytes_per_sample_tx ];
1040
1046
1041
1047
tu_fifo_get_read_info (& audio -> tx_supp_ff [cnt_ff ], & info );
1042
1048
1043
1049
if (info .len_lin != 0 )
1044
1050
{
1045
1051
info .len_lin = tu_min16 (nBytesPerFFToSend , info .len_lin ); // Limit up to desired length
1046
1052
src_end = (uint8_t * )info .ptr_lin + info .len_lin ;
1047
- dst = audiod_interleaved_copy_bytes_fast_encode (audio -> n_bytes_per_sampe_tx , info .ptr_lin , src_end , dst , n_ff_used );
1053
+ dst = audiod_interleaved_copy_bytes_fast_encode (audio -> n_bytes_per_sample_tx , info .ptr_lin , src_end , dst , n_ff_used );
1048
1054
1049
1055
// Limit up to desired length
1050
1056
info .len_wrap = tu_min16 (nBytesPerFFToSend - info .len_lin , info .len_wrap );
@@ -1053,7 +1059,7 @@ static uint16_t audiod_encode_type_I_pcm(uint8_t rhport, audiod_function_t* audi
1053
1059
if (info .len_wrap != 0 )
1054
1060
{
1055
1061
src_end = (uint8_t * )info .ptr_wrap + info .len_wrap ;
1056
- audiod_interleaved_copy_bytes_fast_encode (audio -> n_bytes_per_sampe_tx , info .ptr_wrap , src_end , dst , n_ff_used );
1062
+ audiod_interleaved_copy_bytes_fast_encode (audio -> n_bytes_per_sample_tx , info .ptr_wrap , src_end , dst , n_ff_used );
1057
1063
}
1058
1064
1059
1065
tu_fifo_advance_read_pointer (& audio -> tx_supp_ff [cnt_ff ], info .len_lin + info .len_wrap );
@@ -1782,8 +1788,8 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
1782
1788
1783
1789
// Reconfigure size of support FIFOs - this is necessary to avoid samples to get split in case of a wrap
1784
1790
#if CFG_TUD_AUDIO_ENABLE_ENCODING && CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
1785
- const uint16_t active_fifo_depth = (uint16_t ) ((audio -> tx_supp_ff_sz_max / (audio -> n_channels_per_ff_tx * audio -> n_bytes_per_sampe_tx ))
1786
- * (audio -> n_channels_per_ff_tx * audio -> n_bytes_per_sampe_tx ));
1791
+ const uint16_t active_fifo_depth = (uint16_t ) ((audio -> tx_supp_ff_sz_max / (audio -> n_channels_per_ff_tx * audio -> n_bytes_per_sample_tx ))
1792
+ * (audio -> n_channels_per_ff_tx * audio -> n_bytes_per_sample_tx ));
1787
1793
for (uint8_t cnt = 0 ; cnt < audio -> n_tx_supp_ff ; cnt ++ )
1788
1794
{
1789
1795
tu_fifo_config (& audio -> tx_supp_ff [cnt ], audio -> tx_supp_ff [cnt ].buffer , active_fifo_depth , 1 , true);
@@ -1813,7 +1819,7 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
1813
1819
1814
1820
// Reconfigure size of support FIFOs - this is necessary to avoid samples to get split in case of a wrap
1815
1821
#if CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
1816
- const uint16_t active_fifo_depth = (audio -> rx_supp_ff_sz_max / audio -> n_bytes_per_sampe_rx ) * audio -> n_bytes_per_sampe_rx ;
1822
+ const uint16_t active_fifo_depth = (audio -> rx_supp_ff_sz_max / audio -> n_bytes_per_sample_rx ) * audio -> n_bytes_per_sample_rx ;
1817
1823
for (uint8_t cnt = 0 ; cnt < audio -> n_rx_supp_ff ; cnt ++ )
1818
1824
{
1819
1825
tu_fifo_config (& audio -> rx_supp_ff [cnt ], audio -> rx_supp_ff [cnt ].buffer , active_fifo_depth , 1 , true);
@@ -2587,14 +2593,14 @@ static void audiod_parse_for_AS_params(audiod_function_t* audio, uint8_t const *
2587
2593
#if CFG_TUD_AUDIO_ENABLE_EP_IN
2588
2594
if (as_itf == audio -> ep_in_as_intf_num )
2589
2595
{
2590
- audio -> n_bytes_per_sampe_tx = ((audio_desc_type_I_format_t const * )p_desc )-> bSubslotSize ;
2596
+ audio -> n_bytes_per_sample_tx = ((audio_desc_type_I_format_t const * )p_desc )-> bSubslotSize ;
2591
2597
}
2592
2598
#endif
2593
2599
2594
2600
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
2595
2601
if (as_itf == audio -> ep_out_as_intf_num )
2596
2602
{
2597
- audio -> n_bytes_per_sampe_rx = ((audio_desc_type_I_format_t const * )p_desc )-> bSubslotSize ;
2603
+ audio -> n_bytes_per_sample_rx = ((audio_desc_type_I_format_t const * )p_desc )-> bSubslotSize ;
2598
2604
}
2599
2605
#endif
2600
2606
}
@@ -2613,7 +2619,7 @@ static bool audiod_calc_tx_packet_sz(audiod_function_t* audio)
2613
2619
{
2614
2620
TU_VERIFY (audio -> format_type_tx == AUDIO_FORMAT_TYPE_I );
2615
2621
TU_VERIFY (audio -> n_channels_tx );
2616
- TU_VERIFY (audio -> n_bytes_per_sampe_tx );
2622
+ TU_VERIFY (audio -> n_bytes_per_sample_tx );
2617
2623
TU_VERIFY (audio -> interval_tx );
2618
2624
TU_VERIFY (audio -> sample_rate_tx );
2619
2625
@@ -2622,9 +2628,9 @@ static bool audiod_calc_tx_packet_sz(audiod_function_t* audio)
2622
2628
const uint16_t sample_normimal = (uint16_t )(audio -> sample_rate_tx * interval / ((tud_speed_get () == TUSB_SPEED_FULL ) ? 1000 : 8000 ));
2623
2629
const uint16_t sample_reminder = (uint16_t )(audio -> sample_rate_tx * interval % ((tud_speed_get () == TUSB_SPEED_FULL ) ? 1000 : 8000 ));
2624
2630
2625
- const uint16_t packet_sz_tx_min = (uint16_t )((sample_normimal - 1 ) * audio -> n_channels_tx * audio -> n_bytes_per_sampe_tx );
2626
- const uint16_t packet_sz_tx_norm = (uint16_t )(sample_normimal * audio -> n_channels_tx * audio -> n_bytes_per_sampe_tx );
2627
- const uint16_t packet_sz_tx_max = (uint16_t )((sample_normimal + 1 ) * audio -> n_channels_tx * audio -> n_bytes_per_sampe_tx );
2631
+ const uint16_t packet_sz_tx_min = (uint16_t )((sample_normimal - 1 ) * audio -> n_channels_tx * audio -> n_bytes_per_sample_tx );
2632
+ const uint16_t packet_sz_tx_norm = (uint16_t )(sample_normimal * audio -> n_channels_tx * audio -> n_bytes_per_sample_tx );
2633
+ const uint16_t packet_sz_tx_max = (uint16_t )((sample_normimal + 1 ) * audio -> n_channels_tx * audio -> n_bytes_per_sample_tx );
2628
2634
2629
2635
// Endpoint size must larger than packet size
2630
2636
TU_ASSERT (packet_sz_tx_max <= audio -> ep_in_sz );
0 commit comments