@@ -29,6 +29,15 @@ USBDevice_SAMD21G18x usbd;
29
29
static char isRemoteWakeUpEnabled = 0 ;
30
30
static char isEndpointHalt = 0 ;
31
31
32
+ extern void (*gpf_isr)(void );
33
+
34
+ // USB_Handler ISR
35
+ extern " C" void UDD_Handler (void ) {
36
+ USBDevice.ISRHandler ();
37
+ }
38
+
39
+
40
+
32
41
const uint16_t STRING_LANGUAGE[2 ] = {
33
42
(3 <<8 ) | (2 +2 ),
34
43
0x0409 // English
@@ -285,6 +294,8 @@ void USBDeviceClass::init()
285
294
while (GCLK->STATUS .bit .SYNCBUSY )
286
295
;
287
296
297
+ UHD_SetStack (&UDD_Handler);
298
+
288
299
// Reset USB Device
289
300
usbd.reset ();
290
301
@@ -388,9 +399,6 @@ void USBDeviceClass::initEP(uint32_t ep, uint32_t config)
388
399
// Release OUT EP
389
400
usbd.epBank0SetMultiPacketSize (ep, 64 );
390
401
usbd.epBank0SetByteCount (ep, 0 );
391
-
392
- // The RAM Buffer is empty: we can receive data
393
- // usbd.epBank0ResetReady(ep);
394
402
}
395
403
else if (config == (USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_IN (0 )))
396
404
{
@@ -405,12 +413,12 @@ void USBDeviceClass::initEP(uint32_t ep, uint32_t config)
405
413
else if (config == USB_ENDPOINT_TYPE_CONTROL)
406
414
{
407
415
// XXX: Needed?
408
- usbd.epBank0DisableAutoZLP (ep);
409
- usbd.epBank1DisableAutoZLP (ep);
416
+ // usbd.epBank0DisableAutoZLP(ep);
417
+ // usbd.epBank1DisableAutoZLP(ep);
410
418
411
419
// Setup Control OUT
412
420
usbd.epBank0SetSize (ep, 64 );
413
- usbd.epBank0SetAddress (ep, &udd_ep_out_cache_buffer[0 ]);
421
+ usbd.epBank0SetAddress (ep, &udd_ep_out_cache_buffer[ep ]);
414
422
usbd.epBank0SetType (ep, 1 ); // CONTROL OUT / SETUP
415
423
416
424
// Setup Control IN
@@ -424,8 +432,6 @@ void USBDeviceClass::initEP(uint32_t ep, uint32_t config)
424
432
425
433
// NAK on endpoint OUT, the bank is full.
426
434
usbd.epBank0SetReady (ep);
427
- // NAK on endpoint IN, the bank is not yet filled in.
428
- // usbd.epBank1ResetReady(ep);
429
435
}
430
436
}
431
437
@@ -461,7 +467,6 @@ bool USBDeviceClass::connected()
461
467
uint32_t USBDeviceClass::recvControl (void *_data, uint32_t len)
462
468
{
463
469
uint8_t *data = reinterpret_cast <uint8_t *>(_data);
464
- // NO RXOUT ???????
465
470
466
471
// The RAM Buffer is empty: we can receive data
467
472
usbd.epBank0ResetReady (0 );
@@ -499,17 +504,8 @@ uint32_t USBDeviceClass::recv(uint32_t ep, void *_data, uint32_t len)
499
504
500
505
usbd.epBank0DisableTransferComplete (ep);
501
506
502
- // NAK on endpoint OUT, the bank is full.
503
- // usbd.epBank0SetReady(CDC_ENDPOINT_OUT);
504
-
505
507
memcpy (_data, udd_ep_out_cache_buffer[ep], len);
506
508
507
- // uint8_t *buffer = udd_ep_out_cache_buffer[ep];
508
- // uint8_t *data = reinterpret_cast<uint8_t *>(_data);
509
- // for (uint32_t i=0; i<len; i++) {
510
- // data[i] = buffer[i];
511
- // }
512
-
513
509
// release empty buffer
514
510
if (len && !available (ep)) {
515
511
// The RAM Buffer is empty: we can receive data
@@ -539,40 +535,23 @@ uint8_t USBDeviceClass::armRecvCtrlOUT(uint32_t ep, uint32_t len)
539
535
usbd.epBank0SetAddress (ep, &udd_ep_out_cache_buffer[ep]);
540
536
usbd.epBank0SetMultiPacketSize (ep, 8 );
541
537
usbd.epBank0SetByteCount (ep, 0 );
542
- // usbd.epBank0ResetReady(0);
543
- // while (!usbd.epBank0IsTransferComplete(ep)) {}
544
- // while (usbd.epBank0IsReady(ep)) {}
545
538
546
- // usbd.epBank0SetByteCount(0, 0);
547
- // usbd.epBank0SetMultiPacketSize(0, 8);
548
539
usbd.epBank0ResetReady (ep);
549
540
550
541
// Wait OUT
551
542
while (!usbd.epBank0IsReady (ep)) {}
552
- while (!usbd.epBank0IsTransferComplete (ep)) {} // XXX: while(USB->DEVICE.DeviceEndpoint[ep].EPINTFLAG.bit.TRCPT == 0);
543
+ while (!usbd.epBank0IsTransferComplete (ep)) {}
553
544
return usbd.epBank0ByteCount (ep);
554
545
}
555
546
556
547
uint8_t USBDeviceClass::armRecv (uint32_t ep, uint32_t len)
557
548
{
558
- // usbd.epBank0SetSize(ep, 64);
559
- // usbd.epBank0SetAddress(ep, &udd_ep_out_cache_buffer[ep]);
560
- // usbd.epBank0SetMultiPacketSize(ep, 64); // XXX: Should be "len"?
561
549
uint16_t count = usbd.epBank0ByteCount (ep);
562
550
if (count >= 64 ) {
563
551
usbd.epBank0SetByteCount (ep, count - 64 );
564
552
} else {
565
553
usbd.epBank0SetByteCount (ep, 0 );
566
554
}
567
- // The RAM Buffer is empty: we can receive data
568
- // usbd.epBank0ResetReady(ep);
569
-
570
- // Wait for transfer to complete
571
- // while (!usbd.epBank0IsTransferComplete(ep)) {}
572
- // while (usbd.epBank0IsReady(ep)) {}
573
- // NAK on endpoint OUT, the bank is full.
574
- // usbd.epBank0ResetReady(ep);
575
-
576
555
return usbd.epBank0ByteCount (ep);
577
556
}
578
557
@@ -837,8 +816,7 @@ void USBDeviceClass::ISRHandler()
837
816
stall (0 );
838
817
}
839
818
840
- // XXX: Should be really cleared?
841
- if (usbd.epBank1IsStalled (0 )) // XXX:(USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.STALL)
819
+ if (usbd.epBank1IsStalled (0 ))
842
820
{
843
821
usbd.epBank1AckStalled (0 );
844
822
@@ -878,6 +856,6 @@ void USBDeviceClass::ISRHandler()
878
856
USBDeviceClass USBDevice;
879
857
880
858
// USB_Handler ISR
881
- extern " C" void USB_Handler (void ) {
882
- USBDevice.ISRHandler ();
883
- }
859
+ // extern "C" void USB_Handler(void) {
860
+ // USBDevice.ISRHandler();
861
+ // }
0 commit comments