Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /******************************************************************** |
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 Companys 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 | Summary: |
||
38 | This file contains all of functions, macros, definitions, variables, |
||
39 | datatypes, etc. that are required for usage with the HID function |
||
40 | driver. This file should be included in projects that use the HID |
||
41 | \function driver. |
||
42 | |||
43 | This file is located in the "\<Install Directory\>\\Microchip\\USB\\HID |
||
44 | Device Driver" directory. |
||
45 | |||
46 | Description: |
||
47 | USB HID Function Driver File |
||
48 | |||
49 | This file contains all of functions, macros, definitions, variables, |
||
50 | datatypes, etc. that are required for usage with the HID function |
||
51 | driver. This file should be included in projects that use the HID |
||
52 | \function driver. |
||
53 | |||
54 | This file is located in the "\<Install Directory\>\\Microchip\\USB\\HID |
||
55 | Device Driver" directory. |
||
56 | |||
57 | When including this file in a new project, this file can either be |
||
58 | referenced from the directory in which it was installed or copied |
||
59 | directly into the user application folder. If the first method is |
||
60 | chosen to keep the file located in the folder in which it is installed |
||
61 | then include paths need to be added so that the library and the |
||
62 | application both know where to reference each others files. If the |
||
63 | application folder is located in the same folder as the Microchip |
||
64 | folder (like the current demo folders), then the following include |
||
65 | paths need to be added to the application's project: |
||
66 | |||
67 | ..\\..\\Microchip\\Include |
||
68 | |||
69 | . |
||
70 | |||
71 | If a different directory structure is used, modify the paths as |
||
72 | required. An example using absolute paths instead of relative paths |
||
73 | would be the following: |
||
74 | |||
75 | C:\\Microchip Solutions\\Microchip\\Include |
||
76 | |||
77 | C:\\Microchip Solutions\\My Demo Application |
||
78 | |||
79 | Change History: |
||
80 | Rev Description |
||
81 | ------- ----------------------------------------------------- |
||
82 | 1.0 Initial release |
||
83 | 2.1 Updated for simplicity and to use common coding style |
||
84 | 2.1-2.6 No change |
||
85 | 2.6a Updated the handling of the physical descriptor |
||
86 | 2.7-2.7a No change |
||
87 | *******************************************************************/ |
||
88 | |||
89 | #ifndef USB_FUNCTION_HID_C |
||
90 | #define USB_FUNCTION_HID_C |
||
91 | |||
92 | /** INCLUDES *******************************************************/ |
||
93 | #include "GenericTypeDefs.h" |
||
94 | #include "Compiler.h" |
||
95 | #include "./USB/usb.h" |
||
96 | #include "./USB/usb_function_hid.h" |
||
97 | |||
98 | |||
99 | /** VARIABLES ******************************************************/ |
||
100 | #pragma udata |
||
101 | BYTE idle_rate; |
||
102 | BYTE active_protocol; // [0] Boot Protocol [1] Report Protocol |
||
103 | |||
104 | /** EXTERNAL PROTOTYPES ********************************************/ |
||
105 | #if defined USER_GET_REPORT_HANDLER |
||
106 | void USER_GET_REPORT_HANDLER(void); |
||
107 | #endif |
||
108 | |||
109 | #if defined USER_SET_REPORT_HANDLER |
||
110 | void USER_SET_REPORT_HANDLER(void); |
||
111 | #endif |
||
112 | |||
113 | /** Section: DECLARATIONS ***************************************************/ |
||
114 | #pragma code |
||
115 | |||
116 | /** Section: CLASS SPECIFIC REQUESTS ****************************************/ |
||
117 | |||
118 | /******************************************************************** |
||
119 | Function: |
||
120 | void USBCheckHIDRequest(void) |
||
121 | |||
122 | Summary: |
||
123 | This routine handles HID specific request that happen on EP0. |
||
124 | This function should be called from the USBCBCheckOtherReq() call back |
||
125 | function whenever implementing a HID device. |
||
126 | |||
127 | Description: |
||
128 | This routine handles HID specific request that happen on EP0. These |
||
129 | include, but are not limited to, requests for the HID report |
||
130 | descriptors. This function should be called from the |
||
131 | USBCBCheckOtherReq() call back function whenever using an HID device. |
||
132 | |||
133 | Typical Usage: |
||
134 | <code> |
||
135 | void USBCBCheckOtherReq(void) |
||
136 | { |
||
137 | //Since the stack didn't handle the request I need to check |
||
138 | // my class drivers to see if it is for them |
||
139 | USBCheckHIDRequest(); |
||
140 | } |
||
141 | </code> |
||
142 | |||
143 | PreCondition: |
||
144 | None |
||
145 | |||
146 | Parameters: |
||
147 | None |
||
148 | |||
149 | Return Values: |
||
150 | None |
||
151 | |||
152 | Remarks: |
||
153 | None |
||
154 | |||
155 | *******************************************************************/ |
||
156 | void USBCheckHIDRequest(void) |
||
157 | { |
||
158 | if(SetupPkt.Recipient != USB_SETUP_RECIPIENT_INTERFACE_BITFIELD) return; |
||
159 | if(SetupPkt.bIntfID != HID_INTF_ID) return; |
||
160 | |||
161 | /* |
||
162 | * There are two standard requests that hid.c may support. |
||
163 | * 1. GET_DSC(DSC_HID,DSC_RPT,DSC_PHY); |
||
164 | * 2. SET_DSC(DSC_HID,DSC_RPT,DSC_PHY); |
||
165 | */ |
||
166 | if(SetupPkt.bRequest == USB_REQUEST_GET_DESCRIPTOR) |
||
167 | { |
||
168 | switch(SetupPkt.bDescriptorType) |
||
169 | { |
||
170 | case DSC_HID: //HID Descriptor |
||
171 | if(USBActiveConfiguration == 1) |
||
172 | { |
||
173 | USBEP0SendROMPtr( |
||
174 | (ROM BYTE*)&configDescriptor1 + 18, //18 is a magic number. It is the offset from start of the configuration descriptor to the start of the HID descriptor. |
||
175 | sizeof(USB_HID_DSC)+3, |
||
176 | USB_EP0_INCLUDE_ZERO); |
||
177 | } |
||
178 | break; |
||
179 | case DSC_RPT: //Report Descriptor |
||
180 | if(USBActiveConfiguration == 1) |
||
181 | { |
||
182 | USBEP0SendROMPtr( |
||
183 | (ROM BYTE*)&hid_rpt01, |
||
184 | sizeof(hid_rpt01), //See usbcfg.h |
||
185 | USB_EP0_INCLUDE_ZERO); |
||
186 | } |
||
187 | break; |
||
188 | case DSC_PHY: //Physical Descriptor |
||
189 | //Note: The below placeholder code is commented out. HID Physical Descriptors are optional and are not used |
||
190 | //in many types of HID applications. If an application does not have a physical descriptor, |
||
191 | //then the device should return STALL in response to this request (stack will do this automatically |
||
192 | //if no-one claims ownership of the control transfer). |
||
193 | //If an application does implement a physical descriptor, then make sure to declare |
||
194 | //hid_phy01 (rom structure containing the descriptor data), and hid_phy01 (the size of the descriptors in bytes), |
||
195 | //and then uncomment the below code. |
||
196 | //if(USBActiveConfiguration == 1) |
||
197 | //{ |
||
198 | // USBEP0SendROMPtr((ROM BYTE*)&hid_phy01, sizeof(hid_phy01), USB_EP0_INCLUDE_ZERO); |
||
199 | //} |
||
200 | break; |
||
201 | }//end switch(SetupPkt.bDescriptorType) |
||
202 | }//end if(SetupPkt.bRequest == GET_DSC) |
||
203 | |||
204 | if(SetupPkt.RequestType != USB_SETUP_TYPE_CLASS_BITFIELD) |
||
205 | { |
||
206 | return; |
||
207 | } |
||
208 | |||
209 | switch(SetupPkt.bRequest) |
||
210 | { |
||
211 | case GET_REPORT: |
||
212 | #if defined USER_GET_REPORT_HANDLER |
||
213 | USER_GET_REPORT_HANDLER(); |
||
214 | #endif |
||
215 | break; |
||
216 | case SET_REPORT: |
||
217 | #if defined USER_SET_REPORT_HANDLER |
||
218 | USER_SET_REPORT_HANDLER(); |
||
219 | #endif |
||
220 | break; |
||
221 | case GET_IDLE: |
||
222 | USBEP0SendRAMPtr( |
||
223 | (BYTE*)&idle_rate, |
||
224 | 1, |
||
225 | USB_EP0_INCLUDE_ZERO); |
||
226 | break; |
||
227 | case SET_IDLE: |
||
228 | USBEP0Transmit(USB_EP0_NO_DATA); |
||
229 | idle_rate = SetupPkt.W_Value.byte.HB; |
||
230 | break; |
||
231 | case GET_PROTOCOL: |
||
232 | USBEP0SendRAMPtr( |
||
233 | (BYTE*)&active_protocol, |
||
234 | 1, |
||
235 | USB_EP0_NO_OPTIONS); |
||
236 | break; |
||
237 | case SET_PROTOCOL: |
||
238 | USBEP0Transmit(USB_EP0_NO_DATA); |
||
239 | active_protocol = SetupPkt.W_Value.byte.LB; |
||
240 | break; |
||
241 | }//end switch(SetupPkt.bRequest) |
||
242 | |||
243 | }//end USBCheckHIDRequest |
||
244 | |||
245 | /** USER API *******************************************************/ |
||
246 | |||
247 | #endif |
||
248 | /** EOF usb_function_hid.c ******************************************************/ |
Powered by WebSVN v2.8.3