From 665692b914c4dc384644631ebbbf2b1ce67367c3 Mon Sep 17 00:00:00 2001 From: Michael Dreher Date: Sat, 29 Jun 2013 23:02:25 +0200 Subject: [PATCH] Wakeup for USB host. First clean version --- hardware/keyboardio/cores/keyboardio/USBAPI.h | 1 + .../keyboardio/cores/keyboardio/USBCore.cpp | 45 ++++++++++++++++++- .../keyboardio/cores/keyboardio/USBCore.h | 11 ++++- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/hardware/keyboardio/cores/keyboardio/USBAPI.h b/hardware/keyboardio/cores/keyboardio/USBAPI.h index 5fe97e65..72c50444 100644 --- a/hardware/keyboardio/cores/keyboardio/USBAPI.h +++ b/hardware/keyboardio/cores/keyboardio/USBAPI.h @@ -18,6 +18,7 @@ public: void attach(); void detach(); // Serial port goes down too... void poll(); + bool wakeupHost(); // returns false, when wakeup cannot be processed }; extern USBDevice_ USBDevice; diff --git a/hardware/keyboardio/cores/keyboardio/USBCore.cpp b/hardware/keyboardio/cores/keyboardio/USBCore.cpp index d3e01706..1d4b1d40 100644 --- a/hardware/keyboardio/cores/keyboardio/USBCore.cpp +++ b/hardware/keyboardio/cores/keyboardio/USBCore.cpp @@ -92,6 +92,7 @@ const DeviceDescriptor USB_DeviceDescriptorA = //================================================================== volatile u8 _usbConfiguration = 0; +volatile u8 _usbCurrentStatus = 0; // meaning of bits see usb_20.pdf, Figure 9-4. Information Returned by a GetStatus() Request to a Device static inline void WaitIN(void) { @@ -527,16 +528,37 @@ ISR(USB_COM_vect) { // Standard Requests u8 r = setup.bRequest; + u16 wValue = setup.wValueL | (setup.wValueH << 8); if (GET_STATUS == r) { - Send8(0); // TODO - Send8(0); + if(requestType == (REQUEST_DEVICETOHOST | REQUEST_STANDARD | REQUEST_DEVICE)) + { + Send8(_usbCurrentStatus); + Send8(0); + } + else + { + // TODO: handle the HALT state of an endpoint here + // see "Figure 9-6. Information Returned by a GetStatus() Request to an Endpoint" in usb_20.pdf for more information + Send8(0); + Send8(0); + } } else if (CLEAR_FEATURE == r) { + if((requestType == (REQUEST_HOSTTODEVICE | REQUEST_STANDARD | REQUEST_DEVICE)) + && (wValue == DEVICE_REMOTE_WAKEUP)) + { + _usbCurrentStatus &= ~FEATURE_REMOTE_WAKEUP_ENABLED; + } } else if (SET_FEATURE == r) { + if((requestType == (REQUEST_HOSTTODEVICE | REQUEST_STANDARD | REQUEST_DEVICE)) + && (wValue == DEVICE_REMOTE_WAKEUP)) + { + _usbCurrentStatus |= FEATURE_REMOTE_WAKEUP_ENABLED; + } } else if (SET_ADDRESS == r) { @@ -644,6 +666,7 @@ USBDevice_::USBDevice_() void USBDevice_::attach() { _usbConfiguration = 0; + _usbCurrentStatus = 0; UHWCON = 0x01; // power internal reg USBCON = (1<