Program/USB Device - HID - Custom/mla/framework/usb/src/usb_device_hid.c
/********************************************************************
	Function:
		void USBCheckHIDRequest(void)

 	Summary:
 		This routine handles HID specific request that happen on EP0.
        This function should be called from the USBCBCheckOtherReq() call back
        function whenever implementing a HID device.

 	Description:
 		This routine handles HID specific request that happen on EP0.  These
        include, but are not limited to, requests for the HID report
        descriptors.  This function should be called from the
        USBCBCheckOtherReq() call back function whenever using an HID device.

        Typical Usage:
        <code>
        void USBCBCheckOtherReq(void)
        {
            //Since the stack didn't handle the request I need to check
            //  my class drivers to see if it is for them
            USBCheckHIDRequest();
        }
        </code>

	PreCondition:
		None

	Parameters:
		None

	Return Values:
		None

	Remarks:
		None
 
 *******************************************************************/


This routine handles HID specific request that happen on EP0.
This function should be called from the USBCBCheckOtherReq() call back
function whenever implementing a HID device.

This routine handles HID specific request that happen on EP0.  These
include, but are not limited to, requests for the HID report
descriptors.  This function should be called from the
USBCBCheckOtherReq() call back function whenever using an HID device.

Typical Usage:

void USBCBCheckOtherReq(void)
{
Since the stack didn't handle the request I need to check
my class drivers to see if it is for them
USBCheckHIDRequest();
}

None

None

Return Values:
None

None
This routine handles HID specific request that happen on EP0 . This function should be called from the USBCBCheckOtherReq () call back function whenever implementing a HID device . This routine handles HID specific request that happen on EP0 . These include but are not limited to requests for the HID report descriptors . This function should be called from the USBCBCheckOtherReq () call back function whenever using an HID device . Typical Usage : void USBCBCheckOtherReq ( void ) { Since the stack didn ' t handle the request I need to check my class drivers to see if it is for them USBCheckHIDRequest () ; } None None Return Values : None None
void USBCheckHIDRequest(void)
{
    if(SetupPkt.Recipient != USB_SETUP_RECIPIENT_INTERFACE_BITFIELD) return;
    if(SetupPkt.bIntfID != HID_INTF_ID) return;
    if(SetupPkt.bRequest == USB_REQUEST_GET_DESCRIPTOR)
    {
        switch(SetupPkt.bDescriptorType)
        {
            case DSC_HID: 
                if(USBActiveConfiguration == 1)
                {
                    USBEP0SendROMPtr(
                        (const uint8_t*)&configDescriptor1 + 18,		
                        sizeof(USB_HID_DSC)+3,
                        USB_EP0_INCLUDE_ZERO);
                }
                break;
            case DSC_RPT:  
                {
                    USBEP0SendROMPtr(
                        (const uint8_t*)&hid_rpt01,
                        HID_RPT01_SIZE,     
                        USB_EP0_INCLUDE_ZERO);
                }
                break;
            case DSC_PHY:  
                break;
        }
    }
    if(SetupPkt.RequestType != USB_SETUP_TYPE_CLASS_BITFIELD)
    {
        return;
    }
    switch(SetupPkt.bRequest)
    {
        case GET_REPORT:
            #if defined USER_GET_REPORT_HANDLER
                USER_GET_REPORT_HANDLER();
            #endif
            break;
        case SET_REPORT:
            #if defined USER_SET_REPORT_HANDLER
                USER_SET_REPORT_HANDLER();
            #endif       
            break;
        case GET_IDLE:
            USBEP0SendRAMPtr(
                (uint8_t*)&idle_rate,
                1,
                USB_EP0_INCLUDE_ZERO);
            break;
        case SET_IDLE:
            USBEP0Transmit(USB_EP0_NO_DATA);
            idle_rate = ((USB_SETUP_SET_IDLE_RATE*)&SetupPkt)->duration;
            USB_DEVICE_HID_IDLE_RATE_CALLBACK(((USB_SETUP_SET_IDLE_RATE*)&SetupPkt)->reportId, idle_rate);
            break;
        case GET_PROTOCOL:
            USBEP0SendRAMPtr(
                (uint8_t*)&active_protocol,
                1,
                USB_EP0_NO_OPTIONS);
            break;
        case SET_PROTOCOL:
            USBEP0Transmit(USB_EP0_NO_DATA);
            active_protocol = ((USB_SETUP_SET_PROTOCOL*)&SetupPkt)->protocol;
            break;
    }
}
void USBCheckHIDRequest ( void ) { if ( SetupPkt . Recipient != USB_SETUP_RECIPIENT_INTERFACE_BITFIELD ) return ; if ( SetupPkt . bIntfID != HID_INTF_ID ) return ; if ( SetupPkt . bRequest == USB_REQUEST_GET_DESCRIPTOR ) { switch ( SetupPkt . bDescriptorType ) { case DSC_HID : if ( USBActiveConfiguration == 1 ) { USBEP0SendROMPtr ( ( const uint8_t * ) & configDescriptor1 + 18 , sizeof ( USB_HID_DSC ) + 3 , USB_EP0_INCLUDE_ZERO ) ; } break ; case DSC_RPT : { USBEP0SendROMPtr ( ( const uint8_t * ) & hid_rpt01 , HID_RPT01_SIZE , USB_EP0_INCLUDE_ZERO ) ; } break ; case DSC_PHY : break ; } } if ( SetupPkt . RequestType != USB_SETUP_TYPE_CLASS_BITFIELD ) { return ; } switch ( SetupPkt . bRequest ) { case GET_REPORT : #if defined USER_GET_REPORT_HANDLER USER_GET_REPORT_HANDLER ( ) ; #endif break ; case SET_REPORT : #if defined USER_SET_REPORT_HANDLER USER_SET_REPORT_HANDLER ( ) ; #endif break ; case GET_IDLE : USBEP0SendRAMPtr ( ( uint8_t * ) & idle_rate , 1 , USB_EP0_INCLUDE_ZERO ) ; break ; case SET_IDLE : USBEP0Transmit ( USB_EP0_NO_DATA ) ; idle_rate = ( ( USB_SETUP_SET_IDLE_RATE * ) & SetupPkt ) -> duration ; USB_DEVICE_HID_IDLE_RATE_CALLBACK ( ( ( USB_SETUP_SET_IDLE_RATE * ) & SetupPkt ) -> reportId , idle_rate ) ; break ; case GET_PROTOCOL : USBEP0SendRAMPtr ( ( uint8_t * ) & active_protocol , 1 , USB_EP0_NO_OPTIONS ) ; break ; case SET_PROTOCOL : USBEP0Transmit ( USB_EP0_NO_DATA ) ; active_protocol = ( ( USB_SETUP_SET_PROTOCOL * ) & SetupPkt ) -> protocol ; break ; } }
Function:
void USBCheckHIDRequest(void)
Function : void USBCheckHIDRequest ( void )
/*
     * There are two standard requests that hid.c may support.
     * 1. GET_DSC(DSC_HID,DSC_RPT,DSC_PHY);
     * 2. SET_DSC(DSC_HID,DSC_RPT,DSC_PHY);
     */ //HID Descriptor           //18 is a magic number.  It is the offset from start of the configuration descriptor to the start of the HID descriptor. //Report Descriptor            //if(USBActiveConfiguration == 1) //See usbcfg.h //Physical Descriptor //Note: The below placeholder code is commented out.  HID Physical Descriptors are optional and are not used //in many types of HID applications.  If an application does not have a physical descriptor, //then the device should return STALL in response to this request (stack will do this automatically //if no-one claims ownership of the control transfer). //If an application does implement a physical descriptor, then make sure to declare //hid_phy01 (rom structure containing the descriptor data), and hid_phy01 (the size of the descriptors in uint8_ts), //and then uncomment the below code. //if(USBActiveConfiguration == 1) //{ //    USBEP0SendROMPtr((const uint8_t*)&hid_phy01, sizeof(hid_phy01), USB_EP0_INCLUDE_ZERO); //} //end switch(SetupPkt.bDescriptorType) //end if(SetupPkt.bRequest == GET_DSC) //end switch(SetupPkt.bRequest)