initial usb
[rapper.git] / new_cmsis / usb / usbuser.c
1 /*----------------------------------------------------------------------------\r
2  *      U S B  -  K e r n e l\r
3  *----------------------------------------------------------------------------\r
4  * Name:    usbuser.c\r
5  * Purpose: USB Custom User Module\r
6  * Version: V1.20\r
7  *----------------------------------------------------------------------------\r
8  *      This software is supplied "AS IS" without any warranties, express,\r
9  *      implied or statutory, including but not limited to the implied\r
10  *      warranties of fitness for purpose, satisfactory quality and\r
11  *      noninfringement. Keil extends you a royalty-free right to reproduce\r
12  *      and distribute executable files created using this software for use\r
13  *      on NXP Semiconductors LPC family microcontroller devices only. Nothing\r
14  *      else gives you the right to use this software.\r
15  *\r
16  * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.\r
17  *---------------------------------------------------------------------------*/\r
18 #include "lpc_types.h"\r
19 \r
20 #include "usb.h"\r
21 #include "usbcfg.h"\r
22 #include "usbhw.h"\r
23 #include "usbcore.h"\r
24 #include "usbuser.h"\r
25 #include "cdcuser.h"\r
26 \r
27 \r
28 /*\r
29  *  USB Power Event Callback\r
30  *   Called automatically on USB Power Event\r
31  *    Parameter:       power: On(TRUE)/Off(FALSE)\r
32  */\r
33 \r
34 #if USB_POWER_EVENT\r
35 void USB_Power_Event (uint32_t  power) {\r
36 }\r
37 #endif\r
38 \r
39 \r
40 /*\r
41  *  USB Reset Event Callback\r
42  *   Called automatically on USB Reset Event\r
43  */\r
44 \r
45 #if USB_RESET_EVENT\r
46 void USB_Reset_Event (void) {\r
47   USB_ResetCore();\r
48 }\r
49 #endif\r
50 \r
51 \r
52 /*\r
53  *  USB Suspend Event Callback\r
54  *   Called automatically on USB Suspend Event\r
55  */\r
56 \r
57 #if USB_SUSPEND_EVENT\r
58 void USB_Suspend_Event (void) {\r
59 }\r
60 #endif\r
61 \r
62 \r
63 /*\r
64  *  USB Resume Event Callback\r
65  *   Called automatically on USB Resume Event\r
66  */\r
67 \r
68 #if USB_RESUME_EVENT\r
69 void USB_Resume_Event (void) {\r
70 }\r
71 #endif\r
72 \r
73 \r
74 /*\r
75  *  USB Remote Wakeup Event Callback\r
76  *   Called automatically on USB Remote Wakeup Event\r
77  */\r
78 \r
79 #if USB_WAKEUP_EVENT\r
80 void USB_WakeUp_Event (void) {\r
81 }\r
82 #endif\r
83 \r
84 \r
85 /*\r
86  *  USB Start of Frame Event Callback\r
87  *   Called automatically on USB Start of Frame Event\r
88  */\r
89 \r
90 #if USB_SOF_EVENT\r
91 void USB_SOF_Event (void) {\r
92 }\r
93 #endif\r
94 \r
95 \r
96 /*\r
97  *  USB Error Event Callback\r
98  *   Called automatically on USB Error Event\r
99  *    Parameter:       error: Error Code\r
100  */\r
101 \r
102 #if USB_ERROR_EVENT\r
103 void USB_Error_Event (uint32_t error) {\r
104 }\r
105 #endif\r
106 \r
107 \r
108 /*\r
109  *  USB Set Configuration Event Callback\r
110  *   Called automatically on USB Set Configuration Request\r
111  */\r
112 \r
113 #if USB_CONFIGURE_EVENT\r
114 void USB_Configure_Event (void) {\r
115 \r
116   if (USB_Configuration) {                  /* Check if USB is configured */\r
117     /* add your code here */\r
118   }\r
119 }\r
120 #endif\r
121 \r
122 \r
123 /*\r
124  *  USB Set Interface Event Callback\r
125  *   Called automatically on USB Set Interface Request\r
126  */\r
127 \r
128 #if USB_INTERFACE_EVENT\r
129 void USB_Interface_Event (void) {\r
130 }\r
131 #endif\r
132 \r
133 \r
134 /*\r
135  *  USB Set/Clear Feature Event Callback\r
136  *   Called automatically on USB Set/Clear Feature Request\r
137  */\r
138 \r
139 #if USB_FEATURE_EVENT\r
140 void USB_Feature_Event (void) {\r
141 }\r
142 #endif\r
143 \r
144 \r
145 #define P_EP(n) ((USB_EP_EVENT & (1 << (n))) ? USB_EndPoint##n : NULL)\r
146 \r
147 /* USB Endpoint Events Callback Pointers */\r
148 void (* const USB_P_EP[16]) (uint32_t event) = {\r
149   P_EP(0),\r
150   P_EP(1),\r
151   P_EP(2),\r
152   P_EP(3),\r
153   P_EP(4),\r
154   P_EP(5),\r
155   P_EP(6),\r
156   P_EP(7),\r
157   P_EP(8),\r
158   P_EP(9),\r
159   P_EP(10),\r
160   P_EP(11),\r
161   P_EP(12),\r
162   P_EP(13),\r
163   P_EP(14),\r
164   P_EP(15),\r
165 };\r
166 \r
167 \r
168 /*\r
169  *  USB Endpoint 1 Event Callback\r
170  *   Called automatically on USB Endpoint 1 Event\r
171  *    Parameter:       event\r
172  */\r
173 \r
174 void USB_EndPoint1 (uint32_t event) {\r
175   uint16_t temp;\r
176   static uint16_t serialState;\r
177 \r
178   switch (event) {\r
179     case USB_EVT_IN:\r
180       temp = CDC_GetSerialState();\r
181       if (serialState != temp) {\r
182          serialState = temp;\r
183          CDC_NotificationIn();            /* send SERIAL_STATE notification */\r
184       }\r
185       break;\r
186   }\r
187 }\r
188 \r
189 \r
190 /*\r
191  *  USB Endpoint 2 Event Callback\r
192  *   Called automatically on USB Endpoint 2 Event\r
193  *    Parameter:       event\r
194  */\r
195 \r
196 void USB_EndPoint2 (uint32_t event) {\r
197 \r
198   switch (event) {\r
199     case USB_EVT_OUT:\r
200       CDC_BulkOut ();                /* data received from Host */\r
201       break;\r
202     case USB_EVT_IN:\r
203       CDC_BulkIn ();                 /* data expected from Host */\r
204       break;\r
205   }\r
206 }\r
207 \r
208 \r
209 /*\r
210  *  USB Endpoint 3 Event Callback\r
211  *   Called automatically on USB Endpoint 3 Event\r
212  *    Parameter:       event\r
213  */\r
214 \r
215 void USB_EndPoint3 (uint32_t event) {\r
216 }\r
217 \r
218 \r
219 /*\r
220  *  USB Endpoint 4 Event Callback\r
221  *   Called automatically on USB Endpoint 4 Event\r
222  *    Parameter:       event\r
223  */\r
224 \r
225 void USB_EndPoint4 (uint32_t event) {\r
226 }\r
227 \r
228 \r
229 /*\r
230  *  USB Endpoint 5 Event Callback\r
231  *   Called automatically on USB Endpoint 5 Event\r
232  *    Parameter:       event\r
233  */\r
234 \r
235 void USB_EndPoint5 (uint32_t event) {\r
236 }\r
237 \r
238 \r
239 /*\r
240  *  USB Endpoint 6 Event Callback\r
241  *   Called automatically on USB Endpoint 6 Event\r
242  *    Parameter:       event\r
243  */\r
244 \r
245 void USB_EndPoint6 (uint32_t event) {\r
246 }\r
247 \r
248 \r
249 /*\r
250  *  USB Endpoint 7 Event Callback\r
251  *   Called automatically on USB Endpoint 7 Event\r
252  *    Parameter:       event\r
253  */\r
254 \r
255 void USB_EndPoint7 (uint32_t event) {\r
256 }\r
257 \r
258 \r
259 /*\r
260  *  USB Endpoint 8 Event Callback\r
261  *   Called automatically on USB Endpoint 8 Event\r
262  *    Parameter:       event\r
263  */\r
264 \r
265 void USB_EndPoint8 (uint32_t event) {\r
266 }\r
267 \r
268 \r
269 /*\r
270  *  USB Endpoint 9 Event Callback\r
271  *   Called automatically on USB Endpoint 9 Event\r
272  *    Parameter:       event\r
273  */\r
274 \r
275 void USB_EndPoint9 (uint32_t event) {\r
276 }\r
277 \r
278 \r
279 /*\r
280  *  USB Endpoint 10 Event Callback\r
281  *   Called automatically on USB Endpoint 10 Event\r
282  *    Parameter:       event\r
283  */\r
284 \r
285 void USB_EndPoint10 (uint32_t event) {\r
286 }\r
287 \r
288 \r
289 /*\r
290  *  USB Endpoint 11 Event Callback\r
291  *   Called automatically on USB Endpoint 11 Event\r
292  *    Parameter:       event\r
293  */\r
294 \r
295 void USB_EndPoint11 (uint32_t event) {\r
296 }\r
297 \r
298 \r
299 /*\r
300  *  USB Endpoint 12 Event Callback\r
301  *   Called automatically on USB Endpoint 12 Event\r
302  *    Parameter:       event\r
303  */\r
304 \r
305 void USB_EndPoint12 (uint32_t event) {\r
306 }\r
307 \r
308 \r
309 /*\r
310  *  USB Endpoint 13 Event Callback\r
311  *   Called automatically on USB Endpoint 13 Event\r
312  *    Parameter:       event\r
313  */\r
314 \r
315 void USB_EndPoint13 (uint32_t event) {\r
316 }\r
317 \r
318 \r
319 /*\r
320  *  USB Endpoint 14 Event Callback\r
321  *   Called automatically on USB Endpoint 14 Event\r
322  *    Parameter:       event\r
323  */\r
324 \r
325 void USB_EndPoint14 (uint32_t event) {\r
326 }\r
327 \r
328 \r
329 /*\r
330  *  USB Endpoint 15 Event Callback\r
331  *   Called automatically on USB Endpoint 15 Event\r
332  *    Parameter:       event\r
333  */\r
334 \r
335 void USB_EndPoint15 (uint32_t event) {\r
336 }\r