52 UAC_INFO_T *uac_info = (UAC_INFO_T *)audev->
priv;
59 if(!uac_info->ft_play)
61 return uac_info->ft_play->bNrChannels;
67 return uac_info->ft_rec->bNrChannels;
85 UAC_INFO_T *uac_info = (UAC_INFO_T *)audev->
priv;
92 if(!uac_info->ft_play)
94 *byte_cnt = uac_info->ft_play->bSubframeSize;
95 return uac_info->ft_play->bBitResolution;
99 if(!uac_info->it_microphone)
101 *byte_cnt = uac_info->ft_rec->bSubframeSize;
102 return uac_info->ft_rec->bBitResolution;
109uint32_t srate_to_u32(uint8_t *srate)
111 return (srate[2] << 16) | (srate[1] << 8) | srate[0];
135 int max_cnt, uint8_t *type)
137 UAC_INFO_T *uac_info = (UAC_INFO_T *)audev->
priv;
142 ft = uac_info->ft_play;
144 ft = uac_info->ft_rec;
149 *type = ft->bSamFreqType;
156 srate_list[0] = srate_to_u32(&ft->tSamFreq[0][0]);
157 srate_list[1] = srate_to_u32(&ft->tSamFreq[1][0]);
161 for(i = 0; i < *type; i++)
162 srate_list[i] = srate_to_u32(&ft->tSamFreq[i][0]);
191 UAC_INFO_T *uac_info = (UAC_INFO_T *)audev->
priv;
194 uint8_t bmRequestType;
195 uint8_t tSampleFreq[3];
201 ep = uac_info->epd_play;
203 ep = uac_info->epd_rec;
208 tSampleFreq[0] = *srate & 0xff;
209 tSampleFreq[1] = (*srate >> 8) & 0xff;
210 tSampleFreq[2] = (*srate >> 16) & 0xff;
212 bmRequestType = USB_TYPE_CLASS | USB_RECIP_ENDPOINT;
216 pipe = usb_rcvctrlpipe(udev, 0);
217 bmRequestType |= 0x80;
221 pipe = usb_sndctrlpipe(udev, 0);
225 (SAMPLING_FREQ_CONTROL << 8),
226 ep->bEndpointAddress,
230 *srate = srate_to_u32(tSampleFreq);
270 UAC_INFO_T *uac_info = (UAC_INFO_T *)audev->
priv;
273 uint8_t bmRequestType;
279 fu = uac_info->fu_play;
281 fu = uac_info->fu_rec;
288 bmRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE;
292 pipe = usb_rcvctrlpipe(udev, 0);
293 bmRequestType |= 0x80;
297 pipe = usb_sndctrlpipe(udev, 0);
301 (MUTE_CONTROL << 8) | chn,
363 UAC_INFO_T *uac_info = (UAC_INFO_T *)audev->
priv;
366 uint8_t bmRequestType;
372 fu = uac_info->fu_play;
374 fu = uac_info->fu_rec;
381 bmRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE;
385 pipe = usb_rcvctrlpipe(udev, 0);
386 bmRequestType |= 0x80;
390 pipe = usb_sndctrlpipe(udev, 0);
395 (VOLUME_CONTROL << 8) | chn,
436 UAC_INFO_T *uac_info = (UAC_INFO_T *)audev->
priv;
439 uint8_t bmRequestType;
445 fu = uac_info->fu_play;
447 fu = uac_info->fu_rec;
454 bmRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE;
458 pipe = usb_rcvctrlpipe(udev, 0);
459 bmRequestType |= 0x80;
463 pipe = usb_sndctrlpipe(udev, 0);
467 (AUTOMATIC_GAIN_CONTROL << 8) | chn,
479static void iso_in_irq(
URB_T *urb)
487 if(!audev || !audev->
udev)
513 memcpy(audev->
au_in_buff, buff + cp_len, len);
537 USBAS_DBGMSG(
"v: USBH_SubmitUrb ret %d\n", status);
559 UAC_INFO_T *uac_info = (UAC_INFO_T *)audev->
priv;
562 if(!func || !uac_info)
565 ep = uac_info->epd_rec;
568 USBAS_DBGMSG(
"Isochronous-in endpoint not found in this device!\n");
589 UAC_INFO_T *uac_info = (UAC_INFO_T *)audev->
priv;
597 ep = uac_info->epd_rec;
600 USBAS_DBGMSG(
"Isochronous-in endpoint not found in this device!\n");
607 if(
USBH_SetInterface(audev->
udev, uac_info->ifd_rec->bInterfaceNumber, uac_info->ifd_rec->bAlternateSetting) != 0)
615 USBAS_DBGMSG(
"Failed to allocated URB!\n");
620 audev->
urbin[uidx] = urb;
623 urb->
pipe = usb_rcvisocpipe(audev->
udev, ep->bEndpointAddress);
641 USBAS_DBGMSG(
"Error - failed to submit URB (%d)", ret);
674 UAC_INFO_T *uac_info = (UAC_INFO_T *)audev->
priv;
697static void iso_out_irq(
URB_T *urb)
704 if(!audev || !audev->
udev)
707 ep = ((UAC_INFO_T *)audev->
priv)->epd_play;
731 USBAS_DBGMSG(
"v: USBH_SubmitUrb ret %d\n", status);
749 UAC_INFO_T *uac_info = (UAC_INFO_T *)audev->
priv;
752 if(!func || !uac_info)
755 ep = uac_info->epd_play;
758 USBAS_DBGMSG(
"Isochronous-out endpoint not found in this device!\n");
776 UAC_INFO_T *uac_info = (UAC_INFO_T *)audev->
priv;
784 ep = uac_info->epd_play;
787 USBAS_DBGMSG(
"Isochronous-out endpoint not found in this device!\n");
792 if(
USBH_SetInterface(audev->
udev, uac_info->ifd_play->bInterfaceNumber, uac_info->ifd_play->bAlternateSetting) != 0)
800 USBAS_DBGMSG(
"Failed to allocated URB!\n");
805 audev->
urbout[uidx] = urb;
808 urb->
pipe = usb_sndisocpipe(audev->
udev, ep->bEndpointAddress);
823 USBAS_ERRMSG(
"Audio-out packet buffer overrun!\n");
832 USBAS_DBGMSG(
"Error - failed to submit URB (%d)", ret);
865 UAC_INFO_T *uac_info = (UAC_INFO_T *)audev->
priv;
#define UAC_RET_DEV_NOT_SUPPORTED
#define UAC_RET_OUT_OF_MEMORY
int32_t UAC_StartIsoOutPipe(UAC_DEV_T *audev)
Start to send audio data to UAC device via isochronous out pipe.
int32_t UAC_AutoGainControl(UAC_DEV_T *audev, uint8_t target, uint8_t req, uint16_t chn, uint8_t *gain)
Audio Class device automatic gain control.
int32_t UAC_StopIsoOutPipe(UAC_DEV_T *audev)
Stop UAC device audio out data stream.
int32_t UAC_MuteControl(UAC_DEV_T *audev, uint8_t target, uint8_t req, uint16_t chn, uint8_t *data)
Control Audio Class device mute on/off.
int32_t UAC_GetChannelNumber(UAC_DEV_T *audev, uint8_t target)
Obtain Audio Class device's channel number.
int32_t UAC_GetBitResolution(UAC_DEV_T *audev, uint8_t target, uint8_t *val8)
Obtain Audio Class device subframe bit resolution..
UAC_CB_FUNC * au_out_func
uint8_t iso_outbuf[ISO_OUT_URB_CNT][AU_OUT_MAX_PKTSZ *ISO_FRAME_COUNT]
int32_t UAC_GetSamplingRate(UAC_DEV_T *audev, uint8_t target, uint32_t *srate_list, int max_cnt, uint8_t *type)
Get a list of sampling rate frequences supported by the UAC device.
int32_t UAC_InstallIsoOutCbFun(UAC_DEV_T *audev, UAC_CB_FUNC *func)
Install isochronous-out (speaker) callback function. The UAC driver will call the callback function t...
int32_t UAC_SamplingRateControl(UAC_DEV_T *audev, uint8_t target, uint8_t req, uint32_t *srate)
Set sampling rate frequency.
int32_t UAC_VolumeControl(UAC_DEV_T *audev, uint8_t target, uint8_t req, uint16_t chn, uint16_t *volume)
Audio Class device volume control.
int32_t UAC_StopIsoInPipe(UAC_DEV_T *audev)
Stop UAC device audio in data stream.
URB_T * urbout[ISO_OUT_URB_CNT]
int32_t UAC_InstallIsoInCbFun(UAC_DEV_T *audev, uint8_t *au_in_buff, int bufsiz, UAC_CB_FUNC *func)
Install isochronous-in (microphone) callback function. Received audio data from UAC device will be de...
uint8_t iso_inbuf[ISO_IN_URB_CNT][AU_IN_MAX_PKTSZ *ISO_FRAME_COUNT]
URB_T * urbin[ISO_IN_URB_CNT]
int32_t UAC_StartIsoInPipe(UAC_DEV_T *audev)
Start to receive audio data from UAC device via isochronous in pipe.
int() UAC_CB_FUNC(struct uac_dev_t *dev, uint8_t *data, int len)
URB_T * USBH_AllocUrb(void)
Allocate an URB from USB Core driver internal URB pool.
int32_t USBH_SubmitUrb(URB_T *urb)
Submit an URB to USB core for transfer data.
int transfer_buffer_length
int32_t USBH_UnlinkUrb(URB_T *urb)
Cancel an URB which has been submit to USB core.
int32_t USBH_SetInterface(USB_DEV_T *dev, char interface, char alternate)
Set USB device interface.
ISO_PACKET_DESCRIPTOR_T iso_frame_desc[8]
void USBH_FreeUrb(URB_T *)
Free the URB allocated from USBH_AllocUrb()
void(* complete)(struct urb_t *)
int32_t USBH_SendCtrlMsg(USB_DEV_T *dev, uint32_t pipe, uint8_t request, uint8_t requesttype, uint16_t value, uint16_t index, void *data, uint16_t size, int timeout)
Execute a control transfer.
USB Host core driver header file.
HIDDEN_SYMBOLS struct usb_device USB_DEV_T