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

📄 uachidsys.c

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


void UAC_CtrlGetDescriptorOut(void * pVoid)
{
    gu32BytesInUsbBuf = 0;
    gpu8UsbBuf = 0;
    gIsOverRequest = 0;
}

void UAC_CtrlGetDescriptorIn(void * pVoid)
{
    uint32_t u32Len;


    DBG_PRINTF(" >>> 0x%08x %d size.\n", gpu8UsbBuf, gu32BytesInUsbBuf);
	
    if (gpu8UsbBuf)
    {
        if (gu32BytesInUsbBuf == 0)
        {
            /* Zero packet */
    		DrvUSB_DataIn(0, gpu8UsbBuf, 0);
    		gpu8UsbBuf = 0;
        }
        else
        {
            u32Len = Minimum(gu32BytesInUsbBuf, UAC_MAX_PACKET_SIZE_EP0);
    		DrvUSB_DataIn(0, gpu8UsbBuf, u32Len);
    		gpu8UsbBuf += u32Len;
    		gu32BytesInUsbBuf -= u32Len;
    		
    		if(gu32BytesInUsbBuf == 0)
    		{
                if (u32Len < UAC_MAX_PACKET_SIZE_EP0)
                {
                    /* This should be last IN packet due to it is less than UAC_MAX_PACKET_SIZE_EP0 */
                    gpu8UsbBuf = 0;
                }
                else
                {
                    if (!gIsOverRequest)
                    {
    		            /* This should be the last IN packet because there is no more data to 
                           transfer and it is not over request transfer */
                        gpu8UsbBuf = 0;
                    }
                }
            } 
        }
    }
    else
    {
  	    /* The EP id 1 should always be used as control (OUT) endpoint */
		_DRVUSB_TRIG_EP(1,0x00);
    }
}


/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* FUNCTION                                                                                                */
/*      UAC_CtrlSetupGetDescriptor()	       	                                                           */
/*                                                                                                         */
/* DESCRIPTION                                                                                             */
/*      The callback funciton for get descriptor request ack event.                                        */
/*                                                                                                         */
/* INPUTS                                                                                                  */
/*      pVoid   A pointer of UAC device.                                                                   */
/*                                                                                                         */
/* OUTPUTS                                                                                                 */
/*      None                            				                                                   */
/*                                                                                                         */
/* RETURN                                                                                                  */
/*      None                                                                                               */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/
void UAC_CtrlSetupGetDescriptor(void * pVoid)
{
	S_UAC_DEVICE *psDevice = (S_UAC_DEVICE *) pVoid;
	S_DRVUSB_DEVICE *pInfraDevice = (S_DRVUSB_DEVICE *)psDevice->device;
	uint16_t u16Len;
	s_u8ConfigLenOver64 = 0;

	u16Len = 0;
	u16Len = pInfraDevice->au8Setup[7];
	u16Len <<= 8;
	u16Len += pInfraDevice->au8Setup[6];

    gIsOverRequest = 0;	
	gu32BytesInUsbBuf = 0;
	gpu8UsbBuf = 0;
	
	switch (pInfraDevice->au8Setup[3])
	{
		/* Get Device Descriptor */
		case DESC_DEVICE:
		{
            UAC_PrepareDescriptors(gau8DeviceDescriptor, LEN_DEVICE, u16Len, UAC_MAX_PACKET_SIZE_EP0);
    
    	    /* Prepare the OUT to avoid HOST stop data phase without all data transfered. */
    		_DRVUSB_TRIG_EP(1,0x00);

		    break;
		}
		/* Get Configuration Descriptor */
		case DESC_CONFIG:
		{
            UAC_PrepareDescriptors(gau8ConfigDescriptor, gau8ConfigDescriptor[2] + gau8ConfigDescriptor[3]*256, u16Len, UAC_MAX_PACKET_SIZE_EP0);
			break;
		}

		/* Get HID Descriptor */
    	case DESC_HID: 
    	{
			UAC_PrepareDescriptors(g_UAC_sDevice.pu8HIDDescriptor, LEN_HID, u16Len, UAC_MAX_PACKET_SIZE_EP0);
    		break;
    	}	
    	/* Get Report Descriptor */
		case DESC_HID_RPT: 
    	{
			UAC_PrepareDescriptors(g_UAC_sDevice.pu8ReportDescriptor, g_UAC_sDevice.u32ReportDescriptorSize, u16Len, UAC_MAX_PACKET_SIZE_EP0);
    		break;
        }

		/* Get String Descriptor */
		case DESC_STRING:
		{
    		// Get Language
    		if (pInfraDevice->au8Setup[2] == 0)
    		{
                UAC_PrepareDescriptors(gau8StringLang, 4, u16Len, UAC_MAX_PACKET_SIZE_EP0);
    		}
    		else
    		{
    			// Get String Descriptor
    			switch (pInfraDevice->au8Setup[2])
    			{
    			case 1:
                    UAC_PrepareDescriptors((const uint8_t *)gau8VendorStringDescriptor, gau8VendorStringDescriptor[0], u16Len, UAC_MAX_PACKET_SIZE_EP0);
    				break;
    
    			case 2:
                    UAC_PrepareDescriptors((const uint8_t *)gau8ProductStringDescriptor, gau8ProductStringDescriptor[0], u16Len, UAC_MAX_PACKET_SIZE_EP0);
      				break;
    
    			case 3:
                    UAC_PrepareDescriptors(gau8StringSerial, gau8StringSerial[0], u16Len, UAC_MAX_PACKET_SIZE_EP0);
    				break;

    			case 4:
                    UAC_PrepareDescriptors(gau8StringAudio, gau8StringAudio[0], u16Len, UAC_MAX_PACKET_SIZE_EP0);
    				break;
    
    			default:
    				/* Not support. Reply STALL. */
    				DrvUSB_ClrCtrlReadyAndTrigStall();
    			}
    		}
    
    		break;
		}

		default:
			/* Not support. Reply STALL. */
			DrvUSB_ClrCtrlReadyAndTrigStall();
			break;
	}
}


void UAC_ClassCtrlSetCurRequest(void * pVoid)
{
  	S_UAC_DEVICE *psDevice = (S_UAC_DEVICE *) pVoid;
  	S_DRVUSB_DEVICE *psUsbDevice = (S_DRVUSB_DEVICE *)psDevice->device;
  	
  	if (REC_FEATURE_UNITID == psUsbDevice->au8Setup[5])
  	{
        switch ( psUsbDevice->au8Setup[3])
        {
            case MUTE_CONTROL:
               _DRVUSB_TRIG_EP(1,psUsbDevice->au8Setup[6]); 
               break;
            case VOLUME_CONTROL:
               _DRVUSB_TRIG_EP(1,psUsbDevice->au8Setup[6]); 
               break;
            default:   
                /* STALL control pipe */
        		_DRVUSB_CLEAR_EP_READY_AND_TRIG_STALL(0);
        		_DRVUSB_CLEAR_EP_READY_AND_TRIG_STALL(1);
       	        break;
        }       	      
    }
    else if (PLAY_FEATURE_UNITID == psUsbDevice->au8Setup[5])
  	{
        switch ( psUsbDevice->au8Setup[3])
        {
            case MUTE_CONTROL:
               _DRVUSB_TRIG_EP(1,psUsbDevice->au8Setup[6]); 
               break;
            case VOLUME_CONTROL:
               _DRVUSB_TRIG_EP(1,psUsbDevice->au8Setup[6]); 
               break;
            default:   
                /* STALL control pipe */
        		_DRVUSB_CLEAR_EP_READY_AND_TRIG_STALL(0);
        		_DRVUSB_CLEAR_EP_READY_AND_TRIG_STALL(1);
       	        break;
        }       	      
    }
    else
    {
        /* STALL control pipe */
		_DRVUSB_CLEAR_EP_READY_AND_TRIG_STALL(0);
		_DRVUSB_CLEAR_EP_READY_AND_TRIG_STALL(1);
    } 
}

void UAC_ClassCtrlGetCurRequest(void * pVoid)
{
  	S_UAC_DEVICE *psDevice = (S_UAC_DEVICE *) pVoid;
  	S_DRVUSB_DEVICE *psUsbDevice = (S_DRVUSB_DEVICE *)psDevice->device;

 	if(REC_FEATURE_UNITID == psUsbDevice->au8Setup[5])
  	{
        switch ( psUsbDevice->au8Setup[3])
        {
            case MUTE_CONTROL:
			{
      		    psUsbDevice->sEpCrl[0].u8SramBuffer[0] = psDevice->u8RecMute;
        		_DRVUSB_SET_EP_TOG_BIT(0, FALSE);
        		_DRVUSB_TRIG_EP(0, 1);
               break;
            }
			case VOLUME_CONTROL:
            {
			    psUsbDevice->sEpCrl[0].u8SramBuffer[0] = (uint8_t)(psDevice->i16RecVolume);    
                psUsbDevice->sEpCrl[0].u8SramBuffer[1] = (uint8_t)(psDevice->i16RecVolume >> 8);  
        		_DRVUSB_SET_EP_TOG_BIT(0, FALSE);
        		_DRVUSB_TRIG_EP(0, 2);
                break;
            }
			default:   
                /* STALL control pipe */
        		_DRVUSB_CLEAR_EP_READY_AND_TRIG_STALL(0);
        		_DRVUSB_CLEAR_EP_READY_AND_TRIG_STALL(1);
       	        break;
        }       	      
    }   	 
    else if (PLAY_FEATURE_UNITID == psUsbDevice->au8Setup[5])
  	{
        switch ( psUsbDevice->au8Setup[3])
        {
            case MUTE_CONTROL:
      		{
			    psUsbDevice->sEpCrl[0].u8SramBuffer[0] = psDevice->u8PlayMute;
        		_DRVUSB_SET_EP_TOG_BIT(0, FALSE);
        		_DRVUSB_TRIG_EP(0, 1);
               break;
            }
			case VOLUME_CONTROL:
            {
			    if(psUsbDevice->au8Setup[2] == 1)
                {
                    psUsbDevice->sEpCrl[0].u8SramBuffer[0] = (uint8_t)(psDevice->i16PlayVolumeL);    
                    psUsbDevice->sEpCrl[0].u8SramBuffer[1] = (uint8_t)(psDevice->i16PlayVolumeL >> 8);  
                }
                else
                {
                    psUsbDevice->sEpCrl[0].u8SramBuffer[0] = (uint8_t)(psDevice->i16PlayVolumeR);    
                    psUsbDevice->sEpCrl[0].u8SramBuffer[1] = (uint8_t)(psDevice->i16PlayVolumeR >> 8);  
                }
        		_DRVUSB_SET_EP_TOG_BIT(0, FALSE);
        		_DRVUSB_TRIG_EP(0, 2);
                break;
            }
			default:   
                /* STALL control pipe */
        		_DRVUSB_CLEAR_EP_READY_AND_TRIG_STALL(0);
        		_DRVUSB_CLEAR_EP_READY_AND_TRIG_STALL(1);
       	        break;
        }       	      
    }   	 
    else
    {
        /* STALL control pipe */
		_DRVUSB_CLEAR_EP_READY_AND_TRIG_STALL(0);
		_DRVUSB_CLEAR_EP_READY_AND_TRIG_STALL(1);
    } 
}


void UAC_ClassCtrlGetMinRequest(void * pVoid)
{
 	S_UAC_DEVICE *psDevice = (S_UAC_DEVICE *) pVoid;
  	S_DRVUSB_DEVICE *psUsbDevice = (S_DRVUSB_DEVICE *)psDevice->device;

 	if (REC_FEATURE_UNITID == psUsbDevice->au8Setup[5])
  	{
        switch (psUsbDevice->au8Setup[3])
        {
            case VOLUME_CONTROL:
                psUsbDevice->sEpCrl[0].u8SramBuffer[0] = (uint8_t)(psDevice->i16RecMinVolume);    
                psUsbDevice->sEpCrl[0].u8SramBuffer[1] = (uint8_t)(psDevice->i16RecMinVolume >> 8);  
        		_DRVUSB_SET_EP_TOG_BIT(0, FALSE);
        		_DRVUSB_TRIG_EP(0, 2);
               break;
            default:   
                /* STALL control pipe */
        		_DRVUSB_CLEAR_EP_READY_AND_TRIG_STALL(0);
        		_DRVUSB_CLEAR_EP_READY_AND_TRIG_STALL(1);
       	        break;
        }       	      
    }   	 

⌨️ 快捷键说明

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