?? usb_kbd_enum.lst
字號:
C51 COMPILER V7.06 USB_KBD_ENUM 01/29/2008 10:59:25 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE USB_KBD_ENUM
OBJECT MODULE PLACED IN usb_kbd_enum.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE modules\usb_kbd_enum\usb_kbd_enum.c LARGE OPTIMIZE(9,SPEED) INCDIR(.\;.\;.\
-) DEFINE(KEIL) DEBUG OBJECTEXTEND PRINT(.\usb_kbd_enum.lst) OBJECT(usb_kbd_enum.obj)
stmt level source
1 /*C**************************************************************************
2 * NAME: usb_kbd_enum.c
3 *----------------------------------------------------------------------------
4 * Copyright (c) 2003 Atmel.
5 *----------------------------------------------------------------------------
6 * RELEASE: c5131-usb-kbd-light-1_0_2
7 * REVISION: 1.2
8 *----------------------------------------------------------------------------
9 * PURPOSE:
10 * This file contains the USB Endpoint 0 management routines corresponding
11 * to a USB HID keyboard implementation.
12 *****************************************************************************/
13
14 /*_____ I N C L U D E S ____________________________________________________*/
15
16 #include "config.h"
17 #include "lib_mcu\usb\usb_drv.h"
18 #include "usb_kbd_enum.h"
19
20 /*_____ M A C R O S ________________________________________________________*/
21
22
23 /*_____ D E F I N I T I O N ________________________________________________*/
24
25 code struct usb_st_device_descriptor usb_device_descriptor =
26 {
27 sizeof(usb_device_descriptor), DEVICE, USB_SPECIFICATION, DEVICE_CLASS,
28 DEVICE_SUB_CLASS, DEVICE_PROTOCOL, EP_CONTROL_LENGTH, VENDOR_ID, PRODUCT_ID,
29 RELEASE_NUMBER, MAN_INDEX, PROD_INDEX, SN_INDEX, NB_CONFIGURATION
30 };
31
32 code struct usb_st_manufacturer usb_manufacturer =
33 { sizeof(usb_manufacturer), STRING, USB_MANUFACTURER_NAME };
34
35 code struct usb_st_product usb_product =
36 { sizeof(usb_product), STRING, USB_PRODUCT_NAME };
37
38 code struct usb_st_serial_number usb_serial_number =
39 { sizeof(usb_serial_number), STRING, USB_SERIAL_NUMBER };
40
41 code struct usb_st_language_descriptor usb_language =
42 { sizeof(usb_language), STRING, LANGUAGE_ID };
43
44 code struct
45 { struct usb_st_configuration_descriptor cfg;
46 struct usb_st_interface_descriptor ifc;
47 struct usb_st_hid_descriptor hid ;
48 struct usb_st_endpoint_descriptor ep1 ;
49 Uchar rep[SIZE_OF_REPORT] ;
50 }
51 usb_configuration =
52 {
53 { 9, CONFIGURATION, CONF_LENGTH, NB_INTERFACE, CONF_NB,
54 CONF_INDEX, CONF_ATTRIBUTES, MAX_POWER},
C51 COMPILER V7.06 USB_KBD_ENUM 01/29/2008 10:59:25 PAGE 2
55 { 9, INTERFACE, INTERFACE_NB, ALTERNATE, NB_ENDPOINT, INTERFACE_CLASS,
56 INTERFACE_SUB_CLASS, INTERFACE_PROTOCOL, INTERFACE_INDEX },
57 { 9, HID, 0x1101, 8, 1, REPORT, 0x3B00 },
58 { 7, ENDPOINT, ENDPOINT_NB_1, EP_ATTRIBUTES_1, EP_SIZE_1, EP_INTERVAL_1 },
59 { 0x05,0x01, /* Usage Page (Generic Desktop) */
60 0x09,0x06, /* Usage (Keyboard) */
61 0xA1,0x01, /* Collection (Application) */
62 0x05,0x07, /* Usage Page (Keyboard) */
63 0x19,224, /* Usage Minimum (224) */
64 0x29,231, /* Usage Maximum (231) */
65 0x15,0x00, /* Logical Minimum (0) */
66 0x25,0x01, /* Logical Maximum (1) */
67 0x75,0x01, /* Report Size (1) */
68 0x95,0x08, /* Report Count (8) */
69 0x81,0x02, /* Input (Data, Variable, Absolute) */
70 0x81,0x01, /* Input (Constant) */
71 0x19,0x00, /* Usage Minimum (0) */
72 0x29,101, /* Usage Maximum (101) */
73 0x15,0x00, /* Logical Minimum (0) */
74 0x25,101, /* Logical Maximum (101) */
75 0x75,0x08, /* Report Size (8) */
76 0x95,0x06, /* Report Count (6) */
77 0x81,0x00, /* Input (Data, Array) */
78 0x05,0x08, /* Usage Page (LED) */
79 0x19,0x01, /* Usage Minimum (1) */
80 0x29,0x05, /* Usage Maximum (5) */
81 0x15,0x00, /* Logical Minimum (0) */
82 0x25,0x01, /* Logical Maximum (1) */
83 0x75,0x01, /* Report Size (1) */
84 0x95,0x05, /* Report Count (5) */
85 0x91,0x02, /* Output (Data, Variable, Absolute) */
86 0x95,0x03, /* Report Count (3) */
87 0x91,0x01, /* Output (Constant) */
88 0xC0 /* End Collection */
89 }
90 };
91
92 static bit zlp;
93 static Uchar endpoint_status[2];
94 static Uchar hid_idle_duration;
95 static Uchar *pbuffer;
96 static Uchar bmRequestType;
97
98 Uchar usb_configuration_nb;
99 extern bit usb_connected;
100 /*_____ D E C L A R A T I O N ______________________________________________*/
101
102 static void usb_get_descriptor (void);
103 static void usb_read_request (void);
104 static void usb_set_address (void);
105 static void usb_set_configuration (void);
106 static void usb_clear_feature (void);
107 static void usb_set_feature (void);
108 static void usb_get_status (void);
109 static void usb_get_configuration (void);
110 static void usb_get_interface (void);
111 static void usb_hid_set_report (void);
112 static void usb_hid_set_idle (void);
113 static void usb_hid_get_idle (void);
114
115 /*F**************************************************************************
116 * NAME: usb_var_init
C51 COMPILER V7.06 USB_KBD_ENUM 01/29/2008 10:59:25 PAGE 3
117 *----------------------------------------------------------------------------
118 * PARAMS:
119 *
120 * return:
121 *----------------------------------------------------------------------------
122 * PURPOSE:
123 * This function initializes the USB controller and resets the endpoints FIFOs.
124 *----------------------------------------------------------------------------
125 * EXAMPLE:
126 *----------------------------------------------------------------------------
127 * NOTE:
128 *----------------------------------------------------------------------------
129 * REQUIREMENTS:
130 *****************************************************************************/
131 void usb_var_init (void)
132 {
133 1 endpoint_status[EP_CONTROL] = 0x00;
134 1 endpoint_status[EP_IN] = 0x00;
135 1 usb_connected = FALSE;
136 1 usb_configuration_nb = 0x00;
137 1 }
138
139
140 /*F**************************************************************************
141 * NAME: usb_ep_init
142 *----------------------------------------------------------------------------
143 * PARAMS:
144 *
145 * return:
146 *----------------------------------------------------------------------------
147 * PURPOSE:
148 * This function configures the endpoints.
149 *----------------------------------------------------------------------------
150 * EXAMPLE:
151 *----------------------------------------------------------------------------
152 * NOTE:
153 *----------------------------------------------------------------------------
154 * REQUIREMENTS:
155 *****************************************************************************/
156 void usb_ep_init (void)
157 {
158 1 usb_configure_endpoint(EP_IN , INTERRUPT_IN);
159 1 usb_reset_endpoint(EP_IN);
160 1 }
161
162
163
164 /*F**************************************************************************
165 * NAME: usb_enumeration_process
166 *----------------------------------------------------------------------------
167 * PARAMS:
168 *
169 * return:
170 *----------------------------------------------------------------------------
171 * PURPOSE:
172 * This function manages the enumeration process
173 *----------------------------------------------------------------------------
174 * EXAMPLE:
175 *----------------------------------------------------------------------------
176 * NOTE:
177 *----------------------------------------------------------------------------
178 * REQUIREMENTS:
C51 COMPILER V7.06 USB_KBD_ENUM 01/29/2008 10:59:25 PAGE 4
179 *****************************************************************************/
180 void usb_enumeration_process (void)
181 {
182 1 Usb_select_ep(EP_CONTROL);
183 1 usb_read_request();
184 1 }
185
186
187 /*F**************************************************************************
188 * NAME: usb_read_request
189 *----------------------------------------------------------------------------
190 * PARAMS:
191 *
192 * return:
193 *----------------------------------------------------------------------------
194 * PURPOSE:
195 * This function reads the SETUP request sent to the default control endpoint
196 * and the appropriate function. When exiting of the usb_read_request
197 * function, the device is ready to manage the next request.
198 *----------------------------------------------------------------------------
199 * EXAMPLE:
200 *----------------------------------------------------------------------------
201 * NOTE: list of supported requests:
202 * GET_DESCRIPTOR
203 * GET_CONFIGURATION
204 * SET_ADDRESS
205 * SET_CONFIGURATION or SET_REPORT
206 * CLEAR_FEATURE
207 * SET_FEATURE
208 * GET_STATUS
209 * GET_MAX_LUN
210 * MASS_STORAGE_RESET
211 *----------------------------------------------------------------------------
212 * REQUIREMENTS:
213 *****************************************************************************/
214 void usb_read_request (void)
215 {
216 1 bmRequestType = Usb_read_byte(); /* read bmRequestType */
217 1
218 1 switch (Usb_read_byte()) /* test the bRequest value */
219 1 {
220 2 case GET_DESCRIPTOR:
221 2 usb_get_descriptor();
222 2 break;
223 2 case GET_CONFIGURATION:
224 2 usb_get_configuration();
225 2 break;
226 2 case SET_ADDRESS:
227 2 usb_set_address();
228 2 break;
229 2 case SET_CONFIGURATION: /* or SET_REPORT */
230 2 if (bmRequestType == 0) { usb_set_configuration(); }
231 2 else { usb_hid_set_report(); }
232 2 break;
233 2 case CLEAR_FEATURE:
234 2 usb_clear_feature();
235 2 break;
236 2 case SET_FEATURE:
237 2 usb_set_feature();
238 2 break;
239 2 case GET_STATUS:
240 2 usb_get_status();
C51 COMPILER V7.06 USB_KBD_ENUM 01/29/2008 10:59:25 PAGE 5
241 2 break;
242 2 case GET_INTERFACE: /* HID_SET_IDLE */
243 2 if (bmRequestType == 0x81) { usb_get_interface(); }
244 2 else { usb_hid_set_idle(); }
245 2 break;
246 2 case HID_GET_IDLE:
247 2 usb_hid_get_idle();
248 2 break;
249 2 case SET_DESCRIPTOR:
250 2 case SET_INTERFACE:
251 2 case SYNCH_FRAME:
252 2 default:
253 2 Usb_clear_rx_setup();
254 2 Usb_set_stall_request();
255 2 while (!Usb_stall_sent());
256 2 Usb_clear_stall_request();
257 2 Usb_clear_stalled();
258 2 break;
259 2 }
260 1 Usb_clear_DIR();
261 1 }
262
263
264 /*F**************************************************************************
265 * NAME: usb_set_address
266 *----------------------------------------------------------------------------
267 * PARAMS:
268 *
269 * return:
270 *----------------------------------------------------------------------------
271 * PURPOSE:
272 * This function manages the SET_ADDRESS request. The new address is stored
273 * in the USBADDR register
274 *----------------------------------------------------------------------------
275 * EXAMPLE:
276 *----------------------------------------------------------------------------
277 * NOTE:
278 *----------------------------------------------------------------------------
279 * REQUIREMENTS:
280 *****************************************************************************/
281 void usb_set_address (void)
282 {
283 1 Uchar add;
284 1
285 1 add = Usb_read_byte(); /* store the LSB of wValue = address */
286 1 Usb_clear_rx_setup();
287 1 Usb_set_tx_ready(); /* send a ZLP for STATUS phase */
288 1 Usb_set_FADDEN();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -