-
Notifications
You must be signed in to change notification settings - Fork 162
Update tinyusb to 0.19.0 #554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -192,17 +192,6 @@ tu_static CFG_TUD_MEM_SECTION struct { | |||||||||
| #endif | ||||||||||
| } ctrl_buf; | ||||||||||
|
|
||||||||||
| // Active alternate setting of interfaces | ||||||||||
| tu_static uint8_t alt_setting_1[CFG_TUD_AUDIO_FUNC_1_N_AS_INT]; | ||||||||||
|
|
||||||||||
| #if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_N_AS_INT > 0 | ||||||||||
| tu_static uint8_t alt_setting_2[CFG_TUD_AUDIO_FUNC_2_N_AS_INT]; | ||||||||||
| #endif | ||||||||||
|
|
||||||||||
| #if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_N_AS_INT > 0 | ||||||||||
| tu_static uint8_t alt_setting_3[CFG_TUD_AUDIO_FUNC_3_N_AS_INT]; | ||||||||||
| #endif | ||||||||||
|
|
||||||||||
| // Aligned buffer for feedback EP | ||||||||||
| #if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP | ||||||||||
| tu_static CFG_TUD_MEM_SECTION struct { | ||||||||||
|
|
@@ -234,13 +223,14 @@ typedef struct | |||||||||
| uint8_t ep_in; // TX audio data EP. | ||||||||||
| uint16_t ep_in_sz; // Current size of TX EP | ||||||||||
| uint8_t ep_in_as_intf_num;// Corresponding Standard AS Interface Descriptor (4.9.1) belonging to output terminal to which this EP belongs - 0 is invalid (this fits to UAC2 specification since AS interfaces can not have interface number equal to zero) | ||||||||||
| #endif | ||||||||||
| uint8_t ep_in_alt; // Current alternate setting of TX EP | ||||||||||
| #endif | ||||||||||
|
|
||||||||||
| #if CFG_TUD_AUDIO_ENABLE_EP_OUT | ||||||||||
| uint8_t ep_out; // Incoming (into uC) audio data EP. | ||||||||||
| uint16_t ep_out_sz; // Current size of RX EP | ||||||||||
| uint8_t ep_out_as_intf_num;// Corresponding Standard AS Interface Descriptor (4.9.1) belonging to input terminal to which this EP belongs - 0 is invalid (this fits to UAC2 specification since AS interfaces can not have interface number equal to zero) | ||||||||||
|
|
||||||||||
| uint8_t ep_out_alt; // Current alternate setting of RX EP | ||||||||||
| #if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP | ||||||||||
| uint8_t ep_fb;// Feedback EP. | ||||||||||
| #endif | ||||||||||
|
|
@@ -304,9 +294,6 @@ typedef struct | |||||||||
| uint8_t *ctrl_buf; | ||||||||||
| uint8_t ctrl_buf_sz; | ||||||||||
|
|
||||||||||
| // Current active alternate settings | ||||||||||
| 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! | ||||||||||
|
|
||||||||||
| // EP Transfer buffers and FIFOs | ||||||||||
| #if CFG_TUD_AUDIO_ENABLE_EP_OUT | ||||||||||
| tu_fifo_t ep_out_ff; | ||||||||||
|
|
@@ -475,8 +462,6 @@ static bool audiod_tx_xfer_isr(uint8_t rhport, audiod_function_t* audio, uint16_ | |||||||||
| static bool audiod_get_interface(uint8_t rhport, tusb_control_request_t const *p_request); | ||||||||||
| static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *p_request); | ||||||||||
|
|
||||||||||
| static bool audiod_get_AS_interface_index_global(uint8_t itf, uint8_t *func_id, uint8_t *idxItf, uint8_t const **pp_desc_int); | ||||||||||
| static bool audiod_get_AS_interface_index(uint8_t itf, audiod_function_t *audio, uint8_t *idxItf, uint8_t const **pp_desc_int); | ||||||||||
| static bool audiod_verify_entity_exists(uint8_t itf, uint8_t entityID, uint8_t *func_id); | ||||||||||
| static bool audiod_verify_itf_exists(uint8_t itf, uint8_t *func_id); | ||||||||||
| static bool audiod_verify_ep_exists(uint8_t ep, uint8_t *func_id); | ||||||||||
|
|
@@ -529,11 +514,7 @@ tu_fifo_t *tud_audio_n_get_ep_out_ff(uint8_t func_id) { | |||||||||
| } | ||||||||||
|
|
||||||||||
| static bool audiod_rx_xfer_isr(uint8_t rhport, audiod_function_t* audio, uint16_t n_bytes_received) { | ||||||||||
| uint8_t idxItf; | ||||||||||
| uint8_t const *dummy2; | ||||||||||
|
|
||||||||||
| uint8_t idx_audio_fct = audiod_get_audio_fct_idx(audio); | ||||||||||
| TU_VERIFY(audiod_get_AS_interface_index(audio->ep_out_as_intf_num, audio, &idxItf, &dummy2)); | ||||||||||
|
|
||||||||||
| #if USE_LINEAR_BUFFER_RX | ||||||||||
| // Data currently is in linear buffer, copy into EP OUT FIFO | ||||||||||
|
|
@@ -553,7 +534,7 @@ static bool audiod_rx_xfer_isr(uint8_t rhport, audiod_function_t* audio, uint16_ | |||||||||
| #endif | ||||||||||
|
|
||||||||||
| // Call a weak callback here - a possibility for user to get informed an audio packet was received and data gets now loaded into EP FIFO | ||||||||||
| TU_VERIFY(tud_audio_rx_done_isr(rhport, n_bytes_received, idx_audio_fct, audio->ep_out, audio->alt_setting[idxItf])); | ||||||||||
| TU_VERIFY(tud_audio_rx_done_isr(rhport, n_bytes_received, idx_audio_fct, audio->ep_out, audio->ep_out_alt)); | ||||||||||
|
|
||||||||||
| return true; | ||||||||||
| } | ||||||||||
|
|
@@ -584,14 +565,10 @@ tu_fifo_t *tud_audio_n_get_ep_in_ff(uint8_t func_id) { | |||||||||
| } | ||||||||||
|
|
||||||||||
| static bool audiod_tx_xfer_isr(uint8_t rhport, audiod_function_t * audio, uint16_t n_bytes_sent) { | ||||||||||
| uint8_t idxItf; | ||||||||||
| uint8_t const *dummy2; | ||||||||||
|
|
||||||||||
| uint8_t idx_audio_fct = audiod_get_audio_fct_idx(audio); | ||||||||||
| TU_VERIFY(audiod_get_AS_interface_index(audio->ep_in_as_intf_num, audio, &idxItf, &dummy2)); | ||||||||||
|
|
||||||||||
| // Only send something if current alternate interface is not 0 as in this case nothing is to be sent due to UAC2 specifications | ||||||||||
| if (audio->alt_setting[idxItf] == 0) { return false; } | ||||||||||
| if (audio->ep_in_alt == 0) { return false; } | ||||||||||
|
|
||||||||||
| // Send everything in ISO EP FIFO | ||||||||||
| uint16_t n_bytes_tx; | ||||||||||
|
|
@@ -611,7 +588,7 @@ static bool audiod_tx_xfer_isr(uint8_t rhport, audiod_function_t * audio, uint16 | |||||||||
| #endif | ||||||||||
|
|
||||||||||
| // Call a weak callback here - a possibility for user to get informed former TX was completed and data gets now loaded into EP in buffer | ||||||||||
| TU_VERIFY(tud_audio_tx_done_isr(rhport, n_bytes_sent, idx_audio_fct, audio->ep_in, audio->alt_setting[idxItf])); | ||||||||||
| TU_VERIFY(tud_audio_tx_done_isr(rhport, n_bytes_sent, idx_audio_fct, audio->ep_in, audio->ep_in_alt)); | ||||||||||
|
|
||||||||||
| return true; | ||||||||||
| } | ||||||||||
|
|
@@ -704,25 +681,6 @@ void audiod_init(void) { | |||||||||
| #endif | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Initialize active alternate interface buffers | ||||||||||
| switch (i) { | ||||||||||
| #if CFG_TUD_AUDIO_FUNC_1_N_AS_INT > 0 | ||||||||||
| case 0: | ||||||||||
| audio->alt_setting = alt_setting_1; | ||||||||||
| break; | ||||||||||
| #endif | ||||||||||
| #if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_N_AS_INT > 0 | ||||||||||
| case 1: | ||||||||||
| audio->alt_setting = alt_setting_2; | ||||||||||
| break; | ||||||||||
| #endif | ||||||||||
| #if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_N_AS_INT > 0 | ||||||||||
| case 2: | ||||||||||
| audio->alt_setting = alt_setting_3; | ||||||||||
| break; | ||||||||||
| #endif | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Initialize IN EP FIFO if required | ||||||||||
| #if CFG_TUD_AUDIO_ENABLE_EP_IN | ||||||||||
|
|
||||||||||
|
|
@@ -1029,13 +987,25 @@ static bool audiod_get_interface(uint8_t rhport, tusb_control_request_t const *p | |||||||||
| uint8_t const itf = tu_u16_low(p_request->wIndex); | ||||||||||
|
|
||||||||||
| // Find index of audio streaming interface | ||||||||||
| uint8_t func_id, idxItf; | ||||||||||
| uint8_t const *dummy; | ||||||||||
| uint8_t func_id; | ||||||||||
| TU_VERIFY(audiod_verify_itf_exists(itf, &func_id)); | ||||||||||
|
|
||||||||||
| // Default to 0 if interface not yet activated | ||||||||||
| uint8_t alt = 0; | ||||||||||
| #if CFG_TUD_AUDIO_ENABLE_EP_IN | ||||||||||
| if (_audiod_fct[func_id].ep_in_as_intf_num == itf) { | ||||||||||
| alt = _audiod_fct[func_id].ep_in_alt; | ||||||||||
| } | ||||||||||
| #endif | ||||||||||
| #if CFG_TUD_AUDIO_ENABLE_EP_OUT | ||||||||||
| if (_audiod_fct[func_id].ep_out_as_intf_num == itf) { | ||||||||||
| alt = _audiod_fct[func_id].ep_out_alt; | ||||||||||
| } | ||||||||||
| #endif | ||||||||||
|
|
||||||||||
| TU_VERIFY(audiod_get_AS_interface_index_global(itf, &func_id, &idxItf, &dummy)); | ||||||||||
| TU_VERIFY(tud_control_xfer(rhport, p_request, &_audiod_fct[func_id].alt_setting[idxItf], 1)); | ||||||||||
| TU_VERIFY(tud_control_xfer(rhport, p_request, &alt, 1)); | ||||||||||
|
|
||||||||||
| TU_LOG2(" Get itf: %u - current alt: %u\r\n", itf, _audiod_fct[func_id].alt_setting[idxItf]); | ||||||||||
| TU_LOG2(" Get itf: %u - current alt: %u\r\n", itf, alt); | ||||||||||
|
|
||||||||||
| return true; | ||||||||||
| } | ||||||||||
|
|
@@ -1060,16 +1030,16 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *p | |||||||||
| TU_LOG2(" Set itf: %u - alt: %u\r\n", itf, alt); | ||||||||||
|
|
||||||||||
| // Find index of audio streaming interface and index of interface | ||||||||||
| uint8_t func_id, idxItf; | ||||||||||
| uint8_t const *p_desc; | ||||||||||
| TU_VERIFY(audiod_get_AS_interface_index_global(itf, &func_id, &idxItf, &p_desc)); | ||||||||||
| uint8_t func_id; | ||||||||||
| TU_VERIFY(audiod_verify_itf_exists(itf, &func_id)); | ||||||||||
|
|
||||||||||
| audiod_function_t *audio = &_audiod_fct[func_id]; | ||||||||||
|
|
||||||||||
|
||||||||||
| // Persist the alt-setting for any AS interface, so GET_INTERFACE can report it accurately even when no EP is present | |
| audio->as_itf_alt[itf] = alt; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GET_INTERFACE returns 0 for AudioStreaming interfaces that have no endpoint, because alt is only derived from ep_in_alt/ep_out_alt. This breaks setups where an AS interface without EP is set to a non-zero alternate setting. Track and return the current alt-setting per AS interface regardless of whether an EP is present (e.g., maintain a small per-interface alt map in audiod_function_t, update it in SET_INTERFACE, and read it here as the primary source).