summaryrefslogtreecommitdiff
path: root/usb/device/device.dir
blob: 2988e1e22254a4bf2b26a3af53b4bd52e6e981d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
/* ----------------------------------------------------------------------------
 *         ATMEL Microcontroller Software Support 
 * ----------------------------------------------------------------------------
 * Copyright (c) 2008, Atmel Corporation
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the disclaimer below.
 *
 * Atmel's name may not be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * ----------------------------------------------------------------------------
 */

//------------------------------------------------------------------------------
/// \dir
/// !!!Purpose
///
/// This directory provides definitions, structs and functions for USB %device
/// applications with Atmel AT91 microcontrollers and USB %device framework.
///
/// You can develop your own USB %device products based on the class-specific
/// driver code provided, or just take them as a refference.
///
/// !!!Contents
/// There are two groups for the implement:
///    -# The hardware interface driver for USB peripheral on AT91
///       microcontrollers (UDP or UDPHS), this is a part of the "AT91 USB
///       framework".
///       - "core": hardware interface driver for AT91 USB peripheral
///    -# The %device class driver to class-specific %device.
///       - "audio-speaker"
///       - "ccid"
///       - "cdc-serial"
///       - "hid-keyboard"
///       - "massstorage"
///
/// For more information about what a particular group contains, please refer to
/// its documentation page.
///
/// \note
/// Depending on the project, not all the subdirectories will be available
///  (i.e. the #ccid# directory will not be in projects without USB CCID
///  function).
//------------------------------------------------------------------------------

/**
 \page "USBD API"

 See "USBD API Structures" and "USBD API Methods".\n

 !!!USBD API Structures

 Several specific structures are used by the USBD API to perform various
 operations, such as invoking callbacks or accessing the USBD controller.
 
 There are two %main structures:
 - USBDDriver:
 It is the %main structure of the USB API. It should be instanciated
 in class-specific USB %device driver or user application.
 - USBDDriverDescriptors:
 It is a list of all descriptors used by a USB %device driver. It
 should be instanciated in class-specific USB %device driver or
 user application and passed to USBD by USBDDriver_Initialize.

 !!!USBD API Methods
 
 The USB API provides serveral methods to perform the following operations:
 - Changing the %device state
    - USBD_Init
    - USBD_Connect, USBD_Disconnect
    - USBD_SetAddress
    - USBD_SetConfiguration
    - USBD_GetState
    - "USB Device State Diagram"
 - Handling events coming from the USB controller
    - USBD_IrqHandler
 - Modifying the behavior of an endpoint
    - USBD_ConfigureEndpoint
    - USBD_Stall
    - USBD_Halt
    - USBD_Unhalt
    - USBD_IsHalted
 - Transferring data
    - USBD_Write
    - USBD_Read
    - USBD_IsoWrite
 - Special functions
    - USBD_RemoteWakeUp

 See "USBD API Methods" for detailed informations.

*/

/**
 \page "USBD API Structures"

 !!!USBD API Structures

 Several specific structures are used by the USBD API to perform various
 operations, such as invoking callbacks or accessing the USBD controller.
 
 There are two %main structures:
 - USBDDriver:
 It is the %main structure of the USB API. It should be instanciated
 in class-specific USB %device driver or user application.
 - USBDDriverDescriptors:
 It is a list of all descriptors used by a USB %device driver. It
 should be instanciated in class-specific USB %device driver or
 user application and passed to USBD by USBDDriver_Initialize.

 */

/**
 \page "USBD API Methods"

 !!!USB API methods
 
 The USB API provides serveral methods to perform the following operations:
 - Changing the %device state
    - USBD_Init
    - USBD_Connect, USBD_Disconnect
    - USBD_SetAddress
    - USBD_SetConfiguration
    - USBD_GetState
    - "USB Device State Diagram"
 - Handling events coming from the USB controller
    - USBD_IrqHandler
 - Modifying the behavior of an endpoint
    - USBD_ConfigureEndpoint
    - USBD_Stall
    - USBD_Halt
    - USBD_Unhalt
    - USBD_IsHalted
 - Transferring data
    - USBD_Write
    - USBD_Read
    - USBD_IsoWrite
 - Special functions
    - USBD_RemoteWakeUp

 !!!Controlling the Device State

 Chapter 9 of the USB specification 2.0 describes the various states a %device
 can be in. Most of the methods of this API are used to change between those
 states.

 !!USBD_Init

 USBD_Init is the first method to call in a user application. Technically, it
 must occur just before entering the Attached state. It performs the following
 actions:
    - USB Device driver and endpoint state initialization
    - D+ pull-up configuration and disabling
    - UDP hardware initialization (Peripheral and clock init)

 A USB %device uses a pull-up on the D+ line to signal its connection to the
 host. Depending on the USB controller present on the chip, either an
 internal or external pull-up is used. In both cases, its configuration is
 performed directly by this method. Please refer to the documentation of a
 particular controller for more information about the D+ pull-up.

 The ini callback has to perform several mandatory operations at this point.
 You can find the default operations in USBDCallbacks_Initialized.

 !!USBD_Connect, USBD_Disconnect

 These two methods control the state of the D+ upll-up. This makes it possible
 to connect of disconnect the %device by software when needed. USBD_Connect
 changes the %device state from Powered to Default, while USBD_Disconnect
 changes from either Default, Address or Configured to Powered.

 !!USBD_SetAddress

 USBD_SetAddress extracts the information from the last received
 SETUP packet to either change the %device state from Default to
 Address or from Address to Default. The difference is made
 depending on the value of the wValue field of the request.
 
 This method must only be called right after the SET_ADDRESS
 request is received.
 
 !!USBD_SetConfiguration

 This function operates in a way similar to USBD_SetAddress. When the SETUP
 packet containing a SET_CONFIGURATION request is received,
 USBD_SetConfiguration should be called to extract the new configuration
 value to adopt. If the wValue field of the request is non-zero, then the
 %device must adopt the new configuration and enter the Configuration state;
 otherwise, it returns (or stays) in the Address state.

 !!USBD_GetState

 As its name implies, USBD_GetState simply returns the current state of the USB
 driver. See state definitions on "USB %device states".
 - USBD_STATE_SUSPENDED
 - USBD_STATE_ATTACHED
 - USBD_STATE_POWERED
 - USBD_STATE_DEFAULT
 - USBD_STATE_ADDRESS
 - USBD_STATE_CONFIGURED

 !!Device State Diagram
 See "USB Device State Diagram"

 !!!Event Handling (USBD_IrqHandler)
 Several events can occur at the USB controller level:
 - End of bus reset
 - Reception of a SETUP packet
 - Change of bus activity (active -> idle -> active ..)
 - Completin of an endpoint operation
 - ...

 Whenever such an event occurs, it must be forwarded to the USBD API to be
 handled in an appropriate way. The USBD_IrqHandler performs this
 functionality, so the controller interrupt must be configured to call it.

 Several #callbacks# can be triggered depending on the event notified by
 the controller:
 - Suspend, when the bus is idle
 - Resume, when the bus becomes active again
 - NewRequest, when a setup packet is received on a control endpoint
 - StartOfFrame, every 1 ms (for full-speed controllers) or 125us (for high-
   speed controllers)

 More information about these callbacks and their expected behavior can be
 found in "USBD Callback API".

 !!!Endpoint Behavior Modification

 The USBD API offers following functions to control how an endpoint operates.
 - USBD_ConfigureEndpoint
 - USBD_Stall
 - USBD_Halt
 - USBD_Unhalt
 - USBD_IsHalted

 !!USBD_ConfigureEndpoint
 USBD_ConfigureEndpoint is used to configure an endpoint at the USB controller
 level. An appropriate endpoint descriptor must be provided to do that. The
 descriptor is used to configure the endpoint type (either Control, Bulk,
 Interrupt or Isochronous), direction (IN or OUT) and address.

 Control endpoint 0 is automatically configured by the USBD API when the End of
 bus reset event is signalled by the USB controller. Therefore, there is no need
 to do it manually.

 !!USBD_Stall
 The USBD_Stall method causes and endpoint to acknowledge its next received
 packet with a STALL handshake. Further packets are then handled normally.

 Most of the time, this method should be used with endpoint 0 to signal the
 host that the %device cannot process a command.

 !!USBD_Halt, USBD_Unhalt, USBD_IsHalted
 USBD_Halt sets the Halt status of an endpoint. When in Halt mode, every
 received packet is acknowledged with a STALL handshake instead of being
 handled normally.

 #}USB_Halt#} can be called either with the USB_SET_FEATURE, USB_CLEAR_FEATURE
 or USB_GET_STATUS parameter to modify the endpoint Halt state.

 USBD_Unhalt clears the Halt status of an endpoint.

 USBD_IsHalted gets the Halt status of an endpoint.

 !!!Data Transfer
 Data transfer (IN or OUT) on an endpoint can be performed by calling two
 methods, USBD_Write and USBD_Read.

 !!USBD_Write
 The USBD_Write function sends a data payload on a specific endpoint. If the
 data payload equals or exceeds the maximum packet size of the endpoint, then
 several IN transactions are necessary. This method should only be called on an
 IN or Control endpoint.

 The write is performed #asynchronously#, i.e., the function returns immediately
 without waiting for the transfer to finish. When the transfer is complete, an
 optional user-provided callback function is called. This makes it possible to
 create an #OS-friendly synchronous function# by locking and unlocking a
 semaphore before and after each write.

 This function handles double-buffering, if it is supported by the USB
 controller and if it has been enabled for the endpoint. Do not forget that
 using double-buffering is mandatory for isochronous transactions.

 - #Note#
       The double-buffering this function supported is only in period of each
       write action. That is, when the function is invoked to start transfer
       trunk of data, the data is automatically splitted to several IN
       transactions and ping-pong is started on the 2nd transaction. But when
       all the data of the trunk is finished the ping-pong is stopped. So it can
       not process the list of buffer that should use double-buffering all the
       time. See USBD_IsoWrite for such kind of operations.

 !!USBD_Read
 The USBD_Read reads incoming data on an endpoint. The transfer stops either
 when the provided buffer is full, or a short packet (size inferior to the
 endpoint maximum packet size) is received. This method must only be called on
 an OUT or Control endpoint.

 The read is performed #asynchronously#, i.e., the function returns immediately
 without waiting for the transfer to finish. When the transfer is complete, an
 optional user-provided callback function is called. This makes it possible to
 create an #OS-friendly synchronous function# by locking and unlocking a
 semaphore before and after each read.

 This function handles #double-buffering#, if it is supported by the USB
 controller and if it has been enabled for the endpoint. Do not forget that
 using double-buffering is mandatory for isochronous transactions.

 !!USBD_IsoWrite
 The USBD_IsoWrite function sends a buffer list on a specific endpoint. The each
 buffer's payload should be equals or less than the maximum packet size of the
 endpoint. The transfer ends when all buffera are sent out. And the buffer is
 previously sent can be filled with new data before the transfer ends. To
 maitain a ring buffer for the outgoing stream. This method should only be
 called on an ISO IN endpoint.

 The write is performed #asynchronously#, i.e., the function returns immediately
 without waiting for the transfer to finish. When the transfer is complete, an
 optional user-provided callback function is called. This makes it possible to
 create an #OS-friendly synchronous function# by locking and unlocking a
 semaphore before and after each write.

 This function handles double-buffering, if it is supported by the USB
 controller and if it has been enabled for the endpoint. Do not forget that
 using double-buffering is mandatory for isochronous transactions.

 !!!Special Functions

 - USBD_RemoteWakeUp: This method starts a remote wakeup procedure. This makes
 it possible for a suspended %device to wake a host with may itself be
 suspended.

*/

/**
 \page "USB Device State Diagram"

 \image USBDeviceStateDiagram.png "Changing the Device State"

*/

/* (Image Link Backup)
<img src="USBDeviceStateDiagram.png" border=0 alt="USBDeviceStateDiagram.png" usemap="#USBD_ST_DIA">
<MAP NAME="USBD_ST_DIA">
<AREA shape="poly" coords="172,0,330,0,330,26,172,26,172,0" onmouseover="link('_member','core/USBD_Init53616',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBD_Init&nbsp;&nbsp;(void )',CAPTION,'<strong>Brief description</strong><BR>Initializes the specified USB driver            This<BR>function initializes the current FIFO bank of<BR>endpoints,            configures the pull-up and VBus<BR>lines, disconnects the pull-up and            then<BR>trigger the Init callback.');" onmouseout="return nd();">
<AREA shape="poly" coords="269,390,425,390,425,416,269,416,269,390" onmouseover="link('_member','core/USBD_SetAddress2593655934',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBD_SetAddress&nbsp;&nbsp;(unsigned char address)',CAPTION,'<strong>Brief description</strong><BR>Sets the device address.');" onmouseout="return nd();">
<AREA shape="poly" coords="76,390,233,390,233,416,76,416,76,390" onmouseover="link('_member','core/USBD_SetAddress2593655934',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBD_SetAddress&nbsp;&nbsp;(0)',CAPTION,'<strong>Brief description</strong><BR>Unsets the device address.');" onmouseout="return nd();">
<AREA shape="poly" coords="76,509,233,509,233,535,76,535,76,509" onmouseover="link('_member','core/USBD_SetConfiguration2593655934',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBD_SetConfiguration&nbsp;&nbsp;(0)',CAPTION,'<strong>Brief description</strong><BR>Changes the device state from Configured to Address.');" onmouseout="return nd();">
<AREA shape="poly" coords="261,509,418,509,418,535,261,535,261,509" onmouseover="link('_member','core/USBD_SetConfiguration2593655934',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBD_SetConfiguration&nbsp;&nbsp;(unsigned char cfgnum)',CAPTION,'<strong>Brief description</strong><BR>Changes the device state from Address to Configured.');" onmouseout="return nd();">
<AREA shape="poly" coords="284,242,440,242,440,269,284,269,284,242" onmouseover="link('_member','core/USBD_Connect53616',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBD_Connect&nbsp;&nbsp;(void )',CAPTION,'<strong>Brief description</strong><BR>Enables the pull-up on the D+ line to connect the device to the USB.');" onmouseout="return nd();">
<AREA shape="poly" coords="60,242,217,242,217,269,60,269,60,242" onmouseover="link('_member','core/USBD_Disconnect53616',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBD_Disconnect&nbsp;&nbsp;(void )',CAPTION,'<strong>Brief description</strong><BR>Disables the pull-up on the D+ line to disconnect the<BR>device from the bus.');" onmouseout="return nd();">
</MAP>

<MAP NAME="usbd_cb_invo_fc">
<AREA shape="poly" coords="436,739,600,739,600,765,436,765,436,739" onmouseover="link('_member','core/USBDCallbacks_Resumed53616',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBDCallbacks_Resumed&nbsp;&nbsp;(void )',CAPTION,'<strong>Brief description</strong><BR>Invoked when the USB device leaves the Suspended state.');" onmouseout="return nd();">
<AREA shape="poly" coords="436,406,600,406,600,432,436,432,436,406" onmouseover="link('_member','core/USBDCallbacks_Resumed53616',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBDCallbacks_Resumed&nbsp;&nbsp;(void )',CAPTION,'<strong>Brief description</strong><BR>Invoked when the USB device leaves the Suspended state.');" onmouseout="return nd();">
<AREA shape="poly" coords="436,605,600,605,600,632,436,632,436,605" onmouseover="link('_member','core/USBDCallbacks_Suspended53616',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBDCallbacks_Suspended&nbsp;&nbsp;(void )',CAPTION,'<strong>Brief description</strong><BR>Invoked when the USB device gets suspended. By default,<BR>turns off all LEDs.');" onmouseout="return nd();">
<AREA shape="poly" coords="436,339,600,339,600,365,436,365,436,339" onmouseover="link('_member','coreUSBDCallbacks_Suspended53616',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBDCallbacks_Suspended&nbsp;&nbsp;(void )',CAPTION,'<strong>Brief description</strong><BR>Invoked when the USB device gets suspended. By default,<BR>turns off all LEDs.');" onmouseout="return nd();">
<AREA shape="poly" coords="436,272,600,272,600,299,436,299,436,272" onmouseover="link('_member','core/USBDCallbacks_RequestReceived2520836348',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBDCallbacks_RequestReceived&nbsp;&nbsp;(const USBGenericRequest * request)',CAPTION,'<strong>Brief description</strong><BR>Triggered when the USB host emits a new SETUP request.');" onmouseout="return nd();">
<AREA shape="poly" coords="436,206,600,206,600,232,436,232,436,206" onmouseover="link('_member','core/USBDCallbacks_Reset53616',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBDCallbacks_Reset&nbsp;&nbsp;( void )',CAPTION,'<strong>Brief description</strong><BR>Triggered when the USB host emits a RESET.')">
<AREA shape="poly" coords="436,102,600,102,600,129,436,129,436,102" onmouseover="link('_member','core/USBDCallbacks_Initialized53616',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBDCallbacks_Initialized&nbsp;&nbsp;(void )',CAPTION,'<strong>Brief description</strong><BR>Invoked after the USB driver has been initialized.');" onmouseout="return nd();">
<AREA shape="poly" coords="221,374,384,374,384,400,221,400,221,374" onmouseover="link('_member','core/USBD_IrqHandler53616',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBD_IrqHandler&nbsp;&nbsp;(void )',CAPTION,'<strong>Brief description</strong><BR>UDP interrupt handler. Manages device status changes.');" onmouseout="return nd();">
<AREA shape="poly" coords="221,307,384,307,384,333,221,333,221,307" onmouseover="link('_member','core/USBD_IrqHandler53616',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBD_IrqHandler&nbsp;&nbsp;(void )',CAPTION,'<strong>Brief description</strong><BR>UDP interrupt handler. Manages device status changes.');" onmouseout="return nd();">
<AREA shape="poly" coords="221,240,384,240,384,266,221,266,221,240" onmouseover="link('_member','core/USBD_IrqHandler53616',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBD_IrqHandler&nbsp;&nbsp;(void )',CAPTION,'<strong>Brief description</strong><BR>UDP interrupt handler. Manages device status changes.');" onmouseout="return nd();">
<AREA shape="poly" coords="221,173,384,173,384,199,221,199,221,173" onmouseover="link('_member','core/USBD_IrqHandler53616',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBD_IrqHandler&nbsp;&nbsp;(void )',CAPTION,'<strong>Brief description</strong><BR>UDP interrupt handler. Manages device status changes.');" onmouseout="return nd();">
<AREA shape="poly" coords="221,36,384,36,384,62,221,62,221,36" onmouseover="link('_member','core/USBD_Init53616',this);overLibDiagram();return overlib('<strong>Syntax</strong><BR>void&nbsp;&nbsp;USBD_Init&nbsp;&nbsp;(void )',CAPTION,'<strong>Brief description</strong><BR>Initializes the USB driver.');" onmouseout="return nd();">
<AREA shape="poly" coords="0,407,163,407,163,434,0,434,0,407" onmouseover="overLibDiagram();return overlib('UDP_ISR: AT91C_UDP_SOFINT')" onmouseout="return nd();">
<AREA shape="poly" coords="0,340,163,340,163,367,0,367,0,340" onmouseover="overLibDiagram();return overlib('UDP_ISR: AT91C_UDP_WAKEUP | AT91C_UDP_RXRSM')" onmouseout="return nd();">
<AREA shape="poly" coords="0,273,163,273,163,300,0,300,0,273" onmouseover="overLibDiagram();return overlib('UDP_ISR: AT91C_UDP_RXSUSP')" onmouseout="return nd();">
<AREA shape="poly" coords="0,139,163,139,163,165,0,165,0,139" onmouseover="overLibDiagram();return overlib('UDP_ISR: AT91C_UDP_ENDBUSRES')" onmouseout="return nd();">
<AREA shape="poly" coords="0,206,163,206,163,232,0,232,0,206" onmouseover="overLibDiagram();return overlib('UDP_CSR: AT91C_UDP_RXSETUP')" onmouseout="return nd();">
<AREA shape="poly" coords="436,672,600,672,600,698,436,698,436,672" title="ISR_Vbus">
<AREA shape="poly" coords="436,539,600,539,600,565,436,565,436,539" title="ISR_Vbus">
<AREA shape="poly" coords="482,0,554,0,554,13,482,13,482,0" title="Applications">
<AREA shape="poly" coords="278,0,331,0,331,13,278,13,278,0" title="USBD API">
<AREA shape="poly" coords="36,0,128,0,128,13,36,13,36,0" title="UDP_, UDPHS_">
</MAP>
<IMG SRC="USBDCallbackInvocationFlowchart.png" border=0 ALT="USBDCallbackInvocationFlowchart.png" usemap="#usbd_cb_invo_fc">
*/

/**
 \page "USBD Callback API"

 !!!Callback API

 The callback API is a means of communication between the user application and
 the USBD API. When particular operations must be performed, the USB driver
 calls serveral external functions, refferred to as #callbacks#. They can also
 be invoked to notify the user application of pending events.

 Defining all callbacks is not mandatory. For example, if the %device shall not
 enter low-power mode, then it is appropriate not to provide a Suspend callback.
 If a callback is mandatory, this is notified in its description.

 See USBDCallbacks.h for callback definitions.

 !!!Callback Invocation
 The following events can trigger a callback:
 - USB initialization: USBDCallbacks_Initialized
 - End of bus reset: USBDCallbacks_Reset
 - Device suspend: USBDCallbacks_Suspended
 - Device resume: USBDCallbacks_Resumed
 - SETUP request received: USBDCallbacks_RequestReceived
 - Start of a new USB frame

 \image USBDCallbackInvocationFlowchart.png "Callback Invocation Flowchart"

 !!Init
 The USBDCallbacks_Initialized callback is invoked when the USBD_Init method is
 called. It has to perform several mandatory steps to make it possible to use
 the API:
 - If an OS is used, perform any specific operation to install the driver
 - Configure USB controller interrupt
 - Configure Vbus monitoring PIO and interrupt ( but it's in app layer now )
 The USB controller interrupt must be configured to #call the
 USBD_IrqHandler# API function when triggered. This is necessary to have
 events happening at the USB controller level handled appropriately by the API.

 If a PIO pin is connected to VBus, it is possible to monitor it by configuring
 the pin as an input and enabling the PIO interrupt. The interrupt service
 routine should simply check the Vbus status and then %call the USBD_Connect
 and USBD_Disconnect$ function to put %device into right state.

 Finally, if an OS is being used, then the driver should probably be installed
 prior to use. Interrupt configuration may also be done differently. Please
 refer to the documentation of the OS for more information.

 This callback is #mandatory#.

 !!Reset
 When an End of bus reset has been detected, the USBDCallbacks_Reset callback
 is triggered. The callback should perform #initialization# or #re-
 initialization# of the user-level application. For example, a class driver
 like MSD should re-initialize its internal state when a USB reset is performed.

 !!Suspend
 When the USB %device enters the Suspended state, the USB API notifies this state
 change by invoking the USBDCallbacks_Suspended callback. This can happen either
 when the bus is idle or when the %device is disconnected from the USB.

 If the %device should enter low-power mode when suspended, then this callback
 must perform the required operations to do so, e.g., switching to a slow clock,
 disabling PLLs, etc.

 - }Note: The electrical specification of the USB 2.0 defines a maximum current
    consumption of 500uA for suspended %device. This includes the current passing
    through pull-ups and upll-downs.}

 !!Resume
 The USBDCallbacks_Resumed callback is invoked when the USB %device leaves the
 Suspended state and returns to its previous state (either Powered, Default,
 Address or Configured). This may happen when activity is detected on the USB,
 or when the %device gets connected.

 If the %device was in low-power mode because of the Suspend callback, then this
 callback must perform the necessary poerations to return the %device into a
 normal operation mode, e.g., switching to a fast clock.

 !!NewRequest
 When a SETUP request is received on a control endpoint, the USBD API layer
 triggers the USBDCallbacks_RequestReceived callback to notify the user
 application. The received request can then be accessed through the
 corresponding USBGenericRequest structure.

 SETUP packets are used for class-specific requests (e.g. }GetMaxLUN} in MSD)
 as well as standard USB requests (e.g. }SetConfiguration}). The former are
 described in }USB Device Class Documents}, such as the }Mass Storage Bulk
 Only 1.0}, the latter are defined in the USB Specification 2.0.

 - }Note: that SETUP requests which are not understood by the %device should
   be acknowledged with a STALL handshake. This notifies the host that the
   %device cannot process the command.}

 This callback is #mandatory#.

 !!StartOfFrame
 Every 1ms (for a full-speed %device) or 125us (for a high-speed %device) a
 new USB frame starts. A callback can be invoked whenever this occurs.

 Because the start-of-frame interrupt %puts some stress on the processor
 (since it is called a lot), it is only activated the corresponding
 callback is defined (#now it's NOT defined in current framework#).

*/

/**
 \page "USBD Standard Request Handler"

 !!!Standard Request Handler

 Chapter 9 of the USB specification 2.0 defines a set of standard requests
 which have to be implemented by all devices. Since most class drivers treat
 those requests in the standard way, the USB framework provides a way to easily
 do that.

 !!!USBDDriver_RequestHandler

 USBDDriver_RequestHandler handles the standard requests in an appropriate way.
 It can answer the following commands:

 - GET_DESCRIPTOR
 - SET_ADDRESS
 - SET_CONFIGURATION
 - GET_CONFIGURATION
 - CLEAR_FEATURE
 - SET_FEATURE
 - GET_STATUS

 Simply using this standard request handler enables a %device to be enumerated
 correctly.

 !!Get Descriptor
 The GET_DESCRIPTOR request is used by the host to retrieve information about
 the %device by means of several descriptors.

 The standard request handler simply sends the corresponding descriptor to the
 host. How these descriptors are provided to the function is discussed in
 Structures.

 !!Set Address
 Whenever the host wants to change the %device state from Default to Address, or
 vice-versa, it sends a SET_ADDRESS request. The wValue field contains the new
 address of the %device; if it is null, then the %device returns to the Default
 state.

 The USBD_SetAddress function is called to perform this operation. Note that a
 zero-length packet must be sent prior to doing that, to acknowledge the SETUP
 transfer.

 !!Set Configuration & GetConfiguration
 The SET_CONFIGURATION request makes it possible for the host to select between
 one or more configurations for the %device. GET_CONFIGURATION is used to
 retrieve the currently selected one.

 Those two requests are handled in a very basic way by
 USBDDriver_RequestHandler: it assumes that the %device has only one
 configuration. Therefore, the SET_CONFIGURATION request is simply acknowledged
 with a zero-length packet, and GET_CONFIGURATION is answered with either 0
 or 1. If the user application needs more than one configuration, it will be
 the duty of the class driver handler to service those requests.

 In addition, when the SET_CONFIGURATION request causes the %device to enter the
 Configured state, the standard request handler calls the USBD_ConfigureEndpoint
 method for each endpoint used by the %device;

 !!Clear Feature, Set Feature & Get Status
 Several features of a %device can either be activated or deactivated by the USB
 host:
 - Remote wakeup
 - Endpoint Halt state
 Three requests can be used to either set, clear or get the status of these two
 features: SET_FEATURE, CLEAR_FEATURE and GET_STATUS.
 
 The USBDDriver_RequestHandler method answers a Halt state operation by calling
 the USBD_Halt method on the endpoint with the request.

 !!!Structures
 Several pieces of information must be known to the USBDDriver_RequestHandler
 to be able to process some SETUP commands. For example, all the descriptors
 (configuration, etc.) used by the %device are needed since they must be sent
 to the host when a GET_DESCRIPTOR is received.

 The USBGenericRequest structure is a "standard USB class driver" object used
 to hold the required information. It must be passed as an argument to the
 USBDDriver_RequestHandler method. Another structure, USBDDriverDescriptors, is
 used to store the descriptors list.

 !!!Usage
 The NewRequest callback is used to notify the user application that a new SETUP
 request has been received. SETUP request can either be class-specific or
 standard.

 The correct way to handle incoming requests is to first process class-specific
 requests using a class handler. For example, a Mass Storage implementation will
 define the NewRequest callback to call MSDDriver_RequestHandler. This function
 will handle the necessary requests, and forward the rest to
 USBDDriver_RequestHandler.

 If a request cannot be processed, USBDDriver_RequestHandler will STALL control
 endpoint 0.

*/

/**
 \page "VID, PID, SN & Strings"

 This page collects the definition for USB %device to indicate the Vendor and
 Product information.


 If you need only the functions in demo %driver, you can easily modify these
 definitions to change your device's Identification and Display strings.

 They are defined in the driver c code file that suffixed with
 "DriverDescriptors" under the driver directory.

 !!!VID, PID & SN in Device Descriptor

 Defined as const and used in USBDeviceDescriptor instance initialization.
 Gives identivication to the USB %device by VID and PID. The INF installation
 file should mach the VID & PID so that the %device can be installed.

\code
const USBDeviceDescriptor deviceDescriptor = {...};
\endcode

 - "audio-speaker": "Audio Speaker Device Codes"
 - ccid: "CCID Device IDs"
 - "cdc-serial": "CDC Serial Device IDs"
 - "hid-keyboard": "HID Device Descriptor IDs"
 - massstorage: "MSD Device Descriptor IDs"

 !!!Strings

 The strings gives additional information on the USB %device, normally string
 description about the vendor, product and serial number.

 The strings are defined as a list to initialize the driver's
 USBDDriverDescriptors instance:

 - "audio-speaker": auddSpeakerDriverDescriptors
 - ccid: ccidDriverDescriptors
 - "cdc-serial": cdcdSerialDriverDescriptors
 - "hid-keyboard": hiddKeyboardDriverDescriptors
 - massstorage: msdDriverDescriptors

\code
// String descriptors
const unsigned char *stringDescriptors[] = {

    languageIdDescriptor,
    manufacturerDescriptor,
    productDescriptor,
    serialNumberDescriptor,
};
\endcode
*/
personal git repositories of Harald Welte. Your mileage may vary