Advertisement
Guest User

usb_function_hid.c

a guest
May 17th, 2012
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.37 KB | None | 0 0
  1. /********************************************************************
  2.   File Information:
  3.     FileName:       usb_function_hid.c
  4.     Dependencies:   See INCLUDES section
  5.     Processor:      PIC18 or PIC24 USB Microcontrollers
  6.     Hardware:       The code is natively intended to be used on the following
  7.                     hardware platforms: PICDEM™ FS USB Demo Board,
  8.                     PIC18F87J50 FS USB Plug-In Module, or
  9.                     Explorer 16 + PIC24 USB PIM.  The firmware may be
  10.                     modified for use on other USB platforms by editing the
  11.                     HardwareProfile.h file.
  12.     Complier:       Microchip C18 (for PIC18) or C30 (for PIC24)
  13.     Company:        Microchip Technology, Inc.
  14.    
  15.     Software License Agreement:
  16.    
  17.     The software supplied herewith by Microchip Technology Incorporated
  18.     (the “Company”) for its PIC® Microcontroller is intended and
  19.     supplied to you, the Company’s customer, for use solely and
  20.     exclusively on Microchip PIC Microcontroller products. The
  21.     software is owned by the Company and/or its supplier, and is
  22.     protected under applicable copyright laws. All rights are reserved.
  23.     Any use in violation of the foregoing restrictions may subject the
  24.     user to criminal sanctions under applicable laws, as well as to
  25.     civil liability for the breach of the terms and conditions of this
  26.     license.
  27.    
  28.     THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
  29.     WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
  30.     TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  31.     PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
  32.     IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
  33.     CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  34.  
  35.   File Description:
  36.    
  37.     Change History:
  38.      Rev   Date         Description
  39.      1.0   11/19/2004   Initial release
  40.      2.1   02/26/2007   Updated for simplicity and to use common
  41.                         coding style
  42.  
  43.   Summary:
  44.     This file contains all of functions, macros, definitions, variables,
  45.     datatypes, etc. that are required for usage with the HID function
  46.     driver. This file should be included in projects that use the HID
  47.     \function driver.
  48.    
  49.    
  50.    
  51.     This file is located in the "\<Install Directory\>\\Microchip\\USB\\HID
  52.     Device Driver" directory.
  53.   Description:
  54.     USB HID Function Driver File
  55.    
  56.     This file contains all of functions, macros, definitions, variables,
  57.     datatypes, etc. that are required for usage with the HID function
  58.     driver. This file should be included in projects that use the HID
  59.     \function driver.
  60.    
  61.     This file is located in the "\<Install Directory\>\\Microchip\\USB\\HID
  62.     Device Driver" directory.
  63.    
  64.     When including this file in a new project, this file can either be
  65.     referenced from the directory in which it was installed or copied
  66.     directly into the user application folder. If the first method is
  67.     chosen to keep the file located in the folder in which it is installed
  68.     then include paths need to be added so that the library and the
  69.     application both know where to reference each others files. If the
  70.     application folder is located in the same folder as the Microchip
  71.     folder (like the current demo folders), then the following include
  72.     paths need to be added to the application's project:
  73.    
  74.     ..\\Include
  75.    
  76.     ..\\..\\Include
  77.    
  78.     ..\\..\\Microchip\\Include
  79.    
  80.     ..\\..\\\<Application Folder\>
  81.    
  82.     ..\\..\\..\\\<Application Folder\>
  83.    
  84.     If a different directory structure is used, modify the paths as
  85.     required. An example using absolute paths instead of relative paths
  86.     would be the following:
  87.    
  88.     C:\\Microchip Solutions\\Microchip\\Include
  89.    
  90.     C:\\Microchip Solutions\\My Demo Application  
  91. *******************************************************************/
  92.  
  93. /** INCLUDES *******************************************************/
  94. #include "GenericTypeDefs.h"
  95. #include "Compiler.h"
  96. #include "usb_config.h"
  97. //#include "./USB/usb_device.h"
  98. //#include "./USB/usb_function_hid.h"
  99. #include "usb_device.h"
  100. #include "usb_function_hid.h"
  101.  
  102. /** VARIABLES ******************************************************/
  103. #pragma udata
  104. BYTE idle_rate;
  105. BYTE active_protocol;   // [0] Boot Protocol [1] Report Protocol
  106. BYTE hid_rpt_rx_len;
  107.  
  108. /** PRIVATE PROTOTYPES *********************************************/
  109. void HIDGetReportHandler(void);
  110. void HIDSetReportHandler(void);
  111.  
  112. /** Section: DECLARATIONS ***************************************************/
  113. #pragma code
  114.  
  115. /** Section: CLASS SPECIFIC REQUESTS ****************************************/
  116.  
  117. /********************************************************************
  118.     Function:
  119.         void USBCheckHIDRequest(void)
  120.        
  121.     Summary:
  122.         This routine handles HID specific request that happen on EP0.  
  123.         This function should be called from the USBCBCheckOtherReq() call back
  124.         function whenever implementing a HID device.
  125.  
  126.     Description:
  127.         This routine handles HID specific request that happen on EP0.  These
  128.         include, but are not limited to, requests for the HID report
  129.         descriptors.  This function should be called from the
  130.         USBCBCheckOtherReq() call back function whenever using an HID device.  
  131.  
  132.         Typical Usage:
  133.         <code>
  134.         void USBCBCheckOtherReq(void)
  135.         {
  136.             //Since the stack didn't handle the request I need to check
  137.             //  my class drivers to see if it is for them
  138.             USBCheckHIDRequest();
  139.         }
  140.         </code>
  141.        
  142.     PreCondition:
  143.         None
  144.        
  145.     Parameters:
  146.         None
  147.        
  148.     Return Values:
  149.         None
  150.        
  151.     Remarks:
  152.         None
  153.  
  154.  *******************************************************************/
  155. void USBCheckHIDRequest(void)
  156. {
  157.     if(SetupPkt.Recipient != RCPT_INTF) return;
  158.     if(SetupPkt.bIntfID != HID_INTF_ID) return;
  159.    
  160.     /*
  161.      * There are two standard requests that hid.c may support.
  162.      * 1. GET_DSC(DSC_HID,DSC_RPT,DSC_PHY);
  163.      * 2. SET_DSC(DSC_HID,DSC_RPT,DSC_PHY);
  164.      */
  165.     if(SetupPkt.bRequest == GET_DSC)
  166.     {
  167.         switch(SetupPkt.bDescriptorType)
  168.         {
  169.             case DSC_HID:          
  170.                 if(USBActiveConfiguration == 1)
  171.                 {
  172.                     USBEP0SendROMPtr(
  173.                         (ROM BYTE*)&HIDDescriptor1,        
  174.                         sizeof(USB_HID_DSC)+3,                  //from the start of the configuration descriptor, to the start
  175.                         USB_EP0_INCLUDE_ZERO);                  //of the HID descriptor (which is part of the configuration descriptor).
  176.                 }
  177.                 break;
  178.             case DSC_RPT:            
  179.                 if(USBActiveConfiguration == 1)
  180.                 {
  181.                     USBEP0SendROMPtr(
  182.                         (ROM BYTE*)&hid_rpt01,
  183.                         sizeof(hid_rpt01),     //See usbcfg.h
  184.                         USB_EP0_INCLUDE_ZERO);
  185.                 }
  186.                 break;
  187.             case DSC_PHY:
  188.                 USBEP0Transmit(USB_EP0_NO_DATA);
  189.                 break;
  190.         }//end switch(SetupPkt.bDescriptorType)
  191.     }//end if(SetupPkt.bRequest == GET_DSC)
  192.    
  193.     if(SetupPkt.RequestType != CLASS) return;
  194.     switch(SetupPkt.bRequest)
  195.     {
  196.         case GET_REPORT:
  197.             HIDGetReportHandler();
  198.             break;
  199.         case SET_REPORT:
  200.             HIDSetReportHandler();            
  201.             break;
  202.         case GET_IDLE:
  203.             USBEP0SendRAMPtr(
  204.                 (BYTE*)&idle_rate,
  205.                 1,
  206.                 USB_EP0_INCLUDE_ZERO);
  207.             break;
  208.         case SET_IDLE:
  209.             USBEP0Transmit(USB_EP0_NO_DATA);
  210.             idle_rate = SetupPkt.W_Value.byte.HB;
  211.             break;
  212.         case GET_PROTOCOL:
  213.             USBEP0SendRAMPtr(
  214.                 (BYTE*)&active_protocol,
  215.                 1,
  216.                 USB_EP0_NO_OPTIONS);
  217.             break;
  218.         case SET_PROTOCOL:
  219.             USBEP0Transmit(USB_EP0_NO_DATA);
  220.             active_protocol = SetupPkt.W_Value.byte.LB;
  221.             break;
  222.     }//end switch(SetupPkt.bRequest)
  223.  
  224. }//end USBCheckHIDRequest
  225.  
  226. void HIDGetReportHandler(void)
  227. {
  228. }//end HIDGetReportHandler
  229.  
  230. void HIDSetReportHandler(void)
  231. {
  232. }//end HIDSetReportHandler
  233.  
  234. /** USER API *******************************************************/
  235.  
  236. /** EOF usb_function_hid.c ******************************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement