diff --git a/digistump-avr/libraries/DigisparkKeyboard/DigiKeyboard.h b/digistump-avr/libraries/DigisparkKeyboard/DigiKeyboard.h index d1982fc..f5678fb 100644 --- a/digistump-avr/libraries/DigisparkKeyboard/DigiKeyboard.h +++ b/digistump-avr/libraries/DigisparkKeyboard/DigiKeyboard.h @@ -23,39 +23,39 @@ typedef uint8_t byte; -#define BUFFER_SIZE 2 // Minimum of 2: 1 for modifiers + 1 for keystroke +#define BUFFER_SIZE 2 // Minimum of 2: 1 for modifiers + 1 for keystroke -static uchar idleRate; // in 4 ms units +static uchar idleRate; // in 4 ms units /* We use a simplifed keyboard report descriptor which does not support the * boot protocol. We don't allow setting status LEDs and but we do allow - * simultaneous key presses. + * simultaneous key presses. * The report descriptor has been created with usb.org's "HID Descriptor Tool" * which can be downloaded from http://www.usb.org/developers/hidpage/. * Redundant entries (such as LOGICAL_MINIMUM and USAGE_PAGE) have been omitted * for the second INPUT item. */ const PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { /* USB report descriptor */ - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x06, // USAGE (Keyboard) - 0xa1, 0x01, // COLLECTION (Application) - 0x05, 0x07, // USAGE_PAGE (Keyboard) - 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl) - 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x75, 0x01, // REPORT_SIZE (1) - 0x95, 0x08, // REPORT_COUNT (8) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x95, 0x01, // REPORT_COUNT (simultaneous keystrokes) - 0x75, 0x08, // REPORT_SIZE (8) - 0x25, 0x65, // LOGICAL_MAXIMUM (101) - 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) - 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application) - 0x81, 0x00, // INPUT (Data,Ary,Abs) - 0xc0 // END_COLLECTION + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x06, // USAGE (Keyboard) + 0xa1, 0x01, // COLLECTION (Application) + 0x05, 0x07, // USAGE_PAGE (Keyboard) + 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl) + 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x75, 0x01, // REPORT_SIZE (1) + 0x95, 0x08, // REPORT_COUNT (8) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x95, 0x01, // REPORT_COUNT (simultaneous keystrokes) + 0x75, 0x08, // REPORT_SIZE (8) + 0x25, 0x65, // LOGICAL_MAXIMUM (101) + 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) + 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application) + 0x81, 0x00, // INPUT (Data,Ary,Abs) + 0xc0 // END_COLLECTION }; @@ -126,8 +126,10 @@ const PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] #define KEY_F11 68 #define KEY_F12 69 -#define KEY_ARROW_LEFT 0x50 - +#define KEY_ARROW_UP 82 +#define KEY_ARROW_DOWN 81 +#define KEY_ARROW_LEFT 80 +#define KEY_ARROW_RIGHT 79 class DigiKeyboardDevice : public Print { public: @@ -139,19 +141,19 @@ class DigiKeyboardDevice : public Print { usbInit(); - + sei(); // TODO: Remove the next two lines once we fix // missing first keystroke bug properly. - memset(reportBuffer, 0, sizeof(reportBuffer)); + memset(reportBuffer, 0, sizeof(reportBuffer)); usbSetInterrupt(reportBuffer, sizeof(reportBuffer)); } - + void update() { usbPoll(); } - + // delay while updating until we are finished delaying void delay(long milli) { unsigned long last = millis(); @@ -162,7 +164,7 @@ class DigiKeyboardDevice : public Print { update(); } } - + //sendKeyStroke: sends a key press AND release void sendKeyStroke(byte keyStroke) { sendKeyStroke(keyStroke, 0); @@ -191,21 +193,21 @@ class DigiKeyboardDevice : public Print { usbPoll(); _delay_ms(5); } - + memset(reportBuffer, 0, sizeof(reportBuffer)); - + reportBuffer[0] = modifiers; reportBuffer[1] = keyPress; - + usbSetInterrupt(reportBuffer, sizeof(reportBuffer)); } - + size_t write(uint8_t chr) { uint8_t data = pgm_read_byte_near(ascii_to_scan_code_table + (chr - 8)); sendKeyStroke(data & 0b01111111, data >> 7 ? MOD_SHIFT_RIGHT : 0); return 1; } - + //private: TODO: Make friend? uchar reportBuffer[2]; // buffer for HID reports [ 1 modifier byte + (len-1) key strokes] using Print::write; @@ -215,7 +217,7 @@ DigiKeyboardDevice DigiKeyboard = DigiKeyboardDevice(); #ifdef __cplusplus extern "C"{ -#endif +#endif // USB_PUBLIC uchar usbFunctionSetup uchar usbFunctionSetup(uchar data[8]) { usbRequest_t *rq = (usbRequest_t *)((void *)data); @@ -228,22 +230,22 @@ extern "C"{ /* wValue: ReportType (highbyte), ReportID (lowbyte) */ /* we only have one report type, so don't look at wValue */ - // TODO: Ensure it's okay not to return anything here? + // TODO: Ensure it's okay not to return anything here? return 0; } else if (rq->bRequest == USBRQ_HID_GET_IDLE) { //usbMsgPtr = &idleRate; //return 1; return 0; - + } else if (rq->bRequest == USBRQ_HID_SET_IDLE) { idleRate = rq->wValue.bytes[1]; - + } } else { /* no vendor specific requests implemented */ } - + return 0; } #ifdef __cplusplus