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

📄 uachidsys.c

📁 cortex-m0 LCD1602程序
💻 C
📖 第 1 页 / 共 4 页
字号:
    else if (PLAY_FEATURE_UNITID == psUsbDevice->au8Setup[5])
  	{
        switch (psUsbDevice->au8Setup[3])
        {
            case VOLUME_CONTROL:
                psUsbDevice->sEpCrl[0].u8SramBuffer[0] = (uint8_t)(psDevice->i16PlayMinVolume);    
                psUsbDevice->sEpCrl[0].u8SramBuffer[1] = (uint8_t)(psDevice->i16PlayMinVolume >> 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_ClassCtrlGetMaxRequest(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->i16RecMaxVolume);    
                psUsbDevice->sEpCrl[0].u8SramBuffer[1] = (uint8_t)(psDevice->i16RecMaxVolume >> 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 VOLUME_CONTROL:
                psUsbDevice->sEpCrl[0].u8SramBuffer[0] = (uint8_t)(psDevice->i16PlayMaxVolume);    
                psUsbDevice->sEpCrl[0].u8SramBuffer[1] = (uint8_t)(psDevice->i16PlayMaxVolume >> 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_ClassCtrlGetResRequest(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->i16RecResVolume);    
                psUsbDevice->sEpCrl[0].u8SramBuffer[1] = (uint8_t)(psDevice->i16RecResVolume >> 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 VOLUME_CONTROL:
                psUsbDevice->sEpCrl[0].u8SramBuffer[0] = (uint8_t)(psDevice->i16PlayResVolume);    
                psUsbDevice->sEpCrl[0].u8SramBuffer[1] = (uint8_t)(psDevice->i16PlayResVolume >> 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_ClassCtrlSetCurOutData(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])
  	{
        if (psUsbDevice->au8Setup[3] == MUTE_CONTROL)
        {
            psDevice->u8RecMute = psUsbDevice->sEpCrl[0].u8SramBuffer[0];
        }   
        else if(psUsbDevice->au8Setup[3] == VOLUME_CONTROL)
        {
            psDevice->i16RecVolume =(int16_t) (psUsbDevice->sEpCrl[0].u8SramBuffer[0] | (psUsbDevice->sEpCrl[0].u8SramBuffer[1]<<8));
        }
    }   	 
    else if(PLAY_FEATURE_UNITID == psUsbDevice->au8Setup[5])
  	{
        if (psUsbDevice->au8Setup[3] == MUTE_CONTROL)
        {
            psDevice->u8PlayMute = psUsbDevice->sEpCrl[0].u8SramBuffer[0];
        }   
        else if(psUsbDevice->au8Setup[3] == VOLUME_CONTROL)
        {
            if(psUsbDevice->au8Setup[2] == 1)
            {
                psDevice->i16PlayVolumeL =(int16_t) (psUsbDevice->sEpCrl[0].u8SramBuffer[0] | (psUsbDevice->sEpCrl[0].u8SramBuffer[1]<<8));
            }
            else
            {
                psDevice->i16PlayVolumeR =(int16_t) (psUsbDevice->sEpCrl[0].u8SramBuffer[0] | (psUsbDevice->sEpCrl[0].u8SramBuffer[1]<<8));
            }
        }
    }
	_DRVUSB_SET_EP_TOG_BIT(0, FALSE);
	_DRVUSB_TRIG_EP(0, 0);
}


/* Translate the volume gain form dB value to Q12 integer. Output data is in Q12 */
int32_t UAC_GetRecVolume(void)
{
    int32_t volume;
    int32_t q, r;
    
    /* Just return 0 when MUTE */
    if (g_UAC_sDevice.u8RecMute)
        return 0;
    
    volume = g_UAC_sDevice.i16RecVolume;
    if (volume == -32768)
    {   
        /* MUTE control */
        volume = 0;
    }
    else
    {   
        volume -= g_UAC_sDevice.i16RecMinVolume;
        q = volume >> (8 + 1);
        r = volume & 0x1FF;
        
        volume = gVolumeTbl[q] + ((gVolumeTbl[q+1] - gVolumeTbl[q]) * r >> 9);
    }
    
    return volume;
}

/* Translate the volume gain form dB value to Q12 integer. Output data is in Q12 */
int32_t UAC_GetPlayVolume(int32_t bIsRight)
{
    int32_t volume;
    int32_t q, r;
    
    /* Just return 0 when MUTE */
    if (g_UAC_sDevice.u8PlayMute)
        return 0;
    
    if (bIsRight)
        volume = g_UAC_sDevice.i16PlayVolumeR;
    else        
        volume = g_UAC_sDevice.i16PlayVolumeL;
    
    
    if (volume == -32768)
    {   
        /* MUTE control */
        volume = 0;
    }
    else
    {   
        volume -= g_UAC_sDevice.i16RecMinVolume;
        q = volume >> (8 + 1);
        r = volume & 0x1FF;
        
        volume = gVolumeTbl[q] + ((gVolumeTbl[q+1] - gVolumeTbl[q]) * r >> 9);
    }
    
    return volume;
}

/*************************************************************************/
/*                                                                       */
/* DESCRIPTION                                                           */
/*      interrupt pipe call back function                                */
/*                                                                       */
/* INPUTS                                                                */
/*      pVoid     parameter passed by g_sUsbOps[]                        */
/*                                                                       */
/* OUTPUTS                                                               */
/*      None                                                             */
/*                                                                       */
/* RETURN                                                                */
/*      None                                                             */
/*                                                                       */
/*************************************************************************/
void HID_IntInCallback(void * pVoid)
{
	S_UAC_DEVICE* psDevice = (S_UAC_DEVICE*) pVoid;
	
	if ((uint32_t)pfHID_GetInReport)
	    pfHID_GetInReport(psDevice->pu8Report);
	
	DrvUSB_DataIn(HID_IN_EP_NUM, psDevice->pu8Report, psDevice->u32ReportSize);
}


/*************************************************************************/
/*                                                                       */
/* DESCRIPTION                                                           */
/*      Set report descriptor. if not set, default will be used          */
/*      default HID report descriptor is mouse.                          */
/*                                                                       */
/* INPUTS                                                                */
/*      pu8ReportDescriptor     report descriptor buffer                 */
/*      u32ReportDescriptorSize report descriptor size                   */
/*                                                                       */
/* OUTPUTS                                                               */
/*      None                                                             */
/*                                                                       */
/* RETURN                                                                */
/*      0           Success                                              */
/*		Otherwise	error												 */
/*                                                                       */
/*************************************************************************/
int32_t HID_SetReportDescriptor(const uint8_t* pu8ReportDescriptor, uint32_t u32ReportDescriptorSize)
{
	if (pu8ReportDescriptor == NULL)
	{
		return (E_HID_NULL_POINTER);
	}

	g_UAC_sDevice.pu8ReportDescriptor = pu8ReportDescriptor;
	g_UAC_sDevice.u32ReportDescriptorSize = u32ReportDescriptorSize;
	
	return E_SUCCESS;
}

/*************************************************************************/
/*                                                                       */
/* DESCRIPTION                                                           */
/*      Set report buffer and size for interrupt pipe                    */
/*                                                                       */
/* INPUTS                                                                */
/*      pu8Report     buffer that will be sent to host when interupt IN  */
/*						happen                                           */
/*      u32ReportSize     buffer size                                    */
/*                                                                       */
/* OUTPUTS                                                               */
/*      None                                                             */
/*                                                                       */
/* RETURN                                                                */
/*      0           Success                                              */
/*		Otherwise	error												 */
/*                                                                       */
/*************************************************************************/
int32_t HID_SetReportBuf(uint8_t* pu8Report, uint32_t u32ReportSize)
{
	if (pu8Report == NULL)
	{
		return (E_HID_NULL_POINTER);
	}

	g_UAC_sDevice.pu8Report = pu8Report;
	g_UAC_sDevice.u32ReportSize = u32ReportSize;


	return E_SUCCESS;
}


⌨️ 快捷键说明

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