diff options
Diffstat (limited to 'thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio')
5 files changed, 2126 insertions, 0 deletions
diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio/app_usbd_audio.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio/app_usbd_audio.c new file mode 100644 index 0000000..19e5a36 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio/app_usbd_audio.c @@ -0,0 +1,813 @@ +/** + * Copyright (c) 2016 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "sdk_common.h" +#if NRF_MODULE_ENABLED(APP_USBD_AUDIO) + +#include "app_usbd_audio.h" +#include "app_util_platform.h" + +/** + * @defgroup app_usbd_audio_internals USBD Audio internals + * @{ + * @ingroup app_usbd_audio + * @internal + */ + +STATIC_ASSERT(sizeof(app_usbd_audio_ac_iface_header_desc_t) == 8); +STATIC_ASSERT(sizeof(app_usbd_audio_input_terminal_desc_t) == 12); +STATIC_ASSERT(sizeof(app_usbd_audio_output_terminal_desc_t) == 9); +STATIC_ASSERT(sizeof(app_usbd_audio_feature_unit_desc_t) == 6); +STATIC_ASSERT(sizeof(app_usbd_audio_as_iface_desc_t) == 7); +STATIC_ASSERT(sizeof(app_usbd_audio_as_format_type_one_desc_t) == 8); +STATIC_ASSERT(sizeof(app_usbd_audio_as_format_type_two_desc_t) == 9); +STATIC_ASSERT(sizeof(app_usbd_audio_as_format_type_three_desc_t) == 8); +STATIC_ASSERT(sizeof(app_usbd_audio_as_endpoint_desc_t) == 7); + +#define APP_USBD_AUDIO_CONTROL_IFACE_IDX 0 /**< Audio class control interface index */ +#define APP_USBD_AUDIO_STREAMING_IFACE_IDX 1 /**< Audio class streaming interface index */ + +#define APP_USBD_CDC_AUDIO_STREAMING_EP_IDX 0 /**< Audio streaming isochronous endpoint index */ + +/** + * @brief Auxiliary function to access audio class instance data + * + * @param[in] p_inst Class instance data + * @return Audio class instance data @ref app_usbd_audio_t + */ +static inline app_usbd_audio_t const * audio_get(app_usbd_class_inst_t const * p_inst) +{ + ASSERT(p_inst != NULL); + return (app_usbd_audio_t const *)p_inst; +} + + +/** + * @brief Auxiliary function to access audio class context data + * + * @param[in] p_audio Audio class instance data + * @return Audio class context data @ref app_usbd_audio_ctx_t + */ +static inline app_usbd_audio_ctx_t * audio_ctx_get(app_usbd_audio_t const * p_audio) +{ + ASSERT(p_audio != NULL); + ASSERT(p_audio->specific.p_data != NULL); + return &p_audio->specific.p_data->ctx; +} + + +/** + * @brief User event handler + * + * @param[in] p_inst Class instance + * @param[in] event user Event type @ref app_usbd_audio_user_event_t + */ +static inline void user_event_handler( + app_usbd_class_inst_t const * p_inst, + app_usbd_audio_user_event_t event) +{ + app_usbd_audio_t const * p_audio = audio_get(p_inst); + + if (p_audio->specific.inst.user_ev_handler != NULL) + { + p_audio->specific.inst.user_ev_handler(p_inst, event); + } +} + + +/** + * @brief Select interface + * + * @param[in,out] p_inst Instance of the class + * @param[in] iface_idx Index of the interface inside class structure + * @param[in] alternate Alternate setting that should be selected + */ +static ret_code_t iface_select( + app_usbd_class_inst_t const * const p_inst, + uint8_t iface_idx, + uint8_t alternate) +{ + app_usbd_class_iface_conf_t const * p_iface = app_usbd_class_iface_get(p_inst, iface_idx); + /* Simple check if this is data interface */ + uint8_t const ep_count = app_usbd_class_iface_ep_count_get(p_iface); + + if (ep_count > 0) + { + if (alternate > 1) + { + return NRF_ERROR_INVALID_PARAM; + } + app_usbd_audio_t const * p_audio = audio_get(p_inst); + app_usbd_audio_ctx_t * p_audio_ctx = audio_ctx_get(p_audio); + p_audio_ctx->streaming = (alternate != 0); + + uint8_t i; + + for (i = 0; i < ep_count; ++i) + { + nrf_drv_usbd_ep_t ep_addr = + app_usbd_class_ep_address_get(app_usbd_class_iface_ep_get(p_iface, i)); + if (alternate) + { + app_usbd_ep_enable(ep_addr); + } + else + { + app_usbd_ep_disable(ep_addr); + } + } + return NRF_SUCCESS; + } + return NRF_ERROR_NOT_SUPPORTED; +} + + +static void iface_deselect( + app_usbd_class_inst_t const * const p_inst, + uint8_t iface_idx) +{ + app_usbd_class_iface_conf_t const * p_iface = app_usbd_class_iface_get(p_inst, iface_idx); + + /* Simple check if this is data interface */ + if (p_iface->ep_cnt > 0) + { + app_usbd_audio_t const * p_audio = audio_get(p_inst); + app_usbd_audio_ctx_t * p_audio_ctx = audio_ctx_get(p_audio); + p_audio_ctx->streaming = false; + } + /* Note that all the interface endpoints would be disabled automatically after this function */ +} + + +static uint8_t iface_selection_get( + app_usbd_class_inst_t const * const p_inst, + uint8_t iface_idx) +{ + app_usbd_class_iface_conf_t const * p_iface = app_usbd_class_iface_get(p_inst, iface_idx); + /* Simple check if this is data interface */ + uint8_t const ep_count = app_usbd_class_iface_ep_count_get(p_iface); + + if (ep_count > 0) + { + app_usbd_audio_t const * p_audio = audio_get(p_inst); + app_usbd_audio_ctx_t * p_audio_ctx = audio_ctx_get(p_audio); + return (p_audio_ctx->streaming) ? 1 : 0; + } + return 0; +} + + +/** + * @brief Internal SETUP standard IN request handler + * + * @param[in] p_inst Generic class instance + * @param[in] p_setup_ev Setup event + * + * @return Standard error code + * @retval NRF_SUCCESS if request handled correctly + * @retval NRF_ERROR_NOT_SUPPORTED if request is not supported + */ +static ret_code_t setup_req_std_in(app_usbd_class_inst_t const * p_inst, + app_usbd_setup_evt_t const * p_setup_ev) +{ + /* Only Get Descriptor standard IN request is supported by Audio class */ + if ((app_usbd_setup_req_rec(p_setup_ev->setup.bmRequestType) == APP_USBD_SETUP_REQREC_INTERFACE) + && + (p_setup_ev->setup.bmRequest == APP_USBD_SETUP_STDREQ_GET_DESCRIPTOR)) + { + size_t dsc_len = 0; + size_t max_size; + + uint8_t * p_trans_buff = app_usbd_core_setup_transfer_buff_get(&max_size); + + /* Try to find descriptor in class internals*/ + ret_code_t ret = app_usbd_class_descriptor_find( + p_inst, + p_setup_ev->setup.wValue.hb, + p_setup_ev->setup.wValue.lb, + p_trans_buff, + &dsc_len); + + if (ret != NRF_ERROR_NOT_FOUND) + { + ASSERT(dsc_len < NRF_DRV_USBD_EPSIZE); + return app_usbd_core_setup_rsp(&(p_setup_ev->setup), p_trans_buff, dsc_len); + } + } + + return NRF_ERROR_NOT_SUPPORTED; +} + + +/** + * @brief Internal SETUP class IN request handler + * + * @param[in] p_inst Generic class instance + * @param[in] p_setup_ev Setup event + * + * @return Standard error code + * @retval NRF_SUCCESS if request handled correctly + * @retval NRF_ERROR_NOT_SUPPORTED if request is not supported + */ +static ret_code_t setup_req_class_in( + app_usbd_class_inst_t const * p_inst, + app_usbd_setup_evt_t const * p_setup_ev) +{ + switch (p_setup_ev->setup.bmRequest) + { + case APP_USBD_AUDIO_REQ_GET_CUR: + case APP_USBD_AUDIO_REQ_GET_MIN: + case APP_USBD_AUDIO_REQ_GET_MAX: + case APP_USBD_AUDIO_REQ_SET_RES: + case APP_USBD_AUDIO_REQ_GET_MEM: + { + app_usbd_audio_t const * p_audio = audio_get(p_inst); + app_usbd_audio_ctx_t * p_audio_ctx = audio_ctx_get(p_audio); + + + p_audio_ctx->request.req_type = (app_usbd_audio_req_type_t)p_setup_ev->setup.bmRequest; + p_audio_ctx->request.control = p_setup_ev->setup.wValue.hb; + p_audio_ctx->request.channel = p_setup_ev->setup.wValue.lb; + p_audio_ctx->request.interface = p_setup_ev->setup.wIndex.hb; + p_audio_ctx->request.entity = p_setup_ev->setup.wIndex.lb; + + p_audio_ctx->request.length = p_setup_ev->setup.wLength.w; + + p_audio_ctx->request.req_target = APP_USBD_AUDIO_CLASS_REQ_IN; + + app_usbd_setup_reqrec_t rec = app_usbd_setup_req_rec(p_setup_ev->setup.bmRequestType); + if (rec == APP_USBD_SETUP_REQREC_ENDPOINT) + { + p_audio_ctx->request.req_target = APP_USBD_AUDIO_EP_REQ_IN; + } + + user_event_handler((app_usbd_class_inst_t const *)p_audio, + APP_USBD_AUDIO_USER_EVT_CLASS_REQ); + + return app_usbd_core_setup_rsp(&p_setup_ev->setup, + p_audio_ctx->request.payload, + p_audio_ctx->request.length); + } + + default: + break; + } + + return NRF_ERROR_NOT_SUPPORTED; +} + + +static ret_code_t audio_req_out_data_cb(nrf_drv_usbd_ep_status_t status, void * p_context) +{ + if (status == NRF_USBD_EP_OK) + { + app_usbd_audio_t const * p_audio = p_context; + + user_event_handler((app_usbd_class_inst_t const *)p_audio, + APP_USBD_AUDIO_USER_EVT_CLASS_REQ); + } + + return NRF_SUCCESS; +} + + +static ret_code_t audio_req_out( + app_usbd_class_inst_t const * p_inst, + app_usbd_setup_evt_t const * p_setup_ev) +{ + app_usbd_audio_t const * p_audio = audio_get(p_inst); + app_usbd_audio_ctx_t * p_audio_ctx = audio_ctx_get(p_audio); + + + p_audio_ctx->request.req_type = (app_usbd_audio_req_type_t)p_setup_ev->setup.bmRequest; + p_audio_ctx->request.control = p_setup_ev->setup.wValue.hb; + p_audio_ctx->request.channel = p_setup_ev->setup.wValue.lb; + p_audio_ctx->request.interface = p_setup_ev->setup.wIndex.hb; + p_audio_ctx->request.entity = p_setup_ev->setup.wIndex.lb; + + p_audio_ctx->request.length = p_setup_ev->setup.wLength.w; + + p_audio_ctx->request.req_target = APP_USBD_AUDIO_CLASS_REQ_OUT; + if (app_usbd_setup_req_rec(p_setup_ev->setup.bmRequestType) == APP_USBD_SETUP_REQREC_ENDPOINT) + { + p_audio_ctx->request.req_target = APP_USBD_AUDIO_EP_REQ_OUT; + } + + /*Request setup data*/ + NRF_DRV_USBD_TRANSFER_OUT(transfer, p_audio_ctx->request.payload, p_audio_ctx->request.length); + ret_code_t ret; + CRITICAL_REGION_ENTER(); + ret = app_usbd_ep_transfer(NRF_DRV_USBD_EPOUT0, &transfer); + if (ret == NRF_SUCCESS) + { + app_usbd_core_setup_data_handler_desc_t desc = { + .handler = audio_req_out_data_cb, + .p_context = (void *)p_audio + }; + + ret = app_usbd_core_setup_data_handler_set(NRF_DRV_USBD_EPOUT0, &desc); + } + CRITICAL_REGION_EXIT(); + + return ret; +} + + +/** + * @brief Internal SETUP class OUT request handler + * + * @param[in] p_inst Generic class instance + * @param[in] p_setup_ev Setup event + * + * @return Standard error code + * @retval NRF_SUCCESS if request handled correctly + * @retval NRF_ERROR_NOT_SUPPORTED if request is not supported + */ +static ret_code_t setup_req_class_out( + app_usbd_class_inst_t const * p_inst, + app_usbd_setup_evt_t const * p_setup_ev) +{ + switch (p_setup_ev->setup.bmRequest) + { + case APP_USBD_AUDIO_REQ_SET_CUR: + case APP_USBD_AUDIO_REQ_SET_MIN: + case APP_USBD_AUDIO_REQ_SET_MAX: + case APP_USBD_AUDIO_REQ_SET_RES: + case APP_USBD_AUDIO_REQ_SET_MEM: + return audio_req_out(p_inst, p_setup_ev); + + default: + break; + } + + return NRF_ERROR_NOT_SUPPORTED; +} + + +/** + * @brief Control endpoint handle + * + * @param[in] p_inst Generic class instance + * @param[in] p_setup_ev Setup event + * + * @return Standard error code + * @retval NRF_SUCCESS if request handled correctly + * @retval NRF_ERROR_NOT_SUPPORTED if request is not supported + */ +static ret_code_t setup_event_handler( + app_usbd_class_inst_t const * p_inst, + app_usbd_setup_evt_t const * p_setup_ev) +{ + ASSERT(p_inst != NULL); + ASSERT(p_setup_ev != NULL); + + if (app_usbd_setup_req_dir(p_setup_ev->setup.bmRequestType) == APP_USBD_SETUP_REQDIR_IN) + { + switch (app_usbd_setup_req_typ(p_setup_ev->setup.bmRequestType)) + { + case APP_USBD_SETUP_REQTYPE_STD: + return setup_req_std_in(p_inst, p_setup_ev); + + case APP_USBD_SETUP_REQTYPE_CLASS: + return setup_req_class_in(p_inst, p_setup_ev); + + default: + break; + } + } + else /*APP_USBD_SETUP_REQDIR_OUT*/ + { + switch (app_usbd_setup_req_typ(p_setup_ev->setup.bmRequestType)) + { + case APP_USBD_SETUP_REQTYPE_CLASS: + return setup_req_class_out(p_inst, p_setup_ev); + + default: + break; + } + } + + return NRF_ERROR_NOT_SUPPORTED; +} + + +/** + * @brief Endpoint IN event handler + * + * @param[in] p_inst Generic class instance + * + * @return Standard error code + * @retval NRF_SUCCESS if request handled correctly + * @retval NRF_ERROR_NOT_SUPPORTED if request is not supported + */ +static ret_code_t endpoint_in_event_handler(app_usbd_class_inst_t const * p_inst) +{ + user_event_handler(p_inst, APP_USBD_AUDIO_USER_EVT_TX_DONE); + return NRF_SUCCESS; +} + + +/** + * @brief Endpoint OUT event handler + * + * @param[in] p_inst Generic class instance + * + * @return Standard error code + * @retval NRF_SUCCESS if request handled correctly + * @retval NRF_ERROR_NOT_SUPPORTED if request is not supported + */ +static ret_code_t endpoint_out_event_handler(app_usbd_class_inst_t const * p_inst) +{ + user_event_handler(p_inst, APP_USBD_AUDIO_USER_EVT_RX_DONE); + return NRF_SUCCESS; +} + + +/** + * @brief Auxiliary function to access isochronous endpoint address + * + * @param[in] p_inst Class instance data + * + * @return ISO endpoint address + */ +static inline nrf_drv_usbd_ep_t ep_iso_addr_get(app_usbd_class_inst_t const * p_inst) +{ + app_usbd_class_iface_conf_t const * class_iface; + + class_iface = app_usbd_class_iface_get(p_inst, APP_USBD_AUDIO_STREAMING_IFACE_IDX); + + app_usbd_class_ep_conf_t const * ep_cfg; + ep_cfg = app_usbd_class_iface_ep_get(class_iface, APP_USBD_CDC_AUDIO_STREAMING_EP_IDX); + + return app_usbd_class_ep_address_get(ep_cfg); +} + + +/** + * @brief @ref app_usbd_class_methods_t::event_handler + */ +static ret_code_t audio_event_handler( + app_usbd_class_inst_t const * p_inst, + app_usbd_complex_evt_t const * p_event) +{ + ASSERT(p_inst != NULL); + ASSERT(p_event != NULL); + + ret_code_t ret = NRF_SUCCESS; + + switch (p_event->app_evt.type) + { + case APP_USBD_EVT_DRV_RESET: + break; + + case APP_USBD_EVT_DRV_SETUP: + ret = setup_event_handler(p_inst, (app_usbd_setup_evt_t const *)p_event); + break; + + case APP_USBD_EVT_DRV_EPTRANSFER: + if (NRF_USBD_EPIN_CHECK(p_event->drv_evt.data.eptransfer.ep)) + { + ret = endpoint_in_event_handler(p_inst); + } + else + { + ret = endpoint_out_event_handler(p_inst); + } + break; + + case APP_USBD_EVT_DRV_SUSPEND: + break; + + case APP_USBD_EVT_DRV_RESUME: + break; + + case APP_USBD_EVT_INST_APPEND: + break; + + case APP_USBD_EVT_INST_REMOVE: + break; + + case APP_USBD_EVT_STARTED: + break; + + case APP_USBD_EVT_STOPPED: + break; + + default: + ret = NRF_ERROR_NOT_SUPPORTED; + break; + } + + return ret; +} + + +static size_t audio_get_format_descriptor_size(app_usbd_class_inst_t const * p_inst) +{ + app_usbd_audio_t const * p_audio = audio_get(p_inst); + + return p_audio->specific.inst.p_format_dsc->size; +} + + +static size_t audio_get_format_descriptor_data(app_usbd_class_inst_t const * p_inst, + uint32_t cur_byte) +{ + app_usbd_audio_t const * p_audio = audio_get(p_inst); + + return p_audio->specific.inst.p_format_dsc->p_data[cur_byte]; +} + + +static size_t audio_get_input_descriptor_size(app_usbd_class_inst_t const * p_inst) +{ + app_usbd_audio_t const * p_audio = audio_get(p_inst); + + return p_audio->specific.inst.p_input_dsc->size; +} + + +static size_t audio_get_input_descriptor_data(app_usbd_class_inst_t const * p_inst, + uint32_t cur_byte) +{ + app_usbd_audio_t const * p_audio = audio_get(p_inst); + + return p_audio->specific.inst.p_input_dsc->p_data[cur_byte]; +} + + +static size_t audio_get_output_descriptor_size(app_usbd_class_inst_t const * p_inst) +{ + app_usbd_audio_t const * p_audio = audio_get(p_inst); + + return p_audio->specific.inst.p_output_dsc->size; +} + + +static size_t audio_get_output_descriptor_data(app_usbd_class_inst_t const * p_inst, + uint32_t cur_byte) +{ + app_usbd_audio_t const * p_audio = audio_get(p_inst); + + return p_audio->specific.inst.p_output_dsc->p_data[cur_byte]; +} + + +static size_t audio_get_feature_descriptor_size(app_usbd_class_inst_t const * p_inst) +{ + app_usbd_audio_t const * p_audio = audio_get(p_inst); + + return p_audio->specific.inst.p_feature_dsc->size; +} + + +static size_t audio_get_feature_descriptor_data(app_usbd_class_inst_t const * p_inst, + uint32_t cur_byte) +{ + app_usbd_audio_t const * p_audio = audio_get(p_inst); + + return p_audio->specific.inst.p_feature_dsc->p_data[cur_byte]; +} + + +static uint8_t audio_get_control_interface_number(app_usbd_class_inst_t const * p_inst) +{ + app_usbd_class_iface_conf_t const * ifce = 0; + + ifce = app_usbd_class_iface_get(p_inst, 0); + return app_usbd_class_iface_number_get(ifce); +} + + +/** + * @brief @ref app_usbd_class_methods_t::feed_descriptors + */ + +static bool audio_feed_descriptors(app_usbd_class_descriptor_ctx_t * p_ctx, + app_usbd_class_inst_t const * p_inst, + uint8_t * p_buff, + size_t max_size) +{ + static uint8_t ifaces = 0; + ifaces = app_usbd_class_iface_count_get(p_inst); + ASSERT(ifaces == 2); + app_usbd_audio_t const * p_audio = audio_get(p_inst); + + APP_USBD_CLASS_DESCRIPTOR_BEGIN(p_ctx, p_buff, max_size); + + /* CONTROL INTERFACE DESCRIPTOR */ + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x09); // bLength + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_DESCRIPTOR_INTERFACE); // bDescriptorType = Interface + + static app_usbd_class_iface_conf_t const * p_cur_iface = NULL; + p_cur_iface = app_usbd_class_iface_get(p_inst, 0); + + APP_USBD_CLASS_DESCRIPTOR_WRITE(app_usbd_class_iface_number_get(p_cur_iface)); // bInterfaceNumber + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x00); // bAlternateSetting + APP_USBD_CLASS_DESCRIPTOR_WRITE(app_usbd_class_iface_ep_count_get(p_cur_iface)); // bNumEndpoints + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_AUDIO_CLASS); // bInterfaceClass = Audio + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_AUDIO_SUBCLASS_AUDIOCONTROL); // bInterfaceSubclass (Audio Control) + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_AUDIO_CLASS_PROTOCOL_UNDEFINED); // bInterfaceProtocol + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x00); // iInterface + + /* HEADER INTERFACE */ + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x09); // bLength + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_AUDIO_DESCRIPTOR_INTERFACE); // bDescriptorType = Audio Interfaces + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_AUDIO_AC_IFACE_SUBTYPE_HEADER); // bDescriptorSubtype = Header + APP_USBD_CLASS_DESCRIPTOR_WRITE(LSB_16(0x0100)); // bcdADC LSB + APP_USBD_CLASS_DESCRIPTOR_WRITE(MSB_16(0x0100)); // bcdADC MSB + + static uint16_t header_desc_len = 0; + header_desc_len = 9 + audio_get_feature_descriptor_size(p_inst) + + audio_get_input_descriptor_size(p_inst) + audio_get_output_descriptor_size( + p_inst); + APP_USBD_CLASS_DESCRIPTOR_WRITE(LSB_16(header_desc_len)); // wTotalLength LSB + APP_USBD_CLASS_DESCRIPTOR_WRITE(MSB_16(header_desc_len)); // wTotalLength MSB + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x01); // bInCollection + APP_USBD_CLASS_DESCRIPTOR_WRITE(audio_get_control_interface_number(p_inst) + 1); // baInterfaceNr(1) + + /* INPUT TERMINAL DESCRIPTOR */ + static uint32_t cur_byte = 0; + static size_t input_desc_size = 0; + input_desc_size = audio_get_input_descriptor_size(p_inst); + + for (cur_byte = 0; cur_byte < input_desc_size; cur_byte++) + { + APP_USBD_CLASS_DESCRIPTOR_WRITE(audio_get_input_descriptor_data(p_inst, cur_byte)); + } + + /* FEATURE UNIT DESCRIPTOR */ + static size_t feature_desc_size = 0; + feature_desc_size = audio_get_feature_descriptor_size(p_inst); + + for (cur_byte = 0; cur_byte < feature_desc_size; cur_byte++) + { + APP_USBD_CLASS_DESCRIPTOR_WRITE(audio_get_feature_descriptor_data(p_inst, cur_byte)); + } + + /* OUTPUT TERMINAL DESCRIPTOR */ + static size_t output_desc_size = 0; + output_desc_size = audio_get_output_descriptor_size(p_inst); + + for (cur_byte = 0; cur_byte < output_desc_size; cur_byte++) + { + APP_USBD_CLASS_DESCRIPTOR_WRITE(audio_get_output_descriptor_data(p_inst, cur_byte)); + } + + p_cur_iface++; + + /* STREAM INTERFACE DESCRIPTOR ALT 0 */ + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x09); // bLength + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_DESCRIPTOR_INTERFACE); // bDescriptorType = Interface + APP_USBD_CLASS_DESCRIPTOR_WRITE(audio_get_control_interface_number(p_inst) + 1); // bInterfaceNumber + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x00); // bAlternateSetting + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x00); // bNumEndpoints + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_AUDIO_CLASS); // bInterfaceClass = Audio + APP_USBD_CLASS_DESCRIPTOR_WRITE(p_audio->specific.inst.type_streaming); // bInterfaceSubclass (Audio Control) + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_AUDIO_CLASS_PROTOCOL_UNDEFINED); // bInterfaceProtocol + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x00); // iInterface + + /* STREAM INTERFACE DESCRIPTOR ALT 1 */ + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x09); // bLength + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_DESCRIPTOR_INTERFACE); // bDescriptorType = Interface + APP_USBD_CLASS_DESCRIPTOR_WRITE(audio_get_control_interface_number(p_inst) + 1); // bInterfaceNumber + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x01); // bAlternateSetting + APP_USBD_CLASS_DESCRIPTOR_WRITE(app_usbd_class_iface_ep_count_get(p_cur_iface)); // bNumEndpoints + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_AUDIO_CLASS); // bInterfaceClass = Audio + APP_USBD_CLASS_DESCRIPTOR_WRITE(p_audio->specific.inst.type_streaming); // bInterfaceSubclass (Audio Control) + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_AUDIO_CLASS_PROTOCOL_UNDEFINED); // bInterfaceProtocol + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x00); // iInterface + + /* AudioStreaming GENERAL DESCRIPTOR */ + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x07); // bLength + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_AUDIO_DESCRIPTOR_INTERFACE); // bDescriptorType = Audio Interface + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_AUDIO_AS_IFACE_SUBTYPE_GENERAL); // bDescriptorSubtype = General + APP_USBD_CLASS_DESCRIPTOR_WRITE(audio_get_control_interface_number(p_inst) + 1); // bTerminalLink + APP_USBD_CLASS_DESCRIPTOR_WRITE(p_audio->specific.inst.delay); // bDelay + APP_USBD_CLASS_DESCRIPTOR_WRITE(LSB_16(p_audio->specific.inst.format)); // wFormatTag LSB + APP_USBD_CLASS_DESCRIPTOR_WRITE(MSB_16(p_audio->specific.inst.format)); // wFormatTag MSB + + /* FORMAT DESCRIPTOR */ + static size_t format_desc_size = 0; + format_desc_size = audio_get_format_descriptor_size(p_inst); + + for (cur_byte = 0; cur_byte < format_desc_size; cur_byte++) + { + APP_USBD_CLASS_DESCRIPTOR_WRITE(audio_get_format_descriptor_data(p_inst, cur_byte)); + } + + /* ENDPOINT GENERAL DESCRIPTOR */ + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x07); // bLength + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_AUDIO_DESCRIPTOR_ENDPOINT); // bDescriptorType = Audio Descriptor + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_AUDIO_EP_SUBTYPE_GENERAL); // bDescriptorSubtype = EP General + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x00); // bmAttributes + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x00); // bLockDelayUnits + APP_USBD_CLASS_DESCRIPTOR_WRITE(LSB_16(0x0000)); // wLockDelay LSB + APP_USBD_CLASS_DESCRIPTOR_WRITE(MSB_16(0x0000)); // wLockDelay MSB + + /* ENDPOINT ISO DESCRIPTOR */ + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x09); // bLength + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_DESCRIPTOR_ENDPOINT); // bDescriptorType = Endpoint + + static app_usbd_class_ep_conf_t const * p_cur_ep = NULL; + p_cur_ep = app_usbd_class_iface_ep_get(p_cur_iface, 0); + APP_USBD_CLASS_DESCRIPTOR_WRITE(app_usbd_class_ep_address_get(p_cur_ep)); // bEndpointAddress + APP_USBD_CLASS_DESCRIPTOR_WRITE(APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_ISOCHRONOUS); // bmAttributes + APP_USBD_CLASS_DESCRIPTOR_WRITE(LSB_16(p_audio->specific.inst.ep_size)); // wMaxPacketSize LSB + APP_USBD_CLASS_DESCRIPTOR_WRITE(MSB_16(p_audio->specific.inst.ep_size)); // wMaxPacketSize MSB + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x01); // bInterval + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x00); // bRefresh + APP_USBD_CLASS_DESCRIPTOR_WRITE(0x00); // bSynchAddress + + APP_USBD_CLASS_DESCRIPTOR_END(); +} + +/** @} */ + +const app_usbd_class_methods_t app_usbd_audio_class_methods = { + .event_handler = audio_event_handler, + .feed_descriptors = audio_feed_descriptors, + .iface_select = iface_select, + .iface_deselect = iface_deselect, + .iface_selection_get = iface_selection_get, +}; + + +size_t app_usbd_audio_class_rx_size_get(app_usbd_class_inst_t const * p_inst) +{ + nrf_drv_usbd_ep_t ep_addr; + + ep_addr = ep_iso_addr_get(p_inst); + ASSERT(NRF_USBD_EPISO_CHECK(ep_addr)); + + return (size_t)nrf_drv_usbd_epout_size_get(ep_addr); +} + + +ret_code_t app_usbd_audio_class_rx_start( + app_usbd_class_inst_t const * p_inst, + void * p_buff, + size_t size) +{ + nrf_drv_usbd_ep_t ep_addr; + + ep_addr = ep_iso_addr_get(p_inst); + ASSERT(NRF_USBD_EPISO_CHECK(ep_addr)); + + NRF_DRV_USBD_TRANSFER_OUT(transfer, p_buff, size); + return app_usbd_ep_transfer(ep_addr, &transfer); +} + + +ret_code_t app_usbd_audio_class_tx_start( + app_usbd_class_inst_t const * p_inst, + const void * p_buff, + size_t size) +{ + nrf_drv_usbd_ep_t ep_addr; + + ep_addr = ep_iso_addr_get(p_inst); + ASSERT(NRF_USBD_EPISO_CHECK(ep_addr)); + + NRF_DRV_USBD_TRANSFER_IN(transfer, p_buff, size); + return app_usbd_ep_transfer(ep_addr, &transfer); +} + + +#endif //NRF_MODULE_ENABLED(APP_USBD_AUDIO) diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio/app_usbd_audio.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio/app_usbd_audio.h new file mode 100644 index 0000000..f094bbb --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio/app_usbd_audio.h @@ -0,0 +1,329 @@ +/** + * Copyright (c) 2017 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef APP_USBD_AUDIO_H__ +#define APP_USBD_AUDIO_H__ + +#include <stdint.h> +#include <stdbool.h> + +#include "nrf_drv_usbd.h" +#include "app_usbd.h" +#include "app_usbd_core.h" +#include "app_usbd_class_base.h" +#include "app_usbd_descriptor.h" + +#include "app_usbd_audio_types.h" +#include "app_usbd_audio_desc.h" +#include "app_usbd_audio_internal.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup app_usbd_audio USB AUDIO class + * @ingroup app_usbd + * + * @brief @tagAPI52840 Module with types, definitions, and API used by USB Audio class. + * + * @details Reference specifications: + * - "Universal Serial Bus Device Class Definition for Audio Devices" + * Release 1.0, March 18, 1998. + * - "Universal Serial Bus Device Class Definition for Audio Data Formats" + * Release 1.0, March 18, 1998. + * - "Universal Serial Bus Device Class Definition for Terminal Types" + * Release 1.0, March 18, 1998. + * + * @{ + */ + + +#ifdef DOXYGEN +/** + * @brief Audio class instance type + * + * @ref APP_USBD_CLASS_TYPEDEF + */ +typedef struct { } app_usbd_audio_t; +#else +/*lint -save -e10 -e26 -e123 -e505 */ +APP_USBD_CLASS_TYPEDEF(app_usbd_audio, \ + APP_USBD_AUDIO_CONFIG(0, 1), \ + APP_USBD_AUDIO_INSTANCE_SPECIFIC_DEC, \ + APP_USBD_AUDIO_DATA_SPECIFIC_DEC \ +); +/*lint -restore*/ +#endif + + +/*lint -save -e407 */ + +/** + * @brief Events passed to user event handler + * + * @note Example prototype of user event handler: + * + * @code + void audio_user_ev_handler(app_usbd_class_inst_t const * p_inst, + app_usbd_audio_user_event_t event); + * @endcode + */ +typedef enum app_usbd_audio_user_event_e { + APP_USBD_AUDIO_USER_EVT_CLASS_REQ, /**< User event CLASS_REQ */ + APP_USBD_AUDIO_USER_EVT_RX_DONE, /**< User event RX_DONE */ + APP_USBD_AUDIO_USER_EVT_TX_DONE, /**< User event TX_DONE */ +} app_usbd_audio_user_event_t; + +/*lint -restore*/ + +/** + * @brief Global definition of app_usbd_audio_t class instance + * + * @param instance_name Name of global instance + * @param interfaces_configs Interfaces configurations + * @param user_ev_handler User event handler + * @param format_descriptor Audio class Format descriptor + * @param input_descriptor Audio class Input Terminal descriptor + * @param output_descriptor Audio class Output Terminal descriptor + * @param feature_descriptor Audio class Feature Unit descriptor + * @param delay Streaming delay + * @param format FormatTag (@ref app_usbd_audio_as_iface_format_tag_t) + * @param ep_size Endpoint size + * @param type_str Streaming type MIDISTREAMING/AUDIOSTREAMING + * + * @note This macro is just simplified version of @ref APP_USBD_AUDIO_GLOBAL_DEF_INTERNAL + * + */ +#define APP_USBD_AUDIO_GLOBAL_DEF(instance_name, \ + interfaces_configs, \ + user_ev_handler, \ + format_descriptor, \ + input_descriptor, \ + output_descriptor, \ + feature_descriptor, \ + delay, \ + format, \ + ep_size, \ + type_str) \ + APP_USBD_AUDIO_GLOBAL_DEF_INTERNAL(instance_name, \ + interfaces_configs, \ + user_ev_handler, \ + format_descriptor, \ + input_descriptor, \ + output_descriptor, \ + feature_descriptor, \ + delay, \ + format, \ + ep_size, \ + type_str) + + +/** + * @brief Initializer of Audio Format descriptor + * + * @param name Format descriptor name + * @param ... Format descriptor data +*/ + +#define APP_USBD_AUDIO_FORMAT_DESCRIPTOR(name, ...) \ + static uint8_t const CONCAT_2(name, _data)[] = \ + { \ + __VA_ARGS__ \ + }; \ + static const app_usbd_audio_subclass_desc_t name = \ + { \ + sizeof(CONCAT_2(name, _data)), \ + APP_USBD_AUDIO_AS_IFACE_SUBTYPE_FORMAT_TYPE, \ + CONCAT_2(name,_data) \ + } + +/** + * @brief Initializer of Audio Input descriptor + * + * @param name Input descriptor name + * @param ... Input descriptor data +*/ + +#define APP_USBD_AUDIO_INPUT_DESCRIPTOR(name, ...) \ + static uint8_t const CONCAT_2(name, _data)[] = \ + { \ + __VA_ARGS__ \ + }; \ + static const app_usbd_audio_subclass_desc_t name = \ + { \ + sizeof(CONCAT_2(name, _data)), \ + APP_USBD_AUDIO_AC_IFACE_SUBTYPE_INPUT_TERMINAL, \ + CONCAT_2(name,_data) \ + } + +/** + * @brief Initializer of Audio Output descriptor + * + * @param name Output descriptor name + * @param ... Output descriptor data +*/ + +#define APP_USBD_AUDIO_OUTPUT_DESCRIPTOR(name, ...) \ + static uint8_t const CONCAT_2(name, _data)[] = \ + { \ + __VA_ARGS__ \ + }; \ + static const app_usbd_audio_subclass_desc_t name = \ + { \ + sizeof(CONCAT_2(name, _data)), \ + APP_USBD_AUDIO_AC_IFACE_SUBTYPE_OUTPUT_TERNINAL, \ + CONCAT_2(name,_data) \ + } + +/** + * @brief Initializer of Feture Output descriptor + * + * @param name Feture descriptor name + * @param ... Feture descriptor data +*/ + +#define APP_USBD_AUDIO_FEATURE_DESCRIPTOR(name, ...) \ + static uint8_t const CONCAT_2(name, _data)[] = \ + { \ + __VA_ARGS__ \ + }; \ + static const app_usbd_audio_subclass_desc_t name = \ + { \ + sizeof(CONCAT_2(name, _data)), \ + APP_USBD_AUDIO_AC_IFACE_SUBTYPE_FEATURE_UNIT, \ + CONCAT_2(name,_data) \ + } + +/** + * @@brief Helper function to get class instance from Audio class + * + * @param[in] p_audio Audio class instance (declared by @ref APP_USBD_AUDIO_GLOBAL_DEF) + * @return Base class instance + */ +static inline app_usbd_class_inst_t const * +app_usbd_audio_class_inst_get(app_usbd_audio_t const * p_audio) +{ + return &p_audio->base; +} + +/** + * @brief Helper function to get audio specific request from audio class + * + * @param[in] p_audio Audio class instance (declared by @ref APP_USBD_AUDIO_GLOBAL_DEF) + * @return Audio class specific request + */ +static inline app_usbd_audio_req_t * +app_usbd_audio_class_request_get(app_usbd_audio_t const * p_audio) +{ + return &p_audio->specific.p_data->ctx.request; +} + +/** + * @brief Helper function to get audio from base class instance + * + * @param[in] p_inst Base class instance + * @return Audio class handle + */ +static inline app_usbd_audio_t const * +app_usbd_audio_class_get(app_usbd_class_inst_t const * p_inst) +{ + return (app_usbd_audio_t const *)p_inst; +} + +/** + * @brief Get the size of last received transfer. + * + * @note Call this function in reaction to a SOF event to check if there is any data to process. + * + * @param p_inst Base class instance. + * + * @return Number of bytes received in the last transmission. + */ +size_t app_usbd_audio_class_rx_size_get(app_usbd_class_inst_t const * p_inst); + +/** + * @brief Start audio data copying from the endpoint buffer. + * + * Function to be used to copy data from an audio OUT endpoint to a given buffer. + * When it finishes, an @ref APP_USBD_AUDIO_USER_EVT_RX_DONE event is generated. + * + * @param p_inst Base class instance. + * @param p_buff Target buffer. + * @param size Size of the requested data. + * + * @return Result of the endpoint transmission start. + * + * @sa app_usbd_audio_class_rx_size_get + * + * @note This function should be called in reaction to a SOF event. + * Isochronous endpoints are double buffered and they are automatically switched at every SOF. + */ +ret_code_t app_usbd_audio_class_rx_start( + app_usbd_class_inst_t const * p_inst, + void * p_buff, + size_t size); + +/** + * @brief Start copying audio data to the endpoint buffer. + * + * Function to be used to copy data to an audio IN endpoint from a given buffer. + * When it finishes, an @ref APP_USBD_AUDIO_USER_EVT_TX_DONE event is generated. + * + * @param p_inst Base class instance. + * @param p_buff Source buffer. + * @param size Size of the data to be sent. + * + * @return Result of the endpoint transsmision start. + * + * @note This function should be called in reaction to a SOF event. + * Isochronous endpoints are double buffered and they are automatically switched at every SOF. + */ +ret_code_t app_usbd_audio_class_tx_start( + app_usbd_class_inst_t const * p_inst, + const void * p_buff, + size_t size); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* APP_USBD_AUDIO_H__ */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio/app_usbd_audio_desc.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio/app_usbd_audio_desc.h new file mode 100644 index 0000000..dbc4d41 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio/app_usbd_audio_desc.h @@ -0,0 +1,318 @@ +/** + * Copyright (c) 2016 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef APP_USBD_AUDIO_DESC_H__ +#define APP_USBD_AUDIO_DESC_H__ + +#include "app_usbd_descriptor.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup app_usbd_audio_dsc USB Audio descriptors + * @brief @tagAPI52840 Descriptors used in the USB Audio class. + * @ingroup app_usbd_audio + * @{ + */ + +/** + * @brief Initializer of interface descriptor for AUDIO class + * + * @param interface_number Interface number + * @param alt_setting Interface alternate setting + * @param ep_num Number of endpoints + * @param subclass Audio subclass @ref app_usbd_audio_subclass_t + * */ +#define APP_USBD_AUDIO_INTERFACE_DSC(interface_number, alt_setting, ep_num, subclass) \ + /*.bLength = */ sizeof(app_usbd_descriptor_iface_t), \ + /*.bDescriptorType = */ APP_USBD_DESCRIPTOR_INTERFACE, \ + /*.bInterfaceNumber = */ (interface_number), \ + /*.bAlternateSetting = */ (alt_setting), \ + /*.bNumEndpoints = */ (ep_num), \ + /*.bInterfaceClass = */ APP_USBD_AUDIO_CLASS, \ + /*.bInterfaceSubClass = */ (subclass), \ + /*.bInterfaceProtocol = */ APP_USBD_AUDIO_CLASS_PROTOCOL_UNDEFINED, \ + /*.iInterface = 0, */ 0x00, \ + +/** + * @brief Initializer of isochronous endpoint descriptors for audio class + * + * @param ep ISO endpoint id: @ref NRF_DRV_USBD_EPIN8, @ref NRF_DRV_USBD_EPOUT8 + * @param ep_size Endpoint size (bytes) + * @param interval Endpoint interval (milliseconds) + * @param refresh Refresh value (usually 0) + * @param synch_addr Synch address (usually 0) + * */ +#define APP_USBD_AUDIO_ISO_EP_DSC(ep, ep_size, interval, refresh, synch_addr) \ + /*.bLength = */ sizeof(app_usbd_descriptor_ep_t) + 2, \ + /*.bDescriptorType = */ APP_USBD_DESCRIPTOR_ENDPOINT, \ + /*.bEndpointAddress = */ ep, \ + /*.bmAttributes = */ APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_ISOCHRONOUS, \ + /*.wMaxPacketSize = */ APP_USBD_U16_TO_RAW_DSC(ep_size), \ + /*.bInterval = */ (interval), \ + /*.bRefresh = */ (refresh), \ + /*.bInterval = */ (synch_addr), \ + +/** + * @brief Simplified version of @ref APP_USBD_AUDIO_ISO_EP_DSC for ISO IN endpoint + */ +#define APP_USBD_AUDIO_ISO_EP_IN_DSC(ep_size) \ + APP_USBD_AUDIO_ISO_EP_DSC(NRF_DRV_USBD_EPIN8, ep_size, 1, 0, 0) + +/** + * @brief Simplified version of @ref APP_USBD_AUDIO_ISO_EP_DSC for ISO OUT endpoint + */ +#define APP_USBD_AUDIO_ISO_EP_OUT_DSC(ep_size) \ + APP_USBD_AUDIO_ISO_EP_DSC(NRF_DRV_USBD_EPOUT8, ep_size, 1, 0, 0) + +/** + * @brief Initializer of @ref app_usbd_audio_ac_iface_header_desc_t + * + * @param descriptor_list Descriptor list following audio interface header descriptor + * @param ... List of interfaces following audio control interface + * */ +#define APP_USBD_AUDIO_AC_IFACE_HEADER_DSC(descriptor_list, ...) \ + /*.bLength = */ sizeof(app_usbd_audio_ac_iface_header_desc_t) + \ + (NUM_VA_ARGS(__VA_ARGS__)), \ + /*.bDescriptorType = */ APP_USBD_AUDIO_DESCRIPTOR_INTERFACE, \ + /*.bDescriptorSubtype = */ APP_USBD_AUDIO_AC_IFACE_SUBTYPE_HEADER, \ + /*.bcdADC = */ APP_USBD_U16_TO_RAW_DSC(0x0100), \ + /*.wTotalLength = */ APP_USBD_U16_TO_RAW_DSC( \ + sizeof((uint8_t[]){BRACKET_EXTRACT(descriptor_list)}) + \ + sizeof(app_usbd_audio_ac_iface_header_desc_t) + \ + (NUM_VA_ARGS(__VA_ARGS__))), \ + /*.bInCollection = */ (NUM_VA_ARGS(__VA_ARGS__)), \ + /*.baInterfaceNr[] = */ __VA_ARGS__, \ + + +/** + * @brief Initializer of @ref app_usbd_audio_input_terminal_desc_t + * + * @param terminal_id Terminal ID + * @param terminal_type Terminal type @ref app_usbd_audio_terminal_type_t + * @param nr_channels Number of channels + * @param ch_config CHannel config bitmask + * */ +#define APP_USBD_AUDIO_INPUT_TERMINAL_DSC(terminal_id, terminal_type, nr_channels, ch_config) \ + /*.bLength = */ sizeof(app_usbd_audio_input_terminal_desc_t), \ + /*.bDescriptorType = */ APP_USBD_AUDIO_DESCRIPTOR_INTERFACE, \ + /*.bDescriptorSubtype = */ APP_USBD_AUDIO_AC_IFACE_SUBTYPE_INPUT_TERMINAL, \ + /*.bTerminalID = */ (terminal_id), \ + /*.wTerminalType = */ APP_USBD_U16_TO_RAW_DSC(terminal_type), \ + /*.bAssocTerminal = */ 0, \ + /*.bNrChannels = */ (nr_channels), \ + /*.wChannelConfig = */ APP_USBD_U16_TO_RAW_DSC(ch_config), \ + /*.iChannelNames = */ 0, \ + /*.iTerminal = */ 0, \ + + +/** + * @brief Initializer of @ref app_usbd_audio_output_terminal_desc_t + * + * @param terminal_id Terminal ID + * @param terminal_type Terminal type @ref app_usbd_audio_terminal_type_t + * @param source_id Source ID + * */ +#define APP_USBD_AUDIO_OUTPUT_TERMINAL_DSC(terminal_id, terminal_type, source_id) \ + /*.bLength = */ sizeof(app_usbd_audio_output_terminal_desc_t), \ + /*.bDescriptorType = */ APP_USBD_AUDIO_DESCRIPTOR_INTERFACE, \ + /*.bDescriptorSubtype = */ APP_USBD_AUDIO_AC_IFACE_SUBTYPE_OUTPUT_TERNINAL, \ + /*.bTerminalID = */ (terminal_id), \ + /*.wTerminalType = */ APP_USBD_U16_TO_RAW_DSC(terminal_type), \ + /*.bAssocTerminal = */ 0, \ + /*.bSourceID = */ (source_id), \ + /*.iTerminal = */ 0, \ + + +/** + * @brief Initializer of @ref app_usbd_audio_feature_unit_desc_t + * + * @param unit_id Unit ID + * @param source_id Source ID + * @param ... List of controls + * */ +#define APP_USBD_AUDIO_FEATURE_UNIT_DSC(unit_id, source_id, ...) \ + /*.bLength = */ sizeof(app_usbd_audio_feature_unit_desc_t) + \ + 1 + (NUM_VA_ARGS(__VA_ARGS__)), \ + /*.bDescriptorType = */ APP_USBD_AUDIO_DESCRIPTOR_INTERFACE, \ + /*.bDescriptorSubtype = */ APP_USBD_AUDIO_AC_IFACE_SUBTYPE_FEATURE_UNIT, \ + /*.bUnitID = */ (unit_id), \ + /*.bSourceID = */ (source_id), \ + /*.bControlSize = */ sizeof(uint16_t), \ + /*.bmaControls[] = */ __VA_ARGS__, \ + /*.iFeature = */ 0, \ + + +/** + * @brief Initializer of @ref app_usbd_audio_as_iface_desc_t + * + * @param terminal_link Terminal link + * @param delay Delay + * @param format_tag Format TAG + * */ +#define APP_USBD_AUDIO_AS_IFACE_DSC(terminal_link, delay, format_tag) \ + /*.bLength = */ sizeof(app_usbd_audio_as_iface_desc_t), \ + /*.bDescriptorType = */ APP_USBD_AUDIO_DESCRIPTOR_INTERFACE, \ + /*.bDescriptorSubtype = */ APP_USBD_AUDIO_AS_IFACE_SUBTYPE_GENERAL, \ + /*.bTerminalLink = */ (terminal_link), \ + /*.bDelay = */ (delay), \ + /*.wFormatTag = */ APP_USBD_U16_TO_RAW_DSC(format_tag), \ + +/** + * @brief Initializer of @ref app_usbd_audio_as_format_type_one_desc_t + * + * @param nr_channels Number of channels + * @param subframe_size Subframe size + * @param resolution Bit resolution + * @param freq_type Frequency type + * @param ... List of frequencies + * */ +#define APP_USBD_AUDIO_AS_FORMAT_I_DSC(nr_channels, subframe_size, resolution, freq_type, ...) \ + /*.bLength = */ sizeof(app_usbd_audio_as_format_type_one_desc_t) + \ + (NUM_VA_ARGS(__VA_ARGS__)), \ + /*.bDescriptorType = */ APP_USBD_AUDIO_DESCRIPTOR_INTERFACE, \ + /*.bDescriptorSubtype = */ APP_USBD_AUDIO_AS_IFACE_SUBTYPE_FORMAT_TYPE, \ + /*.bFormatType = */ (1), \ + /*.bNrChannels = */ (nr_channels), \ + /*.bSubframeSize = */ (subframe_size), \ + /*.bBitResolution = */ (resolution), \ + /*.bSamFreqType = */ (freq_type), \ + /*.tSamFreq = */ __VA_ARGS__, \ + +/** + * @brief Initializer of @ref app_usbd_audio_as_format_type_two_desc_t + * + * @param max_bitrate Maximum bitrate + * @param samples_per_frame Samples per frame + * @param freq_type Frequency type + * @param ... List of frequencies + * */ +#define APP_USBD_AUDIO_AS_FORMAT_II_DSC(max_bitrate, samples_per_frame, freq_type, ...) \ + /*.bLength = */ sizeof(app_usbd_audio_as_format_type_two_desc_t) + \ + (NUM_VA_ARGS(__VA_ARGS__)), \ + /*.bDescriptorType = */ APP_USBD_AUDIO_DESCRIPTOR_INTERFACE, \ + /*.bDescriptorSubtype = */ APP_USBD_AUDIO_AS_IFACE_SUBTYPE_FORMAT_TYPE, \ + /*.bFormatType = */ (2), \ + /*.wMaxBitRate = */ APP_USBD_U16_TO_RAW_DSC(max_bitrate), \ + /*.wSamplesPerFrame = */ APP_USBD_U16_TO_RAW_DSC(samples_per_frame), \ + /*.bSamFreqType = */ (freq_type), \ + /*.tSamFreq = */ __VA_ARGS__, \ + +/** +* @brief Initializer of @ref app_usbd_audio_as_format_type_three_desc_t + * + * @param nr_channels Number of channels + * @param subframe_size Subframe size + * @param resolution Bit resolution + * @param freq_type Frequency type + * @param ... List of frequencies + * */ +#define APP_USBD_AUDIO_AS_FORMAT_III_DSC(nr_channels, subframe_size, resolution, freq_type, ...) \ + /*.bLength = */ sizeof(app_usbd_audio_as_format_type_three_desc_t) + \ + (NUM_VA_ARGS(__VA_ARGS__)), \ + /*.bDescriptorType = */ APP_USBD_AUDIO_DESCRIPTOR_INTERFACE, \ + /*.bDescriptorSubtype = */ APP_USBD_AUDIO_AS_IFACE_SUBTYPE_FORMAT_TYPE, \ + /*.bFormatType = */ (3), \ + /*.bNrChannels = */ (nr_channels), \ + /*.bSubframeSize = */ (subframe_size), \ + /*.bBitResolution = */ (resolution), \ + /*.bSamFreqType = */ (freq_type), \ + /*.tSamFreq = */ __VA_ARGS__, \ + + +/** + * @brief Initializer of @ref app_usbd_audio_as_endpoint_desc_t + * + * @param attributes Endpoint attributes + * @param lock_delay_units Lock delay units + * @param lock_delay Lock delay + * */ +#define APP_USBD_AUDIO_EP_GENERAL_DSC(attributes, lock_delay_units, lock_delay) \ + /*.bLength = */ sizeof(app_usbd_audio_as_endpoint_desc_t), \ + /*.bDescriptorType = */ APP_USBD_AUDIO_DESCRIPTOR_ENDPOINT, \ + /*.bDescriptorSubtype = */ APP_USBD_AUDIO_EP_SUBTYPE_GENERAL, \ + /*.bmAttributes = */ (attributes), \ + /*.bLockDelayUnits = */ (lock_delay_units), \ + /*.wLockDelay = */ APP_USBD_U16_TO_RAW_DSC(lock_delay), \ + +/** + * @brief Macro to configure Audio Class control descriptor + * + * @param interface_number Interface number + * @param descriptor_list List of descriptors after Audio interface header descriptor + * @param interface_list List of interfaces passed to @ref APP_USBD_AUDIO_AC_IFACE_HEADER_DSC + * */ +#define APP_USBD_AUDIO_CONTROL_DSC(interface_number, descriptor_list, interface_list) \ + APP_USBD_AUDIO_INTERFACE_DSC(interface_number, 0, 0, APP_USBD_AUDIO_SUBCLASS_AUDIOCONTROL) \ + APP_USBD_AUDIO_AC_IFACE_HEADER_DSC(descriptor_list, BRACKET_EXTRACT(interface_list)) \ + BRACKET_EXTRACT(descriptor_list) + + +/** + * @brief Macro to configure Audio Class streaming descriptor + * + * @param interface_number Interface number + * @param alt_setting Alternate interface setting + * @param ep_num Number of endpoints + */ +#define APP_USBD_AUDIO_STREAMING_DSC(interface_number, alt_setting, ep_num) \ + APP_USBD_AUDIO_INTERFACE_DSC(interface_number, alt_setting, ep_num, \ + APP_USBD_AUDIO_SUBCLASS_AUDIOSTREAMING) + +/** + * @brief Macro to configure Audio Class MIDI streaming descriptor + * + * @param interface_number Interface number + * @param alt_setting Alternate interface setting + * @param ep_num Number of endpoints + */ +#define APP_USBD_AUDIO_MIDI_STREAMING_DSC(interface_number, alt_setting, ep_num) \ + APP_USBD_AUDIO_INTERFACE_DSC(interface_number, alt_setting, ep_num, \ + APP_USBD_AUDIO_SUBCLASS_MIDISTREAMING) + + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* APP_USBD_AUDIO_DESC_H__ */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio/app_usbd_audio_internal.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio/app_usbd_audio_internal.h new file mode 100644 index 0000000..c3371b2 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio/app_usbd_audio_internal.h @@ -0,0 +1,284 @@ +/** + * Copyright (c) 2017 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef APP_USBD_AUDIO_INTERNAL_H__ +#define APP_USBD_AUDIO_INTERNAL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup app_usbd_audio_internal USB Audio internals + * @brief @tagAPI52840 USB Audio class internals. + * @ingroup app_usbd_audio + * @{ + */ + +/** + * @brief Forward declaration of type defined by @ref APP_USBD_CLASS_TYPEDEF in audio class + * + */ +APP_USBD_CLASS_FORWARD(app_usbd_audio); + +/*lint -save -e165*/ +/** + * @brief Forward declaration of @ref app_usbd_audio_user_event_e + * + */ +enum app_usbd_audio_user_event_e; + +/*lint -restore*/ + +/** + * @brief User event handler + * + * @param[in] p_inst Class instance + * @param[in] event User event + * + */ +typedef void (*app_usbd_audio_user_ev_handler_t)(app_usbd_class_inst_t const * p_inst, + enum app_usbd_audio_user_event_e event); + + +/** +* @brief Audio subclass descriptor. +*/ + +typedef struct { + size_t size; + uint8_t type; + uint8_t const * const p_data; +} app_usbd_audio_subclass_desc_t; + +/** + * @brief Audio class part of class instance data + */ +typedef struct { + + app_usbd_audio_subclass_desc_t const * const p_format_dsc; //!< Audio class Format descriptor + app_usbd_audio_subclass_desc_t const * const p_input_dsc; //!< Audio class Input Terminal descriptor + app_usbd_audio_subclass_desc_t const * const p_output_dsc; //!< Audio class Output Terminal descriptor + app_usbd_audio_subclass_desc_t const * const p_feature_dsc; //!< Audio class Feature Unit descriptor + + uint8_t delay; //!< Streaming delay + uint16_t format; //!< FormatTag (@ref app_usbd_audio_as_iface_format_tag_t) + uint16_t ep_size; //!< Endpoint size + + app_usbd_audio_subclass_t type_streaming; //Streaming type MIDISTREAMING/AUDIOSTREAMING (@ref app_usbd_audio_subclass_t) + + app_usbd_audio_user_ev_handler_t user_ev_handler; //!< User event handler +} app_usbd_audio_inst_t; + +/** + * @brief Audio class request target + */ +typedef enum { + APP_USBD_AUDIO_CLASS_REQ_IN, /**< Audio class request IN */ + APP_USBD_AUDIO_CLASS_REQ_OUT, /**< Audio class request OUT */ + APP_USBD_AUDIO_EP_REQ_IN, /**< Audio class endpoint request IN */ + APP_USBD_AUDIO_EP_REQ_OUT, /**< Audio class endpoint request OUT */ +} app_usbd_audio_class_req_target_t; + +/** + * @brief Audio class specific request handled via control endpoint + */ +typedef struct { + app_usbd_audio_class_req_target_t req_target; //!< Request target + app_usbd_audio_req_type_t req_type; //!< Request type + + uint8_t control; //!< Request control field + uint8_t channel; //!< Channel ID + uint8_t interface; //!< Interface ID + uint8_t entity; //!< Entity ID + uint16_t length; //!< Request payload length + + uint8_t payload[64]; //!< Request payload +} app_usbd_audio_req_t; + + +/** + * @brief Audio class context + * + */ +typedef struct { + app_usbd_audio_req_t request; //!< Audio class request + bool streaming; //!< Streaming flag +} app_usbd_audio_ctx_t; + + +/** + * @brief Audio class configuration macro + * + * Used by @ref APP_USBD_AUDIO_GLOBAL_DEF + * + * @param iface_control Interface number of audio control + * @param iface_stream Interface number of audio stream + */ +#define APP_USBD_AUDIO_CONFIG(iface_control, iface_stream) \ + ((iface_control), \ + (iface_stream, 0)) + +/** + * @brief Only IN audio stream configuration + * + * @param iface_control Interface number of audio control + * @param iface_stream_in Interface number of audio stream on IN endpoint + */ +#define APP_USBD_AUDIO_CONFIG_IN(iface_control, iface_stream_in) \ + ((iface_control), (iface_stream_in, NRF_DRV_USBD_EPIN8)) + + +/** + * @brief Only OUT audio stream configuration + * + * @param iface_control Interface number of audio control + * @param iface_stream_out Interface number of audio stream on OUT endpoint + */ +#define APP_USBD_AUDIO_CONFIG_OUT(iface_control, iface_stream_out) \ + ((iface_control), (iface_stream_out, NRF_DRV_USBD_EPOUT8)) + +/** + * @brief Specific class constant data for audio class + * + * @ref app_usbd_audio_inst_t + */ +#define APP_USBD_AUDIO_INSTANCE_SPECIFIC_DEC app_usbd_audio_inst_t inst; + +/** + * @brief Configures audio class instance + * + * @param user_event_handler User event handler + * @param format_descriptor Audio class Format descriptor + * @param input_descriptor Audio class Input Terminal descriptor + * @param output_descriptor Audio class Output Terminal descriptor + * @param feature_descriptor Audio class Feature Unit descriptor + * @param dlay Streaming delay + * @param frmat FormatTag (@ref app_usbd_audio_as_iface_format_tag_t) + * @param ep_siz Endpoint size + * @param type_str Streaming type MIDISTREAMING/AUDIOSTREAMING + */ + #define APP_USBD_AUDIO_INST_CONFIG(user_event_handler, \ + format_descriptor, \ + input_descriptor, \ + output_descriptor, \ + feature_descriptor, \ + dlay, \ + frmat, \ + ep_siz, \ + type_str) \ + .inst = { \ + .user_ev_handler = user_event_handler, \ + .p_format_dsc = format_descriptor, \ + .p_input_dsc = input_descriptor, \ + .p_output_dsc = output_descriptor, \ + .p_feature_dsc = feature_descriptor, \ + .delay = dlay, \ + .format = frmat, \ + .ep_size = ep_siz, \ + .type_streaming = type_str \ + } + +/** + * @brief Specific class data for audio class + * + * @ref app_usbd_audio_ctx_t + */ +#define APP_USBD_AUDIO_DATA_SPECIFIC_DEC app_usbd_audio_ctx_t ctx; + + +/** + * @brief Audio class descriptors config macro + * + * @param interface_number Interface number + * @param ... Extracted endpoint list + */ +#define APP_USBD_AUDIO_DSC_CONFIG(interface_number, ...) { \ + APP_USBD_AUDIO_INTERFACE_DSC(interface_number, \ + 0, \ + 0, \ + APP_USBD_AUDIO_SUBCLASS_AUDIOCONTROL) \ + } + +/** + * @brief Public audio class interface + * + */ +extern const app_usbd_class_methods_t app_usbd_audio_class_methods; + +/** + * @brief Global definition of @ref app_usbd_audio_t class + * + */ + #define APP_USBD_AUDIO_GLOBAL_DEF_INTERNAL(instance_name, \ + interfaces_configs, \ + user_ev_handler, \ + format_descriptor, \ + input_descriptor, \ + output_descriptor, \ + feature_descriptor, \ + delay, \ + format, \ + ep_size, \ + type_str) \ + APP_USBD_CLASS_INST_GLOBAL_DEF( \ + instance_name, \ + app_usbd_audio, \ + &app_usbd_audio_class_methods, \ + interfaces_configs, \ + (APP_USBD_AUDIO_INST_CONFIG(user_ev_handler, \ + format_descriptor, \ + input_descriptor, \ + output_descriptor, \ + feature_descriptor, \ + delay, \ + format, \ + ep_size, \ + type_str)) \ + ) + + +/** @} */ + + +#ifdef __cplusplus +} +#endif + +#endif /* APP_USBD_AUDIO_INTERNAL_H__ */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio/app_usbd_audio_types.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio/app_usbd_audio_types.h new file mode 100644 index 0000000..57fd902 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/libraries/usbd/class/audio/app_usbd_audio_types.h @@ -0,0 +1,382 @@ +/** + * Copyright (c) 2016 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef APP_USBD_AUDIO_TYPES_H__ +#define APP_USBD_AUDIO_TYPES_H__ + +#include "app_util.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup app_usbd_audio_types USB Audio types + * @brief @tagAPI52840 Type definitions for the USB Audio class. + * @ingroup app_usbd_audio + * @{ + */ + +/** @brief Audio class definition in interface descriptor + * + * Fixed value, @ref app_usbd_descriptor_iface_t::bInterfaceClass + * */ +#define APP_USBD_AUDIO_CLASS 0x01 + +/** @brief Audio class protocol definition in interface descriptor + * + * Fixed value, @ref app_usbd_descriptor_iface_t::bInterfaceProtocol + * */ +#define APP_USBD_AUDIO_CLASS_PROTOCOL_UNDEFINED 0x00 + +/** + * @brief Audio subclass possible values + * + * @ref app_usbd_descriptor_iface_t::bInterfaceSubClass + */ +typedef enum { + APP_USBD_AUDIO_SUBCLASS_UNDEFINED = 0x00, /**< UNDEFINED subclass */ + APP_USBD_AUDIO_SUBCLASS_AUDIOCONTROL, /**< AUDIOCONTROL subclass */ + APP_USBD_AUDIO_SUBCLASS_AUDIOSTREAMING, /**< AUDIOSTREAMING subclass */ + APP_USBD_AUDIO_SUBCLASS_MIDISTREAMING /**< MIDISTREAMING subclass */ +} app_usbd_audio_subclass_t; + + +/** + * @brief Audio class specific descriptor types + */ +typedef enum { + APP_USBD_AUDIO_DESCRIPTOR_UNDEFINED = 0x20, /**< UNDEFINED descriptor type */ + APP_USBD_AUDIO_DESCRIPTOR_DEVICE = 0x21, /**< DEVICE descriptor type */ + APP_USBD_AUDIO_DESCRIPTOR_CONFIGURATION = 0x22, /**< CONFIGURATION descriptor type */ + APP_USBD_AUDIO_DESCRIPTOR_STRING = 0x23, /**< STRING descriptor type */ + APP_USBD_AUDIO_DESCRIPTOR_INTERFACE = 0x24, /**< INTERFACE descriptor type */ + APP_USBD_AUDIO_DESCRIPTOR_ENDPOINT = 0x25, /**< ENDPOINT descriptor type */ +} app_usbd_audio_descriptor_type_t; + + +/** + * @brief Audio control interface subtype + */ +typedef enum { + APP_USBD_AUDIO_AC_IFACE_SUBTYPE_UNDEFINED = 0x00, /**< Audio control interface subtype UNDEFINED */ + APP_USBD_AUDIO_AC_IFACE_SUBTYPE_HEADER, /**< Audio control interface subtype HEADER */ + APP_USBD_AUDIO_AC_IFACE_SUBTYPE_INPUT_TERMINAL, /**< Audio control interface subtype INPUT_TERMINAL */ + APP_USBD_AUDIO_AC_IFACE_SUBTYPE_OUTPUT_TERNINAL, /**< Audio control interface subtype OUTPUT_TERNINAL */ + APP_USBD_AUDIO_AC_IFACE_SUBTYPE_MIXER_UNIT, /**< Audio control interface subtype MIXER_UNIT */ + APP_USBD_AUDIO_AC_IFACE_SUBTYPE_SELECTOR_UNIT, /**< Audio control interface subtype SELECTOR_UNIT */ + APP_USBD_AUDIO_AC_IFACE_SUBTYPE_FEATURE_UNIT, /**< Audio control interface subtype FEATURE_UNIT */ + APP_USBD_AUDIO_AC_IFACE_SUBTYPE_PROCESSING_UNIT, /**< Audio control interface subtype PROCESSING_UNIT */ + APP_USBD_AUDIO_AC_IFACE_SUBTYPE_EXTENSION_UNIT, /**< Audio control interface subtype EXTENSION_UNIT */ +} app_usbd_audio_ac_iface_subtype_t; + +/** + * @brief Audio streaming interface subtype + */ +typedef enum { + APP_USBD_AUDIO_AS_IFACE_SUBTYPE_UNDEFINED = 0x00, /**< Audio streaming interface subtype UNDEFINED */ + APP_USBD_AUDIO_AS_IFACE_SUBTYPE_GENERAL, /**< Audio streaming interface subtype GENERAL */ + APP_USBD_AUDIO_AS_IFACE_SUBTYPE_FORMAT_TYPE, /**< Audio streaming interface subtype FORMAT_TYPE */ + APP_USBD_AUDIO_AS_IFACE_SUBTYPE_FORMAT_SPECIFIC, /**< Audio streaming interface subtype FORMAT_SPECIFIC*/ +} app_usbd_audio_as_iface_subtype_t; + + +/** + * @brief Audio class specific endpoint subtypes + */ +typedef enum { + APP_USBD_AUDIO_EP_SUBTYPE_UNDEFINED = 0x00, /**< APP_USBD_AUDIO_EP_SUBTYPE_UNDEFINED */ + APP_USBD_AUDIO_EP_SUBTYPE_GENERAL, /**< APP_USBD_AUDIO_EP_SUBTYPE_GENERAL */ +} app_usbd_audio_ep_subtype_t; + +/** + * @brief Audio class specific requests + * + * @ref nrf_drv_usbd_setup_t::bmRequestType + */ +typedef enum { + APP_USBD_AUDIO_REQ_UNDEFINED = 0x00, /**< UNDEFINED request*/ + + APP_USBD_AUDIO_REQ_SET_CUR = 0x01, /**< SET_CUR request */ + APP_USBD_AUDIO_REQ_SET_MIN = 0x02, /**< SET_MIN request */ + APP_USBD_AUDIO_REQ_SET_MAX = 0x03, /**< SET_MAX request */ + APP_USBD_AUDIO_REQ_SET_RES = 0x04, /**< SET_RES request */ + APP_USBD_AUDIO_REQ_SET_MEM = 0x05, /**< SET_MEM request */ + + APP_USBD_AUDIO_REQ_GET_CUR = 0x81, /**< GET_CUR request */ + APP_USBD_AUDIO_REQ_GET_MIN = 0x82, /**< GET_MIN request */ + APP_USBD_AUDIO_REQ_GET_MAX = 0x83, /**< GET_MAX request */ + APP_USBD_AUDIO_REQ_GET_RES = 0x84, /**< GET_RES request */ + APP_USBD_AUDIO_REQ_GET_MEM = 0x85, /**< GET_MEM request */ + + APP_USBD_AUDIO_REQ_GET_STAT = 0xFF, /**< GET_STAT request */ +} app_usbd_audio_req_type_t; + +/** + * @brief Audio class terminal types + * */ +typedef enum { + /*USB terminals*/ + APP_USBD_AUDIO_TERMINAL_USB_UNDEFINED = 0x0100, /**< USB_UNDEFINED*/ + APP_USBD_AUDIO_TERMINAL_USB_STREAMING = 0x0101, /**< USB_STREAMING */ + APP_USBD_AUDIO_TERMINAL_USB_VENDOR_SPEC = 0x01FF, /**< USB_VENDOR_SPEC*/ + + /*Input terminals*/ + APP_USBD_AUDIO_TERMINAL_IN_UNDEFINED = 0x0200, /**< UNDEFINED */ + APP_USBD_AUDIO_TERMINAL_IN_MICROPHONE = 0x0201, /**< MICROPHONE */ + APP_USBD_AUDIO_TERMINAL_IN_DESKTOP_MIC = 0x0202, /**< DESKTOP_MIC */ + APP_USBD_AUDIO_TERMINAL_IN_PERSONAL_MIC = 0x0203, /**< PERSONAL_MIC */ + APP_USBD_AUDIO_TERMINAL_IN_OM_DIR_MIC = 0x0204, /**< OM_DIR_MIC */ + APP_USBD_AUDIO_TERMINAL_IN_MIC_ARRAY = 0x0205, /**< MIC_ARRAY */ + APP_USBD_AUDIO_TERMINAL_IN_PROC_MIC_ARRAY = 0x0205, /**< PROC_MIC_ARRAY */ + + /*Output terminals*/ + APP_USBD_AUDIO_TERMINAL_OUT_UNDEFINED = 0x0300, /**< UNDEFINED */ + APP_USBD_AUDIO_TERMINAL_OUT_SPEAKER = 0x0301, /**< SPEAKER */ + APP_USBD_AUDIO_TERMINAL_OUT_HEADPHONES = 0x0302, /**< HEADPHONES */ + APP_USBD_AUDIO_TERMINAL_OUT_HEAD_AUDIO = 0x0303, /**< HEAD_AUDIO */ + APP_USBD_AUDIO_TERMINAL_OUT_DESKTOP_SPEAKER = 0x0304, /**< DESKTOP_SPEAKER */ + APP_USBD_AUDIO_TERMINAL_OUT_ROOM_SPEAKER = 0x0305, /**< ROOM_SPEAKER */ + APP_USBD_AUDIO_TERMINAL_OUT_COMM_SPEAKER = 0x0306, /**< COMM_SPEAKER */ + APP_USBD_AUDIO_TERMINAL_OUT_LOW_FREQ_SPEAKER = 0x0307, /**< LOW_FREQ_SPEAKER */ + + /*Input/Output terminals*/ + APP_USBD_AUDIO_TERMINAL_IO_UNDEFINED = 0x0400, /**< UNDEFINED */ + APP_USBD_AUDIO_TERMINAL_IO_HANDSET = 0x0401, /**< HANDSET */ + APP_USBD_AUDIO_TERMINAL_IO_HEADSET = 0x0402, /**< HEADSET */ + APP_USBD_AUDIO_TERMINAL_IO_SPEAKERPHONE_ECHO_NONE = 0x0403, /**< SPEAKERPHONE_ECHO_NONE */ + APP_USBD_AUDIO_TERMINAL_IO_SPEAKERPHONE_ECHO_SUP = 0x0404, /**< SPEAKERPHONE_ECHO_SUP */ + APP_USBD_AUDIO_TERMINAL_IO_SPEAKERPHONE_ECHO_CAN = 0x0405, /**< SPEAKERPHONE_ECHO_CAN */ +} app_usbd_audio_terminal_type_t; + +/** + * @brief Audio class control interface header descriptor + */ +typedef struct { + uint8_t bLength; //!< Length of the descriptor + uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_AUDIO_DESCRIPTOR_INTERFACE + uint8_t bDescriptorSubType; //!< Descriptor subtype @ref APP_USBD_AUDIO_AC_IFACE_SUBTYPE_HEADER + uint8_t bcdADC[2]; //!< BCD ADC + uint8_t wTotalLength[2]; //!< Total interfaces length + uint8_t bInCollection; //!< Input collection + uint8_t baInterfaceNr[]; //!< Interface number list +} app_usbd_audio_ac_iface_header_desc_t; + + +/** + * @brief Possible values of input terminal channel config + * + * @ref app_usbd_audio_input_terminal_desc_t::wChannelConfig + * */ +typedef enum { + APP_USBD_AUDIO_IN_TERM_CH_CONFIG_LEFT_FRONT = (1u << 0), /**< Channel config bit LEFT_FRONT */ + APP_USBD_AUDIO_IN_TERM_CH_CONFIG_RIGHT_FRONT = (1u << 1), /**< Channel config bit RIGHT_FRONT */ + APP_USBD_AUDIO_IN_TERM_CH_CONFIG_CENTER_FRONT = (1u << 2), /**< Channel config bit CENTER_FRONT */ + APP_USBD_AUDIO_IN_TERM_CH_CONFIG_LOW_FREQ_ENH = (1u << 3), /**< Channel config bit LOW_FREQ_ENH */ + APP_USBD_AUDIO_IN_TERM_CH_CONFIG_LEFT_SURROUND = (1u << 4), /**< Channel config bit LEFT_SURROUND */ + APP_USBD_AUDIO_IN_TERM_CH_CONFIG_RIGHT_SURROUND = (1u << 5), /**< Channel config bit RIGHT_SURROUND */ + APP_USBD_AUDIO_IN_TERM_CH_CONFIG_LEFT_OF_CENTER = (1u << 6), /**< Channel config bit LEFT_OF_CENTER */ + APP_USBD_AUDIO_IN_TERM_CH_CONFIG_RIGHT_OF_CENTER = (1u << 7), /**< Channel config bit RIGHT_OF_CENTER */ + APP_USBD_AUDIO_IN_TERM_CH_CONFIG_SURROUND = (1u << 8), /**< Channel config bit SURROUND */ + APP_USBD_AUDIO_IN_TERM_CH_CONFIG_SIDE_LEFT = (1u << 9), /**< Channel config bit SIDE_LEFT */ + APP_USBD_AUDIO_IN_TERM_CH_CONFIG_SIDE_RIGHT = (1u << 10), /**< Channel config bit SIDE_RIGHT */ + APP_USBD_AUDIO_IN_TERM_CH_CONFIG_TOP = (1u << 11), /**< Channel config bit TOP */ +} app_usbd_audio_in_term_ch_config_t; + +/** + * @brief Audio class input terminal descriptor + */ +typedef struct { + uint8_t bLength; //!< Length of the descriptor + uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_AUDIO_DESCRIPTOR_INTERFACE + uint8_t bDescriptorSubType; //!< Descriptor subtype @ref APP_USBD_AUDIO_AC_IFACE_SUBTYPE_INPUT_TERMINAL + uint8_t bTerminalID; //!< Terminal ID + uint8_t wTerminalType[2]; //!< Terminal type + uint8_t bAssocTerminal; //!< Association terminal + uint8_t bNrChannels; //!< Number of channels + uint8_t wChannelConfig[2]; //!< Channel config + uint8_t iChannelNames; //!< Channel names + uint8_t iTerminal; //!< Terminal string ID +} app_usbd_audio_input_terminal_desc_t; + +/** + * @brief Audio class output terminal descriptor + */ +typedef struct { + uint8_t bLength; //!< Length of the descriptor + uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_AUDIO_DESCRIPTOR_INTERFACE + uint8_t bDescriptorSubType; //!< Descriptor subtype @ref APP_USBD_AUDIO_AC_IFACE_SUBTYPE_OUTPUT_TERNINAL + uint8_t bTerminalID; //!< Terminal ID + uint8_t wTerminalType[2]; //!< Terminal type + uint8_t bAssocTerminal; //!< Association terminal + uint8_t bSourceID; //!< Source ID + uint8_t iTerminal; //!< Terminal string ID +} app_usbd_audio_output_terminal_desc_t; + +/** + * @brief Possible values of feature unit control field*/ +typedef enum { + APP_USBD_AUDIO_FEATURE_UNIT_CONTROL_MUTE = (1u << 0), /**< Feature unit control bit MUTE */ + APP_USBD_AUDIO_FEATURE_UNIT_CONTROL_VOLUME = (1u << 1), /**< Feature unit control bit VOLUME */ + APP_USBD_AUDIO_FEATURE_UNIT_CONTROL_BASS = (1u << 2), /**< Feature unit control bit BASS */ + APP_USBD_AUDIO_FEATURE_UNIT_CONTROL_MID = (1u << 3), /**< Feature unit control bit MID */ + APP_USBD_AUDIO_FEATURE_UNIT_CONTROL_TREBLE = (1u << 4), /**< Feature unit control bit TREBLE */ + APP_USBD_AUDIO_FEATURE_UNIT_CONTROL_GRAPH_EQ = (1u << 5), /**< Feature unit control bit GRAPH_EQ */ + APP_USBD_AUDIO_FEATURE_UNIT_CONTROL_AUTO_GAIN = (1u << 6), /**< Feature unit control bit AUTO_GAIN */ + APP_USBD_AUDIO_FEATURE_UNIT_CONTROL_DELAY = (1u << 7), /**< Feature unit control bit DELAY */ + APP_USBD_AUDIO_FEATURE_UNIT_CONTROL_BASS_BOOST = (1u << 8), /**< Feature unit control bit BASS_BOOST*/ + APP_USBD_AUDIO_FEATURE_UNIT_CONTROL_LOUDNESS = (1u << 9), /**< Feature unit control bit LOUDNESS */ +} app_usbd_audio_feature_unit_control_t; + +/** + * @brief Audio class feature unit descriptor + */ +typedef struct { + uint8_t bLength; //!< Length of the descriptor + uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_AUDIO_DESCRIPTOR_INTERFACE + uint8_t bDescriptorSubType; //!< Descriptor subtype @ref APP_USBD_AUDIO_AC_IFACE_SUBTYPE_FEATURE_UNIT + uint8_t bUnitID; //!< Unit ID + uint8_t bSourceID; //!< Source ID + uint8_t bControlSize; //!< Control size + uint8_t bmaControls[]; //!< Controls array +} app_usbd_audio_feature_unit_desc_t; + +/** + * @brief Format tag in audio streaming interface descriptor + * + * @ref app_usbd_audio_as_iface_desc_t::wFormatTag + * */ +typedef enum { + APP_USBD_AUDIO_AS_IFACE_FORMAT_TYPE_I_UNDEFINED = 0x0000, /**< AS format TYPE_I_UNDEFINED */ + APP_USBD_AUDIO_AS_IFACE_FORMAT_PCM = 0x0001, /**< AS format PCM */ + APP_USBD_AUDIO_AS_IFACE_FORMAT_PCM8 = 0x0002, /**< AS format PCM8 */ + APP_USBD_AUDIO_AS_IFACE_FORMAT_IEEE_FLOAT = 0x0003, /**< AS format IEEE_FLOAT */ + APP_USBD_AUDIO_AS_IFACE_FORMAT_ALAW = 0x0004, /**< AS format ALAW */ + APP_USBD_AUDIO_AS_IFACE_FORMAT_MULAW = 0x0005, /**< AS format MULAW */ + + APP_USBD_AUDIO_AS_IFACE_FORMAT_TYPE_II_UNDEFINED = 0x1000, /**< AS format TYPE_II_UNDEFINED */ + APP_USBD_AUDIO_AS_IFACE_FORMAT_MPEG = 0x1001, /**< AS format MPEG */ + APP_USBD_AUDIO_AS_IFACE_FORMAT_AC3 = 0x1002, /**< AS format AC3 */ + + APP_USBD_AUDIO_AS_IFACE_FORMAT_TYPE_III_UNDEFINED = 0x2000, /**< AS format TYPE_III_UNDEFINED */ + APP_USBD_AUDIO_AS_IFACE_FORMAT_IEC1937_AC_3 = 0x2001, /**< AS format IEC1937_AC_3 */ + APP_USBD_AUDIO_AS_IFACE_FORMAT_IEC1937_MPEG_1_LAYER1 = 0x2002, /**< AS format IEC1937_MPEG_1_LAYER1 */ + APP_USBD_AUDIO_AS_IFACE_FORMAT_IEC1937_MPEG_2_NOEXT = 0x2003, /**< AS format IEC1937_MPEG_2_NOEXT */ + APP_USBD_AUDIO_AS_IFACE_FORMAT_IEC1937_MPEG_2_EXT = 0x2004, /**< AS format IEC1937_MPEG_2_EXT */ + APP_USBD_AUDIO_AS_IFACE_FORMAT_IEC1937_MPEG_2_LAYER1_LS = 0x2005, /**< AS format IEC1937_MPEG_2_LAYER1_LS */ + APP_USBD_AUDIO_AS_IFACE_FORMAT_IEC1937_MPEG_2_LAYER23_LS = 0x2005, /**< AS format IEC1937_MPEG_2_LAYER23_LS */ +} app_usbd_audio_as_iface_format_tag_t; + +/** + * @brief Audio class audio streaming interface descriptor + */ +typedef struct { + uint8_t bLength; //!< Length of the descriptor + uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_AUDIO_DESCRIPTOR_INTERFACE + uint8_t bDescriptorSubType; //!< Descriptor subtype @ref app_usbd_audio_ac_iface_subtype_t + uint8_t bTerminalLink; //!< Terminal link + uint8_t bDelay; //!< Delay + uint8_t wFormatTag[2]; //!< Format TAG +} app_usbd_audio_as_iface_desc_t; + +/** + * @brief Audio class audio streaming format type I descriptor + */ +typedef struct { + uint8_t bLength; //!< Length of the descriptor + uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_AUDIO_DESCRIPTOR_INTERFACE + uint8_t bDescriptorSubType; //!< Descriptor subtype @ref app_usbd_audio_as_iface_subtype_t + uint8_t bFormatType; //!< Format type: fixed value 1 + uint8_t bNrChannels; //!< Number of channels + uint8_t bSubframeSize; //!< Subframe size + uint8_t bBitResolution; //!< Bit resolution + uint8_t bSamFreqType; //!< Number of supported sampling frequencies + uint8_t tSamFreq[]; //!< Number of supported sampling frequencies table (24 bit entries) +} app_usbd_audio_as_format_type_one_desc_t; + + +/** + * @brief Audio class audio streaming format type II descriptor + */ +typedef struct { + uint8_t bLength; //!< Length of the descriptor + uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_AUDIO_DESCRIPTOR_INTERFACE + uint8_t bDescriptorSubType; //!< Descriptor subtype @ref app_usbd_audio_as_iface_subtype_t + uint8_t bFormatType; //!< Format type: fixed value 2 + uint8_t wMaxBitRate[2]; //!< Maximum bitrate + uint8_t wSamplesPerFrame[2]; //!< Samples per frame + uint8_t bSamFreqType; //!< Number of supported sampling frequencies + uint8_t tSamFreq[]; //!< Number of supported sampling frequencies table (24 bit entries) +} app_usbd_audio_as_format_type_two_desc_t; + +/** + * @brief Audio class audio streaming format type III descriptor + */ +typedef struct { + uint8_t bLength; //!< Length of the descriptor + uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_AUDIO_DESCRIPTOR_INTERFACE + uint8_t bDescriptorSubType; //!< Descriptor subtype @ref app_usbd_audio_as_iface_subtype_t + uint8_t bFormatType; //!< Format type: fixed value 1 + uint8_t bNrChannels; //!< Number of channels + uint8_t bSubframeSize; //!< Subframe size + uint8_t bBitResolution; //!< Bit resolution + uint8_t bSamFreqType; //!< Number of supported sampling frequencies + uint8_t tSamFreq[]; //!< Number of supported sampling frequencies table (24 bit entries) +} app_usbd_audio_as_format_type_three_desc_t; + +/** + * @brief Audio class audio endpoint descriptor + */ +typedef struct { + uint8_t bLength; //!< Length of the descriptor + uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_AUDIO_DESCRIPTOR_ENDPOINT + uint8_t bDescriptorSubType; //!< Descriptor subtype @ref APP_USBD_AUDIO_EP_SUBTYPE_GENERAL + uint8_t bmAttributes; //!< Audio endpoint attributes + uint8_t bLockDelayUnits; //!< Lock delay units + uint8_t wLockDelay[2]; //!< Lock delay value +} app_usbd_audio_as_endpoint_desc_t; + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* APP_USBD_AUDIO_TYPES_H__ */ + |