@@ -40,7 +40,8 @@ static const uint32_t EndPoints[] =
4040#define TX_RX_LED_PULSE_MS 100
4141volatile uint8_t TxLEDPulse; /* *< Milliseconds remaining for data Tx LED pulse */
4242volatile uint8_t RxLEDPulse; /* *< Milliseconds remaining for data Rx LED pulse */
43-
43+ static char isRemoteWakeUpEnabled = 0 ;
44+ static char isEndpointHalt = 0 ;
4445// ==================================================================
4546// ==================================================================
4647
@@ -86,6 +87,10 @@ const DeviceDescriptor USB_DeviceDescriptor =
8687const DeviceDescriptor USB_DeviceDescriptorA =
8788 D_DEVICE (DEVICE_CLASS,0x00 ,0x00 ,64 ,USB_VID,USB_PID,0x100 ,IMANUFACTURER,IPRODUCT,0 ,1 );
8889
90+ const DeviceDescriptor USB_DeviceQualifier =
91+ D_QUALIFIER (0x00 ,0x00 ,0x00 ,64 ,1 );
92+
93+
8994// ==================================================================
9095// ==================================================================
9196
@@ -183,8 +188,9 @@ uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len)
183188
184189 UDD_Send (ep & 0xF , data, n);
185190
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+ // }
188194 }
189195 // TXLED1; // light the TX LED
190196 // TxLEDPulse = TX_RX_LED_PULSE_MS;
@@ -345,9 +351,24 @@ static bool USBD_SendDescriptor(Setup& setup)
345351 desc_addr = (const uint8_t *)&STRING_IPRODUCT;
346352 else if (setup.wValueL == IMANUFACTURER)
347353 desc_addr = (const uint8_t *)&STRING_IMANUFACTURER;
348- else
354+ else {
349355 return false ;
356+ }
350357 }
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+ }
351372
352373 if (desc_addr == 0 )
353374 {
@@ -401,7 +422,7 @@ static void USB_ISR(void)
401422 if (Is_udd_sof ())
402423 {
403424 udd_ack_sof ();
404- USBD_Flush (CDC_TX);
425+ // USBD_Flush(CDC_TX);
405426 }
406427#endif
407428
@@ -437,15 +458,70 @@ static void USB_ISR(void)
437458 uint8_t r = setup.bRequest ;
438459 if (GET_STATUS == r)
439460 {
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+ }
443483 }
444484 else if (CLEAR_FEATURE == r)
445485 {
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+ }
447504 else if (SET_FEATURE == r)
448505 {
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+ }
449525 }
450526 else if (SET_ADDRESS == r)
451527 {
@@ -466,7 +542,7 @@ static void USB_ISR(void)
466542 else if (GET_CONFIGURATION == r)
467543 {
468544 TRACE_CORE (puts (" >>> EP0 Int: GET_CONFIGURATION\r\n " );)
469- UDD_Send8 (EP0, 1 );
545+ UDD_Send8 (EP0, _usbConfiguration );
470546 }
471547 else if (SET_CONFIGURATION == r)
472548 {
@@ -491,10 +567,13 @@ static void USB_ISR(void)
491567 }
492568 else if (GET_INTERFACE == r)
493569 {
570+ // TODO
494571 TRACE_CORE (puts (" >>> EP0 Int: GET_INTERFACE\r\n " );)
572+ UDD_Send8 (EP0, setup.wIndex );
495573 }
496574 else if (SET_INTERFACE == r)
497575 {
576+ // TODO
498577 TRACE_CORE (puts (" >>> EP0 Int: SET_INTERFACE\r\n " );)
499578 }
500579 }
0 commit comments