⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uachidsys.c

📁 cortex-m0 LCD1602程序
💻 C
📖 第 1 页 / 共 4 页
字号:

/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* 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;
    int32_t configSize;
    
    configSize = u8Cfg[2] + u8Cfg[3] * 256;    


    offset = 0;
    while(1)
    {
        offset += u8Cfg[offset];
        
        /* Limit the max search size */
        //if (offset > LEN_CONFIG_AND_SUBORDINATE)
        if (offset > configSize)
		    break;
    
        if ((u8Cfg[offset + 1] == 0x05) && (u8Cfg[offset + 3] == 0x0D))
        {
            packetSize = u8Cfg[offset + 4] | ((uint16_t)u8Cfg[offset + 5] << 8);
            return packetSize;
        }       
    }
    
    return 0;
}


/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* FUNCTION                                                                                                */
/*      UAC_GetHidDescriptorOffset()	      	                                                           */
/*                                                                                                         */
/* DESCRIPTION                                                                                             */
/*      To get the HID descriptor offset.                                                                  */
/*                                                                                                         */
/* INPUTS                                                                                                  */
/*      u8Cfg   The pointer of configuration descriptor.                                                   */
/*                                                                                                         */
/* OUTPUTS                                                                                                 */
/*      None                            				                                                   */
/*                                                                                                         */
/* RETURN                                                                                                  */
/*      The offset of HID descriptor in configuration descritpor.                                          */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/
uint16_t UAC_GetHidDescriptorOffset(const uint8_t *u8Cfg)
{
    int32_t offset;
    int32_t configSize;
    
    configSize = u8Cfg[2] + u8Cfg[3] * 256;
    
    offset = 0;
    while(1)
    {
        offset += u8Cfg[offset];
        
        /* Limit the max search size */
        if(offset > configSize)
            break;
    
        if ((u8Cfg[offset + 1] == 0x04) && (u8Cfg[offset + 5] == 0x03))
        {
            return offset;
        }       
    }
    
    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)
{		
    if ((uint32_t)pVoid != NULL)
        pfHID_GetInReport = (void(*)(uint8_t *))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)
    {
        gu32BytesInUsbBuf = u32DescriptorSize;
        gIsOverRequest = 1;
    }
    gpu8UsbBuf = pu8Descriptor;

    DBG_PRINTF("Get descriptor 0x%08x %d size.\n", pu8Descriptor, u32DescriptorSize);

	if(gu32BytesInUsbBuf < u32MaxPacketSize)
	{
	    DrvUSB_DataIn(0, gpu8UsbBuf, gu32BytesInUsbBuf); 
	    gpu8UsbBuf = 0;
	    gu32BytesInUsbBuf = 0;   
	}
	else
	{
		DrvUSB_DataIn(0, gpu8UsbBuf, u32MaxPacketSize);
		gpu8UsbBuf += u32MaxPacketSize;
		gu32BytesInUsbBuf -= u32MaxPacketSize;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -