예제 #1
0
파일: HIDSysIO.c 프로젝트: he992790757/C16
void HID_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;
    }

}
예제 #2
0
void HID_CtrlGetDescriptorIn(void * pVoid)
{
    uint32_t u32Len;
//	S_DRVUSB_DEVICE *psDevice = &gsUsbDevice;
//	uint32_t u32EpId;


    DBG_PRINTF(" >>> 0x%08x %d size.\n", gpu8UsbBuf, gu32BytesInUsbBuf);
	
    if(gpu8UsbBuf)
    {

        if(gu32BytesInUsbBuf == 0)
        {
            /* Zero packet */
    		DrvUSB_DataIn(0, gpu8UsbBuf, 0);
    		gpu8UsbBuf = 0;
			//u32Len = 10000;
			//while(u32Len--);
			//_DRVUSB_TRIG_EP(1,0x00);
        }
        else
        {
            u32Len = Minimum(gu32BytesInUsbBuf, HID_MAX_PACKET_SIZE_CTRL);
    		DrvUSB_DataIn(0, gpu8UsbBuf, u32Len);
    		gpu8UsbBuf += u32Len;
    		gu32BytesInUsbBuf -= u32Len;
    		
    		
    		if(gu32BytesInUsbBuf == 0)
    		{
                if(u32Len < HID_MAX_PACKET_SIZE_CTRL)
                {
    		        /* This should be last IN packet due to it is less than HID_MAX_PACKET_SIZE_EP0 */
    		        gpu8UsbBuf = 0;
			//u32Len = 10000;
			//while(u32Len--);
			//_DRVUSB_TRIG_EP(1,0x00);
                }
                else
                {
                    if(!gIsOverRequest)
                    {
                        gpu8UsbBuf = 0;
			//u32Len = 10000;
			//while(u32Len--);
			//_DRVUSB_TRIG_EP(1,0x00);
                    }
                }
    		}
    		
        }
    }
    else
    {
  	    /* The EP id 1 should always be used as control (OUT) endpoint */
		_DRVUSB_TRIG_EP(1,0x00);
    }
}
예제 #3
0
파일: HIDSysIO.c 프로젝트: he992790757/C16
void HID_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, HID_MAX_PACKET_SIZE_EP0);
            DrvUSB_DataIn(0, gpu8UsbBuf, u32Len);
            gpu8UsbBuf += u32Len;
            gu32BytesInUsbBuf -= u32Len;

            if (gu32BytesInUsbBuf == 0)
            {
                if (u32Len < HID_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);
    }
}
예제 #4
0
파일: HIDSysIO.c 프로젝트: he992790757/C16
void HID_IntInCallback(void * pVoid)
{
    S_HID_DEVICE* psDevice = (S_HID_DEVICE*) pVoid;

    if ((uint32_t)pfHID_GetInReport)
        pfHID_GetInReport(psDevice->pu8Report);

    DrvUSB_DataIn(HID_IN_EP_NUM, psDevice->pu8Report, psDevice->u32ReportSize);
}
예제 #5
0
/*---------------------------------------------------------------------------------------------------------*/
void HID_CtrlSetupSetConfiguration(void * pVoid)
{
	S_DRVUSB_DEVICE *pDrvDevice = &gsUsbDevice;
	S_DRVUSB_CLASS *psUsbClass = pDrvDevice->psUsbClass;
	int8_t bIsDeviceConfigure;
	
	bIsDeviceConfigure = psUsbClass->pfnCompare ? psUsbClass->pfnCompare(pDrvDevice->au8Setup[2]) : 1;
	
	if (pDrvDevice->au8Setup[2] == 0)
	{
		// USB address state.
		DrvUSB_SetUsbState(eDRVUSB_ADDRESS);
		pDrvDevice->u8UsbConfiguration = pDrvDevice->au8Setup[2];
		DrvUSB_DataIn(0, NULL, 0);
		
	}
	else if (bIsDeviceConfigure)
	{
		// USB configured state.
		DrvUSB_SetUsbState(eDRVUSB_CONFIGURED);

		//call USB class's start function
		if(psUsbClass->pfnStart)
			psUsbClass->pfnStart(pVoid);

		pDrvDevice->u8UsbConfiguration = pDrvDevice->au8Setup[2];

		DrvUSB_DataIn(0, NULL, 0);
		
	}
	else
	{
		// Not support. Reply STALL.
		DrvUSB_ClrCtrlReadyAndTrigStall();
	}
}
예제 #6
0
파일: HIDSysIO.c 프로젝트: he992790757/C16
void HID_CtrlSetupGetReport(void * pVoid)
{
    S_DRVUSB_DEVICE *psDevice = (S_DRVUSB_DEVICE *)((S_HID_DEVICE *)pVoid)->device;

    DBG_PRINTF("HID - Get Report");
    if (psDevice->au8Setup[3] == 3)
    {
        /* Request Type = Feature */
        const uint8_t au8Data[2] = {0x01, 0x02};

        gpu8UsbBuf = au8Data;
        gu32BytesInUsbBuf = 0;
        DrvUSB_DataIn(0, au8Data, 2);
    }
    else
    {
        DBG_PRINTF(" - Unknown\n");
        _HID_CLR_CTRL_READY_AND_TRIG_STALL();
    }
}
예제 #7
0
//Returns number of MIDI packets sent
uint8_t USBMIDI_Poll(void)
{
	uint8_t bytesToSend = 0;
	uint8_t tempBuffer[MAX_PACKET_SIZE_BULK_IN];

	if(g_UsbInReady == USB_BULK_IN_IS_READY )
	{
		while( (usbMIDI_bufferLen() != 0) && (bytesToSend < MAX_PACKET_SIZE_BULK_IN) )
		{
			memcpy(tempBuffer + bytesToSend, &MIDImsgComplete[rMIDImsgCount], sizeof(usbMIDIMessage_t));
			rMIDImsgCount = (rMIDImsgCount + 1) & MIDI_OUT_MASK;
			bytesToSend = bytesToSend + sizeof(usbMIDIMessage_t);
		}

		if( bytesToSend )
		{
			g_UsbInReady = bytesToSend;
			DrvUSB_DataIn(BULK_IN_EP_NUM, (uint8_t*) &tempBuffer, bytesToSend);
		}
	}
	
	return bytesToSend / sizeof(usbMIDIMessage_t);
}
예제 #8
0
파일: HIDSysIO.c 프로젝트: he992790757/C16
void HID_Start(S_HID_DEVICE *psDevice)
{
    DrvUSB_DataIn(HID_IN_EP_NUM, psDevice->pu8Report, psDevice->u32ReportSize);
    DrvUSB_DataOutTrigger(HID_OUT_EP_NUM, HID_MAX_PACKET_SIZE_EP2);
}
예제 #9
0
void HID_CtrlSetupGetProtocol(void * pVoid)
{
	S_HID_DEVICE *psDevice = (S_HID_DEVICE *) pVoid;
	
	DrvUSB_DataIn(0, (const uint8_t *)&psDevice->isReportProtocol, 1);
}