]> git.zerfleddert.de Git - proxmark3-svn/blob - common/usb_cdc.c
ADD: printConfiguration method for a nice printout of the selected configuration.
[proxmark3-svn] / common / usb_cdc.c
1 /*
2 * at91sam7s USB CDC device implementation
3 *
4 * Copyright (c) 2012, Roel Verdult
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the copyright holders nor the
15 * names of its contributors may be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * based on the "Basic USB Example" from ATMEL (doc6123.pdf)
30 *
31 * @file usb_cdc.c
32 * @brief
33 */
34
35 #include "usb_cdc.h"
36 #include "config_gpio.h"
37
38 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
39 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
40 #define AT91C_EP_IN_SIZE 0x40
41 #define AT91C_EP_OUT 1
42 #define AT91C_EP_OUT_SIZE 0x40
43 #define AT91C_EP_IN 2
44
45 const char devDescriptor[] = {
46 /* Device descriptor */
47 0x12, // bLength
48 0x01, // bDescriptorType
49 0x10,0x01, // Complies with USB Spec. Release (0110h = release 1.10)
50 0x02, // bDeviceClass: CDC class code
51 0x00, // bDeviceSubclass: CDC class sub code
52 0x00, // bDeviceProtocol: CDC Device protocol
53 0x08, // bMaxPacketSize0
54 0x2d,0x2d, // Vendor ID (--)
55 0x4d,0x50, // Product ID (PM), transmitted in reverse
56 0x01,0x00, // Device release number (0001)
57 0x01, // iManufacturer // 0x01
58 0x00, // iProduct
59 0x00, // SerialNumber
60 0x01 // bNumConfigs
61 };
62
63 const char cfgDescriptor[] = {
64 /* ============== CONFIGURATION 1 =========== */
65 /* Configuration 1 descriptor */
66 0x09, // CbLength
67 0x02, // CbDescriptorType
68 0x43, // CwTotalLength 2 EP + Control
69 0x00,
70 0x02, // CbNumInterfaces
71 0x01, // CbConfigurationValue
72 0x00, // CiConfiguration
73 0xC0, // CbmAttributes 0xA0
74 0x00, // CMaxPower
75
76 /* Communication Class Interface Descriptor Requirement */
77 0x09, // bLength
78 0x04, // bDescriptorType
79 0x00, // bInterfaceNumber
80 0x00, // bAlternateSetting
81 0x01, // bNumEndpoints
82 0x02, // bInterfaceClass
83 0x02, // bInterfaceSubclass
84 0x00, // bInterfaceProtocol
85 0x00, // iInterface
86
87 /* Header Functional Descriptor */
88 0x05, // bFunction Length
89 0x24, // bDescriptor type: CS_INTERFACE
90 0x00, // bDescriptor subtype: Header Func Desc
91 0x10, // bcdCDC:1.1
92 0x01,
93
94 /* ACM Functional Descriptor */
95 0x04, // bFunctionLength
96 0x24, // bDescriptor Type: CS_INTERFACE
97 0x02, // bDescriptor Subtype: ACM Func Desc
98 0x00, // bmCapabilities
99
100 /* Union Functional Descriptor */
101 0x05, // bFunctionLength
102 0x24, // bDescriptorType: CS_INTERFACE
103 0x06, // bDescriptor Subtype: Union Func Desc
104 0x00, // bMasterInterface: Communication Class Interface
105 0x01, // bSlaveInterface0: Data Class Interface
106
107 /* Call Management Functional Descriptor */
108 0x05, // bFunctionLength
109 0x24, // bDescriptor Type: CS_INTERFACE
110 0x01, // bDescriptor Subtype: Call Management Func Desc
111 0x00, // bmCapabilities: D1 + D0
112 0x01, // bDataInterface: Data Class Interface 1
113
114 /* Endpoint 1 descriptor */
115 0x07, // bLength
116 0x05, // bDescriptorType
117 0x83, // bEndpointAddress, Endpoint 03 - IN
118 0x03, // bmAttributes INT
119 0x08, // wMaxPacketSize
120 0x00,
121 0xFF, // bInterval
122
123 /* Data Class Interface Descriptor Requirement */
124 0x09, // bLength
125 0x04, // bDescriptorType
126 0x01, // bInterfaceNumber
127 0x00, // bAlternateSetting
128 0x02, // bNumEndpoints
129 0x0A, // bInterfaceClass
130 0x00, // bInterfaceSubclass
131 0x00, // bInterfaceProtocol
132 0x00, // iInterface
133
134 /* First alternate setting */
135 /* Endpoint 1 descriptor */
136 0x07, // bLength
137 0x05, // bDescriptorType
138 0x01, // bEndpointAddress, Endpoint 01 - OUT
139 0x02, // bmAttributes BULK
140 AT91C_EP_OUT_SIZE, // wMaxPacketSize
141 0x00,
142 0x00, // bInterval
143
144 /* Endpoint 2 descriptor */
145 0x07, // bLength
146 0x05, // bDescriptorType
147 0x82, // bEndpointAddress, Endpoint 02 - IN
148 0x02, // bmAttributes BULK
149 AT91C_EP_IN_SIZE, // wMaxPacketSize
150 0x00,
151 0x00 // bInterval
152 };
153
154 const char strDescriptor[] = {
155 26, // Length
156 0x03, // Type is string
157 'p', 0x00,
158 'r', 0x00,
159 'o', 0x00,
160 'x', 0x00,
161 'm', 0x00,
162 'a', 0x00,
163 'r', 0x00,
164 'k', 0x00,
165 '.', 0x00,
166 'o', 0x00,
167 'r', 0x00,
168 'g', 0x00,
169 };
170
171
172 /* USB standard request code */
173 #define STD_GET_STATUS_ZERO 0x0080
174 #define STD_GET_STATUS_INTERFACE 0x0081
175 #define STD_GET_STATUS_ENDPOINT 0x0082
176
177 #define STD_CLEAR_FEATURE_ZERO 0x0100
178 #define STD_CLEAR_FEATURE_INTERFACE 0x0101
179 #define STD_CLEAR_FEATURE_ENDPOINT 0x0102
180
181 #define STD_SET_FEATURE_ZERO 0x0300
182 #define STD_SET_FEATURE_INTERFACE 0x0301
183 #define STD_SET_FEATURE_ENDPOINT 0x0302
184
185 #define STD_SET_ADDRESS 0x0500
186 #define STD_GET_DESCRIPTOR 0x0680
187 #define STD_SET_DESCRIPTOR 0x0700
188 #define STD_GET_CONFIGURATION 0x0880
189 #define STD_SET_CONFIGURATION 0x0900
190 #define STD_GET_INTERFACE 0x0A81
191 #define STD_SET_INTERFACE 0x0B01
192 #define STD_SYNCH_FRAME 0x0C82
193
194 /* CDC Class Specific Request Code */
195 #define GET_LINE_CODING 0x21A1
196 #define SET_LINE_CODING 0x2021
197 #define SET_CONTROL_LINE_STATE 0x2221
198
199 typedef struct {
200 unsigned int dwDTERRate;
201 char bCharFormat;
202 char bParityType;
203 char bDataBits;
204 } AT91S_CDC_LINE_CODING, *AT91PS_CDC_LINE_CODING;
205
206 AT91S_CDC_LINE_CODING line = {
207 115200, // baudrate
208 0, // 1 Stop Bit
209 0, // None Parity
210 8}; // 8 Data bits
211
212 void AT91F_CDC_Enumerate();
213
214 AT91PS_UDP pUdp = AT91C_BASE_UDP;
215 byte_t btConfiguration = 0;
216 byte_t btConnection = 0;
217 byte_t btReceiveBank = AT91C_UDP_RX_DATA_BK0;
218
219 //*----------------------------------------------------------------------------
220 //* \fn usb_disable
221 //* \brief This function deactivates the USB device
222 //*----------------------------------------------------------------------------
223 void usb_disable() {
224 // Disconnect the USB device
225 AT91C_BASE_PIOA->PIO_ODR = GPIO_USB_PU;
226
227 // Clear all lingering interrupts
228 if(pUdp->UDP_ISR & AT91C_UDP_ENDBUSRES) {
229 pUdp->UDP_ICR = AT91C_UDP_ENDBUSRES;
230 }
231 }
232
233 //*----------------------------------------------------------------------------
234 //* \fn usb_enable
235 //* \brief This function Activates the USB device
236 //*----------------------------------------------------------------------------
237 void usb_enable() {
238 // Set the PLL USB Divider
239 AT91C_BASE_CKGR->CKGR_PLLR |= AT91C_CKGR_USBDIV_1 ;
240
241 // Specific Chip USB Initialisation
242 // Enables the 48MHz USB clock UDPCK and System Peripheral USB Clock
243 AT91C_BASE_PMC->PMC_SCER = AT91C_PMC_UDP;
244 AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_UDP);
245
246 // Enable UDP PullUp (USB_DP_PUP) : enable & Clear of the corresponding PIO
247 // Set in PIO mode and Configure in Output
248 AT91C_BASE_PIOA->PIO_PER = GPIO_USB_PU; // Set in PIO mode
249 AT91C_BASE_PIOA->PIO_OER = GPIO_USB_PU; // Configure as Output
250
251 // Clear for set the Pullup resistor
252 AT91C_BASE_PIOA->PIO_CODR = GPIO_USB_PU;
253
254 // Disconnect and reconnect USB controller for 100ms
255 usb_disable();
256
257 // Wait for a short while
258 for (volatile size_t i=0; i<0x100000; i++);
259
260 // Reconnect USB reconnect
261 AT91C_BASE_PIOA->PIO_SODR = GPIO_USB_PU;
262 AT91C_BASE_PIOA->PIO_OER = GPIO_USB_PU;
263 }
264
265 //*----------------------------------------------------------------------------
266 //* \fn usb_check
267 //* \brief Test if the device is configured and handle enumeration
268 //*----------------------------------------------------------------------------
269 bool usb_check() {
270 AT91_REG isr = pUdp->UDP_ISR;
271
272 if (isr & AT91C_UDP_ENDBUSRES) {
273 pUdp->UDP_ICR = AT91C_UDP_ENDBUSRES;
274 // reset all endpoints
275 pUdp->UDP_RSTEP = (unsigned int)-1;
276 pUdp->UDP_RSTEP = 0;
277 // Enable the function
278 pUdp->UDP_FADDR = AT91C_UDP_FEN;
279 // Configure endpoint 0
280 pUdp->UDP_CSR[0] = (AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_CTRL);
281 }
282 else if (isr & AT91C_UDP_EPINT0) {
283 pUdp->UDP_ICR = AT91C_UDP_EPINT0;
284 AT91F_CDC_Enumerate();
285 }
286 return (btConfiguration) ? true : false;
287 }
288
289
290 bool usb_poll()
291 {
292 if (!usb_check()) return false;
293 return (pUdp->UDP_CSR[AT91C_EP_OUT] & btReceiveBank);
294 }
295
296 //*----------------------------------------------------------------------------
297 //* \fn usb_read
298 //* \brief Read available data from Endpoint OUT
299 //*----------------------------------------------------------------------------
300 uint32_t usb_read(byte_t* data, size_t len) {
301 byte_t bank = btReceiveBank;
302 uint32_t packetSize, nbBytesRcv = 0;
303 uint32_t time_out = 0;
304
305 while (len) {
306 if (!usb_check()) break;
307
308 if ( pUdp->UDP_CSR[AT91C_EP_OUT] & bank ) {
309 packetSize = MIN(pUdp->UDP_CSR[AT91C_EP_OUT] >> 16, len);
310 len -= packetSize;
311 while(packetSize--)
312 data[nbBytesRcv++] = pUdp->UDP_FDR[AT91C_EP_OUT];
313 pUdp->UDP_CSR[AT91C_EP_OUT] &= ~(bank);
314 if (bank == AT91C_UDP_RX_DATA_BK0) {
315 bank = AT91C_UDP_RX_DATA_BK1;
316 } else {
317 bank = AT91C_UDP_RX_DATA_BK0;
318 }
319 }
320 if (time_out++ == 0x1fff) break;
321 }
322
323 btReceiveBank = bank;
324 return nbBytesRcv;
325 }
326
327 //*----------------------------------------------------------------------------
328 //* \fn usb_write
329 //* \brief Send through endpoint 2
330 //*----------------------------------------------------------------------------
331 uint32_t usb_write(const byte_t* data, const size_t len) {
332 size_t length = len;
333 uint32_t cpt = 0;
334
335 if (!length) return 0;
336 if (!usb_check()) return 0;
337
338 // Send the first packet
339 cpt = MIN(length, AT91C_EP_IN_SIZE-1);
340 length -= cpt;
341 while (cpt--) pUdp->UDP_FDR[AT91C_EP_IN] = *data++;
342 pUdp->UDP_CSR[AT91C_EP_IN] |= AT91C_UDP_TXPKTRDY;
343
344 while (length) {
345 // Fill the second bank
346 cpt = MIN(length, AT91C_EP_IN_SIZE-1);
347 length -= cpt;
348 while (cpt--) pUdp->UDP_FDR[AT91C_EP_IN] = *data++;
349 // Wait for the the first bank to be sent
350 while (!(pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP)) {
351 if (!usb_check()) return length;
352 }
353 pUdp->UDP_CSR[AT91C_EP_IN] &= ~(AT91C_UDP_TXCOMP);
354 while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP);
355 pUdp->UDP_CSR[AT91C_EP_IN] |= AT91C_UDP_TXPKTRDY;
356 }
357
358 // Wait for the end of transfer
359 while (!(pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP)) {
360 if (!usb_check()) return length;
361 }
362
363 pUdp->UDP_CSR[AT91C_EP_IN] &= ~(AT91C_UDP_TXCOMP);
364 while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP);
365
366 return length;
367 }
368
369 //*----------------------------------------------------------------------------
370 //* \fn AT91F_USB_SendData
371 //* \brief Send Data through the control endpoint
372 //*----------------------------------------------------------------------------
373 unsigned int csrTab[100] = {0x00};
374 unsigned char csrIdx = 0;
375
376 static void AT91F_USB_SendData(AT91PS_UDP pUdp, const char *pData, uint32_t length) {
377 uint32_t cpt = 0;
378 AT91_REG csr;
379
380 do {
381 cpt = MIN(length, 8);
382 length -= cpt;
383
384 while (cpt--)
385 pUdp->UDP_FDR[0] = *pData++;
386
387 if (pUdp->UDP_CSR[0] & AT91C_UDP_TXCOMP) {
388 pUdp->UDP_CSR[0] &= ~(AT91C_UDP_TXCOMP);
389 while (pUdp->UDP_CSR[0] & AT91C_UDP_TXCOMP);
390 }
391
392 pUdp->UDP_CSR[0] |= AT91C_UDP_TXPKTRDY;
393 do {
394 csr = pUdp->UDP_CSR[0];
395
396 // Data IN stage has been stopped by a status OUT
397 if (csr & AT91C_UDP_RX_DATA_BK0) {
398 pUdp->UDP_CSR[0] &= ~(AT91C_UDP_RX_DATA_BK0);
399 return;
400 }
401 } while ( !(csr & AT91C_UDP_TXCOMP) );
402
403 } while (length);
404
405 if (pUdp->UDP_CSR[0] & AT91C_UDP_TXCOMP) {
406 pUdp->UDP_CSR[0] &= ~(AT91C_UDP_TXCOMP);
407 while (pUdp->UDP_CSR[0] & AT91C_UDP_TXCOMP);
408 }
409 }
410
411 //*----------------------------------------------------------------------------
412 //* \fn AT91F_USB_SendZlp
413 //* \brief Send zero length packet through the control endpoint
414 //*----------------------------------------------------------------------------
415 void AT91F_USB_SendZlp(AT91PS_UDP pUdp) {
416 pUdp->UDP_CSR[0] |= AT91C_UDP_TXPKTRDY;
417 while ( !(pUdp->UDP_CSR[0] & AT91C_UDP_TXCOMP) );
418 pUdp->UDP_CSR[0] &= ~(AT91C_UDP_TXCOMP);
419 while (pUdp->UDP_CSR[0] & AT91C_UDP_TXCOMP);
420 }
421
422 //*----------------------------------------------------------------------------
423 //* \fn AT91F_USB_SendStall
424 //* \brief Stall the control endpoint
425 //*----------------------------------------------------------------------------
426 void AT91F_USB_SendStall(AT91PS_UDP pUdp) {
427 pUdp->UDP_CSR[0] |= AT91C_UDP_FORCESTALL;
428 while ( !(pUdp->UDP_CSR[0] & AT91C_UDP_ISOERROR) );
429 pUdp->UDP_CSR[0] &= ~(AT91C_UDP_FORCESTALL | AT91C_UDP_ISOERROR);
430 while (pUdp->UDP_CSR[0] & (AT91C_UDP_FORCESTALL | AT91C_UDP_ISOERROR));
431 }
432
433 //*----------------------------------------------------------------------------
434 //* \fn AT91F_CDC_Enumerate
435 //* \brief This function is a callback invoked when a SETUP packet is received
436 //*----------------------------------------------------------------------------
437 void AT91F_CDC_Enumerate() {
438 byte_t bmRequestType, bRequest;
439 uint16_t wValue, wIndex, wLength, wStatus;
440
441 if ( !(pUdp->UDP_CSR[0] & AT91C_UDP_RXSETUP) )
442 return;
443
444 bmRequestType = pUdp->UDP_FDR[0];
445 bRequest = pUdp->UDP_FDR[0];
446 wValue = (pUdp->UDP_FDR[0] & 0xFF);
447 wValue |= (pUdp->UDP_FDR[0] << 8);
448 wIndex = (pUdp->UDP_FDR[0] & 0xFF);
449 wIndex |= (pUdp->UDP_FDR[0] << 8);
450 wLength = (pUdp->UDP_FDR[0] & 0xFF);
451 wLength |= (pUdp->UDP_FDR[0] << 8);
452
453 if (bmRequestType & 0x80) {
454 pUdp->UDP_CSR[0] |= AT91C_UDP_DIR;
455 while ( !(pUdp->UDP_CSR[0] & AT91C_UDP_DIR) );
456 }
457 pUdp->UDP_CSR[0] &= ~AT91C_UDP_RXSETUP;
458 while ( (pUdp->UDP_CSR[0] & AT91C_UDP_RXSETUP) );
459
460 // Handle supported standard device request Cf Table 9-3 in USB specification Rev 1.1
461 switch ((bRequest << 8) | bmRequestType) {
462 case STD_GET_DESCRIPTOR:
463 if (wValue == 0x100) // Return Device Descriptor
464 AT91F_USB_SendData(pUdp, devDescriptor, MIN(sizeof(devDescriptor), wLength));
465 else if (wValue == 0x200) // Return Configuration Descriptor
466 AT91F_USB_SendData(pUdp, cfgDescriptor, MIN(sizeof(cfgDescriptor), wLength));
467 else if ((wValue & 0x300) == 0x300) // Return String Descriptor
468 AT91F_USB_SendData(pUdp, strDescriptor, MIN(sizeof(strDescriptor), wLength));
469 else
470 AT91F_USB_SendStall(pUdp);
471 break;
472 case STD_SET_ADDRESS:
473 AT91F_USB_SendZlp(pUdp);
474 pUdp->UDP_FADDR = (AT91C_UDP_FEN | wValue);
475 pUdp->UDP_GLBSTATE = (wValue) ? AT91C_UDP_FADDEN : 0;
476 break;
477 case STD_SET_CONFIGURATION:
478 btConfiguration = wValue;
479 AT91F_USB_SendZlp(pUdp);
480 pUdp->UDP_GLBSTATE = (wValue) ? AT91C_UDP_CONFG : AT91C_UDP_FADDEN;
481 pUdp->UDP_CSR[1] = (wValue) ? (AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_BULK_OUT) : 0;
482 pUdp->UDP_CSR[2] = (wValue) ? (AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_BULK_IN) : 0;
483 pUdp->UDP_CSR[3] = (wValue) ? (AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_INT_IN) : 0;
484 break;
485 case STD_GET_CONFIGURATION:
486 AT91F_USB_SendData(pUdp, (char *) &(btConfiguration), sizeof(btConfiguration));
487 break;
488 case STD_GET_STATUS_ZERO:
489 wStatus = 0;
490 AT91F_USB_SendData(pUdp, (char *) &wStatus, sizeof(wStatus));
491 break;
492 case STD_GET_STATUS_INTERFACE:
493 wStatus = 0;
494 AT91F_USB_SendData(pUdp, (char *) &wStatus, sizeof(wStatus));
495 break;
496 case STD_GET_STATUS_ENDPOINT:
497 wStatus = 0;
498 wIndex &= 0x0F;
499 if ((pUdp->UDP_GLBSTATE & AT91C_UDP_CONFG) && (wIndex <= 3)) {
500 wStatus = (pUdp->UDP_CSR[wIndex] & AT91C_UDP_EPEDS) ? 0 : 1;
501 AT91F_USB_SendData(pUdp, (char *) &wStatus, sizeof(wStatus));
502 }
503 else if ((pUdp->UDP_GLBSTATE & AT91C_UDP_FADDEN) && (wIndex == 0)) {
504 wStatus = (pUdp->UDP_CSR[wIndex] & AT91C_UDP_EPEDS) ? 0 : 1;
505 AT91F_USB_SendData(pUdp, (char *) &wStatus, sizeof(wStatus));
506 }
507 else
508 AT91F_USB_SendStall(pUdp);
509 break;
510 case STD_SET_FEATURE_ZERO:
511 AT91F_USB_SendStall(pUdp);
512 break;
513 case STD_SET_FEATURE_INTERFACE:
514 AT91F_USB_SendZlp(pUdp);
515 break;
516 case STD_SET_FEATURE_ENDPOINT:
517 wIndex &= 0x0F;
518 if ((wValue == 0) && wIndex && (wIndex <= 3)) {
519 pUdp->UDP_CSR[wIndex] = 0;
520 AT91F_USB_SendZlp(pUdp);
521 }
522 else
523 AT91F_USB_SendStall(pUdp);
524 break;
525 case STD_CLEAR_FEATURE_ZERO:
526 AT91F_USB_SendStall(pUdp);
527 break;
528 case STD_CLEAR_FEATURE_INTERFACE:
529 AT91F_USB_SendZlp(pUdp);
530 break;
531 case STD_CLEAR_FEATURE_ENDPOINT:
532 wIndex &= 0x0F;
533 if ((wValue == 0) && wIndex && (wIndex <= 3)) {
534 if (wIndex == 1)
535 pUdp->UDP_CSR[1] = (AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_BULK_OUT);
536 else if (wIndex == 2)
537 pUdp->UDP_CSR[2] = (AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_BULK_IN);
538 else if (wIndex == 3)
539 pUdp->UDP_CSR[3] = (AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_ISO_IN);
540 AT91F_USB_SendZlp(pUdp);
541 }
542 else
543 AT91F_USB_SendStall(pUdp);
544 break;
545
546 // handle CDC class requests
547 case SET_LINE_CODING:
548 while ( !(pUdp->UDP_CSR[0] & AT91C_UDP_RX_DATA_BK0) );
549 pUdp->UDP_CSR[0] &= ~(AT91C_UDP_RX_DATA_BK0);
550 AT91F_USB_SendZlp(pUdp);
551 break;
552 case GET_LINE_CODING:
553 AT91F_USB_SendData(pUdp, (char *) &line, MIN(sizeof(line), wLength));
554 break;
555 case SET_CONTROL_LINE_STATE:
556 btConnection = wValue;
557 AT91F_USB_SendZlp(pUdp);
558 break;
559 default:
560 AT91F_USB_SendStall(pUdp);
561 break;
562 }
563 }
Impressum, Datenschutz