@@ -40,7 +40,8 @@ static const uint32_t EndPoints[] =
40
40
#define TX_RX_LED_PULSE_MS 100
41
41
volatile uint8_t TxLEDPulse; /* *< Milliseconds remaining for data Tx LED pulse */
42
42
volatile uint8_t RxLEDPulse; /* *< Milliseconds remaining for data Rx LED pulse */
43
-
43
+ static char isRemoteWakeUpEnabled = 0 ;
44
+ static char isEndpointHalt = 0 ;
44
45
// ==================================================================
45
46
// ==================================================================
46
47
@@ -86,6 +87,10 @@ const DeviceDescriptor USB_DeviceDescriptor =
86
87
const DeviceDescriptor USB_DeviceDescriptorA =
87
88
D_DEVICE (DEVICE_CLASS,0x00 ,0x00 ,64 ,USB_VID,USB_PID,0x100 ,IMANUFACTURER,IPRODUCT,0 ,1 );
88
89
90
+ const DeviceDescriptor USB_DeviceQualifier =
91
+ D_QUALIFIER (0x00 ,0x00 ,0x00 ,64 ,1 );
92
+
93
+
89
94
// ==================================================================
90
95
// ==================================================================
91
96
@@ -183,8 +188,9 @@ uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len)
183
188
184
189
UDD_Send (ep & 0xF , data, n);
185
190
186
- if (!UDD_ReadWriteAllowed (ep & 0xF ) || ((len == 0 ) && (ep & TRANSFER_RELEASE))) // Release full buffer
187
- UDD_ReleaseTX (ep & 0xF );
191
+ // if (!UDD_ReadWriteAllowed(ep & 0xF) || ((len == 0) && (ep & TRANSFER_RELEASE))){ // Release full buffer
192
+ // UDD_ReleaseTX(ep & 0xF);
193
+ // }
188
194
}
189
195
// TXLED1; // light the TX LED
190
196
// TxLEDPulse = TX_RX_LED_PULSE_MS;
@@ -345,9 +351,24 @@ static bool USBD_SendDescriptor(Setup& setup)
345
351
desc_addr = (const uint8_t *)&STRING_IPRODUCT;
346
352
else if (setup.wValueL == IMANUFACTURER)
347
353
desc_addr = (const uint8_t *)&STRING_IMANUFACTURER;
348
- else
354
+ else {
349
355
return false ;
356
+ }
350
357
}
358
+ else if (USB_DEVICE_QUALIFIER == t)
359
+ {
360
+ // Device qualifier descriptor requested
361
+ desc_addr = (const uint8_t *)&USB_DeviceQualifier;
362
+ }
363
+ else if (USB_OTHER_SPEED_CONFIGURATION == t)
364
+ {
365
+ // TODO
366
+ // Other configuration descriptor requested
367
+ }
368
+ else
369
+ {
370
+ // printf("Device ERROR");
371
+ }
351
372
352
373
if (desc_addr == 0 )
353
374
{
@@ -401,7 +422,7 @@ static void USB_ISR(void)
401
422
if (Is_udd_sof ())
402
423
{
403
424
udd_ack_sof ();
404
- USBD_Flush (CDC_TX);
425
+ // USBD_Flush(CDC_TX);
405
426
}
406
427
#endif
407
428
@@ -437,15 +458,70 @@ static void USB_ISR(void)
437
458
uint8_t r = setup.bRequest ;
438
459
if (GET_STATUS == r)
439
460
{
440
- TRACE_CORE (puts (" >>> EP0 Int: GET_STATUS\r\n " );)
441
- UDD_Send8 (EP0, 0 ); // TODO
442
- UDD_Send8 (EP0, 0 );
461
+ if ( setup.bmRequestType == 0 ) // device
462
+ {
463
+ // Send the device status
464
+ TRACE_CORE (puts (" >>> EP0 Int: GET_STATUS\r\n " );)
465
+ // Check current configuration for power mode (if device is configured)
466
+ // TODO
467
+ // Check if remote wake-up is enabled
468
+ // TODO
469
+ UDD_Send8 (EP0, 0 ); // TODO
470
+ UDD_Send8 (EP0, 0 );
471
+ }
472
+ // if( setup.bmRequestType == 2 ) // Endpoint:
473
+ else
474
+ {
475
+ // Send the endpoint status
476
+ // Check if the endpoint if currently halted
477
+ if ( isEndpointHalt == 1 )
478
+ UDD_Send8 (EP0, 1 ); // TODO
479
+ else
480
+ UDD_Send8 (EP0, 0 ); // TODO
481
+ UDD_Send8 (EP0, 0 );
482
+ }
443
483
}
444
484
else if (CLEAR_FEATURE == r)
445
485
{
446
- }
486
+ // Check which is the selected feature
487
+ if ( setup.wValueL == 1 ) // DEVICEREMOTEWAKEUP
488
+ {
489
+ // Enable remote wake-up and send a ZLP
490
+ if ( isRemoteWakeUpEnabled == 1 )
491
+ UDD_Send8 (EP0, 1 );
492
+ else
493
+ UDD_Send8 (EP0, 0 );
494
+ UDD_Send8 (EP0, 0 );
495
+ }
496
+ else // if( setup.wValueL == 0) // ENDPOINTHALT
497
+ {
498
+ isEndpointHalt = 0 ; // TODO
499
+ UDD_Send8 (EP0, 0 );
500
+ UDD_Send8 (EP0, 0 );
501
+ }
502
+
503
+ }
447
504
else if (SET_FEATURE == r)
448
505
{
506
+ // Check which is the selected feature
507
+ if ( setup.wValueL == 1 ) // DEVICEREMOTEWAKEUP
508
+ {
509
+ // Enable remote wake-up and send a ZLP
510
+ isRemoteWakeUpEnabled = 1 ;
511
+ UDD_Send8 (EP0, 0 );
512
+ }
513
+ if ( setup.wValueL == 0 ) // ENDPOINTHALT
514
+ {
515
+ // Halt endpoint
516
+ isEndpointHalt = 1 ;
517
+ // USBD_Halt(USBGenericRequest_GetEndpointNumber(pRequest));
518
+ UDD_Send8 (EP0, 0 );
519
+ }
520
+ if ( setup.wValueL == 2 ) // TEST_MODE
521
+ {
522
+ // 7.1.20 Test Mode Support, 9.4.9 SetFeature
523
+ // TODO
524
+ }
449
525
}
450
526
else if (SET_ADDRESS == r)
451
527
{
@@ -466,7 +542,7 @@ static void USB_ISR(void)
466
542
else if (GET_CONFIGURATION == r)
467
543
{
468
544
TRACE_CORE (puts (" >>> EP0 Int: GET_CONFIGURATION\r\n " );)
469
- UDD_Send8 (EP0, 1 );
545
+ UDD_Send8 (EP0, _usbConfiguration );
470
546
}
471
547
else if (SET_CONFIGURATION == r)
472
548
{
@@ -491,10 +567,13 @@ static void USB_ISR(void)
491
567
}
492
568
else if (GET_INTERFACE == r)
493
569
{
570
+ // TODO
494
571
TRACE_CORE (puts (" >>> EP0 Int: GET_INTERFACE\r\n " );)
572
+ UDD_Send8 (EP0, setup.wIndex );
495
573
}
496
574
else if (SET_INTERFACE == r)
497
575
{
576
+ // TODO
498
577
TRACE_CORE (puts (" >>> EP0 Int: SET_INTERFACE\r\n " );)
499
578
}
500
579
}
0 commit comments