From 9019c901dd7b4e37006eb1f0442a57dacc0b3f0c Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 18 Nov 2010 22:35:49 +0900 Subject: add system controls(power down/wake up) from generic desktop page(HID) --- usb.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) (limited to 'usb.c') diff --git a/usb.c b/usb.c index 7add57daa3..d3aa46e2de 100644 --- a/usb.c +++ b/usb.c @@ -21,6 +21,8 @@ * THE SOFTWARE. */ +#include +#include #include #include #include @@ -82,6 +84,9 @@ #define ENDPOINT0_SIZE 32 +bool remote_wakeup = false; +bool suspend = false; + // 0:control endpoint is enabled automatically by controller. static const uint8_t PROGMEM endpoint_config_table[] = { // enable, UECFG0X(type, direction), UECFG1X(size, bank, allocation) @@ -250,7 +255,7 @@ static uint8_t PROGMEM debug_hid_report_desc[] = { 0xC0 // end collection }; -// audio controls(consumer page) +// audio controls & system controls // http://www.microsoft.com/whdc/archive/w2kbd.mspx static uint8_t PROGMEM extra_hid_report_desc[] = { 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) @@ -272,6 +277,18 @@ static uint8_t PROGMEM extra_hid_report_desc[] = { 0x81, 0x06, // INPUT (Data,Var,Rel) 0x95, 0x05, // REPORT_COUNT (5) 0x81, 0x07, // INPUT (Cnst,Var,Abs) + 0xc0, // END_COLLECTION + + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x80, // USAGE (System Control) + 0xa1, 0x01, // COLLECTION (Application) + 0x85, 0x02, // REPORT_ID (2) + 0x19, 0x81, // USAGE_MINIMUM (System Power Down) + 0x29, 0x83, // USAGE_MAXIMUM (System Wake Up) + 0x95, 0x03, // REPORT_COUNT (3) + 0x81, 0x06, // INPUT (Data,Var,Rel) + 0x95, 0x05, // REPORT_COUNT (5) + 0x81, 0x07, // INPUT (Cnst,Var,Rel) 0xc0 // END_COLLECTION }; @@ -289,7 +306,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = { 4, // bNumInterfaces 1, // bConfigurationValue 0, // iConfiguration - 0xC0, // bmAttributes + 0xA0, // bmAttributes 50, // bMaxPower // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 @@ -484,7 +501,7 @@ void usb_init(void) USB_CONFIG(); // start USB clock UDCON = 0; // enable attach resistor usb_configuration = 0; - UDIEN = (1<= 1 && i <= MAX_ENDPOINT) { usb_send_in(); @@ -709,8 +736,18 @@ ISR(USB_COM_vect) } return; } + } +#endif + if (bmRequestType == 0x00 && wValue == DEVICE_REMOTE_WAKEUP) { + if (bRequest == SET_FEATURE) { + remote_wakeup = true; + } else { + remote_wakeup = false; + } + usb_send_in(); + return; + } } - #endif if (wIndex == KEYBOARD_INTERFACE) { if (bmRequestType == 0xA1) { if (bRequest == HID_GET_REPORT) { -- cgit v1.2.3