📄 uacsys.c
字号:
if (psDevice->u8IsoOutToggle == 0)
{
psDevice->u8IsoOutToggle = 1;
}
else
{
psDevice->u8IsoOutToggle = 0;
}
}
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* FUNCTION */
/* UAC_GetVersion() */
/* */
/* DESCRIPTION */
/* To get the UAC driver version. */
/* */
/* INPUTS */
/* None */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* The UAC driver version. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
uint32_t UAC_GetVersion(void)
{
return UAC_VERSION_NUM;
}
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* FUNCTION */
/* UAC_GetIsoOutPackeSize() */
/* */
/* DESCRIPTION */
/* To get the ISO OUT packet size according configuration descriptor. */
/* */
/* INPUTS */
/* u8Cfg The pointer of configuration descriptor. */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* The packet size of ISO OUT. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
uint16_t UAC_GetIsoOutPackeSize(const uint8_t *u8Cfg)
{
uint16_t packetSize;
int32_t offset;
offset = 0;
while(1)
{
offset += u8Cfg[offset];
/* Limit the max search size */
if (offset > LEN_CONFIG_AND_SUBORDINATE)
break;
if ((u8Cfg[offset + 1] == 0x05) && (u8Cfg[offset + 2] == (ISO_OUT_EP_NUM | EP_OUTPUT)))
{
packetSize = u8Cfg[offset + 4] | ((uint16_t)u8Cfg[offset + 5] << 8);
return packetSize;
}
}
return 0;
}
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* FUNCTION */
/* UAC_Open() */
/* */
/* DESCRIPTION */
/* To initial all descriptors and control handlers of USB Audio Class. */
/* */
/* INPUTS */
/* pVoid The function point of UAC device */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* E_SUCCESS */
/* */
/*---------------------------------------------------------------------------------------------------------*/
int32_t UAC_Open(void * pVoid)
{
g_UAC_sDevice.device = (void *)DrvUSB_InstallClassDevice(&sUacUsbClass);
g_UAC_sDevice.u8IsoOutPacketSize = UAC_GetIsoOutPackeSize(gau8ConfigDescriptor);
g_UAC_sDevice.i16RecMaxVolume = 6144; /* about 24dB */
g_UAC_sDevice.i16RecMinVolume = -32767; /* about -128dB */
g_UAC_sDevice.i16RecResVolume = 256; /* 1dB step */
g_UAC_sDevice.i16PlayMaxVolume = 768; /* about 3dB */
g_UAC_sDevice.i16PlayMinVolume = -8191; /* about -32dB */
g_UAC_sDevice.i16PlayResVolume = 256; /* 1dB step */
DrvUSB_InstallCtrlHandler(g_UAC_sDevice.device, g_asCtrlCallbackEntry,
sizeof(g_asCtrlCallbackEntry) / sizeof(g_asCtrlCallbackEntry[0]));
DrvUSB_EnableSelfPower();
DrvUSB_DisableRemoteWakeup();
return E_SUCCESS;
}
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* FUNCTION */
/* UAC_Close() */
/* */
/* DESCRIPTION */
/* None. */
/* */
/* INPUTS */
/* None */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* E_SUCCESS */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void UAC_Close(void)
{
}
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* FUNCTION */
/* UAC_Reset() */
/* */
/* DESCRIPTION */
/* The function to reset endpoint settings. It would be called at set configuration or set interface. */
/* */
/* INPUTS */
/* psDevice The function point of UAC device */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* E_SUCCESS */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void UAC_Reset(void * *pVoid)
{
uint32_t u32EpId;
S_UAC_DEVICE *psDevice = (S_UAC_DEVICE *)pVoid;
S_DRVUSB_DEVICE *psUsbDevice;
psUsbDevice = (S_DRVUSB_DEVICE *)psDevice->device;
/* Reset ISO IN endpoint setting */
u32EpId = DrvUSB_GetEpIdentity(ISO_IN_EP_NUM, EP_INPUT);
_DRVUSB_SET_CFG(u32EpId, CFG_ISO_IN);
_DRVUSB_SET_CFGP(u32EpId, CFGP_CLRRDY);
_DRVUSB_SET_EP_BUF(u32EpId, (uint32_t)psUsbDevice->sEpCrl[u32EpId].u8SramBuffer);
/* Reset ISO OUT endpoint setting */
u32EpId = DrvUSB_GetEpIdentity(ISO_OUT_EP_NUM, EP_OUTPUT);
_DRVUSB_SET_CFG(u32EpId, CFG_ISO_OUT);
_DRVUSB_SET_CFGP(u32EpId, CFGP_CLRRDY);
}
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* FUNCTION */
/* UAC_IsCfgId() */
/* */
/* DESCRIPTION */
/* To check if it is the specified bConfigurationValue in the confiuration descriptor. */
/* */
/* INPUTS */
/* u8ConfigureValue The bConfigurationValue to check. */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* E_SUCCESS */
/* */
/*---------------------------------------------------------------------------------------------------------*/
int32_t UAC_IsCfgId(uint8_t u8ConfiguationValue)
{
return (u8ConfiguationValue == gau8ConfigDescriptor[5]);
}
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* FUNCTION */
/* UAC_SendOneAudioPacket() */
/* */
/* DESCRIPTION */
/* Send one packet to host. This function is used for sending record data to host. */
/* */
/* INPUTS */
/* pbyAudioData The record data buffer pointer. */
/* u8AudioSize The record data size in byte. */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* None */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void UAC_SendOneAudioPacket(uint8_t *pbyAudioData, uint8_t u8AudioSize)
{
if (u8AudioSize > 0)
{
DrvUSB_DataIn(ISO_IN_EP_NUM, (uint8_t *)pbyAudioData, u8AudioSize);
}
else
{
_DRVUSB_TRIG_EP(DrvUSB_GetEpIdentity(ISO_IN_EP_NUM, EP_INPUT), 0);
}
}
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* FUNCTION */
/* UAC_Init() */
/* */
/* DESCRIPTION */
/* Install the callback functions for device enable, disable, play and record. */
/* */
/* INPUTS */
/* pfnDeviceEnable The callback function to enable audio device (start play/record). */
/* pfnDeviceDisable The callback function to disable audio device (stop play/record). */
/* pfnSendRecData The callback function to prepare the data for ISO IN. */
/* pfnGetPlayData The callback function to get ISO OUT data. */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* None */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void UAC_Init(
UAC_DEVICE_ENABLE pfnDeviceEnable,
UAC_DEVICE_DISABLE pfnDeviceDisable,
UAC_ISO_IN pfnSendRecData,
UAC_ISO_OUT pfnGetPlayData
)
{
pfnUacDeviceEnable = pfnDeviceEnable;
pfnUacDeviceDisable = pfnDeviceDisable;
pfnUacSendRecData = pfnSendRecData;
pfnUacGetPlayData = pfnGetPlayData;
}
void UAC_PrepareDescriptors(const uint8_t *pu8Descriptor, uint32_t u32DescriptorSize, uint32_t u32RequestSize, uint32_t u32MaxPacketSize)
{
gu32BytesInUsbBuf = u32RequestSize;
if(u32RequestSize > u32DescriptorSize)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -