mirror of
https://github.com/ArteryTek/AT32F415_Firmware_Library.git
synced 2026-05-21 09:22:11 +00:00
upload version v2.0.0
This commit is contained in:
631
middlewares/usbd_class/audio/audio_class.c
Normal file
631
middlewares/usbd_class/audio/audio_class.c
Normal file
@@ -0,0 +1,631 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_class.c
|
||||
* @version v2.0.0
|
||||
* @date 2021-11-26
|
||||
* @brief usb audio class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
#include "usbd_core.h"
|
||||
#include "audio_class.h"
|
||||
#include "audio_desc.h"
|
||||
#include "audio_codec.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_audio_class
|
||||
* @brief usb device class audio demo
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_audio_class_private_functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
usb_sts_type class_init_handler(void *udev);
|
||||
usb_sts_type class_clear_handler(void *udev);
|
||||
usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup);
|
||||
usb_sts_type class_ept0_tx_handler(void *udev);
|
||||
usb_sts_type class_ept0_rx_handler(void *udev);
|
||||
usb_sts_type class_in_handler(void *udev, uint8_t ept_num);
|
||||
usb_sts_type class_out_handler(void *udev, uint8_t ept_num);
|
||||
usb_sts_type class_sof_handler(void *udev);
|
||||
usb_sts_type class_event_handler(void *udev, usbd_event_type event);
|
||||
|
||||
void audio_inisoincom_event(void *udev);
|
||||
void audio_req_get_cur(void *udev, usb_setup_type *setup);
|
||||
void audio_req_set_cur(void *udev, usb_setup_type *setup);
|
||||
void audio_req_get_min(void *udev, usb_setup_type *setup);
|
||||
void audio_req_get_max(void *udev, usb_setup_type *setup);
|
||||
void audio_req_get_res(void *udev, usb_setup_type *setup);
|
||||
void audio_get_interface(void *udev, usb_setup_type *setup);
|
||||
void audio_set_interface(void *udev, usb_setup_type *setup);
|
||||
|
||||
usb_audio_type audio_struct = {0, 0, 0, 0, 0, 0x1400, 0, 0, 0, {0x0000, 0x1400, 0x33}, {0x0000, 0x1400, 0x33}};
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler audio_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
class_setup_handler,
|
||||
class_ept0_tx_handler,
|
||||
class_ept0_rx_handler,
|
||||
class_in_handler,
|
||||
class_out_handler,
|
||||
class_sof_handler,
|
||||
class_event_handler,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief initialize usb custom hid endpoint
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_init_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
|
||||
/* open microphone in endpoint */
|
||||
usbd_ept_open(pudev, USBD_AUDIO_MIC_IN_EPT, EPT_ISO_TYPE, AUDIO_MIC_IN_MAXPACKET_SIZE);
|
||||
|
||||
/* open speaker out endpoint */
|
||||
usbd_ept_open(pudev, USBD_AUDIO_SPK_OUT_EPT, EPT_ISO_TYPE, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
#if AUDIO_SUPPORT_FEEDBACK
|
||||
/* open speaker feedback endpoint */
|
||||
usbd_ept_open(pudev, USBD_AUDIO_FEEDBACK_EPT, EPT_ISO_TYPE, AUDIO_FEEDBACK_MAXPACKET_SIZE);
|
||||
#endif
|
||||
/* start receive speaker out data */
|
||||
usbd_ept_recv(pudev, USBD_AUDIO_SPK_OUT_EPT, audio_struct.audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief clear endpoint or other state
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_clear_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
|
||||
/* close in endpoint */
|
||||
usbd_ept_close(pudev, USBD_AUDIO_MIC_IN_EPT);
|
||||
|
||||
/* close in endpoint */
|
||||
usbd_ept_close(pudev, USBD_AUDIO_FEEDBACK_EPT);
|
||||
|
||||
/* close out endpoint */
|
||||
usbd_ept_close(pudev, USBD_AUDIO_SPK_OUT_EPT);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class setup request handler
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup packet
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
uint16_t len;
|
||||
|
||||
switch(setup->bmRequestType & USB_REQ_TYPE_RESERVED)
|
||||
{
|
||||
/* class request */
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
switch(setup->bRequest)
|
||||
{
|
||||
case AUDIO_REQ_GET_CUR:
|
||||
audio_req_get_cur(pudev, setup);
|
||||
break;
|
||||
|
||||
case AUDIO_REQ_SET_CUR:
|
||||
audio_req_set_cur(pudev, setup);
|
||||
break;
|
||||
|
||||
case AUDIO_REQ_GET_MIN:
|
||||
audio_req_get_min(pudev, setup);
|
||||
break;
|
||||
|
||||
case AUDIO_REQ_GET_MAX:
|
||||
audio_req_get_max(pudev, setup);
|
||||
break;
|
||||
|
||||
case AUDIO_REQ_GET_RES:
|
||||
audio_req_get_res(pudev, setup);
|
||||
break;
|
||||
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
/* standard request */
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch(setup->bRequest)
|
||||
{
|
||||
case USB_STD_REQ_GET_DESCRIPTOR:
|
||||
if((setup->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE)
|
||||
{
|
||||
len = MIN(AUDIO_DESCRIPTOR_SIZE, setup->wLength);
|
||||
usbd_ctrl_send(pudev, g_usbd_configuration+18, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
}
|
||||
break;
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
audio_get_interface(udev, setup);
|
||||
break;
|
||||
|
||||
case USB_STD_REQ_SET_INTERFACE:
|
||||
audio_set_interface(udev, setup);
|
||||
usbd_ctrl_send_status(pudev);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device endpoint 0 in status stage complete
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_ept0_tx_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device endpoint 0 out status stage complete
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
uint32_t recv_len = usbd_get_recv_len(pudev, 0);
|
||||
/* ...user code... */
|
||||
if( audio_struct.audio_cmd == AUDIO_REQ_SET_CUR)
|
||||
{
|
||||
/* class process */
|
||||
switch(audio_struct.request_no)
|
||||
{
|
||||
case AUDIO_VOLUME_CONTROL:
|
||||
if(audio_struct.interface == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
audio_struct.spk_volume = (uint16_t)(audio_struct.g_audio_cur[0] |
|
||||
(audio_struct.g_audio_cur[1] << 8));
|
||||
/* set volume */
|
||||
audio_codec_set_spk_volume(audio_struct.spk_volume*100/audio_struct.spk_volume_limits[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_struct.mic_volume = (uint16_t)(audio_struct.g_audio_cur[0] |
|
||||
(audio_struct.g_audio_cur[1] << 8));
|
||||
|
||||
audio_codec_set_mic_volume(audio_struct.mic_volume*256/audio_struct.mic_volume_limits[1]);
|
||||
}
|
||||
break;
|
||||
case AUDIO_MUTE_CONTROL:
|
||||
if(audio_struct.interface == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
audio_struct.spk_mute = audio_struct.g_audio_cur[0];
|
||||
audio_codec_set_spk_mute(audio_struct.spk_mute);
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_struct.mic_mute = audio_struct.g_audio_cur[0];
|
||||
audio_codec_set_mic_mute(audio_struct.mic_mute);
|
||||
}
|
||||
|
||||
break;
|
||||
case AUDIO_FREQ_SET_CONTROL:
|
||||
if(audio_struct.enpd == USBD_AUDIO_MIC_IN_EPT)
|
||||
{
|
||||
audio_struct.mic_freq = (audio_struct.g_audio_cur[0] |
|
||||
(audio_struct.g_audio_cur[1] << 8) |
|
||||
(audio_struct.g_audio_cur[2] << 16));
|
||||
audio_codec_set_mic_freq(audio_struct.mic_freq);
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_struct.spk_freq = (audio_struct.g_audio_cur[0] |
|
||||
(audio_struct.g_audio_cur[1] << 8) |
|
||||
(audio_struct.g_audio_cur[2] << 16));
|
||||
audio_codec_set_spk_freq(audio_struct.spk_freq);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device transmision complete handler
|
||||
* @param udev: usb device core handler type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
uint32_t len = 0;
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
if((ept_num & 0x7F) == (USBD_AUDIO_MIC_IN_EPT & 0x7F))
|
||||
{
|
||||
len = audio_codec_mic_get_data(audio_struct.audio_mic_data);
|
||||
usb_flush_tx_fifo(pudev->usb_reg, USBD_AUDIO_MIC_IN_EPT & 0x7F);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_MIC_IN_EPT, audio_struct.audio_mic_data, len);
|
||||
}
|
||||
|
||||
else if((ept_num & 0x7F) == (USBD_AUDIO_FEEDBACK_EPT & 0x7F))
|
||||
{
|
||||
len = audio_codec_spk_feedback(audio_struct.audio_feed_back);
|
||||
usb_flush_tx_fifo(pudev->usb_reg, USBD_AUDIO_FEEDBACK_EPT & 0x7F);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_FEEDBACK_EPT, audio_struct.audio_feed_back, len);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device endpoint receive data
|
||||
* @param udev: usb device core handler type
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
uint16_t g_rxlen;
|
||||
|
||||
/* get endpoint receive data length */
|
||||
g_rxlen = usbd_get_recv_len(pudev, ept_num);
|
||||
|
||||
if((ept_num & 0x7F) == (USBD_AUDIO_SPK_OUT_EPT & 0x7F))
|
||||
{
|
||||
/* speaker data*/
|
||||
audio_codec_spk_fifo_write(audio_struct.audio_spk_data, g_rxlen);
|
||||
|
||||
/* get next data */
|
||||
usbd_ept_recv(pudev, USBD_AUDIO_SPK_OUT_EPT, audio_struct.audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device sof handler
|
||||
* @param udev: usb device core handler type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_sof_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device event handler
|
||||
* @param udev: usb device core handler type
|
||||
* @param event: usb device event
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
|
||||
/* ...user code... */
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
audio_struct.spk_alt_setting = 0;
|
||||
audio_codec_spk_alt_setting(audio_struct.spk_alt_setting);
|
||||
audio_struct.mic_alt_setting = 0;
|
||||
audio_codec_mic_alt_setting(audio_struct.spk_alt_setting);
|
||||
/* ...user code... */
|
||||
|
||||
break;
|
||||
case USBD_WAKEUP_EVENT:
|
||||
/* ...user code... */
|
||||
|
||||
break;
|
||||
case USBD_INISOINCOM_EVENT:
|
||||
audio_inisoincom_event(udev);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb audio in iso incom event
|
||||
* @param udev: usb device core handler type
|
||||
* @retval none
|
||||
*/
|
||||
void audio_inisoincom_event(void *udev)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
uint32_t fnsof = OTG_DEVICE(pudev->usb_reg)->dsts_bit.soffn;
|
||||
uint32_t epctl_fb = USB_INEPT(pudev->usb_reg, (USBD_AUDIO_FEEDBACK_EPT&0x7F))->diepctl_bit.dpid;
|
||||
uint32_t epctl_in = USB_INEPT(pudev->usb_reg, (USBD_AUDIO_MIC_IN_EPT&0x7F))->diepctl_bit.dpid;
|
||||
uint32_t len = 0;
|
||||
|
||||
if((fnsof & 0x1) == epctl_fb)
|
||||
{
|
||||
USB_INEPT(pudev->usb_reg, (USBD_AUDIO_FEEDBACK_EPT&0x7F))->diepctl_bit.eptdis = 1;
|
||||
USB_INEPT(pudev->usb_reg, (USBD_AUDIO_FEEDBACK_EPT&0x7F))->diepctl_bit.snak = 1;
|
||||
usb_flush_tx_fifo(pudev->usb_reg, USBD_AUDIO_FEEDBACK_EPT&0x7F);
|
||||
|
||||
usbd_ept_send(pudev, USBD_AUDIO_FEEDBACK_EPT, audio_struct.audio_feed_back, 3);
|
||||
}
|
||||
|
||||
if((fnsof & 0x1) == epctl_in)
|
||||
{
|
||||
USB_INEPT(pudev->usb_reg, (USBD_AUDIO_MIC_IN_EPT&0x7F))->diepctl_bit.eptdis = 1;
|
||||
USB_INEPT(pudev->usb_reg, (USBD_AUDIO_MIC_IN_EPT&0x7F))->diepctl_bit.snak = 1;
|
||||
usb_flush_tx_fifo(pudev->usb_reg, USBD_AUDIO_MIC_IN_EPT&0x7F);
|
||||
|
||||
len = audio_codec_mic_get_data(audio_struct.audio_mic_data);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_MIC_IN_EPT, audio_struct.audio_mic_data, len);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb audio request get cur
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_req_get_cur(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
if(HBYTE(setup->wIndex) == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
if(HBYTE(setup->wValue) == AUDIO_MUTE_CONTROL)
|
||||
{
|
||||
usbd_ctrl_send(pudev, &audio_struct.spk_mute, setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&audio_struct.spk_volume, setup->wLength);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(HBYTE(setup->wValue) == AUDIO_MUTE_CONTROL)
|
||||
{
|
||||
usbd_ctrl_send(pudev, &audio_struct.mic_mute, setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&audio_struct.mic_volume, setup->wLength);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb audio request set cur
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_req_set_cur(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
if(setup->wLength > 0)
|
||||
{
|
||||
usbd_ctrl_recv(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
|
||||
audio_struct.audio_cmd = AUDIO_REQ_SET_CUR;
|
||||
audio_struct.audio_cmd_len = setup->wLength;
|
||||
|
||||
switch(setup->bmRequestType & AUDIO_REQ_CONTROL_MASK)
|
||||
{
|
||||
case AUDIO_REQ_CONTROL_INTERFACE:
|
||||
audio_struct.interface = HBYTE(setup->wIndex);
|
||||
if(HBYTE(setup->wValue) == AUDIO_MUTE_CONTROL)
|
||||
{
|
||||
audio_struct.request_no = AUDIO_MUTE_CONTROL;
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_struct.request_no = AUDIO_VOLUME_CONTROL;
|
||||
}
|
||||
break;
|
||||
case AUDIO_REQ_CONTROL_ENDPOINT:
|
||||
audio_struct.enpd = setup->wIndex;
|
||||
audio_struct.request_no = AUDIO_FREQ_SET_CONTROL;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb audio request get min
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_req_get_min(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
if(HBYTE(setup->wIndex) == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&audio_struct.spk_volume_limits[0], setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&audio_struct.mic_volume_limits[0], setup->wLength);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb audio request get max
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_req_get_max(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
if(HBYTE(setup->wIndex) == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&audio_struct.spk_volume_limits[1], setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&audio_struct.mic_volume_limits[1], setup->wLength);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb audio request get res
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_req_get_res(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
if(HBYTE(setup->wIndex) == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&audio_struct.spk_volume_limits[2], setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&audio_struct.mic_volume_limits[2], setup->wLength);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb audio set interface
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_set_interface(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
uint32_t len;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
if(LBYTE(setup->wIndex) == AUDIO_SPK_INTERFACE_NUMBER)
|
||||
{
|
||||
audio_struct.spk_alt_setting = setup->wValue;
|
||||
audio_codec_spk_alt_setting(audio_struct.spk_alt_setting);
|
||||
if(audio_struct.spk_alt_setting )
|
||||
{
|
||||
usbd_ept_recv(pudev, USBD_AUDIO_SPK_OUT_EPT, audio_struct.audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_FEEDBACK_EPT, audio_struct.audio_feed_back, 3);
|
||||
}
|
||||
|
||||
}
|
||||
else if(LBYTE(setup->wIndex) == AUDIO_MIC_INTERFACE_NUMBER)
|
||||
{
|
||||
audio_struct.mic_alt_setting = setup->wValue;
|
||||
audio_codec_mic_alt_setting(audio_struct.mic_alt_setting);
|
||||
if(audio_struct.mic_alt_setting)
|
||||
{
|
||||
len = audio_codec_mic_get_data(audio_struct.audio_mic_data);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_MIC_IN_EPT, audio_struct.audio_mic_data, len);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief usb audio get interface
|
||||
* @param udev: usb device core handler type
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_get_interface(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
if(LBYTE(setup->wIndex) == AUDIO_SPK_INTERFACE_NUMBER)
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&audio_struct.spk_alt_setting, 1);
|
||||
}
|
||||
else if(LBYTE(setup->wIndex) == AUDIO_MIC_INTERFACE_NUMBER)
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&audio_struct.mic_alt_setting, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
130
middlewares/usbd_class/audio/audio_class.h
Normal file
130
middlewares/usbd_class/audio/audio_class.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_class.h
|
||||
* @version v2.0.0
|
||||
* @date 2021-11-26
|
||||
* @brief usb audio class file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AUDIO_CLASS_H
|
||||
#define __AUDIO_CLASS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "usb_std.h"
|
||||
#include "usbd_core.h"
|
||||
#include "audio_conf.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USB_audio_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_audio_class_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief endpoint define
|
||||
*/
|
||||
#define USBD_AUDIO_MIC_IN_EPT 0x81
|
||||
#define USBD_AUDIO_SPK_OUT_EPT 0x02
|
||||
#define USBD_AUDIO_FEEDBACK_EPT 0x83
|
||||
|
||||
/**
|
||||
* @brief endpoint support max size
|
||||
*/
|
||||
#define AUDIO_REMAIN_SIZE 8
|
||||
#define AUDIO_MIC_IN_MAXPACKET_SIZE (AUDIO_SUPPORT_MAX_FREQ * AUDIO_MIC_CHANEL_NUM * (AUDIO_MIC_DEFAULT_BITW / 8) + AUDIO_REMAIN_SIZE)
|
||||
#define AUDIO_SPK_OUT_MAXPACKET_SIZE (AUDIO_SUPPORT_MAX_FREQ * AUDIO_SPK_CHANEL_NUM * (AUDIO_SPK_DEFAULT_BITW / 8) + AUDIO_REMAIN_SIZE)
|
||||
#define AUDIO_FEEDBACK_MAXPACKET_SIZE 0x3
|
||||
|
||||
/**
|
||||
* @brief request type define
|
||||
*/
|
||||
#define AUDIO_REQ_CONTROL_INTERFACE 0x01
|
||||
#define AUDIO_REQ_CONTROL_ENDPOINT 0x02
|
||||
#define AUDIO_REQ_CONTROL_MASK 0x03
|
||||
|
||||
/**
|
||||
* @brief audio set cur type define
|
||||
*/
|
||||
#define AUDIO_MUTE_CONTROL 0x01
|
||||
#define AUDIO_VOLUME_CONTROL 0x02
|
||||
#define AUDIO_FREQ_SET_CONTROL 0x03
|
||||
|
||||
/**
|
||||
* @brief audio descriptor type
|
||||
*/
|
||||
#define AUDIO_DESCRIPTOR_TYPE 0x21
|
||||
#define AUDIO_DESCRIPTOR_SIZE 0x09
|
||||
|
||||
/**
|
||||
* @brief usb audio control struct
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t enpd;
|
||||
uint8_t interface;
|
||||
uint8_t request_no;
|
||||
uint8_t spk_mute;
|
||||
uint8_t mic_mute;
|
||||
uint16_t spk_volume;
|
||||
uint16_t mic_volume;
|
||||
uint32_t spk_freq;
|
||||
uint32_t mic_freq;
|
||||
uint16_t spk_volume_limits[3]; /*[0] is mininum value, [1] is maxnum value, [2] is volume resolution */
|
||||
uint16_t mic_volume_limits[3]; /*[0] is mininum value, [1] is maxnum value, [2] is volume resolution */
|
||||
|
||||
uint8_t audio_cmd;
|
||||
uint32_t audio_cmd_len;
|
||||
uint32_t spk_alt_setting;
|
||||
uint32_t mic_alt_setting;
|
||||
uint8_t g_audio_cur[64];
|
||||
uint8_t audio_spk_data[AUDIO_SPK_OUT_MAXPACKET_SIZE];
|
||||
uint8_t audio_mic_data[AUDIO_MIC_IN_MAXPACKET_SIZE];
|
||||
uint8_t audio_feed_back[AUDIO_FEEDBACK_MAXPACKET_SIZE+1];
|
||||
}usb_audio_type;
|
||||
|
||||
extern usbd_class_handler audio_class_handler;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
90
middlewares/usbd_class/audio/audio_conf.h
Normal file
90
middlewares/usbd_class/audio/audio_conf.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_conf.h
|
||||
* @version v2.0.0
|
||||
* @date 2021-11-26
|
||||
* @brief usb audio config
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AUDIO_CONF_H
|
||||
#define __AUDIO_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USB_audio_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_device_audio_config_definition
|
||||
* @{
|
||||
*/
|
||||
#define AUDIO_SUPPORT_SPK 1
|
||||
#define AUDIO_SUPPORT_MIC 1
|
||||
#define AUDIO_SUPPORT_FEEDBACK 0
|
||||
|
||||
#define AUDIO_SUPPORT_FREQ_16K 1
|
||||
#define AUDIO_SUPPORT_FREQ_48K 1
|
||||
|
||||
|
||||
#define AUDIO_SUPPORT_FREQ (AUDIO_SUPPORT_FREQ_16K + \
|
||||
AUDIO_SUPPORT_FREQ_48K \
|
||||
)
|
||||
|
||||
#define AUDIO_FREQ_16K 16000
|
||||
#define AUDIO_FREQ_48K 48000
|
||||
#define AUDIO_BITW_16 16
|
||||
|
||||
#define AUDIO_MIC_CHANEL_NUM 2
|
||||
#define AUDIO_MIC_DEFAULT_BITW AUDIO_BITW_16
|
||||
|
||||
#define AUDIO_SPK_CHANEL_NUM 2
|
||||
#define AUDIO_SPK_DEFAULT_BITW AUDIO_BITW_16
|
||||
|
||||
|
||||
#define AUDIO_SUPPORT_MAX_FREQ 48
|
||||
#define AUDIO_DEFAULT_FREQ AUDIO_FREQ_48K
|
||||
#define AUDIO_DEFAULT_BITW AUDIO_BITW_16
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
621
middlewares/usbd_class/audio/audio_desc.c
Normal file
621
middlewares/usbd_class/audio/audio_desc.c
Normal file
@@ -0,0 +1,621 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_desc.c
|
||||
* @version v2.0.0
|
||||
* @date 2021-11-26
|
||||
* @brief usb audio device descriptor
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
#include "usb_std.h"
|
||||
#include "usbd_sdr.h"
|
||||
#include "usbd_core.h"
|
||||
#include "audio_desc.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_audio_desc
|
||||
* @brief usb device audio descriptor
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_audio_desc_private_functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
usbd_desc_t *get_device_descriptor(void);
|
||||
usbd_desc_t *get_device_qualifier(void);
|
||||
usbd_desc_t *get_device_configuration(void);
|
||||
usbd_desc_t *get_device_other_speed(void);
|
||||
usbd_desc_t *get_device_lang_id(void);
|
||||
usbd_desc_t *get_device_manufacturer_string(void);
|
||||
usbd_desc_t *get_device_product_string(void);
|
||||
usbd_desc_t *get_device_serial_string(void);
|
||||
usbd_desc_t *get_device_interface_string(void);
|
||||
usbd_desc_t *get_device_config_string(void);
|
||||
|
||||
uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf);
|
||||
static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len);
|
||||
static void get_serial_num(void);
|
||||
static uint8_t g_usbd_desc_buffer[256];
|
||||
|
||||
/**
|
||||
* @brief device descriptor handler structure
|
||||
*/
|
||||
usbd_desc_handler audio_desc_handler =
|
||||
{
|
||||
get_device_descriptor,
|
||||
get_device_qualifier,
|
||||
get_device_configuration,
|
||||
get_device_other_speed,
|
||||
get_device_lang_id,
|
||||
get_device_manufacturer_string,
|
||||
get_device_product_string,
|
||||
get_device_serial_string,
|
||||
get_device_interface_string,
|
||||
get_device_config_string,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief usb device standard descriptor
|
||||
*/
|
||||
uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN] =
|
||||
{
|
||||
USB_DEVICE_DESC_LEN, /* bLength */
|
||||
USB_DESCIPTOR_TYPE_DEVICE, /* bDescriptorType */
|
||||
0x00, /* bcdUSB */
|
||||
0x02,
|
||||
0x00, /* bDeviceClass */
|
||||
0x00, /* bDeviceSubClass */
|
||||
0x00, /* bDeviceProtocol */
|
||||
USB_MAX_EP0_SIZE, /* bMaxPacketSize */
|
||||
LBYTE(USBD_VENDOR_ID), /* idVendor */
|
||||
HBYTE(USBD_VENDOR_ID), /* idVendor */
|
||||
LBYTE(USBD_PRODUCT_ID), /* idProduct */
|
||||
HBYTE(USBD_PRODUCT_ID), /* idProduct */
|
||||
0x00, /* bcdDevice rel. 2.00 */
|
||||
0x02,
|
||||
USB_MFC_STRING, /* Index of manufacturer string */
|
||||
USB_PRODUCT_STRING, /* Index of product string */
|
||||
USB_SERIAL_STRING, /* Index of serial number string */
|
||||
0x01 /* bNumConfigurations */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief usb configuration standard descriptor
|
||||
*/
|
||||
uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] =
|
||||
{
|
||||
USB_DEVICE_CFG_DESC_LEN, /* bLength: configuration descriptor size */
|
||||
USB_DESCIPTOR_TYPE_CONFIGURATION, /* bDescriptorType: configuration */
|
||||
LBYTE(USBD_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
HBYTE(USBD_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
0x1 + AUDIO_INTERFACE_NUM, /* bNumInterfaces: n interface */
|
||||
0x01, /* bConfigurationValue: configuration value */
|
||||
0x00, /* iConfiguration: index of string descriptor describing
|
||||
the configuration */
|
||||
0xC0, /* bmAttributes: self powered */
|
||||
0x32, /* MaxPower 100 mA: this current is used for detecting vbus */
|
||||
|
||||
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: number of interface */
|
||||
0x00, /* bAlternateSetting: alternate set */
|
||||
0x00, /* bNumEndpoints: number of endpoints */
|
||||
USB_CLASS_CODE_AUDIO, /* bInterfaceClass: audio class code */
|
||||
AUDIO_SUBCLASS_AUDIOCONTROL, /* bInterfaceSubClass: audio control */
|
||||
AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol: undefined */
|
||||
0x00, /* iInterface: index of string descriptor */
|
||||
|
||||
0x08+AUDIO_INTERFACE_NUM, /* bLength: size of this descriptor, in bytes 8+n */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: cs interface descriptor type */
|
||||
AUDIO_AC_HEADER, /* bDescriptorSubtype: Header function Descriptor*/
|
||||
LBYTE(BCD_NUM),
|
||||
HBYTE(BCD_NUM), /* bcdCDC: audio device class specification release number */
|
||||
LBYTE(AUDIO_INTERFACE_LEN),
|
||||
HBYTE(AUDIO_INTERFACE_LEN), /* wTotalLength: total number of bytes returned for the class-specific audio control interface */
|
||||
AUDIO_INTERFACE_NUM, /* bInClollection: the number of audio streaming */
|
||||
#if (AUDIO_INTERFACE_NUM == 2) /* two interface */
|
||||
0x02,
|
||||
0x01,
|
||||
#else
|
||||
0x01,
|
||||
#endif
|
||||
|
||||
/* usb microphone config */
|
||||
#if (AUDIO_SUPPORT_MIC == 1)
|
||||
AUDIO_INPUT_TERMINAL_SIZE, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: configuration */
|
||||
AUDIO_AC_INPUT_TERMINAL, /* bDescriptorSubtype: input_terminal type*/
|
||||
AUDIO_MIC_INPUT_TERMINAL_ID, /* bTerminalID: id of this input terminal*/
|
||||
LBYTE(AUDIO_INPUT_TERMINAL_MICROPHONE),
|
||||
HBYTE(AUDIO_INPUT_TERMINAL_MICROPHONE),/* wTerminalType: terminal is microphone */
|
||||
0x00, /* bAssocTerminal: no association */
|
||||
AUDIO_MIC_CHR, /* bNrChannels: two channel */
|
||||
#if (AUDIO_MIC_CHR == 2)
|
||||
0x03, /* wChannelConfig: left front and right front */
|
||||
#endif
|
||||
#if (AUDIO_MIC_CHR == 1)
|
||||
0x00, /* wChannelConfig */
|
||||
#endif
|
||||
0x00, /* wChannelConfig */
|
||||
0x00, /* iChannelNames: unused */
|
||||
0x00, /* iTerminal: unused */
|
||||
|
||||
AUDIO_FEATURE_UNIT_SIZE, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: configuration */
|
||||
AUDIO_AC_FEATURE_UNIT, /* bDescriptorSubtype: feature unit type*/
|
||||
AUDIO_MIC_FEATURE_UNIT_ID, /* bUnitID: id of this feature unit */
|
||||
AUDIO_MIC_INPUT_TERMINAL_ID, /* bSourceID: from input terminal */
|
||||
0x01, /* bControlSize: 1 byte */
|
||||
0x01, /* bmaControls0: mute */
|
||||
0x02, /* bmaControls1: volume */
|
||||
0x00, /* iFeature: unused */
|
||||
|
||||
AUDIO_OUTPUT_TERMINAL_SIZE, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: configuration */
|
||||
AUDIO_AC_OUTPUT_TERMINAL, /* bDescriptorSubtype: output_terminal type*/
|
||||
AUDIO_MIC_OUTPUT_TERMINAL_ID, /* bTerminalID: id of this output terminal*/
|
||||
LBYTE(AUDIO_TERMINAL_TYPE_STREAMING),
|
||||
HBYTE(AUDIO_TERMINAL_TYPE_STREAMING), /* wTerminalType: usb streaming */
|
||||
0x00, /* bAssocTerminal: unused */
|
||||
AUDIO_MIC_FEATURE_UNIT_ID, /* bSourceID: from feature unit terminal */
|
||||
0x00, /* iTerminal: unused */
|
||||
#endif
|
||||
|
||||
#if (AUDIO_SUPPORT_SPK == 1)
|
||||
/* speaker config */
|
||||
AUDIO_INPUT_TERMINAL_SIZE, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: configuration */
|
||||
AUDIO_AC_INPUT_TERMINAL, /* bDescriptorSubtype: input_terminal type*/
|
||||
AUDIO_SPK_INPUT_TERMINAL_ID, /* bTerminalID: id of this input terminal*/
|
||||
LBYTE(AUDIO_TERMINAL_TYPE_STREAMING), /* wTerminalType: usb streaming */
|
||||
HBYTE(AUDIO_TERMINAL_TYPE_STREAMING), /* wTerminalType: usb streaming */
|
||||
0x00, /* bAssocTerminal: no association */
|
||||
AUDIO_SPK_CHR, /* bNrChannels: two channel */
|
||||
#if (AUDIO_SPK_CHR == 2)
|
||||
0x03, /* wChannelConfig: left front and right front */
|
||||
#endif
|
||||
#if (AUDIO_SPK_CHR == 1)
|
||||
0x00, /* wChannelConfig */
|
||||
#endif
|
||||
0x00, /* wChannelConfig */
|
||||
0x00, /* iChannelNames: unused */
|
||||
0x00, /* iTerminal: unused */
|
||||
|
||||
AUDIO_FEATURE_UNIT_SIZE, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: configuration */
|
||||
AUDIO_AC_FEATURE_UNIT, /* bDescriptorSubtype: feature unit type*/
|
||||
AUDIO_SPK_FEATURE_UNIT_ID, /* bUnitID: id of this feature unit */
|
||||
AUDIO_SPK_INPUT_TERMINAL_ID, /* bSourceID: from input terminal */
|
||||
0x01, /* bControlSize: 1 byte */
|
||||
0x01, /* bmaControls0: mute*/
|
||||
0x02, /* bmaControls1: volume */
|
||||
0x00, /* iFeature: unused */
|
||||
|
||||
AUDIO_OUTPUT_TERMINAL_SIZE, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: configuration */
|
||||
AUDIO_AC_OUTPUT_TERMINAL, /* bDescriptorSubtype: output_terminal type*/
|
||||
AUDIO_SPK_OUTPUT_TERMINAL_ID, /* bTerminalID: id of this output terminal*/
|
||||
LBYTE(AUDIO_OUTPUT_TERMINAL_SPEAKER), /* wTerminalType: usb speaker */
|
||||
HBYTE(AUDIO_OUTPUT_TERMINAL_SPEAKER), /* wTerminalType: usb speaker */
|
||||
0x00, /* bAssocTerminal: unused */
|
||||
AUDIO_SPK_FEATURE_UNIT_ID, /* bSourceID: from feature unit terminal */
|
||||
0x00, /* iTerminal: unused */
|
||||
#endif
|
||||
|
||||
#if (AUDIO_SUPPORT_MIC == 1)
|
||||
/* microphone interface */
|
||||
0x09, /* bLength: descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_MIC_INTERFACE_NUMBER, /* bInterfaceNumber: index of this interface */
|
||||
0x00, /* bAlternateSetting: index of this setting */
|
||||
0x00, /* bNumEndpoints: 0 endpoints */
|
||||
USB_CLASS_CODE_AUDIO, /* bInterfaceClass: audio */
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubclass: audio streaming */
|
||||
0x00, /* bInterfaceProtocol: unused */
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x09, /* bLength: descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_MIC_INTERFACE_NUMBER, /* bInterfaceNumber: index of this interface */
|
||||
0x01, /* bAlternateSetting: index of this setting */
|
||||
0x01, /* bNumEndpoints: 1 endpoints */
|
||||
USB_CLASS_CODE_AUDIO, /* bInterfaceClass: audio */
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubclass: audio streaming */
|
||||
0x00, /* bInterfaceProtocol: unused */
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x07, /* bLength: configuration descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_AS_GENERAL, /* bDescriptorSubtype: general sub type*/
|
||||
AUDIO_MIC_OUTPUT_TERMINAL_ID, /* bTerminalLink: unit id of the output terminal */
|
||||
0x01, /* bDelay: interface delay */
|
||||
0x01, /* wFormatTag: pcm format*/
|
||||
0x00, /* wFormatTag: pcm format*/
|
||||
|
||||
0x08 + AUDIO_MIC_FREQ_SIZE * 3, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_AS_FORMAT_TYPE, /* bDescriptorSubtype: format subtype */
|
||||
AUDIO_FORMAT_TYPE_I, /* bFormatType: format type 1 */
|
||||
AUDIO_MIC_CHR, /* bNrChannels: channel number */
|
||||
AUDIO_MIC_BITW / 8, /* bSubFrameSize: per audio subframe */
|
||||
AUDIO_MIC_BITW, /* bBitResolution: n bits per sample */
|
||||
AUDIO_MIC_FREQ_SIZE, /* bSamFreqType: n frequency supported */
|
||||
#if (AUDIO_SUPPORT_FREQ_16K == 1)
|
||||
SAMPLE_FREQ(AT32_AUDIO_FREQ_16K), /* tSamFreq: 16000hz */
|
||||
#endif
|
||||
#if (AUDIO_SUPPORT_FREQ_48K == 1)
|
||||
SAMPLE_FREQ(AT32_AUDIO_FREQ_48K), /* tSamFreq: 48000hz */
|
||||
#endif
|
||||
|
||||
0x09, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_AUDIO_MIC_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_ISO | USB_ETP_DESC_ASYNC, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(AUDIO_MIC_IN_MAXPACKET_SIZE),
|
||||
HBYTE(AUDIO_MIC_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
0x00, /* bRefresh: unused */
|
||||
0x00, /* bSynchAddress: unused */
|
||||
|
||||
0x07, /* bLength: size of endpoint descriptor in bytes */
|
||||
AUDIO_CS_ENDPOINT, /* bDescriptorType: cs endpoint descriptor type */
|
||||
0x01, /* bDescriptorSubtype: general subtype */
|
||||
0x01, /* bmAttributes */
|
||||
0x00, /* bLockDelayUnits: unused */
|
||||
0x00, /* wLockDelay: unused */
|
||||
0x00, /* wLockDelay: unused */
|
||||
#endif
|
||||
|
||||
#if (AUDIO_SUPPORT_SPK == 1)
|
||||
/* speaker interface */
|
||||
0x09, /* bLength: descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_SPK_INTERFACE_NUMBER, /* bInterfaceNumber: index of this interface */
|
||||
0x00, /* bAlternateSetting: index of this setting */
|
||||
0x00, /* bNumEndpoints: 0 endpoints */
|
||||
USB_CLASS_CODE_AUDIO, /* bInterfaceClass: audio */
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubclass: audio streaming */
|
||||
0x00, /* bInterfaceProtocol: unused */
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x09, /* bLength: descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_SPK_INTERFACE_NUMBER, /* bInterfaceNumber: index of this interface */
|
||||
0x01, /* bAlternateSetting: index of this setting */
|
||||
0x01 + AUDIO_SUPPORT_FEEDBACK, /* bNumEndpoints: endpoints */
|
||||
USB_CLASS_CODE_AUDIO, /* bInterfaceClass: audio */
|
||||
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubclass: audio streaming */
|
||||
0x00, /* bInterfaceProtocol: unused */
|
||||
0x00, /* iInterface: unused */
|
||||
|
||||
0x07, /* bLength: configuration descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_AS_GENERAL, /* bDescriptorSubtype: general sub type*/
|
||||
AUDIO_SPK_INPUT_TERMINAL_ID, /* bTerminalLink: unit id of the input terminal */
|
||||
0x01, /* bDelay: interface delay */
|
||||
0x01, /* wFormatTag: pcm format*/
|
||||
0x00, /* wFormatTag: pcm format*/
|
||||
|
||||
0x08 + AUDIO_SPK_FREQ_SIZE * 3, /* bLength: descriptor size */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
AUDIO_AS_FORMAT_TYPE, /* bDescriptorSubtype: format subtype */
|
||||
AUDIO_FORMAT_TYPE_I, /* bFormatType: format type 1 */
|
||||
AUDIO_SPK_CHR, /* bNrChannels: channel number */
|
||||
AUDIO_SPK_BITW / 8, /* bSubFrameSize: per audio subframe */
|
||||
AUDIO_SPK_BITW, /* bBitResolution: n bits per sample */
|
||||
AUDIO_SPK_FREQ_SIZE, /* bSamFreqType: n frequency supported */
|
||||
#if (AUDIO_SUPPORT_FREQ_16K == 1)
|
||||
SAMPLE_FREQ(AT32_AUDIO_FREQ_16K), /* tSamFreq: 16000hz */
|
||||
#endif
|
||||
#if (AUDIO_SUPPORT_FREQ_48K == 1)
|
||||
SAMPLE_FREQ(AT32_AUDIO_FREQ_48K), /* tSamFreq: 48000hz */
|
||||
#endif
|
||||
|
||||
0x09, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_AUDIO_SPK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_ISO | USB_ETP_DESC_ASYNC, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(AUDIO_SPK_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(AUDIO_SPK_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
0x00, /* bRefresh: unused */
|
||||
#if (AUDIO_SUPPORT_FEEDBACK == 1)
|
||||
USBD_AUDIO_FEEDBACK_EPT, /* bSynchAddress: feedback endpoint */
|
||||
#else
|
||||
0x00, /* bSynchAddress: unused */
|
||||
#endif
|
||||
|
||||
0x07, /* bLength: size of endpoint descriptor in bytes */
|
||||
AUDIO_CS_ENDPOINT, /* bDescriptorType: cs endpoint descriptor type */
|
||||
0x01, /* bDescriptorSubtype: general subtype */
|
||||
0x01, /* bmAttributes */
|
||||
0x00, /* bLockDelayUnits: unused */
|
||||
0x00, /* wLockDelay: unused */
|
||||
0x00, /* wLockDelay: unused */
|
||||
|
||||
#if (AUDIO_SUPPORT_FEEDBACK == 1)
|
||||
0x09, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_AUDIO_FEEDBACK_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
0x11, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(AUDIO_FEEDBACK_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HBYTE(AUDIO_FEEDBACK_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
0x08, /* bRefresh: this field indicates the rate at which an iso syncronization
|
||||
pipe provides new syncronization feedback data. this rate must be a power of
|
||||
2, therefore only the power is reported back and the range of this field is from
|
||||
1(2ms) to 9(512ms) */
|
||||
0x00 /* bSynchAddress: 0x00*/
|
||||
#endif
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief usb string lang id
|
||||
*/
|
||||
uint8_t g_string_lang_id[USBD_SIZ_STRING_LANGID] =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USB_DESCIPTOR_TYPE_STRING,
|
||||
0x09,
|
||||
0x04,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief usb string serial
|
||||
*/
|
||||
uint8_t g_string_serial[USBD_SIZ_STRING_SERIAL] =
|
||||
{
|
||||
USBD_SIZ_STRING_SERIAL,
|
||||
USB_DESCIPTOR_TYPE_STRING,
|
||||
};
|
||||
|
||||
|
||||
/* device descriptor */
|
||||
usbd_desc_t device_descriptor =
|
||||
{
|
||||
USB_DEVICE_DESC_LEN,
|
||||
g_usbd_descriptor
|
||||
};
|
||||
|
||||
/* config descriptor */
|
||||
usbd_desc_t config_descriptor =
|
||||
{
|
||||
USBD_CONFIG_DESC_SIZE,
|
||||
g_usbd_configuration
|
||||
};
|
||||
|
||||
/* langid descriptor */
|
||||
usbd_desc_t langid_descriptor =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
g_string_lang_id
|
||||
};
|
||||
|
||||
/* serial descriptor */
|
||||
usbd_desc_t serial_descriptor =
|
||||
{
|
||||
USBD_SIZ_STRING_SERIAL,
|
||||
g_string_serial
|
||||
};
|
||||
|
||||
usbd_desc_t vp_desc;
|
||||
|
||||
/**
|
||||
* @brief standard usb unicode convert
|
||||
* @param string: source string
|
||||
* @param unicode_buf: unicode buffer
|
||||
* @retval length
|
||||
*/
|
||||
uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
{
|
||||
uint16_t str_len = 0, id_pos = 2;
|
||||
uint8_t *tmp_str = string;
|
||||
|
||||
while(*tmp_str != '\0')
|
||||
{
|
||||
str_len ++;
|
||||
unicode_buf[id_pos ++] = *tmp_str ++;
|
||||
unicode_buf[id_pos ++] = 0x00;
|
||||
}
|
||||
|
||||
str_len = str_len * 2 + 2;
|
||||
unicode_buf[0] = str_len;
|
||||
unicode_buf[1] = USB_DESCIPTOR_TYPE_STRING;
|
||||
|
||||
return str_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb int convert to unicode
|
||||
* @param value: int value
|
||||
* @param pbus: unicode buffer
|
||||
* @param len: length
|
||||
* @retval none
|
||||
*/
|
||||
static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
||||
{
|
||||
uint8_t idx = 0;
|
||||
|
||||
for( idx = 0 ; idx < len ; idx ++)
|
||||
{
|
||||
if( ((value >> 28)) < 0xA )
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10;
|
||||
}
|
||||
|
||||
value = value << 4;
|
||||
|
||||
pbuf[2 * idx + 1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb get serial number
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
static void get_serial_num(void)
|
||||
{
|
||||
uint32_t serial0, serial1, serial2;
|
||||
|
||||
serial0 = *(uint32_t*)MCU_ID1;
|
||||
serial1 = *(uint32_t*)MCU_ID2;
|
||||
serial2 = *(uint32_t*)MCU_ID3;
|
||||
|
||||
serial0 += serial2;
|
||||
|
||||
if (serial0 != 0)
|
||||
{
|
||||
usbd_int_to_unicode (serial0, &g_string_serial[2] ,8);
|
||||
usbd_int_to_unicode (serial1, &g_string_serial[18] ,4);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get device descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_descriptor(void)
|
||||
{
|
||||
return &device_descriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get device qualifier
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t * get_device_qualifier(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_configuration(void)
|
||||
{
|
||||
return &config_descriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get other speed descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_other_speed(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get lang id descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_lang_id(void)
|
||||
{
|
||||
return &langid_descriptor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get manufacturer descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_manufacturer_string(void)
|
||||
{
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get product descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_product_string(void)
|
||||
{
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get serial descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_serial_string(void)
|
||||
{
|
||||
get_serial_num();
|
||||
return &serial_descriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get interface descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_interface_string(void)
|
||||
{
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get device config descriptor
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_config_string(void)
|
||||
{
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
239
middlewares/usbd_class/audio/audio_desc.h
Normal file
239
middlewares/usbd_class/audio/audio_desc.h
Normal file
@@ -0,0 +1,239 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_desc.h
|
||||
* @version v2.0.0
|
||||
* @date 2021-11-26
|
||||
* @brief usb audio descriptor header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AUDIO_DESC_H
|
||||
#define __AUDIO_DESC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "audio_class.h"
|
||||
#include "usbd_core.h"
|
||||
#include "audio_conf.h"
|
||||
|
||||
/** @addtogroup AT32F415_middlewares_usbd_class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USB_audio_desc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_audio_desc_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define BCD_NUM 0x0100
|
||||
|
||||
#define USBD_VENDOR_ID 0x2E3C
|
||||
#define USBD_PRODUCT_ID 0x5730
|
||||
|
||||
#define USBD_SIZ_STRING_LANGID 4
|
||||
#define USBD_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
#define USBD_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_DESC_PRODUCT_STRING "AT32 Audio"
|
||||
#define USBD_DESC_CONFIGURATION_STRING "Audio Config"
|
||||
#define USBD_DESC_INTERFACE_STRING "Audio Interface"
|
||||
|
||||
/**
|
||||
* @brief audio interface subclass codes
|
||||
*/
|
||||
#define AUDIO_SUBCLASS_UNDEFINED 0x00
|
||||
#define AUDIO_SUBCLASS_AUDIOCONTROL 0x01
|
||||
#define AUDIO_SUBCLASS_AUDIOSTREAMING 0x02
|
||||
#define AUDIO_SUBCLASS_MIDISTREMING 0x03
|
||||
|
||||
/**
|
||||
* @brief audio class-specific descriptor types
|
||||
*/
|
||||
#define AUDIO_CS_INTERFACE 0x24
|
||||
#define AUDIO_CS_ENDPOINT 0x25
|
||||
#define AUDIO_CS_STRING 0x23
|
||||
#define AUDIO_CS_CONFIGURATION 0x22
|
||||
#define AUDIO_CS_DEVICE 0x21
|
||||
#define AUDIO_CS_UNDEFINED 0x20
|
||||
|
||||
/**
|
||||
* @brief audio interface protocol codes
|
||||
*/
|
||||
#define AUDIO_PROTOCOL_UNDEFINED 0x00
|
||||
|
||||
/**
|
||||
* @brief audio class-specific ac interface descriptor subtypes
|
||||
*/
|
||||
#define AUDIO_AC_DESCRIPTOR_UNDEFINED 0x00
|
||||
#define AUDIO_AC_HEADER 0x01
|
||||
#define AUDIO_AC_INPUT_TERMINAL 0x02
|
||||
#define AUDIO_AC_OUTPUT_TERMINAL 0x03
|
||||
#define AUDIO_AC_MIXER_UNIT 0x04
|
||||
#define AUDIO_AC_SELECTOR_UNIT 0x05
|
||||
#define AUDIO_AC_FEATURE_UNIT 0x06
|
||||
#define AUDIO_AC_PROCESSING_UNIT 0x07
|
||||
#define AUDIO_AC_EXTENSION_UNIT 0x08
|
||||
|
||||
/**
|
||||
* @brief audio class-specific as interface descriptor subtypes
|
||||
*/
|
||||
#define AUDIO_AS_DESCRIPTOR_UNDEFINED 0x00
|
||||
#define AUDIO_AS_GENERAL 0x01
|
||||
#define AUDIO_AS_FORMAT_TYPE 0x02
|
||||
#define AUDIO_AS_FORMAT_SPECIFIC 0x03
|
||||
|
||||
/**
|
||||
* @brief audio class-specific request codes
|
||||
*/
|
||||
#define AUDIO_REQUEST_CODE_UNDEFINED 0x00
|
||||
#define AUDIO_REQ_SET_CUR 0x01
|
||||
#define AUDIO_REQ_GET_CUR 0x81
|
||||
#define AUDIO_REQ_SET_MIN 0x02
|
||||
#define AUDIO_REQ_GET_MIN 0x82
|
||||
#define AUDIO_REQ_SET_MAX 0x03
|
||||
#define AUDIO_REQ_GET_MAX 0x83
|
||||
#define AUDIO_REQ_SET_RES 0x04
|
||||
#define AUDIO_REQ_GET_RES 0x84
|
||||
#define AUDIO_REQ_SET_MEM 0x05
|
||||
#define AUDIO_REQ_GET_MEM 0x85
|
||||
#define AUDIO_REQ_GET_STAT 0xFF
|
||||
|
||||
/**
|
||||
* @brief audio feature unit control selectors
|
||||
*/
|
||||
#define AUDIO_FU_CONTROL_UNDEFINED 0x00
|
||||
#define AUDIO_FU_MUTE_CONTROL 0x01
|
||||
#define AUDIO_FU_VOLUME_CONTROL 0x02
|
||||
#define AUDIO_FU_BASS_CONTROL 0x03
|
||||
#define AUDIO_FU_MID_CONTROL 0x04
|
||||
#define AUDIO_FU_TREBLE_CONTROL 0x05
|
||||
|
||||
/**
|
||||
* @brief audio terminal type
|
||||
*/
|
||||
#define AUDIO_TERMINAL_TYPE_UNDEFINED 0x0100
|
||||
#define AUDIO_TERMINAL_TYPE_STREAMING 0x0101
|
||||
#define AUDIO_TERMINAL_TYPE_VENDOR 0x01FF
|
||||
#define AUDIO_INPUT_TERMINAL_UNDEFINED 0x0200
|
||||
#define AUDIO_INPUT_TERMINAL_MICROPHONE 0x0201
|
||||
#define AUDIO_OUTPUT_TERMINAL_UNDEFINED 0x0300
|
||||
#define AUDIO_OUTPUT_TERMINAL_SPEAKER 0x0301
|
||||
|
||||
/**
|
||||
* @brief audio format type 1
|
||||
*/
|
||||
#define AUDIO_FORMAT_TYPE_I 0x01
|
||||
|
||||
/**
|
||||
* @brief audio interface config
|
||||
*/
|
||||
#define AUDIO_INTERFACE_NUM (AUDIO_SUPPORT_SPK + AUDIO_SUPPORT_MIC)
|
||||
#define AUDIO_INTERFACE_LEN ((0x08 + AUDIO_INTERFACE_NUM) + AUDIO_INTERFACE_NUM * 0x1E)
|
||||
#define AUDIO_MIC_INTERFACE 0x01
|
||||
#define AUDIO_SPK_INTERFACE 0x02
|
||||
|
||||
/**
|
||||
* @brief audio interface descriptor size define
|
||||
*/
|
||||
#define AUDIO_INPUT_TERMINAL_SIZE 0x0C
|
||||
#define AUDIO_OUTPUT_TERMINAL_SIZE 0x09
|
||||
#define AUDIO_FEATURE_UNIT_SIZE 0x09
|
||||
|
||||
/**
|
||||
* @brief audio terminal id define
|
||||
*/
|
||||
#define AUDIO_MIC_INPUT_TERMINAL_ID 0x01
|
||||
#define AUDIO_MIC_FEATURE_UNIT_ID 0x02
|
||||
#define AUDIO_MIC_OUTPUT_TERMINAL_ID 0x03
|
||||
#define AUDIO_SPK_INPUT_TERMINAL_ID 0x04
|
||||
#define AUDIO_SPK_FEATURE_UNIT_ID 0x05
|
||||
#define AUDIO_SPK_OUTPUT_TERMINAL_ID 0x06
|
||||
|
||||
/**
|
||||
* @brief audio interface number
|
||||
*/
|
||||
#define AUDIO_MIC_INTERFACE_NUMBER 0x01
|
||||
#if (AUDIO_SUPPORT_MIC == 1)
|
||||
#define AUDIO_SPK_INTERFACE_NUMBER 0x02
|
||||
#else
|
||||
#define AUDIO_SPK_INTERFACE_NUMBER 0x01
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief audio support freq
|
||||
*/
|
||||
#define AT32_AUDIO_FREQ_16K 16000
|
||||
#define AT32_AUDIO_FREQ_48K 48000
|
||||
|
||||
/**
|
||||
* @brief audio microphone freq and channel config
|
||||
*/
|
||||
#define AUDIO_MIC_FREQ_SIZE (AUDIO_SUPPORT_FREQ)
|
||||
#define AUDIO_MIC_CHR AUDIO_MIC_CHANEL_NUM
|
||||
#define AUDIO_MIC_BITW (AUDIO_MIC_DEFAULT_BITW)
|
||||
|
||||
/**
|
||||
* @brief audio speaker freq and channel config
|
||||
*/
|
||||
#define AUDIO_SPK_FREQ_SIZE (AUDIO_SUPPORT_FREQ)
|
||||
#define AUDIO_SPK_CHR AUDIO_SPK_CHANEL_NUM
|
||||
#define AUDIO_SPK_BITW (AUDIO_SPK_DEFAULT_BITW)
|
||||
|
||||
#define HID_BINTERVAL_TIME 0x01
|
||||
|
||||
|
||||
#define USBD_CONFIG_DESC_SIZE ( 0x12 + AUDIO_INTERFACE_LEN + \
|
||||
+ (0x31 + AUDIO_SPK_FREQ_SIZE * 3) \
|
||||
+ (0x31 + AUDIO_MIC_FREQ_SIZE * 3) \
|
||||
+ (9 * AUDIO_SUPPORT_FEEDBACK) \
|
||||
)
|
||||
#define SAMPLE_FREQ(frq) (uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16))
|
||||
|
||||
#define MCU_ID1 (0x1FFFF7E8)
|
||||
#define MCU_ID2 (0x1FFFF7EC)
|
||||
#define MCU_ID3 (0x1FFFF7F0)
|
||||
|
||||
extern uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN];
|
||||
extern uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE];
|
||||
extern usbd_desc_handler audio_desc_handler;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user