From 09460dd8c9483fd662a53f8eb20d6791a87b0fcc Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 5 Jun 2015 17:33:38 +0200 Subject: [PATCH 01/39] Remove HID core library --- hardware/arduino/avr/cores/arduino/HID.cpp | 518 ------------------- hardware/arduino/avr/cores/arduino/USBAPI.h | 102 +--- hardware/arduino/avr/cores/arduino/USBCore.h | 23 - hardware/arduino/avr/cores/arduino/USBDesc.h | 16 - 4 files changed, 1 insertion(+), 658 deletions(-) delete mode 100644 hardware/arduino/avr/cores/arduino/HID.cpp diff --git a/hardware/arduino/avr/cores/arduino/HID.cpp b/hardware/arduino/avr/cores/arduino/HID.cpp deleted file mode 100644 index 75c37b24b2f..00000000000 --- a/hardware/arduino/avr/cores/arduino/HID.cpp +++ /dev/null @@ -1,518 +0,0 @@ - - -/* Copyright (c) 2011, Peter Barrett -** -** Permission to use, copy, modify, and/or distribute this software for -** any purpose with or without fee is hereby granted, provided that the -** above copyright notice and this permission notice appear in all copies. -** -** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL -** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED -** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR -** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES -** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -** SOFTWARE. -*/ - -#include "USBAPI.h" - -#if defined(USBCON) -#ifdef HID_ENABLED - -//#define RAWHID_ENABLED - -// Singletons for mouse and keyboard - -Mouse_ Mouse; -Keyboard_ Keyboard; - -//================================================================================ -//================================================================================ - -// HID report descriptor - -#define LSB(_x) ((_x) & 0xFF) -#define MSB(_x) ((_x) >> 8) - -#define RAWHID_USAGE_PAGE 0xFFC0 -#define RAWHID_USAGE 0x0C00 -#define RAWHID_TX_SIZE 64 -#define RAWHID_RX_SIZE 64 - -extern const u8 _hidReportDescriptor[] PROGMEM; -const u8 _hidReportDescriptor[] = { - - // Mouse - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54 - 0x09, 0x02, // USAGE (Mouse) - 0xa1, 0x01, // COLLECTION (Application) - 0x09, 0x01, // USAGE (Pointer) - 0xa1, 0x00, // COLLECTION (Physical) - 0x85, 0x01, // REPORT_ID (1) - 0x05, 0x09, // USAGE_PAGE (Button) - 0x19, 0x01, // USAGE_MINIMUM (Button 1) - 0x29, 0x03, // USAGE_MAXIMUM (Button 3) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x95, 0x03, // REPORT_COUNT (3) - 0x75, 0x01, // REPORT_SIZE (1) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x95, 0x01, // REPORT_COUNT (1) - 0x75, 0x05, // REPORT_SIZE (5) - 0x81, 0x03, // INPUT (Cnst,Var,Abs) - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x30, // USAGE (X) - 0x09, 0x31, // USAGE (Y) - 0x09, 0x38, // USAGE (Wheel) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x03, // REPORT_COUNT (3) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0xc0, // END_COLLECTION - 0xc0, // END_COLLECTION - - // Keyboard - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47 - 0x09, 0x06, // USAGE (Keyboard) - 0xa1, 0x01, // COLLECTION (Application) - 0x85, 0x02, // REPORT_ID (2) - 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 (1) - 0x75, 0x08, // REPORT_SIZE (8) - 0x81, 0x03, // INPUT (Cnst,Var,Abs) - - 0x95, 0x06, // REPORT_COUNT (6) - 0x75, 0x08, // REPORT_SIZE (8) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x65, // LOGICAL_MAXIMUM (101) - 0x05, 0x07, // USAGE_PAGE (Keyboard) - - 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) - 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application) - 0x81, 0x00, // INPUT (Data,Ary,Abs) - 0xc0, // END_COLLECTION - -#ifdef RAWHID_ENABLED - // RAW HID - 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), // 30 - 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE), - - 0xA1, 0x01, // Collection 0x01 - 0x85, 0x03, // REPORT_ID (3) - 0x75, 0x08, // report size = 8 bits - 0x15, 0x00, // logical minimum = 0 - 0x26, 0xFF, 0x00, // logical maximum = 255 - - 0x95, 64, // report count TX - 0x09, 0x01, // usage - 0x81, 0x02, // Input (array) - - 0x95, 64, // report count RX - 0x09, 0x02, // usage - 0x91, 0x02, // Output (array) - 0xC0 // end collection -#endif -}; - -extern const HIDDescriptor _hidInterface PROGMEM; -const HIDDescriptor _hidInterface = -{ - D_INTERFACE(HID_INTERFACE,1,3,0,0), - D_HIDREPORT(sizeof(_hidReportDescriptor)), - D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01) -}; - -//================================================================================ -//================================================================================ -// Driver - -u8 _hid_protocol = 1; -u8 _hid_idle = 1; - -#define WEAK __attribute__ ((weak)) - -int WEAK HID_GetInterface(u8* interfaceNum) -{ - interfaceNum[0] += 1; // uses 1 - return USB_SendControl(TRANSFER_PGM,&_hidInterface,sizeof(_hidInterface)); -} - -int WEAK HID_GetDescriptor(int /* i */) -{ - return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,sizeof(_hidReportDescriptor)); -} - -void WEAK HID_SendReport(u8 id, const void* data, int len) -{ - USB_Send(HID_TX, &id, 1); - USB_Send(HID_TX | TRANSFER_RELEASE,data,len); -} - -bool WEAK HID_Setup(Setup& setup) -{ - u8 r = setup.bRequest; - u8 requestType = setup.bmRequestType; - if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType) - { - if (HID_GET_REPORT == r) - { - //HID_GetReport(); - return true; - } - if (HID_GET_PROTOCOL == r) - { - //Send8(_hid_protocol); // TODO - return true; - } - } - - if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType) - { - if (HID_SET_PROTOCOL == r) - { - _hid_protocol = setup.wValueL; - return true; - } - - if (HID_SET_IDLE == r) - { - _hid_idle = setup.wValueL; - return true; - } - } - return false; -} - -//================================================================================ -//================================================================================ -// Mouse - -Mouse_::Mouse_(void) : _buttons(0) -{ -} - -void Mouse_::begin(void) -{ -} - -void Mouse_::end(void) -{ -} - -void Mouse_::click(uint8_t b) -{ - _buttons = b; - move(0,0,0); - _buttons = 0; - move(0,0,0); -} - -void Mouse_::move(signed char x, signed char y, signed char wheel) -{ - u8 m[4]; - m[0] = _buttons; - m[1] = x; - m[2] = y; - m[3] = wheel; - HID_SendReport(1,m,4); -} - -void Mouse_::buttons(uint8_t b) -{ - if (b != _buttons) - { - _buttons = b; - move(0,0,0); - } -} - -void Mouse_::press(uint8_t b) -{ - buttons(_buttons | b); -} - -void Mouse_::release(uint8_t b) -{ - buttons(_buttons & ~b); -} - -bool Mouse_::isPressed(uint8_t b) -{ - if ((b & _buttons) > 0) - return true; - return false; -} - -//================================================================================ -//================================================================================ -// Keyboard - -Keyboard_::Keyboard_(void) -{ -} - -void Keyboard_::begin(void) -{ -} - -void Keyboard_::end(void) -{ -} - -void Keyboard_::sendReport(KeyReport* keys) -{ - HID_SendReport(2,keys,sizeof(KeyReport)); -} - -extern -const uint8_t _asciimap[128] PROGMEM; - -#define SHIFT 0x80 -const uint8_t _asciimap[128] = -{ - 0x00, // NUL - 0x00, // SOH - 0x00, // STX - 0x00, // ETX - 0x00, // EOT - 0x00, // ENQ - 0x00, // ACK - 0x00, // BEL - 0x2a, // BS Backspace - 0x2b, // TAB Tab - 0x28, // LF Enter - 0x00, // VT - 0x00, // FF - 0x00, // CR - 0x00, // SO - 0x00, // SI - 0x00, // DEL - 0x00, // DC1 - 0x00, // DC2 - 0x00, // DC3 - 0x00, // DC4 - 0x00, // NAK - 0x00, // SYN - 0x00, // ETB - 0x00, // CAN - 0x00, // EM - 0x00, // SUB - 0x00, // ESC - 0x00, // FS - 0x00, // GS - 0x00, // RS - 0x00, // US - - 0x2c, // ' ' - 0x1e|SHIFT, // ! - 0x34|SHIFT, // " - 0x20|SHIFT, // # - 0x21|SHIFT, // $ - 0x22|SHIFT, // % - 0x24|SHIFT, // & - 0x34, // ' - 0x26|SHIFT, // ( - 0x27|SHIFT, // ) - 0x25|SHIFT, // * - 0x2e|SHIFT, // + - 0x36, // , - 0x2d, // - - 0x37, // . - 0x38, // / - 0x27, // 0 - 0x1e, // 1 - 0x1f, // 2 - 0x20, // 3 - 0x21, // 4 - 0x22, // 5 - 0x23, // 6 - 0x24, // 7 - 0x25, // 8 - 0x26, // 9 - 0x33|SHIFT, // : - 0x33, // ; - 0x36|SHIFT, // < - 0x2e, // = - 0x37|SHIFT, // > - 0x38|SHIFT, // ? - 0x1f|SHIFT, // @ - 0x04|SHIFT, // A - 0x05|SHIFT, // B - 0x06|SHIFT, // C - 0x07|SHIFT, // D - 0x08|SHIFT, // E - 0x09|SHIFT, // F - 0x0a|SHIFT, // G - 0x0b|SHIFT, // H - 0x0c|SHIFT, // I - 0x0d|SHIFT, // J - 0x0e|SHIFT, // K - 0x0f|SHIFT, // L - 0x10|SHIFT, // M - 0x11|SHIFT, // N - 0x12|SHIFT, // O - 0x13|SHIFT, // P - 0x14|SHIFT, // Q - 0x15|SHIFT, // R - 0x16|SHIFT, // S - 0x17|SHIFT, // T - 0x18|SHIFT, // U - 0x19|SHIFT, // V - 0x1a|SHIFT, // W - 0x1b|SHIFT, // X - 0x1c|SHIFT, // Y - 0x1d|SHIFT, // Z - 0x2f, // [ - 0x31, // bslash - 0x30, // ] - 0x23|SHIFT, // ^ - 0x2d|SHIFT, // _ - 0x35, // ` - 0x04, // a - 0x05, // b - 0x06, // c - 0x07, // d - 0x08, // e - 0x09, // f - 0x0a, // g - 0x0b, // h - 0x0c, // i - 0x0d, // j - 0x0e, // k - 0x0f, // l - 0x10, // m - 0x11, // n - 0x12, // o - 0x13, // p - 0x14, // q - 0x15, // r - 0x16, // s - 0x17, // t - 0x18, // u - 0x19, // v - 0x1a, // w - 0x1b, // x - 0x1c, // y - 0x1d, // z - 0x2f|SHIFT, // - 0x31|SHIFT, // | - 0x30|SHIFT, // } - 0x35|SHIFT, // ~ - 0 // DEL -}; - -uint8_t USBPutChar(uint8_t c); - -// press() adds the specified key (printing, non-printing, or modifier) -// to the persistent key report and sends the report. Because of the way -// USB HID works, the host acts like the key remains pressed until we -// call release(), releaseAll(), or otherwise clear the report and resend. -size_t Keyboard_::press(uint8_t k) -{ - uint8_t i; - if (k >= 136) { // it's a non-printing key (not a modifier) - k = k - 136; - } else if (k >= 128) { // it's a modifier key - _keyReport.modifiers |= (1<<(k-128)); - k = 0; - } else { // it's a printing key - k = pgm_read_byte(_asciimap + k); - if (!k) { - setWriteError(); - return 0; - } - if (k & 0x80) { // it's a capital letter or other character reached with shift - _keyReport.modifiers |= 0x02; // the left shift modifier - k &= 0x7F; - } - } - - // Add k to the key report only if it's not already present - // and if there is an empty slot. - if (_keyReport.keys[0] != k && _keyReport.keys[1] != k && - _keyReport.keys[2] != k && _keyReport.keys[3] != k && - _keyReport.keys[4] != k && _keyReport.keys[5] != k) { - - for (i=0; i<6; i++) { - if (_keyReport.keys[i] == 0x00) { - _keyReport.keys[i] = k; - break; - } - } - if (i == 6) { - setWriteError(); - return 0; - } - } - sendReport(&_keyReport); - return 1; -} - -// release() takes the specified key out of the persistent key report and -// sends the report. This tells the OS the key is no longer pressed and that -// it shouldn't be repeated any more. -size_t Keyboard_::release(uint8_t k) -{ - uint8_t i; - if (k >= 136) { // it's a non-printing key (not a modifier) - k = k - 136; - } else if (k >= 128) { // it's a modifier key - _keyReport.modifiers &= ~(1<<(k-128)); - k = 0; - } else { // it's a printing key - k = pgm_read_byte(_asciimap + k); - if (!k) { - return 0; - } - if (k & 0x80) { // it's a capital letter or other character reached with shift - _keyReport.modifiers &= ~(0x02); // the left shift modifier - k &= 0x7F; - } - } - - // Test the key report to see if k is present. Clear it if it exists. - // Check all positions in case the key is present more than once (which it shouldn't be) - for (i=0; i<6; i++) { - if (0 != k && _keyReport.keys[i] == k) { - _keyReport.keys[i] = 0x00; - } - } - - sendReport(&_keyReport); - return 1; -} - -void Keyboard_::releaseAll(void) -{ - _keyReport.keys[0] = 0; - _keyReport.keys[1] = 0; - _keyReport.keys[2] = 0; - _keyReport.keys[3] = 0; - _keyReport.keys[4] = 0; - _keyReport.keys[5] = 0; - _keyReport.modifiers = 0; - sendReport(&_keyReport); -} - -size_t Keyboard_::write(uint8_t c) -{ - uint8_t p = press(c); // Keydown - release(c); // Keyup - return p; // just return the result of press() since release() almost always returns 1 -} - -#endif - -#endif /* if defined(USBCON) */ diff --git a/hardware/arduino/avr/cores/arduino/USBAPI.h b/hardware/arduino/avr/cores/arduino/USBAPI.h index 5837b3e1130..6f6d1cbc3cb 100644 --- a/hardware/arduino/avr/cores/arduino/USBAPI.h +++ b/hardware/arduino/avr/cores/arduino/USBAPI.h @@ -99,98 +99,7 @@ extern Serial_ Serial; //================================================================================ //================================================================================ -// Mouse - -#define MOUSE_LEFT 1 -#define MOUSE_RIGHT 2 -#define MOUSE_MIDDLE 4 -#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE) - -class Mouse_ -{ -private: - uint8_t _buttons; - void buttons(uint8_t b); -public: - Mouse_(void); - void begin(void); - void end(void); - void click(uint8_t b = MOUSE_LEFT); - void move(signed char x, signed char y, signed char wheel = 0); - void press(uint8_t b = MOUSE_LEFT); // press LEFT by default - void release(uint8_t b = MOUSE_LEFT); // release LEFT by default - bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default -}; -extern Mouse_ Mouse; - -//================================================================================ -//================================================================================ -// Keyboard - -#define KEY_LEFT_CTRL 0x80 -#define KEY_LEFT_SHIFT 0x81 -#define KEY_LEFT_ALT 0x82 -#define KEY_LEFT_GUI 0x83 -#define KEY_RIGHT_CTRL 0x84 -#define KEY_RIGHT_SHIFT 0x85 -#define KEY_RIGHT_ALT 0x86 -#define KEY_RIGHT_GUI 0x87 - -#define KEY_UP_ARROW 0xDA -#define KEY_DOWN_ARROW 0xD9 -#define KEY_LEFT_ARROW 0xD8 -#define KEY_RIGHT_ARROW 0xD7 -#define KEY_BACKSPACE 0xB2 -#define KEY_TAB 0xB3 -#define KEY_RETURN 0xB0 -#define KEY_ESC 0xB1 -#define KEY_INSERT 0xD1 -#define KEY_DELETE 0xD4 -#define KEY_PAGE_UP 0xD3 -#define KEY_PAGE_DOWN 0xD6 -#define KEY_HOME 0xD2 -#define KEY_END 0xD5 -#define KEY_CAPS_LOCK 0xC1 -#define KEY_F1 0xC2 -#define KEY_F2 0xC3 -#define KEY_F3 0xC4 -#define KEY_F4 0xC5 -#define KEY_F5 0xC6 -#define KEY_F6 0xC7 -#define KEY_F7 0xC8 -#define KEY_F8 0xC9 -#define KEY_F9 0xCA -#define KEY_F10 0xCB -#define KEY_F11 0xCC -#define KEY_F12 0xCD - -// Low level key report: up to 6 keys and shift, ctrl etc at once -typedef struct -{ - uint8_t modifiers; - uint8_t reserved; - uint8_t keys[6]; -} KeyReport; - -class Keyboard_ : public Print -{ -private: - KeyReport _keyReport; - void sendReport(KeyReport* keys); -public: - Keyboard_(void); - void begin(void); - void end(void); - virtual size_t write(uint8_t k); - virtual size_t press(uint8_t k); - virtual size_t release(uint8_t k); - virtual void releaseAll(void); -}; -extern Keyboard_ Keyboard; - -//================================================================================ -//================================================================================ -// Low level API +// Low level API typedef struct { @@ -202,15 +111,6 @@ typedef struct uint16_t wLength; } Setup; -//================================================================================ -//================================================================================ -// HID 'Driver' - -int HID_GetInterface(uint8_t* interfaceNum); -int HID_GetDescriptor(int i); -bool HID_Setup(Setup& setup); -void HID_SendReport(uint8_t id, const void* data, int len); - //================================================================================ //================================================================================ // MSC 'Driver' diff --git a/hardware/arduino/avr/cores/arduino/USBCore.h b/hardware/arduino/avr/cores/arduino/USBCore.h index 8d13806896f..bee5a3ee5fb 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.h +++ b/hardware/arduino/avr/cores/arduino/USBCore.h @@ -257,26 +257,6 @@ typedef struct EndpointDescriptor out; } MSCDescriptor; -typedef struct -{ - u8 len; // 9 - u8 dtype; // 0x21 - u8 addr; - u8 versionL; // 0x101 - u8 versionH; // 0x101 - u8 country; - u8 desctype; // 0x22 report - u8 descLenL; - u8 descLenH; -} HIDDescDescriptor; - -typedef struct -{ - InterfaceDescriptor hid; - HIDDescDescriptor desc; - EndpointDescriptor in; -} HIDDescriptor; - #define D_DEVICE(_class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs) \ { 18, 1, 0x200, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs } @@ -293,9 +273,6 @@ typedef struct #define D_IAD(_firstInterface, _count, _class, _subClass, _protocol) \ { 8, 11, _firstInterface, _count, _class, _subClass, _protocol, 0 } -#define D_HIDREPORT(_descriptorLength) \ - { 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength, 0 } - #define D_CDCCS(_subtype,_d0,_d1) { 5, 0x24, _subtype, _d0, _d1 } #define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 } diff --git a/hardware/arduino/avr/cores/arduino/USBDesc.h b/hardware/arduino/avr/cores/arduino/USBDesc.h index 900713e0f92..b3defa5998a 100644 --- a/hardware/arduino/avr/cores/arduino/USBDesc.h +++ b/hardware/arduino/avr/cores/arduino/USBDesc.h @@ -28,14 +28,6 @@ #define CDC_ENPOINT_COUNT 0 #endif -#ifdef HID_ENABLED -#define HID_INTERFACE_COUNT 1 -#define HID_ENPOINT_COUNT 1 -#else -#define HID_INTERFACE_COUNT 0 -#define HID_ENPOINT_COUNT 0 -#endif - #define CDC_ACM_INTERFACE 0 // CDC ACM #define CDC_DATA_INTERFACE 1 // CDC Data #define CDC_FIRST_ENDPOINT 1 @@ -43,10 +35,6 @@ #define CDC_ENDPOINT_OUT (CDC_FIRST_ENDPOINT+1) #define CDC_ENDPOINT_IN (CDC_FIRST_ENDPOINT+2) -#define HID_INTERFACE (CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT) // HID Interface -#define HID_FIRST_ENDPOINT (CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT) -#define HID_ENDPOINT_INT (HID_FIRST_ENDPOINT) - #define INTERFACE_COUNT (MSC_INTERFACE + MSC_INTERFACE_COUNT) #ifdef CDC_ENABLED @@ -54,10 +42,6 @@ #define CDC_TX CDC_ENDPOINT_IN #endif -#ifdef HID_ENABLED -#define HID_TX HID_ENDPOINT_INT -#endif - #define IMANUFACTURER 1 #define IPRODUCT 2 From 5ee69a70eebabebdbeace868115347e8f13bc34b Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 5 Jun 2015 17:34:56 +0200 Subject: [PATCH 02/39] Move EP defines to header --- hardware/arduino/avr/cores/arduino/USBAPI.h | 8 ++++++++ hardware/arduino/avr/cores/arduino/USBCore.cpp | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/USBAPI.h b/hardware/arduino/avr/cores/arduino/USBAPI.h index 6f6d1cbc3cb..d8ad98debd7 100644 --- a/hardware/arduino/avr/cores/arduino/USBAPI.h +++ b/hardware/arduino/avr/cores/arduino/USBAPI.h @@ -41,6 +41,14 @@ typedef unsigned long u32; //================================================================================ // USB +#define EP_TYPE_CONTROL 0x00 +#define EP_TYPE_BULK_IN 0x81 +#define EP_TYPE_BULK_OUT 0x80 +#define EP_TYPE_INTERRUPT_IN 0xC1 +#define EP_TYPE_INTERRUPT_OUT 0xC0 +#define EP_TYPE_ISOCHRONOUS_IN 0x41 +#define EP_TYPE_ISOCHRONOUS_OUT 0x40 + class USBDevice_ { public: diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index b4f7bed7e86..54cd2b478a1 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -20,14 +20,6 @@ #if defined(USBCON) -#define EP_TYPE_CONTROL 0x00 -#define EP_TYPE_BULK_IN 0x81 -#define EP_TYPE_BULK_OUT 0x80 -#define EP_TYPE_INTERRUPT_IN 0xC1 -#define EP_TYPE_INTERRUPT_OUT 0xC0 -#define EP_TYPE_ISOCHRONOUS_IN 0x41 -#define EP_TYPE_ISOCHRONOUS_OUT 0x40 - /** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */ #define TX_RX_LED_PULSE_MS 100 volatile u8 TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */ From 2c5dd2029807a7d3fe76ed86a81643db088b5c2c Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 5 Jun 2015 17:36:40 +0200 Subject: [PATCH 03/39] Use generic composite device descriptor --- hardware/arduino/avr/cores/arduino/USBCore.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index 54cd2b478a1..bac169a065c 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -33,6 +33,7 @@ extern const u8 STRING_PRODUCT[] PROGMEM; extern const u8 STRING_MANUFACTURER[] PROGMEM; extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM; extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM; +extern const DeviceDescriptor USB_DeviceDescriptorB PROGMEM; const u16 STRING_LANGUAGE[2] = { (3<<8) | (2+2), @@ -77,6 +78,9 @@ const DeviceDescriptor USB_DeviceDescriptor = const DeviceDescriptor USB_DeviceDescriptorA = D_DEVICE(DEVICE_CLASS,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1); +const DeviceDescriptor USB_DeviceDescriptorB = + D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1); + //================================================================== //================================================================== @@ -489,7 +493,7 @@ bool SendDescriptor(Setup& setup) { if (setup.wLength == 8) _cdcComposite = 1; - desc_addr = _cdcComposite ? (const u8*)&USB_DeviceDescriptorA : (const u8*)&USB_DeviceDescriptor; + desc_addr = _cdcComposite ? (const u8*)&USB_DeviceDescriptorB : (const u8*)&USB_DeviceDescriptor; } else if (USB_STRING_DESCRIPTOR_TYPE == t) { From 1f534eac3512dd3739630f4f731719233de0d89c Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 5 Jun 2015 17:49:06 +0200 Subject: [PATCH 04/39] move _initEndpoints from PROGMEM to RAM --- hardware/arduino/avr/cores/arduino/USBCore.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index bac169a065c..a866d958c7f 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -313,8 +313,7 @@ int USB_Send(u8 ep, const void* d, int len) return r; } -extern const u8 _initEndpoints[] PROGMEM; -const u8 _initEndpoints[] = +u8 _initEndpoints[] = { 0, @@ -344,11 +343,11 @@ void InitEP(u8 index, u8 type, u8 size) static void InitEndpoints() { - for (u8 i = 1; i < sizeof(_initEndpoints); i++) + for (u8 i = 1; i < sizeof(_initEndpoints) && _initEndpoints[i] != 0; i++) { UENUM = i; UECONX = 1; - UECFG0X = pgm_read_byte(_initEndpoints+i); + UECFG0X = _initEndpoints[i]; UECFG1X = EP_DOUBLE_64; } UERST = 0x7E; // And reset them From 1aec25b855be67ea871d02672a6289c4815146a4 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 5 Jun 2015 17:50:19 +0200 Subject: [PATCH 05/39] add PluggableUSB module --- .../avr/cores/arduino/PluggableUSB.cpp | 86 +++++++++++++++++++ .../arduino/avr/cores/arduino/PluggableUSB.h | 55 ++++++++++++ .../arduino/avr/cores/arduino/USBCore.cpp | 29 ++++--- hardware/arduino/avr/cores/arduino/USBCore.h | 2 + hardware/arduino/avr/cores/arduino/USBDesc.h | 2 +- 5 files changed, 163 insertions(+), 11 deletions(-) create mode 100644 hardware/arduino/avr/cores/arduino/PluggableUSB.cpp create mode 100644 hardware/arduino/avr/cores/arduino/PluggableUSB.h diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp new file mode 100644 index 00000000000..e389c354173 --- /dev/null +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -0,0 +1,86 @@ +/* + PluggableUSB.cpp + Copyright (c) 2015 Arduino LLC + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "USBAPI.h" +#include "PluggableUSB.h" + +#if defined(USBCON) +#ifdef PLUGGABLE_USB_ENABLED + +#define MAX_MODULES 6 + +static u8 startIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; +static u8 firstEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; + +static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; +static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; + +extern u8 _initEndpoints[]; + +PUSBCallbacks cbs[MAX_MODULES]; +u8 modules_count = 0; + +int PUSB_GetInterface(u8* interfaceNum) +{ + int ret = 0; + for (u8 i=0; i= MAX_MODULES) { + return 0; + } + cbs[modules_count] = *cb; + + *interface = lastIf; + lastIf++; + for ( u8 i = 0; i< cb->numEndpoints; i++) { + _initEndpoints[lastEp] = cb->endpointType[i]; + lastEp++; + } + modules_count++; + return lastEp-1; + // restart USB layer??? +} + +#endif + +#endif /* if defined(USBCON) */ \ No newline at end of file diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h new file mode 100644 index 00000000000..7b3722c99c2 --- /dev/null +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -0,0 +1,55 @@ +/* + PluggableUSB.h + Copyright (c) 2015 Arduino LLC + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef PUSB_h +#define PUSB_h + +#include "USBAPI.h" +#include + +#if defined(USBCON) + +typedef struct +{ + bool (*setup)(Setup& setup, u8 i); + int (*getInterface)(u8* interfaceNum); + int (*getDescriptor)(int t); + int numEndpoints; + u8 endpointType[6]; +} PUSBCallbacks; + +typedef struct +{ + u8 interface; + u8 firstEndpoint; +} PUSBReturn; + +int PUSB_AddFunction(PUSBCallbacks *cb, u8 *interface); + +int PUSB_GetInterface(u8* interfaceNum); + +int PUSB_GetDescriptor(int t); + +bool PUSB_Setup(Setup& setup, u8 i); + +void PUSB_Begin(); + +#endif + +#endif diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index a866d958c7f..16e4a052206 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -17,6 +17,7 @@ */ #include "USBAPI.h" +#include "PluggableUSB.h" #if defined(USBCON) @@ -323,8 +324,14 @@ u8 _initEndpoints[] = EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN #endif -#ifdef HID_ENABLED - EP_TYPE_INTERRUPT_IN // HID_ENDPOINT_INT +#ifdef PLUGGABLE_USB_ENABLED + //allocate 6 endpoints and remove const so they can be changed by the user + 0, + 0, + 0, + 0, + 0, + 0, #endif }; @@ -365,9 +372,8 @@ bool ClassInterfaceRequest(Setup& setup) return CDC_Setup(setup); #endif -#ifdef HID_ENABLED - if (HID_INTERFACE == i) - return HID_Setup(setup); +#ifdef PLUGGABLE_USB_ENABLED + return PUSB_Setup(setup, i); #endif return false; } @@ -447,8 +453,8 @@ int SendInterfaces() total = CDC_GetInterface(&interfaces); #endif -#ifdef HID_ENABLED - total += HID_GetInterface(&interfaces); +#ifdef PLUGGABLE_USB_ENABLED + PUSB_GetInterface(&interfaces); #endif return interfaces; @@ -477,14 +483,17 @@ u8 _cdcComposite = 0; static bool SendDescriptor(Setup& setup) { + int ret; u8 t = setup.wValueH; if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t) return SendConfiguration(setup.wLength); InitControl(setup.wLength); -#ifdef HID_ENABLED - if (HID_REPORT_DESCRIPTOR_TYPE == t) - return HID_GetDescriptor(t); +#ifdef PLUGGABLE_USB_ENABLED + ret = PUSB_GetDescriptor(t); + if (ret != 0) { + return (ret > 0 ? true : false); + } #endif const u8* desc_addr = 0; diff --git a/hardware/arduino/avr/cores/arduino/USBCore.h b/hardware/arduino/avr/cores/arduino/USBCore.h index bee5a3ee5fb..cd2191c8658 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.h +++ b/hardware/arduino/avr/cores/arduino/USBCore.h @@ -18,6 +18,8 @@ #ifndef __USBCORE_H__ #define __USBCORE_H__ +#include "USBAPI.h" + // Standard requests #define GET_STATUS 0 #define CLEAR_FEATURE 1 diff --git a/hardware/arduino/avr/cores/arduino/USBDesc.h b/hardware/arduino/avr/cores/arduino/USBDesc.h index b3defa5998a..3a98f9d2436 100644 --- a/hardware/arduino/avr/cores/arduino/USBDesc.h +++ b/hardware/arduino/avr/cores/arduino/USBDesc.h @@ -17,7 +17,7 @@ */ #define CDC_ENABLED -#define HID_ENABLED +#define PLUGGABLE_USB_ENABLED #ifdef CDC_ENABLED From ec43b6c8292508baa0d20bb03741008088d9bb36 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 5 Jun 2015 17:51:09 +0200 Subject: [PATCH 06/39] remove useless variable --- hardware/arduino/avr/cores/arduino/USBCore.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index 16e4a052206..5f70d865032 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -446,11 +446,10 @@ int USB_RecvControl(void* d, int len) int SendInterfaces() { - int total = 0; u8 interfaces = 0; #ifdef CDC_ENABLED - total = CDC_GetInterface(&interfaces); + CDC_GetInterface(&interfaces); #endif #ifdef PLUGGABLE_USB_ENABLED From b2a6b61a2f05dcaf979fa9f4fd8a9cdfbe788cf4 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 5 Jun 2015 17:51:44 +0200 Subject: [PATCH 07/39] add weak setupUSB() hook override this function to insert additional USB endpoints --- hardware/arduino/avr/cores/arduino/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hardware/arduino/avr/cores/arduino/main.cpp b/hardware/arduino/avr/cores/arduino/main.cpp index 72074de4b16..f4346ece0a0 100644 --- a/hardware/arduino/avr/cores/arduino/main.cpp +++ b/hardware/arduino/avr/cores/arduino/main.cpp @@ -27,6 +27,9 @@ int atexit(void (* /*func*/ )()) { return 0; } void initVariant() __attribute__((weak)); void initVariant() { } +void setupUSB() __attribute__((weak)); +void setupUSB() { } + int main(void) { init(); @@ -34,6 +37,7 @@ int main(void) initVariant(); #if defined(USBCON) + setupUSB(); USBDevice.attach(); #endif From 018fb96a3959db502a34bcb4dddc75ac9bd327e9 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 5 Jun 2015 17:54:46 +0200 Subject: [PATCH 08/39] move HID to general external library add pluggableUSB hooks and HID singleton initialize with HID.begin() in setupUSB() --- libraries/HID/HID.cpp | 560 ++++++++++++++++++++++++++++++++++++++++++ libraries/HID/HID.h | 167 +++++++++++++ 2 files changed, 727 insertions(+) create mode 100644 libraries/HID/HID.cpp create mode 100644 libraries/HID/HID.h diff --git a/libraries/HID/HID.cpp b/libraries/HID/HID.cpp new file mode 100644 index 00000000000..f49c90e8d23 --- /dev/null +++ b/libraries/HID/HID.cpp @@ -0,0 +1,560 @@ +/* Copyright (c) 2015, Arduino LLC +** +** Original code (pre-library): Copyright (c) 2011, Peter Barrett +** +** Permission to use, copy, modify, and/or distribute this software for +** any purpose with or without fee is hereby granted, provided that the +** above copyright notice and this permission notice appear in all copies. +** +** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR +** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES +** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +** SOFTWARE. +*/ + +#include "PluggableUSB.h" +#include "HID.h" + +#if defined(USBCON) + +//#define RAWHID_ENABLED + +// Singletons for mouse and keyboard + +Mouse_ Mouse; +Keyboard_ Keyboard; +HID_ HID; + +//================================================================================ +//================================================================================ + +// HID report descriptor + +#define LSB(_x) ((_x) & 0xFF) +#define MSB(_x) ((_x) >> 8) + +#define RAWHID_USAGE_PAGE 0xFFC0 +#define RAWHID_USAGE 0x0C00 +#define RAWHID_TX_SIZE 64 +#define RAWHID_RX_SIZE 64 + +static u8 HID_INTERFACE; +static u8 HID_FIRST_ENDPOINT; +static u8 HID_ENDPOINT_INT; + +static PUSBCallbacks cb; + +extern const u8 _hidReportDescriptor[] PROGMEM; +const u8 _hidReportDescriptor[] = { + + // Mouse + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54 + 0x09, 0x02, // USAGE (Mouse) + 0xa1, 0x01, // COLLECTION (Application) + 0x09, 0x01, // USAGE (Pointer) + 0xa1, 0x00, // COLLECTION (Physical) + 0x85, 0x01, // REPORT_ID (1) + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) + 0x29, 0x03, // USAGE_MAXIMUM (Button 3) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x95, 0x03, // REPORT_COUNT (3) + 0x75, 0x01, // REPORT_SIZE (1) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x95, 0x01, // REPORT_COUNT (1) + 0x75, 0x05, // REPORT_SIZE (5) + 0x81, 0x03, // INPUT (Cnst,Var,Abs) + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x30, // USAGE (X) + 0x09, 0x31, // USAGE (Y) + 0x09, 0x38, // USAGE (Wheel) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x03, // REPORT_COUNT (3) + 0x81, 0x06, // INPUT (Data,Var,Rel) + 0xc0, // END_COLLECTION + 0xc0, // END_COLLECTION + + // Keyboard + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47 + 0x09, 0x06, // USAGE (Keyboard) + 0xa1, 0x01, // COLLECTION (Application) + 0x85, 0x02, // REPORT_ID (2) + 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 (1) + 0x75, 0x08, // REPORT_SIZE (8) + 0x81, 0x03, // INPUT (Cnst,Var,Abs) + + 0x95, 0x06, // REPORT_COUNT (6) + 0x75, 0x08, // REPORT_SIZE (8) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x65, // LOGICAL_MAXIMUM (101) + 0x05, 0x07, // USAGE_PAGE (Keyboard) + + 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) + 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application) + 0x81, 0x00, // INPUT (Data,Ary,Abs) + 0xc0, // END_COLLECTION + +#ifdef RAWHID_ENABLED + // RAW HID + 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), // 30 + 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE), + + 0xA1, 0x01, // Collection 0x01 + 0x85, 0x03, // REPORT_ID (3) + 0x75, 0x08, // report size = 8 bits + 0x15, 0x00, // logical minimum = 0 + 0x26, 0xFF, 0x00, // logical maximum = 255 + + 0x95, 64, // report count TX + 0x09, 0x01, // usage + 0x81, 0x02, // Input (array) + + 0x95, 64, // report count RX + 0x09, 0x02, // usage + 0x91, 0x02, // Output (array) + 0xC0 // end collection +#endif +}; + +HIDDescriptor _hidInterface; + +//================================================================================ +//================================================================================ +// Driver + +u8 _hid_protocol = 1; +u8 _hid_idle = 1; + +#define WEAK __attribute__ ((weak)) + +int WEAK HID_GetInterface(u8* interfaceNum) +{ + interfaceNum[0] += 1; // uses 1 + return USB_SendControl(0,&_hidInterface,sizeof(_hidInterface)); +} + +int WEAK HID_GetDescriptor(int t) +{ + if (HID_REPORT_DESCRIPTOR_TYPE == t) { + return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,sizeof(_hidReportDescriptor)); + } else { + return 0; + } +} + +void WEAK HID_SendReport(u8 id, const void* data, int len) +{ + USB_Send(HID_TX, &id, 1); + USB_Send(HID_TX | TRANSFER_RELEASE,data,len); +} + +bool WEAK HID_Setup(Setup& setup, u8 i) +{ + if (HID_INTERFACE != i) { + return false; + } else { + u8 r = setup.bRequest; + u8 requestType = setup.bmRequestType; + if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType) + { + if (HID_GET_REPORT == r) + { + //HID_GetReport(); + return true; + } + if (HID_GET_PROTOCOL == r) + { + //Send8(_hid_protocol); // TODO + return true; + } + } + + if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType) + { + if (HID_SET_PROTOCOL == r) + { + _hid_protocol = setup.wValueL; + return true; + } + + if (HID_SET_IDLE == r) + { + _hid_idle = setup.wValueL; + return true; + } + } + return false; + } +} + +// to be called by begin(), will trigger USB disconnection and reconnection +int HID_Plug(void) +{ + u8 interface; + u8 res; + + cb.setup = &HID_Setup; + cb.getInterface = &HID_GetInterface; + cb.getDescriptor = &HID_GetDescriptor; + cb.numEndpoints = 1; + cb.endpointType[0] = EP_TYPE_INTERRUPT_IN; + res = PUSB_AddFunction(&cb, &interface); + HID_INTERFACE = interface; + HID_FIRST_ENDPOINT = res; + HID_ENDPOINT_INT = res; + + _hidInterface = + { + D_INTERFACE(HID_INTERFACE,1,3,0,0), + D_HIDREPORT(sizeof(_hidReportDescriptor)), + D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01) + }; + + return res; +} + +HID_::HID_(void) +{ +} + +int HID_::begin(void) +{ + return HID_Plug(); +} + +//================================================================================ +//================================================================================ +// Mouse + +Mouse_::Mouse_(void) : _buttons(0) +{ +} + +void Mouse_::begin(void) +{ +} + +void Mouse_::end(void) +{ +} + +void Mouse_::click(uint8_t b) +{ + _buttons = b; + move(0,0,0); + _buttons = 0; + move(0,0,0); +} + +void Mouse_::move(signed char x, signed char y, signed char wheel) +{ + u8 m[4]; + m[0] = _buttons; + m[1] = x; + m[2] = y; + m[3] = wheel; + HID_SendReport(1,m,4); +} + +void Mouse_::buttons(uint8_t b) +{ + if (b != _buttons) + { + _buttons = b; + move(0,0,0); + } +} + +void Mouse_::press(uint8_t b) +{ + buttons(_buttons | b); +} + +void Mouse_::release(uint8_t b) +{ + buttons(_buttons & ~b); +} + +bool Mouse_::isPressed(uint8_t b) +{ + if ((b & _buttons) > 0) + return true; + return false; +} + +//================================================================================ +//================================================================================ +// Keyboard + +Keyboard_::Keyboard_(void) +{ +} + +void Keyboard_::begin(void) +{ +} + +void Keyboard_::end(void) +{ +} + +void Keyboard_::sendReport(KeyReport* keys) +{ + HID_SendReport(2,keys,sizeof(KeyReport)); +} + +extern +const uint8_t _asciimap[128] PROGMEM; + +#define SHIFT 0x80 +const uint8_t _asciimap[128] = +{ + 0x00, // NUL + 0x00, // SOH + 0x00, // STX + 0x00, // ETX + 0x00, // EOT + 0x00, // ENQ + 0x00, // ACK + 0x00, // BEL + 0x2a, // BS Backspace + 0x2b, // TAB Tab + 0x28, // LF Enter + 0x00, // VT + 0x00, // FF + 0x00, // CR + 0x00, // SO + 0x00, // SI + 0x00, // DEL + 0x00, // DC1 + 0x00, // DC2 + 0x00, // DC3 + 0x00, // DC4 + 0x00, // NAK + 0x00, // SYN + 0x00, // ETB + 0x00, // CAN + 0x00, // EM + 0x00, // SUB + 0x00, // ESC + 0x00, // FS + 0x00, // GS + 0x00, // RS + 0x00, // US + + 0x2c, // ' ' + 0x1e|SHIFT, // ! + 0x34|SHIFT, // " + 0x20|SHIFT, // # + 0x21|SHIFT, // $ + 0x22|SHIFT, // % + 0x24|SHIFT, // & + 0x34, // ' + 0x26|SHIFT, // ( + 0x27|SHIFT, // ) + 0x25|SHIFT, // * + 0x2e|SHIFT, // + + 0x36, // , + 0x2d, // - + 0x37, // . + 0x38, // / + 0x27, // 0 + 0x1e, // 1 + 0x1f, // 2 + 0x20, // 3 + 0x21, // 4 + 0x22, // 5 + 0x23, // 6 + 0x24, // 7 + 0x25, // 8 + 0x26, // 9 + 0x33|SHIFT, // : + 0x33, // ; + 0x36|SHIFT, // < + 0x2e, // = + 0x37|SHIFT, // > + 0x38|SHIFT, // ? + 0x1f|SHIFT, // @ + 0x04|SHIFT, // A + 0x05|SHIFT, // B + 0x06|SHIFT, // C + 0x07|SHIFT, // D + 0x08|SHIFT, // E + 0x09|SHIFT, // F + 0x0a|SHIFT, // G + 0x0b|SHIFT, // H + 0x0c|SHIFT, // I + 0x0d|SHIFT, // J + 0x0e|SHIFT, // K + 0x0f|SHIFT, // L + 0x10|SHIFT, // M + 0x11|SHIFT, // N + 0x12|SHIFT, // O + 0x13|SHIFT, // P + 0x14|SHIFT, // Q + 0x15|SHIFT, // R + 0x16|SHIFT, // S + 0x17|SHIFT, // T + 0x18|SHIFT, // U + 0x19|SHIFT, // V + 0x1a|SHIFT, // W + 0x1b|SHIFT, // X + 0x1c|SHIFT, // Y + 0x1d|SHIFT, // Z + 0x2f, // [ + 0x31, // bslash + 0x30, // ] + 0x23|SHIFT, // ^ + 0x2d|SHIFT, // _ + 0x35, // ` + 0x04, // a + 0x05, // b + 0x06, // c + 0x07, // d + 0x08, // e + 0x09, // f + 0x0a, // g + 0x0b, // h + 0x0c, // i + 0x0d, // j + 0x0e, // k + 0x0f, // l + 0x10, // m + 0x11, // n + 0x12, // o + 0x13, // p + 0x14, // q + 0x15, // r + 0x16, // s + 0x17, // t + 0x18, // u + 0x19, // v + 0x1a, // w + 0x1b, // x + 0x1c, // y + 0x1d, // z + 0x2f|SHIFT, // + 0x31|SHIFT, // | + 0x30|SHIFT, // } + 0x35|SHIFT, // ~ + 0 // DEL +}; + +uint8_t USBPutChar(uint8_t c); + +// press() adds the specified key (printing, non-printing, or modifier) +// to the persistent key report and sends the report. Because of the way +// USB HID works, the host acts like the key remains pressed until we +// call release(), releaseAll(), or otherwise clear the report and resend. +size_t Keyboard_::press(uint8_t k) +{ + uint8_t i; + if (k >= 136) { // it's a non-printing key (not a modifier) + k = k - 136; + } else if (k >= 128) { // it's a modifier key + _keyReport.modifiers |= (1<<(k-128)); + k = 0; + } else { // it's a printing key + k = pgm_read_byte(_asciimap + k); + if (!k) { + setWriteError(); + return 0; + } + if (k & 0x80) { // it's a capital letter or other character reached with shift + _keyReport.modifiers |= 0x02; // the left shift modifier + k &= 0x7F; + } + } + + // Add k to the key report only if it's not already present + // and if there is an empty slot. + if (_keyReport.keys[0] != k && _keyReport.keys[1] != k && + _keyReport.keys[2] != k && _keyReport.keys[3] != k && + _keyReport.keys[4] != k && _keyReport.keys[5] != k) { + + for (i=0; i<6; i++) { + if (_keyReport.keys[i] == 0x00) { + _keyReport.keys[i] = k; + break; + } + } + if (i == 6) { + setWriteError(); + return 0; + } + } + sendReport(&_keyReport); + return 1; +} + +// release() takes the specified key out of the persistent key report and +// sends the report. This tells the OS the key is no longer pressed and that +// it shouldn't be repeated any more. +size_t Keyboard_::release(uint8_t k) +{ + uint8_t i; + if (k >= 136) { // it's a non-printing key (not a modifier) + k = k - 136; + } else if (k >= 128) { // it's a modifier key + _keyReport.modifiers &= ~(1<<(k-128)); + k = 0; + } else { // it's a printing key + k = pgm_read_byte(_asciimap + k); + if (!k) { + return 0; + } + if (k & 0x80) { // it's a capital letter or other character reached with shift + _keyReport.modifiers &= ~(0x02); // the left shift modifier + k &= 0x7F; + } + } + + // Test the key report to see if k is present. Clear it if it exists. + // Check all positions in case the key is present more than once (which it shouldn't be) + for (i=0; i<6; i++) { + if (0 != k && _keyReport.keys[i] == k) { + _keyReport.keys[i] = 0x00; + } + } + + sendReport(&_keyReport); + return 1; +} + +void Keyboard_::releaseAll(void) +{ + _keyReport.keys[0] = 0; + _keyReport.keys[1] = 0; + _keyReport.keys[2] = 0; + _keyReport.keys[3] = 0; + _keyReport.keys[4] = 0; + _keyReport.keys[5] = 0; + _keyReport.modifiers = 0; + sendReport(&_keyReport); +} + +size_t Keyboard_::write(uint8_t c) +{ + uint8_t p = press(c); // Keydown + release(c); // Keyup + return p; // just return the result of press() since release() almost always returns 1 +} + +#endif /* if defined(USBCON) */ diff --git a/libraries/HID/HID.h b/libraries/HID/HID.h new file mode 100644 index 00000000000..cb30ec7cf54 --- /dev/null +++ b/libraries/HID/HID.h @@ -0,0 +1,167 @@ +/* + HID.h + + Copyright (c) 2015, Arduino LLC + Original code (pre-library): Copyright (c) 2011, Peter Barrett + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef HID_h +#define HID_h + +#include + +#if defined(USBCON) + +//================================================================================ +//================================================================================ +// Mouse + +#define MOUSE_LEFT 1 +#define MOUSE_RIGHT 2 +#define MOUSE_MIDDLE 4 +#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE) + +class Mouse_ +{ +private: + uint8_t _buttons; + void buttons(uint8_t b); +public: + Mouse_(void); + void begin(void); + void end(void); + void click(uint8_t b = MOUSE_LEFT); + void move(signed char x, signed char y, signed char wheel = 0); + void press(uint8_t b = MOUSE_LEFT); // press LEFT by default + void release(uint8_t b = MOUSE_LEFT); // release LEFT by default + bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default +}; +extern Mouse_ Mouse; + +//================================================================================ +//================================================================================ +// Keyboard + +#define KEY_LEFT_CTRL 0x80 +#define KEY_LEFT_SHIFT 0x81 +#define KEY_LEFT_ALT 0x82 +#define KEY_LEFT_GUI 0x83 +#define KEY_RIGHT_CTRL 0x84 +#define KEY_RIGHT_SHIFT 0x85 +#define KEY_RIGHT_ALT 0x86 +#define KEY_RIGHT_GUI 0x87 + +#define KEY_UP_ARROW 0xDA +#define KEY_DOWN_ARROW 0xD9 +#define KEY_LEFT_ARROW 0xD8 +#define KEY_RIGHT_ARROW 0xD7 +#define KEY_BACKSPACE 0xB2 +#define KEY_TAB 0xB3 +#define KEY_RETURN 0xB0 +#define KEY_ESC 0xB1 +#define KEY_INSERT 0xD1 +#define KEY_DELETE 0xD4 +#define KEY_PAGE_UP 0xD3 +#define KEY_PAGE_DOWN 0xD6 +#define KEY_HOME 0xD2 +#define KEY_END 0xD5 +#define KEY_CAPS_LOCK 0xC1 +#define KEY_F1 0xC2 +#define KEY_F2 0xC3 +#define KEY_F3 0xC4 +#define KEY_F4 0xC5 +#define KEY_F5 0xC6 +#define KEY_F6 0xC7 +#define KEY_F7 0xC8 +#define KEY_F8 0xC9 +#define KEY_F9 0xCA +#define KEY_F10 0xCB +#define KEY_F11 0xCC +#define KEY_F12 0xCD + +// Low level key report: up to 6 keys and shift, ctrl etc at once +typedef struct +{ + uint8_t modifiers; + uint8_t reserved; + uint8_t keys[6]; +} KeyReport; + +class Keyboard_ : public Print +{ +private: + KeyReport _keyReport; + void sendReport(KeyReport* keys); +public: + Keyboard_(void); + void begin(void); + void end(void); + virtual size_t write(uint8_t k); + virtual size_t press(uint8_t k); + virtual size_t release(uint8_t k); + virtual void releaseAll(void); +}; +extern Keyboard_ Keyboard; + +//================================================================================ +//================================================================================ +// HID 'Driver' + +class HID_ +{ +public: + HID_(void); + int begin(void); +}; + +int HID_Plug(void); +int HID_GetInterface(u8* interfaceNum); +int HID_GetDescriptor(int t); +bool HID_Setup(Setup& setup, u8 i); +void HID_SendReport(uint8_t id, const void* data, int len); + +extern HID_ HID; + +typedef struct +{ + u8 len; // 9 + u8 dtype; // 0x21 + u8 addr; + u8 versionL; // 0x101 + u8 versionH; // 0x101 + u8 country; + u8 desctype; // 0x22 report + u8 descLenL; + u8 descLenH; +} HIDDescDescriptor; + +typedef struct +{ + InterfaceDescriptor hid; + HIDDescDescriptor desc; + EndpointDescriptor in; +} HIDDescriptor; + +#define HID_TX HID_ENDPOINT_INT + +#define D_HIDREPORT(_descriptorLength) \ + { 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength, 0 } + + +#endif + +#endif \ No newline at end of file From 91ccab4f09dedd789a81eaa7f3c7bf3028e906f5 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 8 Jun 2015 09:39:15 +0200 Subject: [PATCH 09/39] make CDC function non removable --- hardware/arduino/avr/cores/arduino/CDC.cpp | 2 -- hardware/arduino/avr/cores/arduino/USBCore.cpp | 12 ------------ hardware/arduino/avr/cores/arduino/USBDesc.h | 8 -------- 3 files changed, 22 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/CDC.cpp b/hardware/arduino/avr/cores/arduino/CDC.cpp index 5d4f2a08086..2ea1353d28b 100644 --- a/hardware/arduino/avr/cores/arduino/CDC.cpp +++ b/hardware/arduino/avr/cores/arduino/CDC.cpp @@ -20,7 +20,6 @@ #include #if defined(USBCON) -#ifdef CDC_ENABLED typedef struct { @@ -207,5 +206,4 @@ Serial_::operator bool() { Serial_ Serial; -#endif #endif /* if defined(USBCON) */ diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index 5f70d865032..53c71d905f6 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -66,11 +66,7 @@ const u8 STRING_PRODUCT[] PROGMEM = USB_PRODUCT; const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER; -#ifdef CDC_ENABLED #define DEVICE_CLASS 0x02 -#else -#define DEVICE_CLASS 0x00 -#endif // DEVICE DESCRIPTOR const DeviceDescriptor USB_DeviceDescriptor = @@ -318,11 +314,9 @@ u8 _initEndpoints[] = { 0, -#ifdef CDC_ENABLED EP_TYPE_INTERRUPT_IN, // CDC_ENDPOINT_ACM EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN -#endif #ifdef PLUGGABLE_USB_ENABLED //allocate 6 endpoints and remove const so they can be changed by the user @@ -367,10 +361,8 @@ bool ClassInterfaceRequest(Setup& setup) { u8 i = setup.wIndex; -#ifdef CDC_ENABLED if (CDC_ACM_INTERFACE == i) return CDC_Setup(setup); -#endif #ifdef PLUGGABLE_USB_ENABLED return PUSB_Setup(setup, i); @@ -448,9 +440,7 @@ int SendInterfaces() { u8 interfaces = 0; -#ifdef CDC_ENABLED CDC_GetInterface(&interfaces); -#endif #ifdef PLUGGABLE_USB_ENABLED PUSB_GetInterface(&interfaces); @@ -629,9 +619,7 @@ ISR(USB_GEN_vect) // Start of Frame - happens every millisecond so we use it for TX and RX LED one-shot timing, too if (udint & (1< Date: Mon, 8 Jun 2015 10:54:12 +0200 Subject: [PATCH 10/39] add arduino header to HID library --- libraries/HID/HID.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/HID/HID.h b/libraries/HID/HID.h index cb30ec7cf54..b43e3f039a6 100644 --- a/libraries/HID/HID.h +++ b/libraries/HID/HID.h @@ -23,6 +23,7 @@ #define HID_h #include +#include #if defined(USBCON) From f67318a8b152a1a6dc47f82844c8cab2bad1bcaf Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 8 Jun 2015 11:30:34 +0200 Subject: [PATCH 11/39] remove useless variables --- .../avr/cores/arduino/PluggableUSB.cpp | 13 +++++------ .../arduino/avr/cores/arduino/PluggableUSB.h | 12 +++++----- libraries/HID/HID.cpp | 22 +++++++------------ libraries/HID/HID.h | 6 ++--- 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index e389c354173..b5e94eeb66b 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -25,9 +25,6 @@ #define MAX_MODULES 6 -static u8 startIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; -static u8 firstEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; - static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; @@ -36,18 +33,18 @@ extern u8 _initEndpoints[]; PUSBCallbacks cbs[MAX_MODULES]; u8 modules_count = 0; -int PUSB_GetInterface(u8* interfaceNum) +int8_t PUSB_GetInterface(u8* interfaceNum) { - int ret = 0; + int8_t ret = 0; for (u8 i=0; i= MAX_MODULES) { return 0; diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index 7b3722c99c2..877a9b00f92 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -28,9 +28,9 @@ typedef struct { bool (*setup)(Setup& setup, u8 i); - int (*getInterface)(u8* interfaceNum); - int (*getDescriptor)(int t); - int numEndpoints; + int8_t (*getInterface)(u8* interfaceNum); + int8_t (*getDescriptor)(int8_t t); + int8_t numEndpoints; u8 endpointType[6]; } PUSBCallbacks; @@ -40,11 +40,11 @@ typedef struct u8 firstEndpoint; } PUSBReturn; -int PUSB_AddFunction(PUSBCallbacks *cb, u8 *interface); +int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8 *interface); -int PUSB_GetInterface(u8* interfaceNum); +int8_t PUSB_GetInterface(u8* interfaceNum); -int PUSB_GetDescriptor(int t); +int8_t PUSB_GetDescriptor(int8_t t); bool PUSB_Setup(Setup& setup, u8 i); diff --git a/libraries/HID/HID.cpp b/libraries/HID/HID.cpp index f49c90e8d23..7806108ccb3 100644 --- a/libraries/HID/HID.cpp +++ b/libraries/HID/HID.cpp @@ -29,6 +29,8 @@ Mouse_ Mouse; Keyboard_ Keyboard; HID_ HID; +static u8 HID_ENDPOINT_INT; + //================================================================================ //================================================================================ @@ -43,10 +45,6 @@ HID_ HID; #define RAWHID_RX_SIZE 64 static u8 HID_INTERFACE; -static u8 HID_FIRST_ENDPOINT; -static u8 HID_ENDPOINT_INT; - -static PUSBCallbacks cb; extern const u8 _hidReportDescriptor[] PROGMEM; const u8 _hidReportDescriptor[] = { @@ -144,13 +142,13 @@ u8 _hid_idle = 1; #define WEAK __attribute__ ((weak)) -int WEAK HID_GetInterface(u8* interfaceNum) +int8_t WEAK HID_GetInterface(u8* interfaceNum) { interfaceNum[0] += 1; // uses 1 return USB_SendControl(0,&_hidInterface,sizeof(_hidInterface)); } -int WEAK HID_GetDescriptor(int t) +int8_t WEAK HID_GetDescriptor(int8_t t) { if (HID_REPORT_DESCRIPTOR_TYPE == t) { return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,sizeof(_hidReportDescriptor)); @@ -205,20 +203,16 @@ bool WEAK HID_Setup(Setup& setup, u8 i) } // to be called by begin(), will trigger USB disconnection and reconnection -int HID_Plug(void) +int8_t HID_Plug(void) { - u8 interface; - u8 res; + PUSBCallbacks cb; cb.setup = &HID_Setup; cb.getInterface = &HID_GetInterface; cb.getDescriptor = &HID_GetDescriptor; cb.numEndpoints = 1; cb.endpointType[0] = EP_TYPE_INTERRUPT_IN; - res = PUSB_AddFunction(&cb, &interface); - HID_INTERFACE = interface; - HID_FIRST_ENDPOINT = res; - HID_ENDPOINT_INT = res; + HID_ENDPOINT_INT = PUSB_AddFunction(&cb, &HID_INTERFACE); _hidInterface = { @@ -227,7 +221,7 @@ int HID_Plug(void) D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01) }; - return res; + return HID_ENDPOINT_INT; } HID_::HID_(void) diff --git a/libraries/HID/HID.h b/libraries/HID/HID.h index b43e3f039a6..70a72135a35 100644 --- a/libraries/HID/HID.h +++ b/libraries/HID/HID.h @@ -129,9 +129,9 @@ class HID_ int begin(void); }; -int HID_Plug(void); -int HID_GetInterface(u8* interfaceNum); -int HID_GetDescriptor(int t); +int8_t HID_Plug(void); +int8_t HID_GetInterface(u8* interfaceNum); +int8_t HID_GetDescriptor(int8_t t); bool HID_Setup(Setup& setup, u8 i); void HID_SendReport(uint8_t id, const void* data, int len); From 7b5c25f534f7b79508b2473361a58590e3e23586 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 8 Jun 2015 12:31:24 +0200 Subject: [PATCH 12/39] implement PUSB modules as linked list --- .../avr/cores/arduino/PluggableUSB.cpp | 39 ++++++++++++++++--- .../arduino/avr/cores/arduino/PluggableUSB.h | 2 +- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index b5e94eeb66b..15195b01a11 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -28,16 +28,27 @@ static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; +class PUSBListNode { +public: + PUSBListNode *next = NULL; + PUSBCallbacks cb; +}; + extern u8 _initEndpoints[]; -PUSBCallbacks cbs[MAX_MODULES]; -u8 modules_count = 0; +//PUSBCallbacks cbs[MAX_MODULES]; +static u8 modules_count = 0; + +static PUSBListNode* rootNode = NULL; +static PUSBListNode* lastNode = NULL; int8_t PUSB_GetInterface(u8* interfaceNum) { int8_t ret = 0; + PUSBListNode* node = rootNode; for (u8 i=0; icb.getInterface(interfaceNum); + node = node->next; } return ret; } @@ -45,8 +56,10 @@ int8_t PUSB_GetInterface(u8* interfaceNum) int8_t PUSB_GetDescriptor(int8_t t) { int8_t ret = 0; + PUSBListNode* node = rootNode; for (u8 i=0; icb.getDescriptor(t); + node = node->next; } return ret; } @@ -54,8 +67,10 @@ int8_t PUSB_GetDescriptor(int8_t t) bool PUSB_Setup(Setup& setup, u8 j) { bool ret = false; + PUSBListNode* node = rootNode; for (u8 i=0; icb.setup(setup, j); + node = node->next; } return ret; } @@ -65,7 +80,19 @@ int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8* interface) if (modules_count >= MAX_MODULES) { return 0; } - cbs[modules_count] = *cb; + + PUSBListNode *node = new PUSBListNode; + + node->cb.setup = cb->setup; + node->cb.getInterface = cb->getInterface; + node->cb.getDescriptor = cb->getDescriptor; + + if (modules_count == 0) { + rootNode = node; + lastNode = node; + } else { + lastNode->next = node; + } *interface = lastIf; lastIf++; diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index 877a9b00f92..e066d37758d 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -31,7 +31,7 @@ typedef struct int8_t (*getInterface)(u8* interfaceNum); int8_t (*getDescriptor)(int8_t t); int8_t numEndpoints; - u8 endpointType[6]; + u8 endpointType[]; } PUSBCallbacks; typedef struct From 4a552055bf85829961e22add04bb6a60f82fac24 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 8 Jun 2015 13:19:53 +0200 Subject: [PATCH 13/39] remove Mouse and Keyboard from HID module --- libraries/HID/HID.cpp | 411 +----------------------------------------- libraries/HID/HID.h | 95 +--------- 2 files changed, 6 insertions(+), 500 deletions(-) diff --git a/libraries/HID/HID.cpp b/libraries/HID/HID.cpp index 7806108ccb3..a5708e7fd5f 100644 --- a/libraries/HID/HID.cpp +++ b/libraries/HID/HID.cpp @@ -23,10 +23,6 @@ //#define RAWHID_ENABLED -// Singletons for mouse and keyboard - -Mouse_ Mouse; -Keyboard_ Keyboard; HID_ HID; static u8 HID_ENDPOINT_INT; @@ -46,91 +42,6 @@ static u8 HID_ENDPOINT_INT; static u8 HID_INTERFACE; -extern const u8 _hidReportDescriptor[] PROGMEM; -const u8 _hidReportDescriptor[] = { - - // Mouse - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54 - 0x09, 0x02, // USAGE (Mouse) - 0xa1, 0x01, // COLLECTION (Application) - 0x09, 0x01, // USAGE (Pointer) - 0xa1, 0x00, // COLLECTION (Physical) - 0x85, 0x01, // REPORT_ID (1) - 0x05, 0x09, // USAGE_PAGE (Button) - 0x19, 0x01, // USAGE_MINIMUM (Button 1) - 0x29, 0x03, // USAGE_MAXIMUM (Button 3) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x95, 0x03, // REPORT_COUNT (3) - 0x75, 0x01, // REPORT_SIZE (1) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x95, 0x01, // REPORT_COUNT (1) - 0x75, 0x05, // REPORT_SIZE (5) - 0x81, 0x03, // INPUT (Cnst,Var,Abs) - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x30, // USAGE (X) - 0x09, 0x31, // USAGE (Y) - 0x09, 0x38, // USAGE (Wheel) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x03, // REPORT_COUNT (3) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0xc0, // END_COLLECTION - 0xc0, // END_COLLECTION - - // Keyboard - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47 - 0x09, 0x06, // USAGE (Keyboard) - 0xa1, 0x01, // COLLECTION (Application) - 0x85, 0x02, // REPORT_ID (2) - 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 (1) - 0x75, 0x08, // REPORT_SIZE (8) - 0x81, 0x03, // INPUT (Cnst,Var,Abs) - - 0x95, 0x06, // REPORT_COUNT (6) - 0x75, 0x08, // REPORT_SIZE (8) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x65, // LOGICAL_MAXIMUM (101) - 0x05, 0x07, // USAGE_PAGE (Keyboard) - - 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) - 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application) - 0x81, 0x00, // INPUT (Data,Ary,Abs) - 0xc0, // END_COLLECTION - -#ifdef RAWHID_ENABLED - // RAW HID - 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), // 30 - 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE), - - 0xA1, 0x01, // Collection 0x01 - 0x85, 0x03, // REPORT_ID (3) - 0x75, 0x08, // report size = 8 bits - 0x15, 0x00, // logical minimum = 0 - 0x26, 0xFF, 0x00, // logical maximum = 255 - - 0x95, 64, // report count TX - 0x09, 0x01, // usage - 0x81, 0x02, // Input (array) - - 0x95, 64, // report count RX - 0x09, 0x02, // usage - 0x91, 0x02, // Output (array) - 0xC0 // end collection -#endif -}; - HIDDescriptor _hidInterface; //================================================================================ @@ -151,7 +62,7 @@ int8_t WEAK HID_GetInterface(u8* interfaceNum) int8_t WEAK HID_GetDescriptor(int8_t t) { if (HID_REPORT_DESCRIPTOR_TYPE == t) { - return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,sizeof(_hidReportDescriptor)); + return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,getsizeof_hidReportDescriptor()); } else { return 0; } @@ -217,7 +128,7 @@ int8_t HID_Plug(void) _hidInterface = { D_INTERFACE(HID_INTERFACE,1,3,0,0), - D_HIDREPORT(sizeof(_hidReportDescriptor)), + D_HIDREPORT(getsizeof_hidReportDescriptor()), D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01) }; @@ -233,322 +144,4 @@ int HID_::begin(void) return HID_Plug(); } -//================================================================================ -//================================================================================ -// Mouse - -Mouse_::Mouse_(void) : _buttons(0) -{ -} - -void Mouse_::begin(void) -{ -} - -void Mouse_::end(void) -{ -} - -void Mouse_::click(uint8_t b) -{ - _buttons = b; - move(0,0,0); - _buttons = 0; - move(0,0,0); -} - -void Mouse_::move(signed char x, signed char y, signed char wheel) -{ - u8 m[4]; - m[0] = _buttons; - m[1] = x; - m[2] = y; - m[3] = wheel; - HID_SendReport(1,m,4); -} - -void Mouse_::buttons(uint8_t b) -{ - if (b != _buttons) - { - _buttons = b; - move(0,0,0); - } -} - -void Mouse_::press(uint8_t b) -{ - buttons(_buttons | b); -} - -void Mouse_::release(uint8_t b) -{ - buttons(_buttons & ~b); -} - -bool Mouse_::isPressed(uint8_t b) -{ - if ((b & _buttons) > 0) - return true; - return false; -} - -//================================================================================ -//================================================================================ -// Keyboard - -Keyboard_::Keyboard_(void) -{ -} - -void Keyboard_::begin(void) -{ -} - -void Keyboard_::end(void) -{ -} - -void Keyboard_::sendReport(KeyReport* keys) -{ - HID_SendReport(2,keys,sizeof(KeyReport)); -} - -extern -const uint8_t _asciimap[128] PROGMEM; - -#define SHIFT 0x80 -const uint8_t _asciimap[128] = -{ - 0x00, // NUL - 0x00, // SOH - 0x00, // STX - 0x00, // ETX - 0x00, // EOT - 0x00, // ENQ - 0x00, // ACK - 0x00, // BEL - 0x2a, // BS Backspace - 0x2b, // TAB Tab - 0x28, // LF Enter - 0x00, // VT - 0x00, // FF - 0x00, // CR - 0x00, // SO - 0x00, // SI - 0x00, // DEL - 0x00, // DC1 - 0x00, // DC2 - 0x00, // DC3 - 0x00, // DC4 - 0x00, // NAK - 0x00, // SYN - 0x00, // ETB - 0x00, // CAN - 0x00, // EM - 0x00, // SUB - 0x00, // ESC - 0x00, // FS - 0x00, // GS - 0x00, // RS - 0x00, // US - - 0x2c, // ' ' - 0x1e|SHIFT, // ! - 0x34|SHIFT, // " - 0x20|SHIFT, // # - 0x21|SHIFT, // $ - 0x22|SHIFT, // % - 0x24|SHIFT, // & - 0x34, // ' - 0x26|SHIFT, // ( - 0x27|SHIFT, // ) - 0x25|SHIFT, // * - 0x2e|SHIFT, // + - 0x36, // , - 0x2d, // - - 0x37, // . - 0x38, // / - 0x27, // 0 - 0x1e, // 1 - 0x1f, // 2 - 0x20, // 3 - 0x21, // 4 - 0x22, // 5 - 0x23, // 6 - 0x24, // 7 - 0x25, // 8 - 0x26, // 9 - 0x33|SHIFT, // : - 0x33, // ; - 0x36|SHIFT, // < - 0x2e, // = - 0x37|SHIFT, // > - 0x38|SHIFT, // ? - 0x1f|SHIFT, // @ - 0x04|SHIFT, // A - 0x05|SHIFT, // B - 0x06|SHIFT, // C - 0x07|SHIFT, // D - 0x08|SHIFT, // E - 0x09|SHIFT, // F - 0x0a|SHIFT, // G - 0x0b|SHIFT, // H - 0x0c|SHIFT, // I - 0x0d|SHIFT, // J - 0x0e|SHIFT, // K - 0x0f|SHIFT, // L - 0x10|SHIFT, // M - 0x11|SHIFT, // N - 0x12|SHIFT, // O - 0x13|SHIFT, // P - 0x14|SHIFT, // Q - 0x15|SHIFT, // R - 0x16|SHIFT, // S - 0x17|SHIFT, // T - 0x18|SHIFT, // U - 0x19|SHIFT, // V - 0x1a|SHIFT, // W - 0x1b|SHIFT, // X - 0x1c|SHIFT, // Y - 0x1d|SHIFT, // Z - 0x2f, // [ - 0x31, // bslash - 0x30, // ] - 0x23|SHIFT, // ^ - 0x2d|SHIFT, // _ - 0x35, // ` - 0x04, // a - 0x05, // b - 0x06, // c - 0x07, // d - 0x08, // e - 0x09, // f - 0x0a, // g - 0x0b, // h - 0x0c, // i - 0x0d, // j - 0x0e, // k - 0x0f, // l - 0x10, // m - 0x11, // n - 0x12, // o - 0x13, // p - 0x14, // q - 0x15, // r - 0x16, // s - 0x17, // t - 0x18, // u - 0x19, // v - 0x1a, // w - 0x1b, // x - 0x1c, // y - 0x1d, // z - 0x2f|SHIFT, // - 0x31|SHIFT, // | - 0x30|SHIFT, // } - 0x35|SHIFT, // ~ - 0 // DEL -}; - -uint8_t USBPutChar(uint8_t c); - -// press() adds the specified key (printing, non-printing, or modifier) -// to the persistent key report and sends the report. Because of the way -// USB HID works, the host acts like the key remains pressed until we -// call release(), releaseAll(), or otherwise clear the report and resend. -size_t Keyboard_::press(uint8_t k) -{ - uint8_t i; - if (k >= 136) { // it's a non-printing key (not a modifier) - k = k - 136; - } else if (k >= 128) { // it's a modifier key - _keyReport.modifiers |= (1<<(k-128)); - k = 0; - } else { // it's a printing key - k = pgm_read_byte(_asciimap + k); - if (!k) { - setWriteError(); - return 0; - } - if (k & 0x80) { // it's a capital letter or other character reached with shift - _keyReport.modifiers |= 0x02; // the left shift modifier - k &= 0x7F; - } - } - - // Add k to the key report only if it's not already present - // and if there is an empty slot. - if (_keyReport.keys[0] != k && _keyReport.keys[1] != k && - _keyReport.keys[2] != k && _keyReport.keys[3] != k && - _keyReport.keys[4] != k && _keyReport.keys[5] != k) { - - for (i=0; i<6; i++) { - if (_keyReport.keys[i] == 0x00) { - _keyReport.keys[i] = k; - break; - } - } - if (i == 6) { - setWriteError(); - return 0; - } - } - sendReport(&_keyReport); - return 1; -} - -// release() takes the specified key out of the persistent key report and -// sends the report. This tells the OS the key is no longer pressed and that -// it shouldn't be repeated any more. -size_t Keyboard_::release(uint8_t k) -{ - uint8_t i; - if (k >= 136) { // it's a non-printing key (not a modifier) - k = k - 136; - } else if (k >= 128) { // it's a modifier key - _keyReport.modifiers &= ~(1<<(k-128)); - k = 0; - } else { // it's a printing key - k = pgm_read_byte(_asciimap + k); - if (!k) { - return 0; - } - if (k & 0x80) { // it's a capital letter or other character reached with shift - _keyReport.modifiers &= ~(0x02); // the left shift modifier - k &= 0x7F; - } - } - - // Test the key report to see if k is present. Clear it if it exists. - // Check all positions in case the key is present more than once (which it shouldn't be) - for (i=0; i<6; i++) { - if (0 != k && _keyReport.keys[i] == k) { - _keyReport.keys[i] = 0x00; - } - } - - sendReport(&_keyReport); - return 1; -} - -void Keyboard_::releaseAll(void) -{ - _keyReport.keys[0] = 0; - _keyReport.keys[1] = 0; - _keyReport.keys[2] = 0; - _keyReport.keys[3] = 0; - _keyReport.keys[4] = 0; - _keyReport.keys[5] = 0; - _keyReport.modifiers = 0; - sendReport(&_keyReport); -} - -size_t Keyboard_::write(uint8_t c) -{ - uint8_t p = press(c); // Keydown - release(c); // Keyup - return p; // just return the result of press() since release() almost always returns 1 -} - #endif /* if defined(USBCON) */ diff --git a/libraries/HID/HID.h b/libraries/HID/HID.h index 70a72135a35..ba1ec6cf07e 100644 --- a/libraries/HID/HID.h +++ b/libraries/HID/HID.h @@ -27,97 +27,6 @@ #if defined(USBCON) -//================================================================================ -//================================================================================ -// Mouse - -#define MOUSE_LEFT 1 -#define MOUSE_RIGHT 2 -#define MOUSE_MIDDLE 4 -#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE) - -class Mouse_ -{ -private: - uint8_t _buttons; - void buttons(uint8_t b); -public: - Mouse_(void); - void begin(void); - void end(void); - void click(uint8_t b = MOUSE_LEFT); - void move(signed char x, signed char y, signed char wheel = 0); - void press(uint8_t b = MOUSE_LEFT); // press LEFT by default - void release(uint8_t b = MOUSE_LEFT); // release LEFT by default - bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default -}; -extern Mouse_ Mouse; - -//================================================================================ -//================================================================================ -// Keyboard - -#define KEY_LEFT_CTRL 0x80 -#define KEY_LEFT_SHIFT 0x81 -#define KEY_LEFT_ALT 0x82 -#define KEY_LEFT_GUI 0x83 -#define KEY_RIGHT_CTRL 0x84 -#define KEY_RIGHT_SHIFT 0x85 -#define KEY_RIGHT_ALT 0x86 -#define KEY_RIGHT_GUI 0x87 - -#define KEY_UP_ARROW 0xDA -#define KEY_DOWN_ARROW 0xD9 -#define KEY_LEFT_ARROW 0xD8 -#define KEY_RIGHT_ARROW 0xD7 -#define KEY_BACKSPACE 0xB2 -#define KEY_TAB 0xB3 -#define KEY_RETURN 0xB0 -#define KEY_ESC 0xB1 -#define KEY_INSERT 0xD1 -#define KEY_DELETE 0xD4 -#define KEY_PAGE_UP 0xD3 -#define KEY_PAGE_DOWN 0xD6 -#define KEY_HOME 0xD2 -#define KEY_END 0xD5 -#define KEY_CAPS_LOCK 0xC1 -#define KEY_F1 0xC2 -#define KEY_F2 0xC3 -#define KEY_F3 0xC4 -#define KEY_F4 0xC5 -#define KEY_F5 0xC6 -#define KEY_F6 0xC7 -#define KEY_F7 0xC8 -#define KEY_F8 0xC9 -#define KEY_F9 0xCA -#define KEY_F10 0xCB -#define KEY_F11 0xCC -#define KEY_F12 0xCD - -// Low level key report: up to 6 keys and shift, ctrl etc at once -typedef struct -{ - uint8_t modifiers; - uint8_t reserved; - uint8_t keys[6]; -} KeyReport; - -class Keyboard_ : public Print -{ -private: - KeyReport _keyReport; - void sendReport(KeyReport* keys); -public: - Keyboard_(void); - void begin(void); - void end(void); - virtual size_t write(uint8_t k); - virtual size_t press(uint8_t k); - virtual size_t release(uint8_t k); - virtual void releaseAll(void); -}; -extern Keyboard_ Keyboard; - //================================================================================ //================================================================================ // HID 'Driver' @@ -162,6 +71,10 @@ typedef struct #define D_HIDREPORT(_descriptorLength) \ { 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength, 0 } +extern const u8 _hidReportDescriptor[] PROGMEM; + +// MUST be declared by the module +size_t getsizeof_hidReportDescriptor(); #endif From c2a083b57b730c1884852d81a16562fdaed4907c Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 8 Jun 2015 13:20:26 +0200 Subject: [PATCH 14/39] standalone Mouse library --- libraries/Mouse/Mouse.cpp | 125 ++++++++++++++++++++++++++++++++++++++ libraries/Mouse/Mouse.h | 55 +++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 libraries/Mouse/Mouse.cpp create mode 100644 libraries/Mouse/Mouse.h diff --git a/libraries/Mouse/Mouse.cpp b/libraries/Mouse/Mouse.cpp new file mode 100644 index 00000000000..aeeaae5dcf2 --- /dev/null +++ b/libraries/Mouse/Mouse.cpp @@ -0,0 +1,125 @@ +/* + Mouse.cpp + + Copyright (c) 2015, Arduino LLC + Original code (pre-library): Copyright (c) 2011, Peter Barrett + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#if 1 //defined(USBCON) + +#include "Mouse.h" + +const u8 _hidReportDescriptor[] PROGMEM = { + + // Mouse + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54 + 0x09, 0x02, // USAGE (Mouse) + 0xa1, 0x01, // COLLECTION (Application) + 0x09, 0x01, // USAGE (Pointer) + 0xa1, 0x00, // COLLECTION (Physical) + 0x85, 0x01, // REPORT_ID (1) + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) + 0x29, 0x03, // USAGE_MAXIMUM (Button 3) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x95, 0x03, // REPORT_COUNT (3) + 0x75, 0x01, // REPORT_SIZE (1) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x95, 0x01, // REPORT_COUNT (1) + 0x75, 0x05, // REPORT_SIZE (5) + 0x81, 0x03, // INPUT (Cnst,Var,Abs) + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x30, // USAGE (X) + 0x09, 0x31, // USAGE (Y) + 0x09, 0x38, // USAGE (Wheel) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x03, // REPORT_COUNT (3) + 0x81, 0x06, // INPUT (Data,Var,Rel) + 0xc0, // END_COLLECTION + 0xc0, // END_COLLECTION +}; + +size_t getsizeof_hidReportDescriptor() { + return sizeof(_hidReportDescriptor); +} + +Mouse_ Mouse; + +//================================================================================ +//================================================================================ +// Mouse + +Mouse_::Mouse_(void) : _buttons(0) +{ +} + +void Mouse_::begin(void) +{ +} + +void Mouse_::end(void) +{ +} + +void Mouse_::click(uint8_t b) +{ + _buttons = b; + move(0,0,0); + _buttons = 0; + move(0,0,0); +} + +void Mouse_::move(signed char x, signed char y, signed char wheel) +{ + u8 m[4]; + m[0] = _buttons; + m[1] = x; + m[2] = y; + m[3] = wheel; + HID_SendReport(1,m,4); +} + +void Mouse_::buttons(uint8_t b) +{ + if (b != _buttons) + { + _buttons = b; + move(0,0,0); + } +} + +void Mouse_::press(uint8_t b) +{ + buttons(_buttons | b); +} + +void Mouse_::release(uint8_t b) +{ + buttons(_buttons & ~b); +} + +bool Mouse_::isPressed(uint8_t b) +{ + if ((b & _buttons) > 0) + return true; + return false; +} + +#endif diff --git a/libraries/Mouse/Mouse.h b/libraries/Mouse/Mouse.h new file mode 100644 index 00000000000..34245662fc3 --- /dev/null +++ b/libraries/Mouse/Mouse.h @@ -0,0 +1,55 @@ +/* + Mouse.h + + Copyright (c) 2015, Arduino LLC + Original code (pre-library): Copyright (c) 2011, Peter Barrett + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef MOUSE_h +#define MOUSE_h + +#if 1 //defined(USBCON) + +#include "HID.h" +//================================================================================ +//================================================================================ +// Mouse + +#define MOUSE_LEFT 1 +#define MOUSE_RIGHT 2 +#define MOUSE_MIDDLE 4 +#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE) + +class Mouse_ +{ +private: + uint8_t _buttons; + void buttons(uint8_t b); +public: + Mouse_(void); + void begin(void); + void end(void); + void click(uint8_t b = MOUSE_LEFT); + void move(signed char x, signed char y, signed char wheel = 0); + void press(uint8_t b = MOUSE_LEFT); // press LEFT by default + void release(uint8_t b = MOUSE_LEFT); // release LEFT by default + bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default +}; +extern Mouse_ Mouse; + +#endif +#endif \ No newline at end of file From fe825c8f9b919c78df3d982274ef7f1583680ea8 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 8 Jun 2015 13:21:02 +0200 Subject: [PATCH 15/39] standalone Keyboard library --- libraries/Keyboard/Keyboard.cpp | 289 ++++++++++++++++++++++++++++++++ libraries/Keyboard/Keyboard.h | 123 ++++++++++++++ 2 files changed, 412 insertions(+) create mode 100644 libraries/Keyboard/Keyboard.cpp create mode 100644 libraries/Keyboard/Keyboard.h diff --git a/libraries/Keyboard/Keyboard.cpp b/libraries/Keyboard/Keyboard.cpp new file mode 100644 index 00000000000..24eb776ef10 --- /dev/null +++ b/libraries/Keyboard/Keyboard.cpp @@ -0,0 +1,289 @@ +/* + Keyboard.cpp + + Copyright (c) 2015, Arduino LLC + Original code (pre-library): Copyright (c) 2011, Peter Barrett + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#if defined(USBCON) + +#include "HID.h" +#include "Keyboard.h" + +//================================================================================ +//================================================================================ +// Keyboard + +Keyboard_ Keyboard; + +Keyboard_::Keyboard_(void) +{ +} + +void Keyboard_::begin(void) +{ +} + +void Keyboard_::end(void) +{ +} + +void Keyboard_::sendReport(KeyReport* keys) +{ + HID_SendReport(2,keys,sizeof(KeyReport)); +} + +extern +const uint8_t _asciimap[128] PROGMEM; + +#define SHIFT 0x80 +const uint8_t _asciimap[128] = +{ + 0x00, // NUL + 0x00, // SOH + 0x00, // STX + 0x00, // ETX + 0x00, // EOT + 0x00, // ENQ + 0x00, // ACK + 0x00, // BEL + 0x2a, // BS Backspace + 0x2b, // TAB Tab + 0x28, // LF Enter + 0x00, // VT + 0x00, // FF + 0x00, // CR + 0x00, // SO + 0x00, // SI + 0x00, // DEL + 0x00, // DC1 + 0x00, // DC2 + 0x00, // DC3 + 0x00, // DC4 + 0x00, // NAK + 0x00, // SYN + 0x00, // ETB + 0x00, // CAN + 0x00, // EM + 0x00, // SUB + 0x00, // ESC + 0x00, // FS + 0x00, // GS + 0x00, // RS + 0x00, // US + + 0x2c, // ' ' + 0x1e|SHIFT, // ! + 0x34|SHIFT, // " + 0x20|SHIFT, // # + 0x21|SHIFT, // $ + 0x22|SHIFT, // % + 0x24|SHIFT, // & + 0x34, // ' + 0x26|SHIFT, // ( + 0x27|SHIFT, // ) + 0x25|SHIFT, // * + 0x2e|SHIFT, // + + 0x36, // , + 0x2d, // - + 0x37, // . + 0x38, // / + 0x27, // 0 + 0x1e, // 1 + 0x1f, // 2 + 0x20, // 3 + 0x21, // 4 + 0x22, // 5 + 0x23, // 6 + 0x24, // 7 + 0x25, // 8 + 0x26, // 9 + 0x33|SHIFT, // : + 0x33, // ; + 0x36|SHIFT, // < + 0x2e, // = + 0x37|SHIFT, // > + 0x38|SHIFT, // ? + 0x1f|SHIFT, // @ + 0x04|SHIFT, // A + 0x05|SHIFT, // B + 0x06|SHIFT, // C + 0x07|SHIFT, // D + 0x08|SHIFT, // E + 0x09|SHIFT, // F + 0x0a|SHIFT, // G + 0x0b|SHIFT, // H + 0x0c|SHIFT, // I + 0x0d|SHIFT, // J + 0x0e|SHIFT, // K + 0x0f|SHIFT, // L + 0x10|SHIFT, // M + 0x11|SHIFT, // N + 0x12|SHIFT, // O + 0x13|SHIFT, // P + 0x14|SHIFT, // Q + 0x15|SHIFT, // R + 0x16|SHIFT, // S + 0x17|SHIFT, // T + 0x18|SHIFT, // U + 0x19|SHIFT, // V + 0x1a|SHIFT, // W + 0x1b|SHIFT, // X + 0x1c|SHIFT, // Y + 0x1d|SHIFT, // Z + 0x2f, // [ + 0x31, // bslash + 0x30, // ] + 0x23|SHIFT, // ^ + 0x2d|SHIFT, // _ + 0x35, // ` + 0x04, // a + 0x05, // b + 0x06, // c + 0x07, // d + 0x08, // e + 0x09, // f + 0x0a, // g + 0x0b, // h + 0x0c, // i + 0x0d, // j + 0x0e, // k + 0x0f, // l + 0x10, // m + 0x11, // n + 0x12, // o + 0x13, // p + 0x14, // q + 0x15, // r + 0x16, // s + 0x17, // t + 0x18, // u + 0x19, // v + 0x1a, // w + 0x1b, // x + 0x1c, // y + 0x1d, // z + 0x2f|SHIFT, // + 0x31|SHIFT, // | + 0x30|SHIFT, // } + 0x35|SHIFT, // ~ + 0 // DEL +}; + +uint8_t USBPutChar(uint8_t c); + +// press() adds the specified key (printing, non-printing, or modifier) +// to the persistent key report and sends the report. Because of the way +// USB HID works, the host acts like the key remains pressed until we +// call release(), releaseAll(), or otherwise clear the report and resend. +size_t Keyboard_::press(uint8_t k) +{ + uint8_t i; + if (k >= 136) { // it's a non-printing key (not a modifier) + k = k - 136; + } else if (k >= 128) { // it's a modifier key + _keyReport.modifiers |= (1<<(k-128)); + k = 0; + } else { // it's a printing key + k = pgm_read_byte(_asciimap + k); + if (!k) { + setWriteError(); + return 0; + } + if (k & 0x80) { // it's a capital letter or other character reached with shift + _keyReport.modifiers |= 0x02; // the left shift modifier + k &= 0x7F; + } + } + + // Add k to the key report only if it's not already present + // and if there is an empty slot. + if (_keyReport.keys[0] != k && _keyReport.keys[1] != k && + _keyReport.keys[2] != k && _keyReport.keys[3] != k && + _keyReport.keys[4] != k && _keyReport.keys[5] != k) { + + for (i=0; i<6; i++) { + if (_keyReport.keys[i] == 0x00) { + _keyReport.keys[i] = k; + break; + } + } + if (i == 6) { + setWriteError(); + return 0; + } + } + sendReport(&_keyReport); + return 1; +} + +// release() takes the specified key out of the persistent key report and +// sends the report. This tells the OS the key is no longer pressed and that +// it shouldn't be repeated any more. +size_t Keyboard_::release(uint8_t k) +{ + uint8_t i; + if (k >= 136) { // it's a non-printing key (not a modifier) + k = k - 136; + } else if (k >= 128) { // it's a modifier key + _keyReport.modifiers &= ~(1<<(k-128)); + k = 0; + } else { // it's a printing key + k = pgm_read_byte(_asciimap + k); + if (!k) { + return 0; + } + if (k & 0x80) { // it's a capital letter or other character reached with shift + _keyReport.modifiers &= ~(0x02); // the left shift modifier + k &= 0x7F; + } + } + + // Test the key report to see if k is present. Clear it if it exists. + // Check all positions in case the key is present more than once (which it shouldn't be) + for (i=0; i<6; i++) { + if (0 != k && _keyReport.keys[i] == k) { + _keyReport.keys[i] = 0x00; + } + } + + sendReport(&_keyReport); + return 1; +} + +void Keyboard_::releaseAll(void) +{ + _keyReport.keys[0] = 0; + _keyReport.keys[1] = 0; + _keyReport.keys[2] = 0; + _keyReport.keys[3] = 0; + _keyReport.keys[4] = 0; + _keyReport.keys[5] = 0; + _keyReport.modifiers = 0; + sendReport(&_keyReport); +} + +size_t Keyboard_::write(uint8_t c) +{ + uint8_t p = press(c); // Keydown + release(c); // Keyup + return p; // just return the result of press() since release() almost always returns 1 +} + +Keyboard_ Keyboard; + +#endif diff --git a/libraries/Keyboard/Keyboard.h b/libraries/Keyboard/Keyboard.h new file mode 100644 index 00000000000..152df1080c4 --- /dev/null +++ b/libraries/Keyboard/Keyboard.h @@ -0,0 +1,123 @@ +/* + Keyboard.h + + Copyright (c) 2015, Arduino LLC + Original code (pre-library): Copyright (c) 2011, Peter Barrett + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#if defined(USBCON) + +//================================================================================ +//================================================================================ +// Keyboard + +extern const u8 _hidReportDescriptor[] PROGMEM; +const u8 _hidReportDescriptor[] = { + + // Keyboard + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47 + 0x09, 0x06, // USAGE (Keyboard) + 0xa1, 0x01, // COLLECTION (Application) + 0x85, 0x02, // REPORT_ID (2) + 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 (1) + 0x75, 0x08, // REPORT_SIZE (8) + 0x81, 0x03, // INPUT (Cnst,Var,Abs) + + 0x95, 0x06, // REPORT_COUNT (6) + 0x75, 0x08, // REPORT_SIZE (8) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x65, // LOGICAL_MAXIMUM (101) + 0x05, 0x07, // USAGE_PAGE (Keyboard) + + 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) + 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application) + 0x81, 0x00, // INPUT (Data,Ary,Abs) + 0xc0, // END_COLLECTION +}; + +#define KEY_LEFT_CTRL 0x80 +#define KEY_LEFT_SHIFT 0x81 +#define KEY_LEFT_ALT 0x82 +#define KEY_LEFT_GUI 0x83 +#define KEY_RIGHT_CTRL 0x84 +#define KEY_RIGHT_SHIFT 0x85 +#define KEY_RIGHT_ALT 0x86 +#define KEY_RIGHT_GUI 0x87 + +#define KEY_UP_ARROW 0xDA +#define KEY_DOWN_ARROW 0xD9 +#define KEY_LEFT_ARROW 0xD8 +#define KEY_RIGHT_ARROW 0xD7 +#define KEY_BACKSPACE 0xB2 +#define KEY_TAB 0xB3 +#define KEY_RETURN 0xB0 +#define KEY_ESC 0xB1 +#define KEY_INSERT 0xD1 +#define KEY_DELETE 0xD4 +#define KEY_PAGE_UP 0xD3 +#define KEY_PAGE_DOWN 0xD6 +#define KEY_HOME 0xD2 +#define KEY_END 0xD5 +#define KEY_CAPS_LOCK 0xC1 +#define KEY_F1 0xC2 +#define KEY_F2 0xC3 +#define KEY_F3 0xC4 +#define KEY_F4 0xC5 +#define KEY_F5 0xC6 +#define KEY_F6 0xC7 +#define KEY_F7 0xC8 +#define KEY_F8 0xC9 +#define KEY_F9 0xCA +#define KEY_F10 0xCB +#define KEY_F11 0xCC +#define KEY_F12 0xCD + +// Low level key report: up to 6 keys and shift, ctrl etc at once +typedef struct +{ + uint8_t modifiers; + uint8_t reserved; + uint8_t keys[6]; +} KeyReport; + +class Keyboard_ : public Print +{ +private: + KeyReport _keyReport; + void sendReport(KeyReport* keys); +public: + Keyboard_(void); + void begin(void); + void end(void); + virtual size_t write(uint8_t k); + virtual size_t press(uint8_t k); + virtual size_t release(uint8_t k); + virtual void releaseAll(void); +}; +extern Keyboard_ Keyboard; + +#endif From feaa14fa5625ab07fd582526f3fa5e75f49c4171 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 8 Jun 2015 13:21:23 +0200 Subject: [PATCH 16/39] standalone MouseAndKeyboard library --- .../MouseAndKeyboard/MouseAndKeyboard.cpp | 0 libraries/MouseAndKeyboard/MouseAndKeyboard.h | 84 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 libraries/MouseAndKeyboard/MouseAndKeyboard.cpp create mode 100644 libraries/MouseAndKeyboard/MouseAndKeyboard.h diff --git a/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp b/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/libraries/MouseAndKeyboard/MouseAndKeyboard.h b/libraries/MouseAndKeyboard/MouseAndKeyboard.h new file mode 100644 index 00000000000..f134b9d8def --- /dev/null +++ b/libraries/MouseAndKeyboard/MouseAndKeyboard.h @@ -0,0 +1,84 @@ +extern const u8 _hidReportDescriptor[] PROGMEM; +const u8 _hidReportDescriptor[] = { + + // Mouse + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54 + 0x09, 0x02, // USAGE (Mouse) + 0xa1, 0x01, // COLLECTION (Application) + 0x09, 0x01, // USAGE (Pointer) + 0xa1, 0x00, // COLLECTION (Physical) + 0x85, 0x01, // REPORT_ID (1) + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) + 0x29, 0x03, // USAGE_MAXIMUM (Button 3) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x95, 0x03, // REPORT_COUNT (3) + 0x75, 0x01, // REPORT_SIZE (1) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x95, 0x01, // REPORT_COUNT (1) + 0x75, 0x05, // REPORT_SIZE (5) + 0x81, 0x03, // INPUT (Cnst,Var,Abs) + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x30, // USAGE (X) + 0x09, 0x31, // USAGE (Y) + 0x09, 0x38, // USAGE (Wheel) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x03, // REPORT_COUNT (3) + 0x81, 0x06, // INPUT (Data,Var,Rel) + 0xc0, // END_COLLECTION + 0xc0, // END_COLLECTION + + // Keyboard + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47 + 0x09, 0x06, // USAGE (Keyboard) + 0xa1, 0x01, // COLLECTION (Application) + 0x85, 0x02, // REPORT_ID (2) + 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 (1) + 0x75, 0x08, // REPORT_SIZE (8) + 0x81, 0x03, // INPUT (Cnst,Var,Abs) + + 0x95, 0x06, // REPORT_COUNT (6) + 0x75, 0x08, // REPORT_SIZE (8) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x65, // LOGICAL_MAXIMUM (101) + 0x05, 0x07, // USAGE_PAGE (Keyboard) + + 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) + 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application) + 0x81, 0x00, // INPUT (Data,Ary,Abs) + 0xc0, // END_COLLECTION + +#ifdef RAWHID_ENABLED + // RAW HID + 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), // 30 + 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE), + + 0xA1, 0x01, // Collection 0x01 + 0x85, 0x03, // REPORT_ID (3) + 0x75, 0x08, // report size = 8 bits + 0x15, 0x00, // logical minimum = 0 + 0x26, 0xFF, 0x00, // logical maximum = 255 + + 0x95, 64, // report count TX + 0x09, 0x01, // usage + 0x81, 0x02, // Input (array) + + 0x95, 64, // report count RX + 0x09, 0x02, // usage + 0x91, 0x02, // Output (array) + 0xC0 // end collection +#endif +}; From 344896ed70cfc0a66f8cdb9c8ce49142566ef205 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 8 Jun 2015 14:34:45 +0200 Subject: [PATCH 17/39] Fix HID derived libraries and add automatic setupUSB() weak hook --- libraries/Keyboard/Keyboard.cpp | 43 +- libraries/Keyboard/Keyboard.h | 38 +- libraries/Mouse/Mouse.cpp | 4 + .../MouseAndKeyboard/MouseAndKeyboard.cpp | 423 ++++++++++++++++++ libraries/MouseAndKeyboard/MouseAndKeyboard.h | 169 +++---- 5 files changed, 563 insertions(+), 114 deletions(-) diff --git a/libraries/Keyboard/Keyboard.cpp b/libraries/Keyboard/Keyboard.cpp index 24eb776ef10..8d5a9aeac6d 100644 --- a/libraries/Keyboard/Keyboard.cpp +++ b/libraries/Keyboard/Keyboard.cpp @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#if defined(USBCON) +#if 1 #include "HID.h" #include "Keyboard.h" @@ -47,6 +47,39 @@ void Keyboard_::sendReport(KeyReport* keys) HID_SendReport(2,keys,sizeof(KeyReport)); } +const u8 _hidReportDescriptor[] PROGMEM = { + + // Keyboard + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47 + 0x09, 0x06, // USAGE (Keyboard) + 0xa1, 0x01, // COLLECTION (Application) + 0x85, 0x02, // REPORT_ID (2) + 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 (1) + 0x75, 0x08, // REPORT_SIZE (8) + 0x81, 0x03, // INPUT (Cnst,Var,Abs) + + 0x95, 0x06, // REPORT_COUNT (6) + 0x75, 0x08, // REPORT_SIZE (8) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x65, // LOGICAL_MAXIMUM (101) + 0x05, 0x07, // USAGE_PAGE (Keyboard) + + 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) + 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application) + 0x81, 0x00, // INPUT (Data,Ary,Abs) + 0xc0, // END_COLLECTION +}; + extern const uint8_t _asciimap[128] PROGMEM; @@ -184,6 +217,14 @@ const uint8_t _asciimap[128] = 0 // DEL }; +size_t getsizeof_hidReportDescriptor() { + return sizeof(_hidReportDescriptor); +} + +void WEAK setupUSB() { + HID.begin(); +} + uint8_t USBPutChar(uint8_t c); // press() adds the specified key (printing, non-printing, or modifier) diff --git a/libraries/Keyboard/Keyboard.h b/libraries/Keyboard/Keyboard.h index 152df1080c4..66bf9b6a12d 100644 --- a/libraries/Keyboard/Keyboard.h +++ b/libraries/Keyboard/Keyboard.h @@ -19,46 +19,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#if defined(USBCON) +#if 1 + +#include "HID.h" //================================================================================ //================================================================================ // Keyboard -extern const u8 _hidReportDescriptor[] PROGMEM; -const u8 _hidReportDescriptor[] = { - - // Keyboard - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47 - 0x09, 0x06, // USAGE (Keyboard) - 0xa1, 0x01, // COLLECTION (Application) - 0x85, 0x02, // REPORT_ID (2) - 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 (1) - 0x75, 0x08, // REPORT_SIZE (8) - 0x81, 0x03, // INPUT (Cnst,Var,Abs) - - 0x95, 0x06, // REPORT_COUNT (6) - 0x75, 0x08, // REPORT_SIZE (8) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x65, // LOGICAL_MAXIMUM (101) - 0x05, 0x07, // USAGE_PAGE (Keyboard) - - 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) - 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application) - 0x81, 0x00, // INPUT (Data,Ary,Abs) - 0xc0, // END_COLLECTION -}; - #define KEY_LEFT_CTRL 0x80 #define KEY_LEFT_SHIFT 0x81 #define KEY_LEFT_ALT 0x82 diff --git a/libraries/Mouse/Mouse.cpp b/libraries/Mouse/Mouse.cpp index aeeaae5dcf2..6068e6b3305 100644 --- a/libraries/Mouse/Mouse.cpp +++ b/libraries/Mouse/Mouse.cpp @@ -66,6 +66,10 @@ Mouse_ Mouse; //================================================================================ // Mouse +void WEAK setupUSB() { + HID.begin(); +} + Mouse_::Mouse_(void) : _buttons(0) { } diff --git a/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp b/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp index e69de29bb2d..e7db2399d4e 100644 --- a/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp +++ b/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp @@ -0,0 +1,423 @@ +#if 1 //defined(USBCON) + +#include "MouseAndKeyboard.h" + +const u8 _hidReportDescriptor[] PROGMEM = { + + // Mouse + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54 + 0x09, 0x02, // USAGE (Mouse) + 0xa1, 0x01, // COLLECTION (Application) + 0x09, 0x01, // USAGE (Pointer) + 0xa1, 0x00, // COLLECTION (Physical) + 0x85, 0x01, // REPORT_ID (1) + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) + 0x29, 0x03, // USAGE_MAXIMUM (Button 3) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x95, 0x03, // REPORT_COUNT (3) + 0x75, 0x01, // REPORT_SIZE (1) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x95, 0x01, // REPORT_COUNT (1) + 0x75, 0x05, // REPORT_SIZE (5) + 0x81, 0x03, // INPUT (Cnst,Var,Abs) + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x30, // USAGE (X) + 0x09, 0x31, // USAGE (Y) + 0x09, 0x38, // USAGE (Wheel) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x03, // REPORT_COUNT (3) + 0x81, 0x06, // INPUT (Data,Var,Rel) + 0xc0, // END_COLLECTION + 0xc0, // END_COLLECTION + + // Keyboard + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47 + 0x09, 0x06, // USAGE (Keyboard) + 0xa1, 0x01, // COLLECTION (Application) + 0x85, 0x02, // REPORT_ID (2) + 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 (1) + 0x75, 0x08, // REPORT_SIZE (8) + 0x81, 0x03, // INPUT (Cnst,Var,Abs) + + 0x95, 0x06, // REPORT_COUNT (6) + 0x75, 0x08, // REPORT_SIZE (8) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x65, // LOGICAL_MAXIMUM (101) + 0x05, 0x07, // USAGE_PAGE (Keyboard) + + 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) + 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application) + 0x81, 0x00, // INPUT (Data,Ary,Abs) + 0xc0, // END_COLLECTION + +#ifdef RAWHID_ENABLED + // RAW HID + 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), // 30 + 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE), + + 0xA1, 0x01, // Collection 0x01 + 0x85, 0x03, // REPORT_ID (3) + 0x75, 0x08, // report size = 8 bits + 0x15, 0x00, // logical minimum = 0 + 0x26, 0xFF, 0x00, // logical maximum = 255 + + 0x95, 64, // report count TX + 0x09, 0x01, // usage + 0x81, 0x02, // Input (array) + + 0x95, 64, // report count RX + 0x09, 0x02, // usage + 0x91, 0x02, // Output (array) + 0xC0 // end collection +#endif +}; + +size_t getsizeof_hidReportDescriptor() { + return sizeof(_hidReportDescriptor); +} + +void WEAK setupUSB() { + HID.begin(); +} + +Mouse_ Mouse; + +//================================================================================ +//================================================================================ +// Mouse + +Mouse_::Mouse_(void) : _buttons(0) +{ +} + +void Mouse_::begin(void) +{ +} + +void Mouse_::end(void) +{ +} + +void Mouse_::click(uint8_t b) +{ + _buttons = b; + move(0,0,0); + _buttons = 0; + move(0,0,0); +} + +void Mouse_::move(signed char x, signed char y, signed char wheel) +{ + u8 m[4]; + m[0] = _buttons; + m[1] = x; + m[2] = y; + m[3] = wheel; + HID_SendReport(1,m,4); +} + +void Mouse_::buttons(uint8_t b) +{ + if (b != _buttons) + { + _buttons = b; + move(0,0,0); + } +} + +void Mouse_::press(uint8_t b) +{ + buttons(_buttons | b); +} + +void Mouse_::release(uint8_t b) +{ + buttons(_buttons & ~b); +} + +bool Mouse_::isPressed(uint8_t b) +{ + if ((b & _buttons) > 0) + return true; + return false; +} + +//================================================================================ +//================================================================================ +// Keyboard + +Keyboard_ Keyboard; + +Keyboard_::Keyboard_(void) +{ +} + +void Keyboard_::begin(void) +{ +} + +void Keyboard_::end(void) +{ +} + +void Keyboard_::sendReport(KeyReport* keys) +{ + HID_SendReport(2,keys,sizeof(KeyReport)); +} + +extern +const uint8_t _asciimap[128] PROGMEM; + +#define SHIFT 0x80 +const uint8_t _asciimap[128] = +{ + 0x00, // NUL + 0x00, // SOH + 0x00, // STX + 0x00, // ETX + 0x00, // EOT + 0x00, // ENQ + 0x00, // ACK + 0x00, // BEL + 0x2a, // BS Backspace + 0x2b, // TAB Tab + 0x28, // LF Enter + 0x00, // VT + 0x00, // FF + 0x00, // CR + 0x00, // SO + 0x00, // SI + 0x00, // DEL + 0x00, // DC1 + 0x00, // DC2 + 0x00, // DC3 + 0x00, // DC4 + 0x00, // NAK + 0x00, // SYN + 0x00, // ETB + 0x00, // CAN + 0x00, // EM + 0x00, // SUB + 0x00, // ESC + 0x00, // FS + 0x00, // GS + 0x00, // RS + 0x00, // US + + 0x2c, // ' ' + 0x1e|SHIFT, // ! + 0x34|SHIFT, // " + 0x20|SHIFT, // # + 0x21|SHIFT, // $ + 0x22|SHIFT, // % + 0x24|SHIFT, // & + 0x34, // ' + 0x26|SHIFT, // ( + 0x27|SHIFT, // ) + 0x25|SHIFT, // * + 0x2e|SHIFT, // + + 0x36, // , + 0x2d, // - + 0x37, // . + 0x38, // / + 0x27, // 0 + 0x1e, // 1 + 0x1f, // 2 + 0x20, // 3 + 0x21, // 4 + 0x22, // 5 + 0x23, // 6 + 0x24, // 7 + 0x25, // 8 + 0x26, // 9 + 0x33|SHIFT, // : + 0x33, // ; + 0x36|SHIFT, // < + 0x2e, // = + 0x37|SHIFT, // > + 0x38|SHIFT, // ? + 0x1f|SHIFT, // @ + 0x04|SHIFT, // A + 0x05|SHIFT, // B + 0x06|SHIFT, // C + 0x07|SHIFT, // D + 0x08|SHIFT, // E + 0x09|SHIFT, // F + 0x0a|SHIFT, // G + 0x0b|SHIFT, // H + 0x0c|SHIFT, // I + 0x0d|SHIFT, // J + 0x0e|SHIFT, // K + 0x0f|SHIFT, // L + 0x10|SHIFT, // M + 0x11|SHIFT, // N + 0x12|SHIFT, // O + 0x13|SHIFT, // P + 0x14|SHIFT, // Q + 0x15|SHIFT, // R + 0x16|SHIFT, // S + 0x17|SHIFT, // T + 0x18|SHIFT, // U + 0x19|SHIFT, // V + 0x1a|SHIFT, // W + 0x1b|SHIFT, // X + 0x1c|SHIFT, // Y + 0x1d|SHIFT, // Z + 0x2f, // [ + 0x31, // bslash + 0x30, // ] + 0x23|SHIFT, // ^ + 0x2d|SHIFT, // _ + 0x35, // ` + 0x04, // a + 0x05, // b + 0x06, // c + 0x07, // d + 0x08, // e + 0x09, // f + 0x0a, // g + 0x0b, // h + 0x0c, // i + 0x0d, // j + 0x0e, // k + 0x0f, // l + 0x10, // m + 0x11, // n + 0x12, // o + 0x13, // p + 0x14, // q + 0x15, // r + 0x16, // s + 0x17, // t + 0x18, // u + 0x19, // v + 0x1a, // w + 0x1b, // x + 0x1c, // y + 0x1d, // z + 0x2f|SHIFT, // + 0x31|SHIFT, // | + 0x30|SHIFT, // } + 0x35|SHIFT, // ~ + 0 // DEL +}; + +size_t getsizeof_hidReportDescriptor() { + return sizeof(_hidReportDescriptor); +} + +uint8_t USBPutChar(uint8_t c); + +// press() adds the specified key (printing, non-printing, or modifier) +// to the persistent key report and sends the report. Because of the way +// USB HID works, the host acts like the key remains pressed until we +// call release(), releaseAll(), or otherwise clear the report and resend. +size_t Keyboard_::press(uint8_t k) +{ + uint8_t i; + if (k >= 136) { // it's a non-printing key (not a modifier) + k = k - 136; + } else if (k >= 128) { // it's a modifier key + _keyReport.modifiers |= (1<<(k-128)); + k = 0; + } else { // it's a printing key + k = pgm_read_byte(_asciimap + k); + if (!k) { + setWriteError(); + return 0; + } + if (k & 0x80) { // it's a capital letter or other character reached with shift + _keyReport.modifiers |= 0x02; // the left shift modifier + k &= 0x7F; + } + } + + // Add k to the key report only if it's not already present + // and if there is an empty slot. + if (_keyReport.keys[0] != k && _keyReport.keys[1] != k && + _keyReport.keys[2] != k && _keyReport.keys[3] != k && + _keyReport.keys[4] != k && _keyReport.keys[5] != k) { + + for (i=0; i<6; i++) { + if (_keyReport.keys[i] == 0x00) { + _keyReport.keys[i] = k; + break; + } + } + if (i == 6) { + setWriteError(); + return 0; + } + } + sendReport(&_keyReport); + return 1; +} + +// release() takes the specified key out of the persistent key report and +// sends the report. This tells the OS the key is no longer pressed and that +// it shouldn't be repeated any more. +size_t Keyboard_::release(uint8_t k) +{ + uint8_t i; + if (k >= 136) { // it's a non-printing key (not a modifier) + k = k - 136; + } else if (k >= 128) { // it's a modifier key + _keyReport.modifiers &= ~(1<<(k-128)); + k = 0; + } else { // it's a printing key + k = pgm_read_byte(_asciimap + k); + if (!k) { + return 0; + } + if (k & 0x80) { // it's a capital letter or other character reached with shift + _keyReport.modifiers &= ~(0x02); // the left shift modifier + k &= 0x7F; + } + } + + // Test the key report to see if k is present. Clear it if it exists. + // Check all positions in case the key is present more than once (which it shouldn't be) + for (i=0; i<6; i++) { + if (0 != k && _keyReport.keys[i] == k) { + _keyReport.keys[i] = 0x00; + } + } + + sendReport(&_keyReport); + return 1; +} + +void Keyboard_::releaseAll(void) +{ + _keyReport.keys[0] = 0; + _keyReport.keys[1] = 0; + _keyReport.keys[2] = 0; + _keyReport.keys[3] = 0; + _keyReport.keys[4] = 0; + _keyReport.keys[5] = 0; + _keyReport.modifiers = 0; + sendReport(&_keyReport); +} + +size_t Keyboard_::write(uint8_t c) +{ + uint8_t p = press(c); // Keydown + release(c); // Keyup + return p; // just return the result of press() since release() almost always returns 1 +} + +#endif \ No newline at end of file diff --git a/libraries/MouseAndKeyboard/MouseAndKeyboard.h b/libraries/MouseAndKeyboard/MouseAndKeyboard.h index f134b9d8def..40bf340d75c 100644 --- a/libraries/MouseAndKeyboard/MouseAndKeyboard.h +++ b/libraries/MouseAndKeyboard/MouseAndKeyboard.h @@ -1,84 +1,97 @@ -extern const u8 _hidReportDescriptor[] PROGMEM; -const u8 _hidReportDescriptor[] = { - - // Mouse - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54 - 0x09, 0x02, // USAGE (Mouse) - 0xa1, 0x01, // COLLECTION (Application) - 0x09, 0x01, // USAGE (Pointer) - 0xa1, 0x00, // COLLECTION (Physical) - 0x85, 0x01, // REPORT_ID (1) - 0x05, 0x09, // USAGE_PAGE (Button) - 0x19, 0x01, // USAGE_MINIMUM (Button 1) - 0x29, 0x03, // USAGE_MAXIMUM (Button 3) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x95, 0x03, // REPORT_COUNT (3) - 0x75, 0x01, // REPORT_SIZE (1) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x95, 0x01, // REPORT_COUNT (1) - 0x75, 0x05, // REPORT_SIZE (5) - 0x81, 0x03, // INPUT (Cnst,Var,Abs) - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x30, // USAGE (X) - 0x09, 0x31, // USAGE (Y) - 0x09, 0x38, // USAGE (Wheel) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x03, // REPORT_COUNT (3) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0xc0, // END_COLLECTION - 0xc0, // END_COLLECTION +#ifndef MOUSEANDKEYBOARD_h - // Keyboard - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47 - 0x09, 0x06, // USAGE (Keyboard) - 0xa1, 0x01, // COLLECTION (Application) - 0x85, 0x02, // REPORT_ID (2) - 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 (1) - 0x75, 0x08, // REPORT_SIZE (8) - 0x81, 0x03, // INPUT (Cnst,Var,Abs) - - 0x95, 0x06, // REPORT_COUNT (6) - 0x75, 0x08, // REPORT_SIZE (8) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x65, // LOGICAL_MAXIMUM (101) - 0x05, 0x07, // USAGE_PAGE (Keyboard) - - 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) - 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application) - 0x81, 0x00, // INPUT (Data,Ary,Abs) - 0xc0, // END_COLLECTION +#if 1 //defined(USBCON) -#ifdef RAWHID_ENABLED - // RAW HID - 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), // 30 - 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE), +#include "HID.h" +//================================================================================ +//================================================================================ +// Mouse - 0xA1, 0x01, // Collection 0x01 - 0x85, 0x03, // REPORT_ID (3) - 0x75, 0x08, // report size = 8 bits - 0x15, 0x00, // logical minimum = 0 - 0x26, 0xFF, 0x00, // logical maximum = 255 +#define MOUSE_LEFT 1 +#define MOUSE_RIGHT 2 +#define MOUSE_MIDDLE 4 +#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE) - 0x95, 64, // report count TX - 0x09, 0x01, // usage - 0x81, 0x02, // Input (array) +class Mouse_ +{ +private: + uint8_t _buttons; + void buttons(uint8_t b); +public: + Mouse_(void); + void begin(void); + void end(void); + void click(uint8_t b = MOUSE_LEFT); + void move(signed char x, signed char y, signed char wheel = 0); + void press(uint8_t b = MOUSE_LEFT); // press LEFT by default + void release(uint8_t b = MOUSE_LEFT); // release LEFT by default + bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default +}; +extern Mouse_ Mouse; + +//================================================================================ +//================================================================================ +// Keyboard + +#define KEY_LEFT_CTRL 0x80 +#define KEY_LEFT_SHIFT 0x81 +#define KEY_LEFT_ALT 0x82 +#define KEY_LEFT_GUI 0x83 +#define KEY_RIGHT_CTRL 0x84 +#define KEY_RIGHT_SHIFT 0x85 +#define KEY_RIGHT_ALT 0x86 +#define KEY_RIGHT_GUI 0x87 - 0x95, 64, // report count RX - 0x09, 0x02, // usage - 0x91, 0x02, // Output (array) - 0xC0 // end collection -#endif +#define KEY_UP_ARROW 0xDA +#define KEY_DOWN_ARROW 0xD9 +#define KEY_LEFT_ARROW 0xD8 +#define KEY_RIGHT_ARROW 0xD7 +#define KEY_BACKSPACE 0xB2 +#define KEY_TAB 0xB3 +#define KEY_RETURN 0xB0 +#define KEY_ESC 0xB1 +#define KEY_INSERT 0xD1 +#define KEY_DELETE 0xD4 +#define KEY_PAGE_UP 0xD3 +#define KEY_PAGE_DOWN 0xD6 +#define KEY_HOME 0xD2 +#define KEY_END 0xD5 +#define KEY_CAPS_LOCK 0xC1 +#define KEY_F1 0xC2 +#define KEY_F2 0xC3 +#define KEY_F3 0xC4 +#define KEY_F4 0xC5 +#define KEY_F5 0xC6 +#define KEY_F6 0xC7 +#define KEY_F7 0xC8 +#define KEY_F8 0xC9 +#define KEY_F9 0xCA +#define KEY_F10 0xCB +#define KEY_F11 0xCC +#define KEY_F12 0xCD + +// Low level key report: up to 6 keys and shift, ctrl etc at once +typedef struct +{ + uint8_t modifiers; + uint8_t reserved; + uint8_t keys[6]; +} KeyReport; + +class Keyboard_ : public Print +{ +private: + KeyReport _keyReport; + void sendReport(KeyReport* keys); +public: + Keyboard_(void); + void begin(void); + void end(void); + virtual size_t write(uint8_t k); + virtual size_t press(uint8_t k); + virtual size_t release(uint8_t k); + virtual void releaseAll(void); }; +extern Keyboard_ Keyboard; + +#endif \ No newline at end of file From 8f0a43390389d4690a6250482476c5dd1f642549 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 8 Jun 2015 14:46:27 +0200 Subject: [PATCH 18/39] export WEAK macro --- libraries/HID/HID.cpp | 2 -- libraries/HID/HID.h | 2 ++ libraries/MouseAndKeyboard/MouseAndKeyboard.cpp | 7 ++----- libraries/MouseAndKeyboard/MouseAndKeyboard.h | 1 + 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/libraries/HID/HID.cpp b/libraries/HID/HID.cpp index a5708e7fd5f..e195f8e77df 100644 --- a/libraries/HID/HID.cpp +++ b/libraries/HID/HID.cpp @@ -51,8 +51,6 @@ HIDDescriptor _hidInterface; u8 _hid_protocol = 1; u8 _hid_idle = 1; -#define WEAK __attribute__ ((weak)) - int8_t WEAK HID_GetInterface(u8* interfaceNum) { interfaceNum[0] += 1; // uses 1 diff --git a/libraries/HID/HID.h b/libraries/HID/HID.h index ba1ec6cf07e..a75774f7b91 100644 --- a/libraries/HID/HID.h +++ b/libraries/HID/HID.h @@ -76,6 +76,8 @@ extern const u8 _hidReportDescriptor[] PROGMEM; // MUST be declared by the module size_t getsizeof_hidReportDescriptor(); +#define WEAK __attribute__ ((weak)) + #endif #endif \ No newline at end of file diff --git a/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp b/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp index e7db2399d4e..2bc762295d6 100644 --- a/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp +++ b/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp @@ -1,6 +1,7 @@ #if 1 //defined(USBCON) #include "MouseAndKeyboard.h" +#include "HID.h" const u8 _hidReportDescriptor[] PROGMEM = { @@ -87,7 +88,7 @@ const u8 _hidReportDescriptor[] PROGMEM = { }; size_t getsizeof_hidReportDescriptor() { - return sizeof(_hidReportDescriptor); + return sizeof(_hidReportDescriptor); } void WEAK setupUSB() { @@ -316,10 +317,6 @@ const uint8_t _asciimap[128] = 0 // DEL }; -size_t getsizeof_hidReportDescriptor() { - return sizeof(_hidReportDescriptor); -} - uint8_t USBPutChar(uint8_t c); // press() adds the specified key (printing, non-printing, or modifier) diff --git a/libraries/MouseAndKeyboard/MouseAndKeyboard.h b/libraries/MouseAndKeyboard/MouseAndKeyboard.h index 40bf340d75c..b83382c553a 100644 --- a/libraries/MouseAndKeyboard/MouseAndKeyboard.h +++ b/libraries/MouseAndKeyboard/MouseAndKeyboard.h @@ -94,4 +94,5 @@ class Keyboard_ : public Print }; extern Keyboard_ Keyboard; +#endif #endif \ No newline at end of file From a031921708c539fb76c8952296d9890d5a48ff16 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 8 Jun 2015 17:17:37 +0200 Subject: [PATCH 19/39] add stub MIDIUSB library only a proof of concept for PluggableUSB module --- libraries/MIDIUSB/MIDIUSB.cpp | 215 ++++++++++++++++++++++++++++++++++ libraries/MIDIUSB/MIDIUSB.h | 155 ++++++++++++++++++++++++ 2 files changed, 370 insertions(+) create mode 100644 libraries/MIDIUSB/MIDIUSB.cpp create mode 100644 libraries/MIDIUSB/MIDIUSB.h diff --git a/libraries/MIDIUSB/MIDIUSB.cpp b/libraries/MIDIUSB/MIDIUSB.cpp new file mode 100644 index 00000000000..329b40bc23f --- /dev/null +++ b/libraries/MIDIUSB/MIDIUSB.cpp @@ -0,0 +1,215 @@ +// Copyright (c) 2015, Gary Grewal +/* +** Permission to use, copy, modify, and/or distribute this software for +** any purpose with or without fee is hereby granted, provided that the +** above copyright notice and this permission notice appear in all copies. +** +** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR +** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES +** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +** SOFTWARE. +*/ +#include "PluggableUSB.h" +#include "MIDIUSB.h" + +#define MIDI_BUFFER_SIZE 128 + + +static u8 MIDI_AC_INTERFACE; // MIDI AC Interface +static u8 MIDI_INTERFACE; +static u8 MIDI_FIRST_ENDPOINT; +static u8 MIDI_ENDPOINT_OUT; +static u8 MIDI_ENDPOINT_IN; + +#define MIDI_RX MIDI_ENDPOINT_OUT +#define MIDI_TX MIDI_ENDPOINT_IN + +struct ring_bufferMIDI +{ + midiEventPacket_t midiEvent[MIDI_BUFFER_SIZE]; + volatile uint32_t head; + volatile uint32_t tail; +}; + +ring_bufferMIDI midi_rx_buffer = {{0,0,0,0 }, 0, 0}; + +static MIDIDescriptor _midiInterface; + +void WEAK setupUSB() { + MidiUSB.begin(); +} + +int8_t WEAK MIDI_GetInterface(uint8_t* interfaceNum) +{ + interfaceNum[0] += 2; // uses 2 + return USB_SendControl(0,&_midiInterface,sizeof(_midiInterface)); +} +bool WEAK MIDI_Setup(Setup& setup, u8 i) +{ + //Support requests here if needed. Typically these are optional + return false; +} + +int8_t WEAK MIDI_GetDescriptor(int8_t t) +{ + return 0; +} + +void MIDI_::accept(void) +{ + // static uint32_t mguard = 0; + + // // synchronized access to guard + // do { + // if (__LDREXW(&mguard) != 0) { + // __CLREX(); + // return; // busy + // } + // } while (__STREXW(1, &mguard) != 0); // retry until write succeed + + // ring_bufferMIDI *buffer = &midi_rx_buffer; + // uint32_t i = (uint32_t)(buffer->head+1) % MIDI_BUFFER_SIZE; + + // // if we should be storing the received character into the location + // // just before the tail (meaning that the head would advance to the + // // current location of the tail), we're about to overflow the buffer + // // and so we don't write the character or advance the head. + // while (i != buffer->tail) { + // int c; + // midiEventPacket_t event; + // if (!USB_Available(MIDI_RX)) { + // udd_ack_fifocon(MIDI_RX); + // break; + // } + // c = USB_Recv(MIDI_RX, &event, sizeof(event) ); + + // //MIDI paacket has to be 4 bytes + // if(c < 4) + // return; + // buffer->midiEvent[buffer->head] = event; + // buffer->head = i; + + // i = (i + 1) % MIDI_BUFFER_SIZE; + // } + + // // release the guard + // mguard = 0; +} + +uint32_t MIDI_::available(void) +{ + + ring_bufferMIDI *buffer = &midi_rx_buffer; + return (uint32_t)(MIDI_BUFFER_SIZE + buffer->head - buffer->tail) % MIDI_BUFFER_SIZE; +} + + +midiEventPacket_t MIDI_::read(void) +{ + ring_bufferMIDI *buffer = &midi_rx_buffer; + midiEventPacket_t c = buffer->midiEvent[buffer->tail]; + c.header = 0; + c.byte1 = 0; + c.byte2 = 0; + c.byte3 = 0; + + // if the head isn't ahead of the tail, we don't have any characters + if (buffer->head == buffer->tail) + { + return c; + } + else + { + midiEventPacket_t c = buffer->midiEvent[buffer->tail]; + buffer->tail = (uint32_t)(buffer->tail + 1) % MIDI_BUFFER_SIZE; + if (USB_Available(MIDI_RX)) + accept(); + return c; + } +} + +void MIDI_::flush(void) +{ + USB_Flush(MIDI_TX); +} + +size_t MIDI_::write(const uint8_t *buffer, size_t size) +{ + /* only try to send bytes if the high-level MIDI connection itself + is open (not just the pipe) - the OS should set lineState when the port + is opened and clear lineState when the port is closed. + bytes sent before the user opens the connection or after + the connection is closed are lost - just like with a UART. */ + + // TODO - ZE - check behavior on different OSes and test what happens if an + // open connection isn't broken cleanly (cable is yanked out, host dies + // or locks up, or host virtual serial port hangs) + + int r = USB_Send(MIDI_TX, buffer, size); + + if (r > 0) + { + return r; + } else + { + return 0; + } + return 0; +} + +void MIDI_::sendMIDI(midiEventPacket_t event) +{ + uint8_t data[4]; + data[0] = event.header; + data[1] = event.byte1; + data[2] = event.byte2; + data[3] = event.byte3; + write(data, 4); +} + +int8_t MIDI_plug(void) +{ + PUSBCallbacks cb; + + cb.setup = &MIDI_Setup; + cb.getInterface = &MIDI_GetInterface; + cb.getDescriptor = &MIDI_GetDescriptor; + cb.numEndpoints = 2; + cb.endpointType[0] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT + cb.endpointType[1] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN + + MIDI_ENDPOINT_OUT = PUSB_AddFunction(&cb, &MIDI_AC_INTERFACE); + MIDI_ENDPOINT_IN = MIDI_ENDPOINT_OUT + 1; + MIDI_INTERFACE = MIDI_AC_INTERFACE + 1; + + _midiInterface = + { + D_IAD(MIDI_AC_INTERFACE, 2, MIDI_AUDIO, MIDI_AUDIO_CONTROL, 0), + D_INTERFACE(MIDI_AC_INTERFACE,0,MIDI_AUDIO,MIDI_AUDIO_CONTROL,0), + D_AC_INTERFACE(0x1, MIDI_INTERFACE), + D_INTERFACE(MIDI_INTERFACE,2, MIDI_AUDIO,MIDI_STREAMING,0), + D_AS_INTERFACE, + D_MIDI_INJACK(MIDI_JACK_EMD, 0x1), + D_MIDI_INJACK(MIDI_JACK_EXT, 0x2), + D_MIDI_OUTJACK(MIDI_JACK_EMD, 0x3, 1, 2, 1), + D_MIDI_OUTJACK(MIDI_JACK_EXT, 0x4, 1, 1, 1), + D_MIDI_JACK_EP(USB_ENDPOINT_OUT(MIDI_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,512), + D_MIDI_AC_JACK_EP(1, 1), + D_MIDI_JACK_EP(USB_ENDPOINT_IN(MIDI_ENDPOINT_IN),USB_ENDPOINT_TYPE_BULK,512), + D_MIDI_AC_JACK_EP (1, 3) + }; + + return MIDI_ENDPOINT_IN; +} + +int8_t MIDI_::begin() +{ + return MIDI_plug(); +} + + +MIDI_ MidiUSB; \ No newline at end of file diff --git a/libraries/MIDIUSB/MIDIUSB.h b/libraries/MIDIUSB/MIDIUSB.h new file mode 100644 index 00000000000..2dcdf877983 --- /dev/null +++ b/libraries/MIDIUSB/MIDIUSB.h @@ -0,0 +1,155 @@ +//================================================================================ +//================================================================================ +// MIDI USB class + +#ifndef MIDIUSB_h +#define MIDIUSB_h + +#include +#include + +#if defined(USBCON) + +typedef struct +{ + uint8_t header; + uint8_t byte1; + uint8_t byte2; + uint8_t byte3; +}midiEventPacket_t; + +#define EP_TYPE_BULK_OUT_MIDI EP_TYPE_BULK_OUT +#define EP_TYPE_BULK_IN_MIDI EP_TYPE_BULK_IN + +class MIDI_ +{ +// private: +// RingBuffer *_midi_rx_buffer; +public: + int8_t begin(); + + virtual uint32_t available(void); + virtual void accept(void); + virtual midiEventPacket_t read(void); + virtual void flush(void); + virtual void sendMIDI(midiEventPacket_t event); + virtual size_t write(const uint8_t *buffer, size_t size); + operator bool(); +}; +extern MIDI_ MidiUSB; + +#define MIDI_AUDIO 0x01 +#define MIDI_AUDIO_CONTROL 0x01 +#define MIDI_CS_INTERFACE 0x24 +#define MIDI_CS_ENDPOINT 0x25 +#define MIDI_STREAMING 0x3 +#define MIDI_JACK_EMD 0x01 +#define MIDI_JACK_EXT 0X02 + +typedef struct +{ + uint8_t len; // 9 + uint8_t dtype; // 4 + uint8_t dsubType; + uint16_t bcdADc; + uint16_t wTotalLength; + uint8_t bInCollection; + uint8_t interfaceNumbers; +} MIDI_ACInterfaceDescriptor; + +typedef struct +{ + uint8_t len; // 9 + uint8_t dtype; // 4 + uint8_t dsubType; + uint8_t jackType; + uint8_t jackID; + uint8_t jackStrIndex; +} MIDIJackinDescriptor; + +typedef struct +{ + uint8_t len; // 9 + uint8_t dtype; // 4 + uint8_t dsubType; + uint8_t jackType; + uint8_t jackID; + uint8_t nPins; + uint8_t srcJackID; + uint8_t srcPinID; + uint8_t jackStrIndex; +} MIDIJackOutDescriptor; + +typedef struct +{ + EndpointDescriptor len; // 9 + uint8_t refresh; // 4 + uint8_t sync; +} MIDI_EPDescriptor; + +typedef struct +{ + uint8_t len; // 5 + uint8_t dtype; // 0x24 + uint8_t subtype; + uint8_t embJacks; + uint8_t jackID; +} MIDI_EP_ACDescriptor; + +typedef struct +{ + uint8_t len; // 9 + uint8_t dtype; // 4 + uint8_t dsubType; + uint16_t bcdADc; + uint16_t wTotalLength; +} MIDI_ASInterfaceDescriptor; + +typedef struct +{ + // IAD + IADDescriptor iad; + // MIDI Audio Control Interface + InterfaceDescriptor Audio_ControlInterface; + MIDI_ACInterfaceDescriptor Audio_ControlInterface_SPC; + + // MIDI Audio Streaming Interface + InterfaceDescriptor Audio_StreamInterface; + MIDI_ASInterfaceDescriptor Audio_StreamInterface_SPC; + + MIDIJackinDescriptor MIDI_In_Jack_Emb; + MIDIJackinDescriptor MIDI_In_Jack_Ext; + MIDIJackOutDescriptor MIDI_Out_Jack_Emb; + MIDIJackOutDescriptor MIDI_Out_Jack_Ext; + + MIDI_EPDescriptor MIDI_In_Jack_Endpoint; + MIDI_EP_ACDescriptor MIDI_In_Jack_Endpoint_SPC; + MIDI_EPDescriptor MIDI_Out_Jack_Endpoint; + MIDI_EP_ACDescriptor MIDI_Out_Jack_Endpoint_SPC; +} MIDIDescriptor; + +#define D_AC_INTERFACE(_streamingInterfaces, _MIDIInterface) \ + { 9, MIDI_CS_INTERFACE, 0x1, 0x0100, 0x0009, _streamingInterfaces, _MIDIInterface } + +#define D_AS_INTERFACE \ + { 0x7, MIDI_CS_INTERFACE, 0x01,0x0100, 0x0041} + +#define D_MIDI_INJACK(jackProp, _jackID) \ + { 0x06, MIDI_CS_INTERFACE, 0x02, jackProp, _jackID, 0 } + +#define D_MIDI_OUTJACK(jackProp, _jackID, _nPins, _srcID, _srcPin) \ + { 0x09, MIDI_CS_INTERFACE, 0x3, jackProp, _jackID, _nPins, _srcID, _srcPin, 0 } + +#define D_MIDI_JACK_EP(_addr,_attr,_packetSize) \ + { 9, 5, _addr,_attr,_packetSize, 0, 0, 0} + +#define D_MIDI_AC_JACK_EP(_nMIDI, _iDMIDI) \ + { 5, MIDI_CS_ENDPOINT, 0x1, _nMIDI, _iDMIDI} + +#define D_CDCCS(_subtype,_d0,_d1) { 5, 0x24, _subtype, _d0, _d1 } +#define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 } + +#define WEAK __attribute__ ((weak)) + +#endif +#endif \ No newline at end of file From f37547e8fd420499231003b631036ea6c21c5d9a Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 8 Jun 2015 17:34:59 +0200 Subject: [PATCH 20/39] add numInterfaces field to PUSBCallbacks --- hardware/arduino/avr/cores/arduino/PluggableUSB.cpp | 4 ++-- hardware/arduino/avr/cores/arduino/PluggableUSB.h | 1 + hardware/arduino/avr/cores/arduino/USBCore.cpp | 4 ---- libraries/HID/HID.cpp | 1 + libraries/MIDIUSB/MIDIUSB.cpp | 1 + 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index 15195b01a11..f59fc67e38a 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -95,13 +95,13 @@ int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8* interface) } *interface = lastIf; - lastIf++; + lastIf += cb->numInterfaces; for ( u8 i = 0; i< cb->numEndpoints; i++) { _initEndpoints[lastEp] = cb->endpointType[i]; lastEp++; } modules_count++; - return lastEp-1; + return lastEp - cb->numEndpoints; // restart USB layer??? } diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index e066d37758d..8e7f5d7616b 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -31,6 +31,7 @@ typedef struct int8_t (*getInterface)(u8* interfaceNum); int8_t (*getDescriptor)(int8_t t); int8_t numEndpoints; + int8_t numInterfaces; u8 endpointType[]; } PUSBCallbacks; diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index 53c71d905f6..d936a6bfb30 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -33,7 +33,6 @@ extern const u16 STRING_LANGUAGE[] PROGMEM; extern const u8 STRING_PRODUCT[] PROGMEM; extern const u8 STRING_MANUFACTURER[] PROGMEM; extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM; -extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM; extern const DeviceDescriptor USB_DeviceDescriptorB PROGMEM; const u16 STRING_LANGUAGE[2] = { @@ -72,9 +71,6 @@ const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER; const DeviceDescriptor USB_DeviceDescriptor = D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1); -const DeviceDescriptor USB_DeviceDescriptorA = - D_DEVICE(DEVICE_CLASS,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1); - const DeviceDescriptor USB_DeviceDescriptorB = D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1); diff --git a/libraries/HID/HID.cpp b/libraries/HID/HID.cpp index e195f8e77df..8bab60ae44a 100644 --- a/libraries/HID/HID.cpp +++ b/libraries/HID/HID.cpp @@ -120,6 +120,7 @@ int8_t HID_Plug(void) cb.getInterface = &HID_GetInterface; cb.getDescriptor = &HID_GetDescriptor; cb.numEndpoints = 1; + cb.numInterfaces = 1; cb.endpointType[0] = EP_TYPE_INTERRUPT_IN; HID_ENDPOINT_INT = PUSB_AddFunction(&cb, &HID_INTERFACE); diff --git a/libraries/MIDIUSB/MIDIUSB.cpp b/libraries/MIDIUSB/MIDIUSB.cpp index 329b40bc23f..e3fab0e4792 100644 --- a/libraries/MIDIUSB/MIDIUSB.cpp +++ b/libraries/MIDIUSB/MIDIUSB.cpp @@ -179,6 +179,7 @@ int8_t MIDI_plug(void) cb.getInterface = &MIDI_GetInterface; cb.getDescriptor = &MIDI_GetDescriptor; cb.numEndpoints = 2; + cb.numInterfaces = 2; cb.endpointType[0] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT cb.endpointType[1] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN From ada0e4c2f372fbc4d2b2f007ea8e23223d6f9db9 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 12 Jun 2015 15:15:03 +0200 Subject: [PATCH 21/39] remove 3 endpoints to match at32u4 limit --- hardware/arduino/avr/cores/arduino/USBCore.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index d936a6bfb30..b0160e28760 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -315,10 +315,7 @@ u8 _initEndpoints[] = EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN #ifdef PLUGGABLE_USB_ENABLED - //allocate 6 endpoints and remove const so they can be changed by the user - 0, - 0, - 0, + //allocate 3 endpoints and remove const so they can be changed by the user 0, 0, 0, From 89928b4e1567895319671a98b5a501e21a408466 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 23 Jun 2015 16:59:56 +0000 Subject: [PATCH 22/39] rework PUSBCallbacks initialization --- .../avr/cores/arduino/PluggableUSB.cpp | 28 ++++++------------- .../arduino/avr/cores/arduino/PluggableUSB.h | 11 ++++++-- libraries/HID/HID.cpp | 25 +++++++++++------ libraries/MIDIUSB/MIDIUSB.cpp | 27 +++++++++++------- 4 files changed, 50 insertions(+), 41 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index f59fc67e38a..00f400d56b3 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -28,12 +28,6 @@ static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; -class PUSBListNode { -public: - PUSBListNode *next = NULL; - PUSBCallbacks cb; -}; - extern u8 _initEndpoints[]; //PUSBCallbacks cbs[MAX_MODULES]; @@ -47,7 +41,7 @@ int8_t PUSB_GetInterface(u8* interfaceNum) int8_t ret = 0; PUSBListNode* node = rootNode; for (u8 i=0; icb.getInterface(interfaceNum); + ret = node->cb->getInterface(interfaceNum); node = node->next; } return ret; @@ -58,7 +52,7 @@ int8_t PUSB_GetDescriptor(int8_t t) int8_t ret = 0; PUSBListNode* node = rootNode; for (u8 i=0; icb.getDescriptor(t); + ret = node->cb->getDescriptor(t); node = node->next; } return ret; @@ -69,24 +63,18 @@ bool PUSB_Setup(Setup& setup, u8 j) bool ret = false; PUSBListNode* node = rootNode; for (u8 i=0; icb.setup(setup, j); + ret = node->cb->setup(setup, j); node = node->next; } return ret; } -int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8* interface) +int8_t PUSB_AddFunction(PUSBListNode *node, u8* interface) { if (modules_count >= MAX_MODULES) { return 0; } - PUSBListNode *node = new PUSBListNode; - - node->cb.setup = cb->setup; - node->cb.getInterface = cb->getInterface; - node->cb.getDescriptor = cb->getDescriptor; - if (modules_count == 0) { rootNode = node; lastNode = node; @@ -95,13 +83,13 @@ int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8* interface) } *interface = lastIf; - lastIf += cb->numInterfaces; - for ( u8 i = 0; i< cb->numEndpoints; i++) { - _initEndpoints[lastEp] = cb->endpointType[i]; + lastIf += node->cb->numInterfaces; + for ( u8 i = 0; i< node->cb->numEndpoints; i++) { + _initEndpoints[lastEp] = node->cb->endpointType[i]; lastEp++; } modules_count++; - return lastEp - cb->numEndpoints; + return lastEp - node->cb->numEndpoints; // restart USB layer??? } diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index 8e7f5d7616b..f729deb098f 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -32,7 +32,7 @@ typedef struct int8_t (*getDescriptor)(int8_t t); int8_t numEndpoints; int8_t numInterfaces; - u8 endpointType[]; + uint8_t *endpointType; } PUSBCallbacks; typedef struct @@ -41,7 +41,14 @@ typedef struct u8 firstEndpoint; } PUSBReturn; -int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8 *interface); +class PUSBListNode { +public: + PUSBListNode *next = NULL; + PUSBCallbacks *cb; + PUSBListNode(PUSBCallbacks *ncb) {cb = ncb;} +}; + +int8_t PUSB_AddFunction(PUSBListNode *node, u8 *interface); int8_t PUSB_GetInterface(u8* interfaceNum); diff --git a/libraries/HID/HID.cpp b/libraries/HID/HID.cpp index 8bab60ae44a..4621cb4e1ee 100644 --- a/libraries/HID/HID.cpp +++ b/libraries/HID/HID.cpp @@ -114,15 +114,22 @@ bool WEAK HID_Setup(Setup& setup, u8 i) // to be called by begin(), will trigger USB disconnection and reconnection int8_t HID_Plug(void) { - PUSBCallbacks cb; - - cb.setup = &HID_Setup; - cb.getInterface = &HID_GetInterface; - cb.getDescriptor = &HID_GetDescriptor; - cb.numEndpoints = 1; - cb.numInterfaces = 1; - cb.endpointType[0] = EP_TYPE_INTERRUPT_IN; - HID_ENDPOINT_INT = PUSB_AddFunction(&cb, &HID_INTERFACE); + static uint8_t endpointType[1]; + + endpointType[0] = EP_TYPE_INTERRUPT_IN; + + static PUSBCallbacks cb = { + .setup = &HID_Setup, + .getInterface = &HID_GetInterface, + .getDescriptor = &HID_GetDescriptor, + .numEndpoints = 1, + .numInterfaces = 1, + .endpointType = endpointType, + }; + + static PUSBListNode node(&cb); + + HID_ENDPOINT_INT = PUSB_AddFunction(&node, &HID_INTERFACE); _hidInterface = { diff --git a/libraries/MIDIUSB/MIDIUSB.cpp b/libraries/MIDIUSB/MIDIUSB.cpp index e3fab0e4792..fcc2bbf12a5 100644 --- a/libraries/MIDIUSB/MIDIUSB.cpp +++ b/libraries/MIDIUSB/MIDIUSB.cpp @@ -16,7 +16,7 @@ #include "PluggableUSB.h" #include "MIDIUSB.h" -#define MIDI_BUFFER_SIZE 128 +#define MIDI_BUFFER_SIZE 16 static u8 MIDI_AC_INTERFACE; // MIDI AC Interface @@ -173,17 +173,24 @@ void MIDI_::sendMIDI(midiEventPacket_t event) int8_t MIDI_plug(void) { - PUSBCallbacks cb; - cb.setup = &MIDI_Setup; - cb.getInterface = &MIDI_GetInterface; - cb.getDescriptor = &MIDI_GetDescriptor; - cb.numEndpoints = 2; - cb.numInterfaces = 2; - cb.endpointType[0] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT - cb.endpointType[1] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN + static uint8_t endpointType[2]; - MIDI_ENDPOINT_OUT = PUSB_AddFunction(&cb, &MIDI_AC_INTERFACE); + endpointType[0] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT + endpointType[1] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN + + static PUSBCallbacks cb = { + .setup = &MIDI_Setup, + .getInterface = &MIDI_GetInterface, + .getDescriptor = &MIDI_GetDescriptor, + .numEndpoints = 1, + .numInterfaces = 2, + .endpointType = endpointType, + }; + + static PUSBListNode node(&cb); + + MIDI_ENDPOINT_OUT = PUSB_AddFunction(&node, &MIDI_AC_INTERFACE); MIDI_ENDPOINT_IN = MIDI_ENDPOINT_OUT + 1; MIDI_INTERFACE = MIDI_AC_INTERFACE + 1; From 071323196d1d64f09655a5643456c3483536d245 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 23 Jun 2015 17:28:31 +0000 Subject: [PATCH 23/39] enforce single use of HID submodule --- libraries/Keyboard/Keyboard.h | 8 +++++++- libraries/Mouse/Mouse.h | 8 +++++++- libraries/MouseAndKeyboard/MouseAndKeyboard.h | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/libraries/Keyboard/Keyboard.h b/libraries/Keyboard/Keyboard.h index 66bf9b6a12d..6bfa0b8535e 100644 --- a/libraries/Keyboard/Keyboard.h +++ b/libraries/Keyboard/Keyboard.h @@ -19,7 +19,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#if 1 +#if defined(_USING_HID) + +#error "Can only attach one submodule to HID module" + +#else + +#define _USING_HID #include "HID.h" diff --git a/libraries/Mouse/Mouse.h b/libraries/Mouse/Mouse.h index 34245662fc3..50f00a54896 100644 --- a/libraries/Mouse/Mouse.h +++ b/libraries/Mouse/Mouse.h @@ -22,7 +22,13 @@ #ifndef MOUSE_h #define MOUSE_h -#if 1 //defined(USBCON) +#if defined(_USING_HID) + +#error "Can only attach one submodule to HID module" + +#else + +#define _USING_HID #include "HID.h" //================================================================================ diff --git a/libraries/MouseAndKeyboard/MouseAndKeyboard.h b/libraries/MouseAndKeyboard/MouseAndKeyboard.h index b83382c553a..0c67206a208 100644 --- a/libraries/MouseAndKeyboard/MouseAndKeyboard.h +++ b/libraries/MouseAndKeyboard/MouseAndKeyboard.h @@ -1,6 +1,12 @@ #ifndef MOUSEANDKEYBOARD_h -#if 1 //defined(USBCON) +#if defined(_USING_HID) + +#error "Can only attach one submodule to HID module" + +#else + +#define _USING_HID #include "HID.h" //================================================================================ From e211f1ea76ed1dc192c1a3fcb3ac8b18326e4675 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 23 Jun 2015 17:50:53 +0000 Subject: [PATCH 24/39] remove setupUSB weak hook and replace with global constructors thanks @matthijskooijman --- hardware/arduino/avr/cores/arduino/main.cpp | 1 - libraries/HID/HID.cpp | 10 +--------- libraries/Keyboard/Keyboard.cpp | 4 ---- libraries/MIDIUSB/MIDIUSB.cpp | 10 +--------- libraries/MIDIUSB/MIDIUSB.h | 2 ++ libraries/Mouse/Mouse.cpp | 4 ---- libraries/MouseAndKeyboard/MouseAndKeyboard.cpp | 4 ---- 7 files changed, 4 insertions(+), 31 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/main.cpp b/hardware/arduino/avr/cores/arduino/main.cpp index f4346ece0a0..434cd403c0d 100644 --- a/hardware/arduino/avr/cores/arduino/main.cpp +++ b/hardware/arduino/avr/cores/arduino/main.cpp @@ -37,7 +37,6 @@ int main(void) initVariant(); #if defined(USBCON) - setupUSB(); USBDevice.attach(); #endif diff --git a/libraries/HID/HID.cpp b/libraries/HID/HID.cpp index 4621cb4e1ee..bd7d25c3d84 100644 --- a/libraries/HID/HID.cpp +++ b/libraries/HID/HID.cpp @@ -111,8 +111,7 @@ bool WEAK HID_Setup(Setup& setup, u8 i) } } -// to be called by begin(), will trigger USB disconnection and reconnection -int8_t HID_Plug(void) +HID_::HID_(void) { static uint8_t endpointType[1]; @@ -137,17 +136,10 @@ int8_t HID_Plug(void) D_HIDREPORT(getsizeof_hidReportDescriptor()), D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01) }; - - return HID_ENDPOINT_INT; -} - -HID_::HID_(void) -{ } int HID_::begin(void) { - return HID_Plug(); } #endif /* if defined(USBCON) */ diff --git a/libraries/Keyboard/Keyboard.cpp b/libraries/Keyboard/Keyboard.cpp index 8d5a9aeac6d..a331d75da77 100644 --- a/libraries/Keyboard/Keyboard.cpp +++ b/libraries/Keyboard/Keyboard.cpp @@ -221,10 +221,6 @@ size_t getsizeof_hidReportDescriptor() { return sizeof(_hidReportDescriptor); } -void WEAK setupUSB() { - HID.begin(); -} - uint8_t USBPutChar(uint8_t c); // press() adds the specified key (printing, non-printing, or modifier) diff --git a/libraries/MIDIUSB/MIDIUSB.cpp b/libraries/MIDIUSB/MIDIUSB.cpp index fcc2bbf12a5..939ca6bf5fd 100644 --- a/libraries/MIDIUSB/MIDIUSB.cpp +++ b/libraries/MIDIUSB/MIDIUSB.cpp @@ -39,10 +39,6 @@ ring_bufferMIDI midi_rx_buffer = {{0,0,0,0 }, 0, 0}; static MIDIDescriptor _midiInterface; -void WEAK setupUSB() { - MidiUSB.begin(); -} - int8_t WEAK MIDI_GetInterface(uint8_t* interfaceNum) { interfaceNum[0] += 2; // uses 2 @@ -171,9 +167,8 @@ void MIDI_::sendMIDI(midiEventPacket_t event) write(data, 4); } -int8_t MIDI_plug(void) +MIDI_::MIDI_(void) { - static uint8_t endpointType[2]; endpointType[0] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT @@ -210,13 +205,10 @@ int8_t MIDI_plug(void) D_MIDI_JACK_EP(USB_ENDPOINT_IN(MIDI_ENDPOINT_IN),USB_ENDPOINT_TYPE_BULK,512), D_MIDI_AC_JACK_EP (1, 3) }; - - return MIDI_ENDPOINT_IN; } int8_t MIDI_::begin() { - return MIDI_plug(); } diff --git a/libraries/MIDIUSB/MIDIUSB.h b/libraries/MIDIUSB/MIDIUSB.h index 2dcdf877983..7fad154730a 100644 --- a/libraries/MIDIUSB/MIDIUSB.h +++ b/libraries/MIDIUSB/MIDIUSB.h @@ -26,6 +26,8 @@ class MIDI_ // private: // RingBuffer *_midi_rx_buffer; public: + MIDI_(void); + int8_t begin(); virtual uint32_t available(void); diff --git a/libraries/Mouse/Mouse.cpp b/libraries/Mouse/Mouse.cpp index 6068e6b3305..aeeaae5dcf2 100644 --- a/libraries/Mouse/Mouse.cpp +++ b/libraries/Mouse/Mouse.cpp @@ -66,10 +66,6 @@ Mouse_ Mouse; //================================================================================ // Mouse -void WEAK setupUSB() { - HID.begin(); -} - Mouse_::Mouse_(void) : _buttons(0) { } diff --git a/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp b/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp index 2bc762295d6..809ff9d50bd 100644 --- a/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp +++ b/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp @@ -91,10 +91,6 @@ size_t getsizeof_hidReportDescriptor() { return sizeof(_hidReportDescriptor); } -void WEAK setupUSB() { - HID.begin(); -} - Mouse_ Mouse; //================================================================================ From 91a115a35350c01709ce19fa07de8b061b0fd179 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 26 Jun 2015 14:53:27 +0200 Subject: [PATCH 25/39] move HID library to AVR specific location --- {libraries => hardware/arduino/avr/libraries}/HID/HID.cpp | 0 {libraries => hardware/arduino/avr/libraries}/HID/HID.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {libraries => hardware/arduino/avr/libraries}/HID/HID.cpp (100%) rename {libraries => hardware/arduino/avr/libraries}/HID/HID.h (100%) diff --git a/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp similarity index 100% rename from libraries/HID/HID.cpp rename to hardware/arduino/avr/libraries/HID/HID.cpp diff --git a/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h similarity index 100% rename from libraries/HID/HID.h rename to hardware/arduino/avr/libraries/HID/HID.h From 175240a90649309075436d73d0f34c4fcdd10f40 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 26 Jun 2015 15:05:57 +0200 Subject: [PATCH 26/39] Add support for waking up a host via USB HID this is a rework of commit fbcf94801b8bba7f1c8c79cc7ae402b6b9dbb2d3 --- hardware/arduino/avr/cores/arduino/USBAPI.h | 1 + .../arduino/avr/cores/arduino/USBCore.cpp | 161 +++++++++++++++--- hardware/arduino/avr/cores/arduino/USBCore.h | 11 +- 3 files changed, 150 insertions(+), 23 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/USBAPI.h b/hardware/arduino/avr/cores/arduino/USBAPI.h index d8ad98debd7..251e4b9577f 100644 --- a/hardware/arduino/avr/cores/arduino/USBAPI.h +++ b/hardware/arduino/avr/cores/arduino/USBAPI.h @@ -58,6 +58,7 @@ class USBDevice_ 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/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index b0160e28760..9095d79b970 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -78,6 +78,8 @@ const DeviceDescriptor USB_DeviceDescriptorB = //================================================================== 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 +volatile u8 _usbSuspendState = 0; // copy of UDINT to check SUSPI and WAKEUPI bits static inline void WaitIN(void) { @@ -329,7 +331,7 @@ static void InitEP(u8 index, u8 type, u8 size) { UENUM = index; - UECONX = 1; + UECONX = (1< Date: Fri, 26 Jun 2015 15:25:59 +0200 Subject: [PATCH 27/39] squash of Overhaul USB HID as a library all code from #1803 included --- libraries/CompleteHID/CompleteHID.cpp | 714 ++++++++++++++++++ libraries/CompleteHID/CompleteHID.h | 156 ++++ libraries/CompleteHID/HIDTables.h | 677 +++++++++++++++++ .../examples/AbsoluteMouse/AbsoluteMouse.ino | 28 + .../ConsumerAndSystemControl.ino | 47 ++ 5 files changed, 1622 insertions(+) create mode 100644 libraries/CompleteHID/CompleteHID.cpp create mode 100644 libraries/CompleteHID/CompleteHID.h create mode 100644 libraries/CompleteHID/HIDTables.h create mode 100644 libraries/CompleteHID/examples/AbsoluteMouse/AbsoluteMouse.ino create mode 100644 libraries/CompleteHID/examples/ConsumerAndSystemControl/ConsumerAndSystemControl.ino diff --git a/libraries/CompleteHID/CompleteHID.cpp b/libraries/CompleteHID/CompleteHID.cpp new file mode 100644 index 00000000000..7c427ad957f --- /dev/null +++ b/libraries/CompleteHID/CompleteHID.cpp @@ -0,0 +1,714 @@ +#if 1 //defined(USBCON) + +#include "CompleteHID.h" +#include "HIDTables.h" +#include "HID.h" + +#define HID_MOUSE_ABS_ENABLED + +Keyboard_ Keyboard; +Mouse_ Mouse; + +#define LSB(_x) ((_x) & 0xFF) +#define MSB(_x) ((_x) >> 8) + +#define RAWHID_USAGE_PAGE 0xFFC0 +#define RAWHID_USAGE 0x0C00 +#define RAWHID_TX_SIZE 64 +#define RAWHID_RX_SIZE 64 + +#define HID_REPORTID_KEYBOARD (1) +#define HID_REPORTID_MOUSE (2) +#define HID_REPORTID_MOUSE_ABS (3) +#define HID_REPORTID_SYSTEMCONTROL (4) +#define HID_REPORTID_CONSUMERCONTROL (5) +#define HID_REPORTID_RAWHID (6) + +#define HID_REPORT_KEYBOARD /* Keyboard */ \ + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) 47 */ \ + 0x09, 0x06, /* USAGE (Keyboard) */ \ + 0xa1, 0x01, /* COLLECTION (Application) */ \ + 0x85, HID_REPORTID_KEYBOARD, /* REPORT_ID */ \ + 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ \ +\ + /* Keyboard Modifiers (shift, alt, ...) */ \ + 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 (1) */ \ + 0x75, 0x08, /* REPORT_SIZE (8) */ \ + 0x81, 0x03, /* INPUT (Cnst,Var,Abs) */ \ +\ + /* Keyboard keys */ \ + 0x95, 0x06, /* REPORT_COUNT (6) */ \ + 0x75, 0x08, /* REPORT_SIZE (8) */ \ + 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \ + 0x26, 0xDF, 0x00, /* LOGICAL_MAXIMUM (239) */ \ + 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ \ + 0x19, 0x00, /* USAGE_MINIMUM (Reserved (no event indicated)) */ \ + 0x29, 0xDF, /* USAGE_MAXIMUM (Left Control - 1) */ \ + 0x81, 0x00, /* INPUT (Data,Ary,Abs) */ \ + 0xc0 /* END_COLLECTION */ + +#define HID_REPORT_MOUSE_ABSOLUTE /* Mouse absolute */ \ + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \ + 0x09, 0x02, /* USAGE (Mouse) */ \ + 0xa1, 0x01, /* COLLECTION (Application) */ \ + 0x09, 0x01, /* USAGE (Pointer) */ \ + 0xa1, 0x00, /* COLLECTION (Physical) */ \ + 0x85, HID_REPORTID_MOUSE_ABS, /* REPORT_ID */ \ + 0x05, 0x09, /* USAGE_PAGE (Button) */ \ + 0x19, 0x01, /* USAGE_MINIMUM (Button 1) */ \ + 0x29, 0x03, /* USAGE_MAXIMUM (Button 3) */ \ + 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \ + 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \ + 0x95, 0x03, /* REPORT_COUNT (3) */ \ + 0x75, 0x01, /* REPORT_SIZE (1) */ \ + 0x81, 0x02, /* INPUT (Data,Var,Abs) */ \ + 0x95, 0x01, /* REPORT_COUNT (1) */ \ + 0x75, 0x05, /* REPORT_SIZE (5) */ \ + 0x81, 0x03, /* INPUT (Cnst,Var,Abs) */ \ + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \ + 0x09, 0x30, /* USAGE (X) */ \ + 0x09, 0x31, /* USAGE (Y) */ \ + 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \ + 0x26, 0xff, 0x7f, /* LOGICAL_MAXIMUM (32767) */ \ + 0x75, 0x10, /* REPORT_SIZE (16) */ \ + 0x95, 0x02, /* REPORT_COUNT (2) */ \ + 0x81, 0x02, /* INPUT (Data,Var,Abs) */ \ + 0xc0, /* END_COLLECTION */ \ + 0xc0 /* END_COLLECTION */ + +#define HID_REPORT_MOUSE_RELATIVE /* Mouse relative */ \ + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) 54 */ \ + 0x09, 0x02, /* USAGE (Mouse) */ \ + 0xa1, 0x01, /* COLLECTION (Application) */ \ + 0x09, 0x01, /* USAGE (Pointer) */ \ + 0xa1, 0x00, /* COLLECTION (Physical) */ \ + 0x85, HID_REPORTID_MOUSE, /* REPORT_ID */ \ + 0x05, 0x09, /* USAGE_PAGE (Button) */ \ + 0x19, 0x01, /* USAGE_MINIMUM (Button 1) */ \ + 0x29, 0x05, /* USAGE_MAXIMUM (Button 5) */ \ + 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \ + 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \ + 0x95, 0x05, /* REPORT_COUNT (5) */ \ + 0x75, 0x01, /* REPORT_SIZE (1) */ \ + 0x81, 0x02, /* INPUT (Data,Var,Abs) */ \ + 0x95, 0x01, /* REPORT_COUNT (1) */ \ + 0x75, 0x03, /* REPORT_SIZE (3) */ \ + 0x81, 0x01, /* INPUT (Cnst,Var,Abs) */ \ + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \ + 0x09, 0x30, /* USAGE (X) */ \ + 0x09, 0x31, /* USAGE (Y) */ \ + 0x09, 0x38, /* USAGE (Wheel) */ \ + 0x15, 0x81, /* LOGICAL_MINIMUM (-127) */ \ + 0x25, 0x7f, /* LOGICAL_MAXIMUM (127) */ \ + 0x75, 0x08, /* REPORT_SIZE (8) */ \ + 0x95, 0x03, /* REPORT_COUNT (3) */ \ + 0x81, 0x06, /* INPUT (Data,Var,Rel) */ \ + 0xc0, /* END_COLLECTION */ \ + 0xc0 /* END_COLLECTION */ + +#define HID_REPORT_SYSTEMCONTROL /* System Control (Power Down, Sleep, Wakeup, ...) */ \ + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \ + 0x09, 0x80, /* USAGE (System Control) */ \ + 0xa1, 0x01, /* COLLECTION (Application) */ \ + 0x85, HID_REPORTID_SYSTEMCONTROL, /* REPORT_ID */ \ + 0x09, 0x81, /* USAGE (System Power Down) */ \ + 0x09, 0x82, /* USAGE (System Sleep) */ \ + 0x09, 0x83, /* USAGE (System Wakeup) */ \ + 0x09, 0x8E, /* USAGE (System Cold Restart) */ \ + 0x09, 0x8F, /* USAGE (System Warm Restart) */ \ + 0x09, 0xA0, /* USAGE (System Dock) */ \ + 0x09, 0xA1, /* USAGE (System Undock) */ \ + 0x09, 0xA7, /* USAGE (System Speaker Mute) */ \ + 0x09, 0xA8, /* USAGE (System Hibernate) */ \ + /* although these display usages are not that important, they don't cost */ \ + /* much more than declaring the otherwise necessary constant fill bits */ \ + 0x09, 0xB0, /* USAGE (System Display Invert) */ \ + 0x09, 0xB1, /* USAGE (System Display Internal) */ \ + 0x09, 0xB2, /* USAGE (System Display External) */ \ + 0x09, 0xB3, /* USAGE (System Display Both) */ \ + 0x09, 0xB4, /* USAGE (System Display Dual) */ \ + 0x09, 0xB5, /* USAGE (System Display Toggle Intern/Extern) */ \ + 0x09, 0xB6, /* USAGE (System Display Swap) */ \ + 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \ + 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \ + 0x75, 0x01, /* REPORT_SIZE (1) */ \ + 0x95, 0x10, /* REPORT_COUNT (16) */ \ + 0x81, 0x02, /* INPUT (Data,Var,Abs) */ \ + 0xc0 /* END_COLLECTION */ + +#define HID_REPORT_CONSUMERCONTROL /* Consumer Control (Sound/Media keys) */ \ + 0x05, 0x0c, /* USAGE_PAGE (Consumer Devices) */ \ + 0x09, 0x01, /* USAGE (Consumer Control) */ \ + 0xa1, 0x01, /* COLLECTION (Application) */ \ + 0x85, HID_REPORTID_CONSUMERCONTROL, /* REPORT_ID */ \ + 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \ + 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \ + 0x75, 0x01, /* REPORT_SIZE (1) */ \ + 0x95, 0x08, /* REPORT_COUNT (8) */ \ + 0x09, 0xe2, /* USAGE (Mute) 0x01 */ \ + 0x09, 0xe9, /* USAGE (Volume Up) 0x02 */ \ + 0x09, 0xea, /* USAGE (Volume Down) 0x03 */ \ + 0x09, 0xcd, /* USAGE (Play/Pause) 0x04 */ \ + 0x09, 0xb7, /* USAGE (Stop) 0x05 */ \ + 0x09, 0xb6, /* USAGE (Scan Previous Track) 0x06 */ \ + 0x09, 0xb5, /* USAGE (Scan Next Track) 0x07 */ \ + 0x09, 0xb8, /* USAGE (Eject) 0x08 */ \ + 0x81, 0x02, /* INPUT (Data,Var,Abs) */ \ + 0xc0 + +#define HID_REPORT_RAWHID /* RAW HID */ \ + 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), /* 30 */ \ + 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE), \ +\ + 0xA1, 0x01, /* Collection 0x01 */ \ + 0x85, HID_REPORTID_RAWHID, /* REPORT_ID */ \ + 0x75, 0x08, /* report size = 8 bits */ \ + 0x15, 0x00, /* logical minimum = 0 */ \ + 0x26, 0xFF, 0x00, /* logical maximum = 255 */ \ +\ + 0x95, 64, /* report count TX */ \ + 0x09, 0x01, /* usage */ \ + 0x81, 0x02, /* Input (array) */ \ +\ + 0x95, 64, /* report count RX */ \ + 0x09, 0x02, /* usage */ \ + 0x91, 0x02, /* Output (array) */ \ + 0xC0 /* end collection */ + +extern const u8 _hidReportDescriptor[] PROGMEM; +const u8 _hidReportDescriptor[] = { + + HID_REPORT_KEYBOARD, + HID_REPORT_MOUSE_RELATIVE, +#ifdef HID_MOUSE_ABS_ENABLED + HID_REPORT_MOUSE_ABSOLUTE, +#endif + HID_REPORT_SYSTEMCONTROL, + HID_REPORT_CONSUMERCONTROL, +#if RAWHID_ENABLED + HID_REPORT_RAWHID +#endif +}; + +size_t getsizeof_hidReportDescriptor() { + return sizeof(_hidReportDescriptor); +} + +//================================================================================ +//================================================================================ +// Mouse + +Mouse_::Mouse_(void) : _buttons(0) +{ +} + +void Mouse_::begin(void) +{ +} + +void Mouse_::end(void) +{ +} + +void Mouse_::click(uint8_t b) +{ + _buttons = b; + move(0,0,0); + _buttons = 0; + move(0,0,0); +} + +void Mouse_::move(signed char x, signed char y, signed char wheel) +{ + u8 m[4]; + m[0] = _buttons; + m[1] = x; + m[2] = y; + m[3] = wheel; + HID_SendReport(HID_REPORTID_MOUSE,m,sizeof(m)); +} + +// X and Y have the range of 0 to 32767. +// The USB Host will convert them to pixels on the screen. +// +// x=0,y=0 is top-left corner of the screen +// x=32767,y=0 is the top right corner +// x=32767,y=32767 is the bottom right corner +// x=0,y=32767 is the bottom left corner +// +// When converting these coordinates to pixels on screen, Mac OS X's +// default HID driver maps the inner 85% of the coordinate space to +// the screen's physical dimensions. This means that any value between +// 0 and 2293 or 30474 and 32767 will move the mouse to the screen +// edge on a Mac +// +// For details, see: +// http://lists.apple.com/archives/usb/2011/Jun/msg00032.html + + +void Mouse_::moveAbsolute(uint16_t x, uint16_t y) +{ + u8 m[5]; + m[0] = _buttons; + m[1] = LSB(x); + m[2] = MSB(x); + m[3] = LSB(y); + m[4] = MSB(y); + HID_SendReport(HID_REPORTID_MOUSE_ABS,m,sizeof(m)); +} + +void Mouse_::buttons(uint8_t b) +{ + if (b != _buttons) + { + _buttons = b; + move(0,0,0); + } +} + +void Mouse_::press(uint8_t b) +{ + buttons(_buttons | b); +} + +void Mouse_::release(uint8_t b) +{ + buttons(_buttons & ~b); +} + +bool Mouse_::isPressed(uint8_t b) +{ + if ((b & _buttons) > 0) + return true; + return false; +} + +//================================================================================ +//================================================================================ +// Keyboard + +Keyboard_::Keyboard_(void) +{ +} + +void Keyboard_::begin(void) +{ +} + +void Keyboard_::end(void) +{ +} + +void Keyboard_::sendReport(KeyReport* keys) +{ + HID_SendReport(HID_REPORTID_KEYBOARD,keys,sizeof(*keys)); +} + +extern +const uint8_t _asciimap[128] PROGMEM; + +#define SHIFT 0x80 +const uint8_t _asciimap[128] = +{ + 0x00, // NUL + 0x00, // SOH + 0x00, // STX + 0x00, // ETX + 0x00, // EOT + 0x00, // ENQ + 0x00, // ACK + 0x00, // BEL + 0x2a, // BS Backspace + 0x2b, // TAB Tab + 0x28, // LF Enter + 0x00, // VT + 0x00, // FF + 0x00, // CR + 0x00, // SO + 0x00, // SI + 0x00, // DEL + 0x00, // DC1 + 0x00, // DC2 + 0x00, // DC3 + 0x00, // DC4 + 0x00, // NAK + 0x00, // SYN + 0x00, // ETB + 0x00, // CAN + 0x00, // EM + 0x00, // SUB + 0x00, // ESC + 0x00, // FS + 0x00, // GS + 0x00, // RS + 0x00, // US + + 0x2c, // ' ' + 0x1e|SHIFT, // ! + 0x34|SHIFT, // " + 0x20|SHIFT, // # + 0x21|SHIFT, // $ + 0x22|SHIFT, // % + 0x24|SHIFT, // & + 0x34, // ' + 0x26|SHIFT, // ( + 0x27|SHIFT, // ) + 0x25|SHIFT, // * + 0x2e|SHIFT, // + + 0x36, // , + 0x2d, // - + 0x37, // . + 0x38, // / + 0x27, // 0 + 0x1e, // 1 + 0x1f, // 2 + 0x20, // 3 + 0x21, // 4 + 0x22, // 5 + 0x23, // 6 + 0x24, // 7 + 0x25, // 8 + 0x26, // 9 + 0x33|SHIFT, // : + 0x33, // ; + 0x36|SHIFT, // < + 0x2e, // = + 0x37|SHIFT, // > + 0x38|SHIFT, // ? + 0x1f|SHIFT, // @ + 0x04|SHIFT, // A + 0x05|SHIFT, // B + 0x06|SHIFT, // C + 0x07|SHIFT, // D + 0x08|SHIFT, // E + 0x09|SHIFT, // F + 0x0a|SHIFT, // G + 0x0b|SHIFT, // H + 0x0c|SHIFT, // I + 0x0d|SHIFT, // J + 0x0e|SHIFT, // K + 0x0f|SHIFT, // L + 0x10|SHIFT, // M + 0x11|SHIFT, // N + 0x12|SHIFT, // O + 0x13|SHIFT, // P + 0x14|SHIFT, // Q + 0x15|SHIFT, // R + 0x16|SHIFT, // S + 0x17|SHIFT, // T + 0x18|SHIFT, // U + 0x19|SHIFT, // V + 0x1a|SHIFT, // W + 0x1b|SHIFT, // X + 0x1c|SHIFT, // Y + 0x1d|SHIFT, // Z + 0x2f, // [ + 0x31, // bslash + 0x30, // ] + 0x23|SHIFT, // ^ + 0x2d|SHIFT, // _ + 0x35, // ` + 0x04, // a + 0x05, // b + 0x06, // c + 0x07, // d + 0x08, // e + 0x09, // f + 0x0a, // g + 0x0b, // h + 0x0c, // i + 0x0d, // j + 0x0e, // k + 0x0f, // l + 0x10, // m + 0x11, // n + 0x12, // o + 0x13, // p + 0x14, // q + 0x15, // r + 0x16, // s + 0x17, // t + 0x18, // u + 0x19, // v + 0x1a, // w + 0x1b, // x + 0x1c, // y + 0x1d, // z + 0x2f|SHIFT, // + 0x31|SHIFT, // | + 0x30|SHIFT, // } + 0x35|SHIFT, // ~ + 0 // DEL +}; + +uint8_t USBPutChar(uint8_t c); + + + // pressKeycode() adds the specified key (printing, non-printing, or modifier) + // to the persistent key report and sends the report. Because of the way + // USB HID works, the host acts like the key remains pressed until we + // call releaseKeycode(), releaseAll(), or otherwise clear the report and resend. + size_t Keyboard_::pressKeycode(uint8_t k) + { + if (!addKeycodeToReport(k)) { + return 0; + } + sendReport(&_keyReport); + } + + size_t Keyboard_::addKeycodeToReport(uint8_t k) + { + uint8_t index = 0; + uint8_t done = 0; + + if ((k >= HID_KEYBOARD_LEFT_CONTROL) && (k <= HID_KEYBOARD_RIGHT_GUI)) { + // it's a modifier key + _keyReport.modifiers |= (0x01 << (k - HID_KEYBOARD_LEFT_CONTROL)); + } else { + // it's some other key: + // Add k to the key report only if it's not already present + // and if there is an empty slot. + for (index = 0; index < KEYREPORT_KEYCOUNT; index++) { + if (_keyReport.keys[index] != k) { // is k already in list? + if (0 == _keyReport.keys[index]) { // have we found an empty slot? + _keyReport.keys[index] = k; + done = 1; + break; + } + } else { + done = 1; + break; + } + + } + + // use separate variable to check if slot was found + // for style reasons - we do not know how the compiler + // handles the for() index when it leaves the loop + if (0 == done) { + setWriteError(); + return 0; + } + } + + return 1; + } + + // press() transforms the given key to the actual keycode and calls + // pressKeycode() to actually press this key. + // + size_t Keyboard_::press(uint8_t k) + { + if (k >= KEY_RIGHT_GUI + 1) { + // it's a non-printing key (not a modifier) + k = k - (KEY_RIGHT_GUI + 1); + } else { + if (k >= KEY_LEFT_CTRL) { + // it's a modifier key + k = k - KEY_LEFT_CTRL + HID_KEYBOARD_LEFT_CONTROL; + } else { + k = pgm_read_byte(_asciimap + k); + if (k) { + if (k & SHIFT) { + // it's a capital letter or other character reached with shift + // the left shift modifier + addKeycodeToReport(HID_KEYBOARD_LEFT_SHIFT); + k = k ^ SHIFT; + } + } else { + return 0; + } + } + } + + pressKeycode(k); + return 1; + } + +// System Control +// k is one of the SYSTEM_CONTROL defines which come from the HID usage table "Generic Desktop Page (0x01)" +// in "HID Usage Tables" (HUT1_12v2.pdf) +size_t Keyboard_::systemControl(uint8_t k) +{ + if(k <= 16) + { + u16 mask = 0; + u8 m[2]; + + if(k > 0) + { + mask = 1 << (k - 1); + } + + m[0] = LSB(mask); + m[1] = MSB(mask); + HID_SendReport(HID_REPORTID_SYSTEMCONTROL,m,sizeof(m)); + + // these are all OSCs, so send a clear to make it possible to send it again later + m[0] = 0; + m[1] = 0; + HID_SendReport(HID_REPORTID_SYSTEMCONTROL,m,sizeof(m)); + return 1; + } + else + { + setWriteError(); + return 0; + } +} + +// Consumer Control +// k is one of the CONSUMER_CONTROL defines which come from the HID usage table "Consumer Devices Page (0x0c)" +// in "HID Usage Tables" (HUT1_12v2.pdf) +size_t Keyboard_::consumerControl(uint8_t k) +{ + if(k <= 8) + { + u16 mask = 0; + u8 m[2]; + + if(k > 0) + { + mask = 1 << (k - 1); + } + + m[0] = LSB(mask); + m[1] = MSB(mask); + HID_SendReport(HID_REPORTID_CONSUMERCONTROL,m,sizeof(m)); + + // these are all OSCs, so send a clear to make it possible to send it again later + m[0] = 0; + m[1] = 0; + HID_SendReport(HID_REPORTID_CONSUMERCONTROL,m,sizeof(m)); + return 1; + } + else + { + setWriteError(); + return 0; + } +} + +// releaseKeycode() takes the specified key out of the persistent key report and +// sends the report. This tells the OS the key is no longer pressed and that +// it shouldn't be repeated any more. +// When send is set to FALSE (= 0) no sendReport() is executed. This comes in +// handy when combining key releases (e.g. SHIFT+A). +size_t Keyboard_::releaseKeycode(uint8_t k) +{ + if (!removeKeycodeFromReport(k)) { + return 0; + } + sendReport(&_keyReport); +} + +size_t Keyboard_::removeKeycodeFromReport(uint8_t k) +{ + uint8_t indexA; + uint8_t indexB; + uint8_t count; + + if ((k >= HID_KEYBOARD_LEFT_CONTROL) && (k <= HID_KEYBOARD_RIGHT_GUI)) { + // it's a modifier key + _keyReport.modifiers = _keyReport.modifiers & (~(0x01 << (k - HID_KEYBOARD_LEFT_CONTROL))); + } else { + // it's some other key: + // Test the key report to see if k is present. Clear it if it exists. + // Check all positions in case the key is present more than once (which it shouldn't be) + for (indexA = 0; indexA < KEYREPORT_KEYCOUNT; indexA++) { + if (_keyReport.keys[indexA] == k) { + _keyReport.keys[indexA] = 0; + } + } + + // finally rearrange the keys list so that the free (= 0x00) are at the + // end of the keys list - some implementations stop for keys at the + // first occurence of an 0x00 in the keys list + // so (0x00)(0x01)(0x00)(0x03)(0x02)(0x00) becomes + // (0x01)(0x03)(0x02)(0x00)(0x00)(0x00) + count = 0; // holds the number of zeros we've found + indexA = 0; + while ((indexA + count) < KEYREPORT_KEYCOUNT) { + if (0 == _keyReport.keys[indexA]) { + count++; // one more zero + for (indexB = indexA; indexB < KEYREPORT_KEYCOUNT-count; indexB++) { + _keyReport.keys[indexB] = _keyReport.keys[indexB+1]; + } + _keyReport.keys[KEYREPORT_KEYCOUNT-count] = 0; + } else { + indexA++; // one more non-zero + } + } + } + + return 1; +} + +// release() transforms the given key to the actual keycode and calls +// releaseKeycode() to actually release this key. +// +size_t Keyboard_::release(uint8_t k) +{ + uint8_t i; + + if (k >= KEY_RIGHT_GUI + 1) { + // it's a non-printing key (not a modifier) + k = k - (KEY_RIGHT_GUI + 1); + } else { + if (k >= KEY_LEFT_CTRL) { + // it's a modifier key + k = k - KEY_LEFT_CTRL + HID_KEYBOARD_LEFT_CONTROL; + } else { + k = pgm_read_byte(_asciimap + k); + if (k) { + if ((k & SHIFT)) { + // it's a capital letter or other character reached with shift + // the left shift modifier + removeKeycodeFromReport(HID_KEYBOARD_LEFT_SHIFT); + k = k ^ SHIFT; + } + } else { + return 0; + } + } + } + + releaseKeycode(k); + return 1; +} + +void Keyboard_::releaseAll(void) +{ + _keyReport.keys[0] = 0; + _keyReport.keys[1] = 0; + _keyReport.keys[2] = 0; + _keyReport.keys[3] = 0; + _keyReport.keys[4] = 0; + _keyReport.keys[5] = 0; + _keyReport.modifiers = 0; + sendReport(&_keyReport); +} + +size_t Keyboard_::write(uint8_t c) +{ + uint8_t p = press(c); // Keydown + release(c); // Keyup + return p; // just return the result of press() since release() almost always returns 1 +} + +size_t Keyboard_::writeKeycode(uint8_t c) +{ + uint8_t p = pressKeycode(c); // Keydown + uint8_t r = releaseKeycode(c); // Keyup + return (p); // just return the result of pressKeycode() since release() almost always returns 1 +} + +#endif \ No newline at end of file diff --git a/libraries/CompleteHID/CompleteHID.h b/libraries/CompleteHID/CompleteHID.h new file mode 100644 index 00000000000..bc6c949850f --- /dev/null +++ b/libraries/CompleteHID/CompleteHID.h @@ -0,0 +1,156 @@ +#ifndef MOUSEANDKEYBOARD_h + +#if defined(_USING_HID) + +#error "Can only attach one submodule to HID module" + +#else + +#define _USING_HID + +#include "HID.h" +#include "HIDTables.h" + +//================================================================================ +//================================================================================ +// Mouse + +#define MOUSE_LEFT 1 +#define MOUSE_RIGHT 2 +#define MOUSE_MIDDLE 4 +#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE) + +class Mouse_ +{ +private: + uint8_t _buttons; + void buttons(uint8_t b); +public: + Mouse_(void); + void begin(void); + void end(void); + void click(uint8_t b = MOUSE_LEFT); + void move(signed char x, signed char y, signed char wheel = 0); + void moveAbsolute(uint16_t x, uint16_t y); + void press(uint8_t b = MOUSE_LEFT); // press LEFT by default + void release(uint8_t b = MOUSE_LEFT); // release LEFT by default + bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default +}; +extern Mouse_ Mouse; + +//================================================================================ +//================================================================================ +// Keyboard + +#define KEY_LEFT_CTRL 0x80 +#define KEY_LEFT_SHIFT 0x81 +#define KEY_LEFT_ALT 0x82 +#define KEY_LEFT_GUI 0x83 +#define KEY_RIGHT_CTRL 0x84 +#define KEY_RIGHT_SHIFT 0x85 +#define KEY_RIGHT_ALT 0x86 +#define KEY_RIGHT_GUI 0x87 + +#define KEY_UP_ARROW 0xDA +#define KEY_DOWN_ARROW 0xD9 +#define KEY_LEFT_ARROW 0xD8 +#define KEY_RIGHT_ARROW 0xD7 +#define KEY_BACKSPACE 0xB2 +#define KEY_TAB 0xB3 +#define KEY_RETURN 0xB0 +#define KEY_ESC 0xB1 +#define KEY_INSERT 0xD1 +#define KEY_DELETE 0xD4 +#define KEY_PAGE_UP 0xD3 +#define KEY_PAGE_DOWN 0xD6 +#define KEY_HOME 0xD2 +#define KEY_END 0xD5 +#define KEY_CAPS_LOCK 0xC1 +#define KEY_F1 0xC2 +#define KEY_F2 0xC3 +#define KEY_F3 0xC4 +#define KEY_F4 0xC5 +#define KEY_F5 0xC6 +#define KEY_F6 0xC7 +#define KEY_F7 0xC8 +#define KEY_F8 0xC9 +#define KEY_F9 0xCA +#define KEY_F10 0xCB +#define KEY_F11 0xCC +#define KEY_F12 0xCD + +// Low level key report: up to 6 keys and shift, ctrl etc at once +#define KEYREPORT_KEYCOUNT 0x06 +typedef struct +{ + uint8_t modifiers; + uint8_t reserved; + uint8_t keys[KEYREPORT_KEYCOUNT]; +} KeyReport; + +class Keyboard_ : public Print +{ +private: + KeyReport _keyReport; + void sendReport(KeyReport* keys); +public: + Keyboard_(void); + void begin(void); + void end(void); + virtual size_t write(uint8_t k); + virtual size_t press(uint8_t k); + virtual size_t release(uint8_t k); + virtual size_t writeKeycode(uint8_t k); + virtual size_t pressKeycode(uint8_t k); + virtual size_t releaseKeycode(uint8_t k); + virtual size_t addKeycodeToReport(uint8_t k); + virtual size_t removeKeycodeFromReport(uint8_t k); + virtual void releaseAll(void); + virtual size_t systemControl(uint8_t k); + virtual size_t consumerControl(uint8_t k); +}; +extern Keyboard_ Keyboard; + +// System Control values for Keyboard_::systemControl() +// these defines come from the HID usage table "Generic Desktop Page (0x01)" +// in the USB standard document "HID Usage Tables" (HUT1_12v2.pdf) +// Currently this list contains only OSC (one shot control) values, +// the implementation of systemControl will have to be changed when +// adding OOC or RTC values. +#define SYSTEM_CONTROL_POWER_DOWN 1 +#define SYSTEM_CONTROL_SLEEP 2 +#define SYSTEM_CONTROL_WAKEUP 3 +#define SYSTEM_CONTROL_COLD_RESTART 4 +#define SYSTEM_CONTROL_WARM_RESTART 5 +#define SYSTEM_CONTROL_DOCK 6 +#define SYSTEM_CONTROL_UNDOCK 7 +#define SYSTEM_CONTROL_SPEAKER_MUTE 8 +#define SYSTEM_CONTROL_HIBERNATE 9 +#define SYSTEM_CONTROL_DISPLAY_INVERT 10 +#define SYSTEM_CONTROL_DISPLAY_INTERNAL 11 +#define SYSTEM_CONTROL_DISPLAY_EXTERNAL 12 +#define SYSTEM_CONTROL_DISPLAY_BOTH 13 +#define SYSTEM_CONTROL_DISPLAY_DUAL 14 +#define SYSTEM_CONTROL_DISPLAY_TOGGLE_INT_EXT 15 +#define SYSTEM_CONTROL_DISPLAY_SWAP 16 + + + +// Consumer Control values for Keyboard_::systemControl() +// these defines come from the HID usage table "Consumer Device Page (0x0c)" +// in the USB standard document "HID Usage Tables" (HUT1_12v2.pdf) +// Currently this list contains only OSC (one shot control) values, +// the implementation of systemControl will have to be changed when +// adding OOC or RTC values. + +#define CONSUMER_CONTROL_VOLUME_MUTE 1 +#define CONSUMER_CONTROL_VOLUME_UP 2 +#define CONSUMER_CONTROL_VOLUME_DOWN 3 +#define CONSUMER_CONTROL_PLAY_PAUSE 4 +#define CONSUMER_CONTROL_STOP 5 +#define CONSUMER_CONTROL_PREV_TRACK 6 +#define CONSUMER_CONTROL_NEXT_TRACK 7 +#define CONSUMER_CONTROL_EJECT 8 + +#endif +#endif \ No newline at end of file diff --git a/libraries/CompleteHID/HIDTables.h b/libraries/CompleteHID/HIDTables.h new file mode 100644 index 00000000000..a00de5fafef --- /dev/null +++ b/libraries/CompleteHID/HIDTables.h @@ -0,0 +1,677 @@ +#ifndef __HIDTables__ +#define HID___HIDTables__ + + +// These mappings were extracted and transcribed from +// http://www.usb.org_SLASH_developers_SLASH_devclass_docs_SLASH_Hut1_12v2.pdf +// +// In most cases, I've preserved the "official" USB Implementers forum +// "Usage Name", though I've standardized some abbreviations and spacing +// that were inconsistent in the original specification. Non alpha-numeric +// characters in symbol names were converted into those characters' names. +// +// To match Arduino code style, all hid usage names are fully upper case. +// +// Not every HID usage listed in this file is currently supported by Arduino +// In particular, any System Control or Consumer Control entry that doesn't +// have a comment indicating that it's "HID type OSC" will require additional +// code in the Arduino core to work. +// +// Non-working usages are listed here in the interest of not having to manually +// convert more usage names each and every time our HID stack gets a little bit +// better. +// +// +// -- Jesse Vincent , January 2014 + + + +// System control mappings + +#define HID_SYSTEM_POWER_DOWN 0x81 // HID type OSC +#define HID_SYSTEM_SLEEP 0x82 // HID type OSC +#define HID_SYSTEM_WAKE_UP 0x83 // HID type OSC +#define HID_SYSTEM_CONTEXT_MENU 0x84 // HID type OSC +#define HID_SYSTEM_MAIN_MENU 0x85 // HID type OSC +#define HID_SYSTEM_APP_MENU 0x86 // HID type OSC +#define HID_SYSTEM_MENU_HELP 0x87 // HID type OSC +#define HID_SYSTEM_MENU_EXIT 0x88 // HID type OSC +#define HID_SYSTEM_MENU_SELECT 0x89 // HID type OSC +#define HID_SYSTEM_MENU_RIGHT 0x8A // HID type RTC +#define HID_SYSTEM_MENU_LEFT 0x8B // HID type RTC +#define HID_SYSTEM_MENU_UP 0x8C // HID type RTC +#define HID_SYSTEM_MENU_DOWN 0x8D // HID type RTC +#define HID_SYSTEM_COLD_RESTART 0x8E // HID type OSC +#define HID_SYSTEM_WARM_RESTART 0x8F // HID type OSC +#define HID_D_PAD_UP 0x90 // HID type OOC +#define HID_D_PAD_DOWN 0x91 // HID type OOC +#define HID_D_PAD_RIGHT 0x92 // HID type OOC +#define HID_D_PAD_LEFT 0x93 // HID type OOC +// 0x94-0x9F are reserved +#define HID_SYSTEM_DOCK 0xA0 // HID type OSC +#define HID_SYSTEM_UNDOCK 0xA1 // HID type OSC +#define HID_SYSTEM_SETUP 0xA2 // HID type OSC +#define HID_SYSTEM_BREAK 0xA3 // HID type OSC +#define HID_SYSTEM_DEBUGGER_BREAK 0xA4 // HID type OSC +#define HID_APPLICATION_BREAK 0xA5 // HID type OSC +#define HID_APPLICATION_DEBUGGER_BREAK 0xA6 // HID type OSC +#define HID_SYSTEM_SPEAKER_MUTE 0xA7 // HID type OSC +#define HID_SYSTEM_HIBERNATE 0xA8 // HID type OSC +// 0xA9-0xAF are reserved +#define HID_SYSTEM_DISPLAY_INVERT 0xB0 // HID type OSC +#define HID_SYSTEM_DISPLAY_INTERNAL 0xB1 // HID type OSC +#define HID_SYSTEM_DISPLAY_EXTERNAL 0xB2 // HID type OSC +#define HID_SYSTEM_DISPLAY_BOTH 0xB3 // HID type OSC +#define HID_SYSTEM_DISPLAY_DUAL 0xB4 // HID type OSC +#define HID_SYSTEM_DISPLAY_TOGGLE_INT_SLASH_EXT 0xB5 // HID type OSC +#define HID_SYSTEM_DISPLAY_SWAP_PRIMARY_SLASH_SECONDARY 0xB6 // HID type OSC +#define HID_SYSTEM_DISPLAY_LCD_AUTOSCALE 0xB7 // HID type OSC + +// Keyboard HID mappings + +// Reserved (no_event_indicated) 0x00 +#define HID_KEYBOARD_ERROR_ROLLOVER 0x01 +#define HID_KEYBOARD_POST_FAIL 0x02 +#define HID_KEYBOARD_ERROR_UNDEFINED 0x03 +#define HID_KEYBOARD_A_AND_A 0x04 +#define HID_KEYBOARD_B_AND_B 0x05 +#define HID_KEYBOARD_C_AND_C 0x06 +#define HID_KEYBOARD_D_AND_D 0x07 +#define HID_KEYBOARD_E_AND_E 0x08 +#define HID_KEYBOARD_F_AND_F 0x09 +#define HID_KEYBOARD_G_AND_G 0x0A +#define HID_KEYBOARD_H_AND_H 0x0B +#define HID_KEYBOARD_I_AND_I 0x0C +#define HID_KEYBOARD_J_AND_J 0x0D +#define HID_KEYBOARD_K_AND_K 0x0E +#define HID_KEYBOARD_L_AND_L 0x0F +#define HID_KEYBOARD_M_AND_M 0x10 +#define HID_KEYBOARD_N_AND_N 0x11 +#define HID_KEYBOARD_O_AND_O 0x12 +#define HID_KEYBOARD_P_AND_P 0x13 +#define HID_KEYBOARD_Q_AND_Q 0x14 +#define HID_KEYBOARD_R_AND_R 0x15 +#define HID_KEYBOARD_S_AND_S 0x16 +#define HID_KEYBOARD_T_AND_T 0x17 +#define HID_KEYBOARD_U_AND_U 0x18 +#define HID_KEYBOARD_V_AND_V 0x19 +#define HID_KEYBOARD_W_AND_W 0x1A +#define HID_KEYBOARD_X_AND_X 0x1B +#define HID_KEYBOARD_Y_AND_Y 0x1C +#define HID_KEYBOARD_Z_AND_Z 0x1D +#define HID_KEYBOARD_1_AND_EXCLAMATION_POINT 0x1E +#define HID_KEYBOARD_2_AND_AT 0x1F +#define HID_KEYBOARD_3_AND_POUND 0x20 +#define HID_KEYBOARD_4_AND_DOLLAR 0x21 +#define HID_KEYBOARD_5_AND_PERCENT 0x22 +#define HID_KEYBOARD_6_AND_CARAT 0x23 +#define HID_KEYBOARD_7_AND_AMPERSAND 0x24 +#define HID_KEYBOARD_8_AND_ASTERISK 0x25 +#define HID_KEYBOARD_9_AND_LEFT_PAREN 0x26 +#define HID_KEYBOARD_0_AND_RIGHT_PAREN 0x27 +#define HID_KEYBOARD_ENTER 0x28 // (MARKED AS ENTER_SLASH_RETURN) +#define HID_KEYBOARD_ESCAPE 0x29 +#define HID_KEYBOARD_DELETE 0x2A // (BACKSPACE) +#define HID_KEYBOARD_TAB 0x2B +#define HID_KEYBOARD_SPACEBAR 0x2C +#define HID_KEYBOARD_MINUS_AND_UNDERSCORE 0x2D // (UNDERSCORE) +#define HID_KEYBOARD_EQUALS_AND_PLUS 0x2E +#define HID_KEYBOARD_LEFT_BRACKET_AND_LEFT_CURLY_BRACE 0x2F +#define HID_KEYBOARD_RIGHT_BRACKET_AND_RIGHT_CURLY_BRACE 0x30 +#define HID_KEYBOARD_BACKSLASH_AND_PIPE 0x31 +#define HID_KEYBOARD_NON_US_POUND_AND_TILDE 0x32 +#define HID_KEYBOARD_SEMICOLON_AND_COLON 0x33 +#define HID_KEYBOARD_QUOTE_AND_DOUBLEQUOTE 0x34 +#define HID_KEYBOARD_GRAVE_ACCENT_AND_TILDE 0x35 +#define HID_KEYBOARD_COMMA_AND_LESS_THAN 0x36 +#define HID_KEYBOARD_PERIOD_AND_GREATER_THAN 0x37 +#define HID_KEYBOARD_SLASH_AND_QUESTION_MARK 0x38 +#define HID_KEYBOARD_CAPS_LOCK 0x39 +#define HID_KEYBOARD_F1 0x3A +#define HID_KEYBOARD_F2 0x3B +#define HID_KEYBOARD_F3 0x3C +#define HID_KEYBOARD_F4 0x3D +#define HID_KEYBOARD_F5 0x3E +#define HID_KEYBOARD_F6 0x3F +#define HID_KEYBOARD_F7 0x40 +#define HID_KEYBOARD_F8 0x41 +#define HID_KEYBOARD_F9 0x42 +#define HID_KEYBOARD_F10 0x43 +#define HID_KEYBOARD_F11 0x44 +#define HID_KEYBOARD_F12 0x45 +#define HID_KEYBOARD_PRINTSCREEN 0x46 +#define HID_KEYBOARD_SCROLL_LOCK 0x47 +#define HID_KEYBOARD_PAUSE 0x48 +#define HID_KEYBOARD_INSERT 0x49 +#define HID_KEYBOARD_HOME 0x4A +#define HID_KEYBOARD_PAGE_UP 0x4B +#define HID_KEYBOARD_DELETE_FORWARD 0x4C +#define HID_KEYBOARD_END 0x4D +#define HID_KEYBOARD_PAGE_DOWN 0x4E +#define HID_KEYBOARD_RIGHTARROW 0x4F +#define HID_KEYBOARD_LEFTARROW 0x50 +#define HID_KEYBOARD_DOWNARROW 0x51 +#define HID_KEYBOARD_UPARROW 0x52 +#define HID_KEYPAD_NUM_LOCK_AND_CLEAR 0x53 +#define HID_KEYPAD_DIVIDE 0x54 +#define HID_KEYPAD_MULTIPLY 0x55 +#define HID_KEYPAD_SUBTRACT 0x56 +#define HID_KEYPAD_ADD 0x57 +#define HID_KEYPAD_ENTER 0x58 +#define HID_KEYPAD_1_AND_END 0x59 +#define HID_KEYPAD_2_AND_DOWN_ARROW 0x5A +#define HID_KEYPAD_3_AND_PAGE_DOWN 0x5B +#define HID_KEYPAD_4_AND_LEFT_ARROW 0x5C +#define HID_KEYPAD_5 0x5D +#define HID_KEYPAD_6_AND_RIGHT_ARROW 0x5E +#define HID_KEYPAD_7_AND_HOME 0x5F +#define HID_KEYPAD_8_AND_UP_ARROW 0x60 +#define HID_KEYPAD_9_AND_PAGE_UP 0x61 +#define HID_KEYPAD_0_AND_INSERT 0x62 +#define HID_KEYPAD_PERIOD_AND_DELETE 0x63 +#define HID_KEYBOARD_NON_US_BACKSLASH_AND_PIPE 0x64 +#define HID_KEYBOARD_APPLICATION 0x65 +#define HID_KEYBOARD_POWER 0x66 +#define HID_KEYPAD_EQUALS 0x67 +#define HID_KEYBOARD_F13 0x68 +#define HID_KEYBOARD_F14 0x69 +#define HID_KEYBOARD_F15 0x6A +#define HID_KEYBOARD_F16 0x6B +#define HID_KEYBOARD_F17 0x6C +#define HID_KEYBOARD_F18 0x6D +#define HID_KEYBOARD_F19 0x6E +#define HID_KEYBOARD_F20 0x6F +#define HID_KEYBOARD_F21 0x70 +#define HID_KEYBOARD_F22 0x71 +#define HID_KEYBOARD_F23 0x72 +#define HID_KEYBOARD_F24 0x73 +#define HID_KEYBOARD_EXECUTE 0x74 +#define HID_KEYBOARD_HELP 0x75 +#define HID_KEYBOARD_MENU 0x76 +#define HID_KEYBOARD_SELECT 0x77 +#define HID_KEYBOARD_STOP 0x78 +#define HID_KEYBOARD_AGAIN 0x79 +#define HID_KEYBOARD_UNDO 0x7A +#define HID_KEYBOARD_CUT 0x7B +#define HID_KEYBOARD_COPY 0x7C +#define HID_KEYBOARD_PASTE 0x7D +#define HID_KEYBOARD_FIND 0x7E +#define HID_KEYBOARD_MUTE 0x7F +#define HID_KEYBOARD_VOLUME_UP 0x80 +#define HID_KEYBOARD_VOLUME_DOWN 0x81 +#define HID_KEYBOARD_LOCKING_CAPS_LOCK 0x82 +#define HID_KEYBOARD_LOCKING_NUM_LOCK 0x83 +#define HID_KEYBOARD_LOCKING_SCROLL_LOCK 0x84 +#define HID_KEYPAD_COMMA 0x85 +#define HID_KEYPAD_EQUAL_SIGN 0x86 +#define HID_KEYBOARD_INTERNATIONAL1 0x87 +#define HID_KEYBOARD_INTERNATIONAL2 0x88 +#define HID_KEYBOARD_INTERNATIONAL3 0x89 +#define HID_KEYBOARD_INTERNATIONAL4 0x8A +#define HID_KEYBOARD_INTERNATIONAL5 0x8B +#define HID_KEYBOARD_INTERNATIONAL6 0x8C +#define HID_KEYBOARD_INTERNATIONAL7 0x8D +#define HID_KEYBOARD_INTERNATIONAL8 0x8E +#define HID_KEYBOARD_INTERNATIONAL9 0x8F +#define HID_KEYBOARD_LANG1 0x90 +#define HID_KEYBOARD_LANG2 0x91 +#define HID_KEYBOARD_LANG3 0x92 +#define HID_KEYBOARD_LANG4 0x93 +#define HID_KEYBOARD_LANG5 0x94 +#define HID_KEYBOARD_LANG6 0x95 +#define HID_KEYBOARD_LANG7 0x96 +#define HID_KEYBOARD_LANG8 0x97 +#define HID_KEYBOARD_LANG9 0x98 +#define HID_KEYBOARD_ALTERNATE_ERASE 0x99 +#define HID_KEYBOARD_SYSREQ_SLASH_ATTENTION 0x9A +#define HID_KEYBOARD_CANCEL 0x9B +#define HID_KEYBOARD_CLEAR 0x9C +#define HID_KEYBOARD_PRIOR 0x9D +#define HID_KEYBOARD_RETURN 0x9E +#define HID_KEYBOARD_SEPARATOR 0x9F +#define HID_KEYBOARD_OUT 0xA0 +#define HID_KEYBOARD_OPER 0xA1 +#define HID_KEYBOARD_CLEAR_SLASH_AGAIN 0xA2 +#define HID_KEYBOARD_CRSEL_SLASH_PROPS 0xA3 +#define HID_KEYBOARD_EXSEL 0xA4 +// Reserved 0xA5-AF +#define HID_KEYPAD_00 0xB0 +#define HID_KEYPAD_000 0xB1 +#define HID_THOUSANDS_SEPARATOR 0xB2 +#define HID_DECIMAL_SEPARATOR 0xB3 +#define HID_CURRENCY_UNIT 0xB4 +#define HID_CURRENCY_SUBUNIT 0xB5 +#define HID_KEYPAD_LEFT_PAREN 0xB6 +#define HID_KEYPAD_RIGHT_PAREN 0xB7 +#define HID_KEYPAD_LEFT_CURLY_BRACE 0xB8 +#define HID_KEYPAD_RIGHT_CURLY_BRACE 0xB9 +#define HID_KEYPAD_TAB 0xBA +#define HID_KEYPAD_BACKSPACE 0xBB +#define HID_KEYPAD_A 0xBC +#define HID_KEYPAD_B 0xBD +#define HID_KEYPAD_C 0xBE +#define HID_KEYPAD_D 0xBF +#define HID_KEYPAD_E 0xC0 +#define HID_KEYPAD_F 0xC1 +#define HID_KEYPAD_XOR 0xC2 +#define HID_KEYPAD_CARAT 0xC3 +#define HID_KEYPAD_PERCENT 0xC4 +#define HID_KEYPAD_LESS_THAN 0xC5 +#define HID_KEYPAD_GREATER_THAN 0xC6 +#define HID_KEYPAD_AMPERSAND 0xC7 +#define HID_KEYPAD_DOUBLEAMPERSAND 0xC8 +#define HID_KEYPAD_PIPE 0xC9 +#define HID_KEYPAD_DOUBLEPIPE 0xCA +#define HID_KEYPAD_COLON 0xCB +#define HID_KEYPAD_POUND_SIGN 0xCC +#define HID_KEYPAD_SPACE 0xCD +#define HID_KEYPAD_AT_SIGN 0xCE +#define HID_KEYPAD_EXCLAMATION_POINT 0xCF +#define HID_KEYPAD_MEMORY_STORE 0xD0 +#define HID_KEYPAD_MEMORY_RECALL 0xD1 +#define HID_KEYPAD_MEMORY_CLEAR 0xD2 +#define HID_KEYPAD_MEMORY_ADD 0xD3 +#define HID_KEYPAD_MEMORY_SUBTRACT 0xD4 +#define HID_KEYPAD_MEMORY_MULTIPLY 0xD5 +#define HID_KEYPAD_MEMORY_DIVIDE 0xD6 +#define HID_KEYPAD_PLUS_SLASH_MINUS 0xD7 +#define HID_KEYPAD_CLEAR 0xD8 +#define HID_KEYPAD_CLEAR_ENTRY 0xD9 +#define HID_KEYPAD_BINARY 0xDA +#define HID_KEYPAD_OCTAL 0xDB +#define HID_KEYPAD_DECIMAL 0xDC +#define HID_KEYPAD_HEXADECIMAL 0xDD + +// 0xDE-0xDF - RESERVED +#define HID_KEYBOARD_LEFT_CONTROL 0xE0 +#define HID_KEYBOARD_LEFT_SHIFT 0xE1 +#define HID_KEYBOARD_LEFT_ALT 0xE2 +#define HID_KEYBOARD_LEFT_GUI 0xE3 +#define HID_KEYBOARD_RIGHT_CONTROL 0xE4 +#define HID_KEYBOARD_RIGHT_SHIFT 0xE5 +#define HID_KEYBOARD_RIGHT_ALT 0xE6 +#define HID_KEYBOARD_RIGHT_GUI 0xE7 + + +// Consumer_Page_(0x0C) 0x15 +#define HID_CONSUMER_NUMERIC_KEY_PAD 0x02 // HID type NARY +#define HID_CONSUMER_PROGRAMMABLE_BUTTONS 0x03 // HID type NARY +#define HID_CONSUMER_MICROPHONE_CA 0x04 +#define HID_CONSUMER_HEADPHONE_CA 0x05 +#define HID_CONSUMER_GRAPHIC_EQUALIZER_CA 0x06 +// Reserved 0x07-1F +#define HID_CONSUMER_PLUS_10 0x20 // HID type OSC +#define HID_CONSUMER_PLUS_100 0x21 // HID type OSC +#define HID_CONSUMER_AM_SLASH_PM 0x22 // HID type OSC +// Reserved 0x23-3F +#define HID_CONSUMER_POWER 0x30 // HID type OOC +#define HID_CONSUMER_RESET 0x31 // HID type OSC +#define HID_CONSUMER_SLEEP 0x32 // HID type OSC +#define HID_CONSUMER_SLEEP_AFTER 0x33 // HID type OSC +#define HID_CONSUMER_SLEEP_MODE 0x34 // HID type RTC +#define HID_CONSUMER_ILLUMINATION 0x35 // HID type OOC +#define HID_CONSUMER_FUNCTION_BUTTONS 0x36 // HID type NARY +// Reserved 0x37-3F +#define HID_CONSUMER_MENU 0x40 // HID type OOC +#define HID_CONSUMER_MENU_PICK 0x41 // HID type OSC +#define HID_CONSUMER_MENU_UP 0x42 // HID type OSC +#define HID_CONSUMER_MENU_DOWN 0x43 // HID type OSC +#define HID_CONSUMER_MENU_LEFT 0x44 // HID type OSC +#define HID_CONSUMER_MENU_RIGHT 0x45 // HID type OSC +#define HID_CONSUMER_MENU_ESCAPE 0x46 // HID type OSC +#define HID_CONSUMER_MENU_VALUE_INCREASE 0x47 // HID type OSC +#define HID_CONSUMER_MENU_VALUE_DECREASE 0x48 // HID type OSC +// Reserved 0x49-5F +#define HID_CONSUMER_DATA_ON_SCREEN 0x60 // HID type OOC +#define HID_CONSUMER_CLOSED_CAPTION 0x61 // HID type OOC +#define HID_CONSUMER_CLOSED_CAPTION_SELECT 0x62 // HID type OSC +#define HID_CONSUMER_VCR_SLASH_TV 0x63 // HID type OOC +#define HID_CONSUMER_BROADCAST_MODE 0x64 // HID type OSC +#define HID_CONSUMER_SNAPSHOT 0x65 // HID type OSC +#define HID_CONSUMER_STILL 0x66 // HID type OSC +// Reserved 0x67-7F +#define HID_CONSUMER_SELECTION 0x80 // HID type NARY +#define HID_CONSUMER_ASSIGN_SELECTION 0x81 // HID type OSC +#define HID_CONSUMER_MODE_STEP 0x82 // HID type OSC +#define HID_CONSUMER_RECALL_LAST 0x83 // HID type OSC +#define HID_CONSUMER_ENTER_CHANNEL 0x84 // HID type OSC +#define HID_CONSUMER_ORDER_MOVIE 0x85 // HID type OSC +#define HID_CONSUMER_CHANNEL 0x86 // HID type LC +#define HID_CONSUMER_MEDIA_SELECTION 0x87 // HID type NARY +#define HID_CONSUMER_MEDIA_SELECT_COMPUTER 0x88 // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_TV 0x89 // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_WWW 0x8A // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_DVD 0x8B // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_TELEPHONE 0x8C // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_PROGRAM_GUIDE 0x8D // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_VIDEO_PHONE 0x8E // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_GAMES 0x8F // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_MESSAGES 0x90 // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_CD 0x91 // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_VCR 0x92 // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_TUNER 0x93 // HID type SEL +#define HID_CONSUMER_QUIT 0x94 // HID type OSC +#define HID_CONSUMER_HELP 0x95 // HID type OOC +#define HID_CONSUMER_MEDIA_SELECT_TAPE 0x96 // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_CABLE 0x97 // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_SATELLITE 0x98 // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_SECURITY 0x99 // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_HOME 0x9A // HID type SEL +#define HID_CONSUMER_MEDIA_SELECT_CALL 0x9B // HID type SEL +#define HID_CONSUMER_CHANNEL_INCREMENT 0x9C // HID type OSC +#define HID_CONSUMER_CHANNEL_DECREMENT 0x9D // HID type OSC +#define HID_CONSUMER_MEDIA_SELECT_SAP 0x9E // HID type SEL +// Reserved 0x9F +#define HID_CONSUMER_VCR_PLUS 0xA0 // HID type OSC +#define HID_CONSUMER_ONCE 0xA1 // HID type OSC +#define HID_CONSUMER_DAILY 0xA2 // HID type OSC +#define HID_CONSUMER_WEEKLY 0xA3 // HID type OSC +#define HID_CONSUMER_MONTHLY 0xA4 // HID type OSC +// Reserved 0xA5-AF +#define HID_CONSUMER_PLAY 0xB0 // HID type OOC +#define HID_CONSUMER_PAUSE 0xB1 // HID type OOC +#define HID_CONSUMER_RECORD 0xB2 // HID type OOC +#define HID_CONSUMER_FAST_FORWARD 0xB3 // HID type OOC +#define HID_CONSUMER_REWIND 0xB4 // HID type OOC +#define HID_CONSUMER_SCAN_NEXT_TRACK 0xB5 // HID type OSC +#define HID_CONSUMER_SCAN_PREVIOUS_TRACK 0xB6 // HID type OSC +#define HID_CONSUMER_STOP 0xB7 // HID type OSC +#define HID_CONSUMER_EJECT 0xB8 // HID type OSC +#define HID_CONSUMER_RANDOM_PLAY 0xB9 // HID type OOC +#define HID_CONSUMER_SELECT_DISC 0xBA // HID type NARY +#define HID_CONSUMER_ENTER_DISC_MC 0xBB +#define HID_CONSUMER_REPEAT 0xBC // HID type OSC +#define HID_CONSUMER_TRACKING 0xBD // HID type LC +#define HID_CONSUMER_TRACK_NORMAL 0xBE // HID type OSC +#define HID_CONSUMER_SLOW_TRACKING 0xBF // HID type LC +#define HID_CONSUMER_FRAME_FORWARD 0xC0 // HID type RTC +#define HID_CONSUMER_FRAME_BACK 0xC1 // HID type RTC +#define HID_CONSUMER_MARK 0xC2 // HID type OSC +#define HID_CONSUMER_CLEAR_MARK 0xC3 // HID type OSC +#define HID_CONSUMER_REPEAT_FROM_MARK 0xC4 // HID type OOC +#define HID_CONSUMER_RETURN_TO_MARK 0xC5 // HID type OSC +#define HID_CONSUMER_SEARCH_MARK_FORWARD 0xC6 // HID type OSC +#define HID_CONSUMER_SEARCH_MARK_BACKWARDS 0xC7 // HID type OSC +#define HID_CONSUMER_COUNTER_RESET 0xC8 // HID type OSC +#define HID_CONSUMER_SHOW_COUNTER 0xC9 // HID type OSC +#define HID_CONSUMER_TRACKING_INCREMENT 0xCA // HID type RTC +#define HID_CONSUMER_TRACKING_DECREMENT 0xCB // HID type RTC +#define HID_CONSUMER_STOP_SLASH_EJECT 0xCC // HID type OSC +#define HID_CONSUMER_PLAY_SLASH_PAUSE 0xCD // HID type OSC +#define HID_CONSUMER_PLAY_SLASH_SKIP 0xCE // HID type OSC +// Reserved 0xCF-DF +#define HID_CONSUMER_VOLUME 0xE0 // HID type LC +#define HID_CONSUMER_BALANCE 0xE1 // HID type LC +#define HID_CONSUMER_MUTE 0xE2 // HID type OOC +#define HID_CONSUMER_BASS 0xE3 // HID type LC +#define HID_CONSUMER_TREBLE 0xE4 // HID type LC +#define HID_CONSUMER_BASS_BOOST 0xE5 // HID type OOC +#define HID_CONSUMER_SURROUND_MODE 0xE6 // HID type OSC +#define HID_CONSUMER_LOUDNESS 0xE7 // HID type OOC +#define HID_CONSUMER_MPX 0xE8 // HID type OOC +#define HID_CONSUMER_VOLUME_INCREMENT 0xE9 // HID type RTC +#define HID_CONSUMER_VOLUME_DECREMENT 0xEA // HID type RTC +// Reserved 0xEB-EF +#define HID_CONSUMER_SPEED_SELECT 0xF0 // HID type OSC +#define HID_CONSUMER_PLAYBACK_SPEED 0xF1 // HID type NARY +#define HID_CONSUMER_STANDARD_PLAY 0xF2 // HID type SEL +#define HID_CONSUMER_LONG_PLAY 0xF3 // HID type SEL +#define HID_CONSUMER_EXTENDED_PLAY 0xF4 // HID type SEL +#define HID_CONSUMER_SLOW 0xF5 // HID type OSC +// Reserved 0xF6-FF +#define HID_CONSUMER_FAN_ENABLE 0x100 // HID type OOC +#define HID_CONSUMER_FAN_SPEED 0x101 // HID type LC +#define HID_CONSUMER_LIGHT_ENABLE 0x102 // HID type OOC +#define HID_CONSUMER_LIGHT_ILLUMINATION_LEVEL 0x103 // HID type LC +#define HID_CONSUMER_CLIMATE_CONTROL_ENABLE 0x104 // HID type OOC +#define HID_CONSUMER_ROOM_TEMPERATURE 0x105 // HID type LC +#define HID_CONSUMER_SECURITY_ENABLE 0x106 // HID type OOC +#define HID_CONSUMER_FIRE_ALARM 0x107 // HID type OSC +#define HID_CONSUMER_POLICE_ALARM 0x108 // HID type OSC +#define HID_CONSUMER_PROXIMITY 0x109 // HID type LC +#define HID_CONSUMER_MOTION 0x10A // HID type OSC +#define HID_CONSUMER_DURESS_ALARM 0x10B // HID type OSC +#define HID_CONSUMER_HOLDUP_ALARM 0x10C // HID type OSC +#define HID_CONSUMER_MEDICAL_ALARM 0x10D // HID type OSC +// Reserved 0x10E-14F +#define HID_CONSUMER_BALANCE_RIGHT 0x150 // HID type RTC +#define HID_CONSUMER_BALANCE_LEFT 0x151 // HID type RTC +#define HID_CONSUMER_BASS_INCREMENT 0x152 // HID type RTC +#define HID_CONSUMER_BASS_DECREMENT 0x153 // HID type RTC +#define HID_CONSUMER_TREBLE_INCREMENT 0x154 // HID type RTC +#define HID_CONSUMER_TREBLE_DECREMENT 0x155 // HID type RTC +// Reserved 0x156-15F +#define HID_CONSUMER_SPEAKER_SYSTEM 0x160 // HID type CL +#define HID_CONSUMER_CHANNEL_LEFT 0x161 // HID type CL +#define HID_CONSUMER_CHANNEL_RIGHT 0x162 // HID type CL +#define HID_CONSUMER_CHANNEL_CENTER 0x163 // HID type CL +#define HID_CONSUMER_CHANNEL_FRONT 0x164 // HID type CL +#define HID_CONSUMER_CHANNEL_CENTER_FRONT 0x165 // HID type CL +#define HID_CONSUMER_CHANNEL_SIDE 0x166 // HID type CL +#define HID_CONSUMER_CHANNEL_SURROUND 0x167 // HID type CL +#define HID_CONSUMER_CHANNEL_LOW_FREQUENCY_ENHANCEMENT 0x168 // HID type CL +#define HID_CONSUMER_CHANNEL_TOP 0x169 // HID type CL +#define HID_CONSUMER_CHANNEL_UNKNOWN 0x16A // HID type CL +// Reserved 0x16B-16F +#define HID_CONSUMER_SUB-CHANNEL 0x170 // HID type LC +#define HID_CONSUMER_SUB-CHANNEL_INCREMENT 0x171 // HID type OSC +#define HID_CONSUMER_SUB-CHANNEL_DECREMENT 0x172 // HID type OSC +#define HID_CONSUMER_ALTERNATE_AUDIO_INCREMENT 0x173 // HID type OSC +#define HID_CONSUMER_ALTERNATE_AUDIO_DECREMENT 0x174 // HID type OSC +// Reserved 0x175-17F +#define HID_CONSUMER_APPLICATION_LAUNCH_BUTTONS 0x180 // HID type NARY +#define HID_CONSUMER_AL_LAUNCH_BUTTON_CONFIGURATION_TOOL 0x181 // HID type SEL +#define HID_CONSUMER_AL_PROGRAMMABLE_BUTTON_CONFIGURATION 0x182 // HID type SEL +#define HID_CONSUMER_AL_CONSUMER_CONTROL_CONFIGURATION 0x183 // HID type SEL +#define HID_CONSUMER_AL_WORD_PROCESSOR 0x184 // HID type SEL +#define HID_CONSUMER_AL_TEXT_EDITOR 0x185 // HID type SEL +#define HID_CONSUMER_AL_SPREADSHEET 0x186 // HID type SEL +#define HID_CONSUMER_AL_GRAPHICS_EDITOR 0x187 // HID type SEL +#define HID_CONSUMER_AL_PRESENTATION_APP 0x188 // HID type SEL +#define HID_CONSUMER_AL_DATABASE_APP 0x189 // HID type SEL +#define HID_CONSUMER_AL_EMAIL_READER 0x18A // HID type SEL +#define HID_CONSUMER_AL_NEWSREADER 0x18B // HID type SEL +#define HID_CONSUMER_AL_VOICEMAIL 0x18C // HID type SEL +#define HID_CONSUMER_AL_CONTACTS_SLASH_ADDRESS_BOOK 0x18D // HID type SEL +#define HID_CONSUMER_AL_CALENDAR_SLASH_SCHEDULE 0x18E // HID type SEL +#define HID_CONSUMER_AL_TASK_SLASH_PROJECT_MANAGER 0x18F // HID type SEL +#define HID_CONSUMER_AL_LOG_SLASH_JOURNAL_SLASH_TIMECARD 0x190 // HID type SEL +#define HID_CONSUMER_AL_CHECKBOOK_SLASH_FINANCE 0x191 // HID type SEL +#define HID_CONSUMER_AL_CALCULATOR 0x192 // HID type SEL +#define HID_CONSUMER_AL_A_SLASH_V_CAPTURE_SLASH_PLAYBACK 0x193 // HID type SEL +#define HID_CONSUMER_AL_LOCAL_MACHINE_BROWSER 0x194 // HID type SEL +#define HID_CONSUMER_AL_LAN_SLASH_WAN_BROWSER 0x195 // HID type SEL +#define HID_CONSUMER_AL_INTERNET_BROWSER 0x196 // HID type SEL +#define HID_CONSUMER_AL_REMOTE_NETWORKING_SLASH_ISP_CONNECT 0x197 // HID type SEL +#define HID_CONSUMER_AL_NETWORK_CONFERENCE 0x198 // HID type SEL +#define HID_CONSUMER_AL_NETWORK_CHAT 0x199 // HID type SEL +#define HID_CONSUMER_AL_TELEPHONY_SLASH_DIALER 0x19A // HID type SEL +#define HID_CONSUMER_AL_LOGON 0x19B // HID type SEL +#define HID_CONSUMER_AL_LOGOFF 0x19C // HID type SEL +#define HID_CONSUMER_AL_LOGON_SLASH_LOGOFF 0x19D // HID type SEL +#define HID_CONSUMER_AL_TERMINAL_LOCK_SLASH_SCREENSAVER 0x19E // HID type SEL +#define HID_CONSUMER_AL_CONTROL_PANEL 0x19F // HID type SEL +#define HID_CONSUMER_AL_COMMAND_LINE_PROCESSOR_SLASH_RUN 0x1A0 // HID type SEL +#define HID_CONSUMER_AL_PROCESS_SLASH_TASK_MANAGER 0x1A1 // HID type SEL +#define HID_CONSUMER_AL_SELECT_TASK_SLASH_APPLICATION 0x1A2 // HID type SEL +#define HID_CONSUMER_AL_NEXT_TASK_SLASH_APPLICATION 0x1A3 // HID type SEL +#define HID_CONSUMER_AL_PREVIOUS_TASK_SLASH_APPLICATION 0x1A4 // HID type SEL +#define HID_CONSUMER_AL_PREEMPTIVE_HALT_TASK_SLASH_APPLICATION 0x1A5 // HID type SEL +#define HID_CONSUMER_AL_INTEGRATED_HELP_CENTER 0x1A6 // HID type SEL +#define HID_CONSUMER_AL_DOCUMENTS 0x1A7 // HID type SEL +#define HID_CONSUMER_AL_THESAURUS 0x1A8 // HID type SEL +#define HID_CONSUMER_AL_DICTIONARY 0x1A9 // HID type SEL +#define HID_CONSUMER_AL_DESKTOP 0x1AA // HID type SEL +#define HID_CONSUMER_AL_SPELL_CHECK 0x1AB // HID type SEL +#define HID_CONSUMER_AL_GRAMMAR_CHECK 0x1AC // HID type SEL +#define HID_CONSUMER_AL_WIRELESS_STATUS 0x1AD // HID type SEL +#define HID_CONSUMER_AL_KEYBOARD_LAYOUT 0x1AE // HID type SEL +#define HID_CONSUMER_AL_VIRUS_PROTECTION 0x1AF // HID type SEL +#define HID_CONSUMER_AL_ENCRYPTION 0x1B0 // HID type SEL +#define HID_CONSUMER_AL_SCREEN_SAVER 0x1B1 // HID type SEL +#define HID_CONSUMER_AL_ALARMS 0x1B2 // HID type SEL +#define HID_CONSUMER_AL_CLOCK 0x1B3 // HID type SEL +#define HID_CONSUMER_AL_FILE_BROWSER 0x1B4 // HID type SEL +#define HID_CONSUMER_AL_POWER_STATUS 0x1B5 // HID type SEL +#define HID_CONSUMER_AL_IMAGE_BROWSER 0x1B6 // HID type SEL +#define HID_CONSUMER_AL_AUDIO_BROWSER 0x1B7 // HID type SEL +#define HID_CONSUMER_AL_MOVIE_BROWSER 0x1B8 // HID type SEL +#define HID_CONSUMER_AL_DIGITAL_RIGHTS_MANAGER 0x1B9 // HID type SEL +#define HID_CONSUMER_AL_DIGITAL_WALLET 0x1BA // HID type SEL +// _Reserved 0x1BB +#define HID_CONSUMER_AL_INSTANT_MESSAGING 0x1BC // HID type SEL +#define HID_CONSUMER_AL_OEM_FEATURES_SLASH__TIPS_SLASH_TUTORIAL_BROWSER 0x1BD // HID type SEL +#define HID_CONSUMER_AL_OEM_HELP 0x1BE // HID type SEL +#define HID_CONSUMER_AL_ONLINE_COMMUNITY 0x1BF // HID type SEL +#define HID_CONSUMER_AL_ENTERTAINMENT_CONTENT_BROWSER 0x1C0 // HID type SEL +#define HID_CONSUMER_AL_ONLINE_SHOPPING_BROWSER 0x1C1 // HID type SEL +#define HID_CONSUMER_AL_SMARTCARD_INFORMATION_SLASH_HELP 0x1C2 // HID type SEL +#define HID_CONSUMER_AL_MARKET_MONITOR_SLASH_FINANCE_BROWSER 0x1C3 // HID type SEL +#define HID_CONSUMER_AL_CUSTOMIZED_CORPORATE_NEWS_BROWSER 0x1C4 // HID type SEL +#define HID_CONSUMER_AL_ONLINE_ACTIVITY_BROWSER 0x1C5 // HID type SEL +#define HID_CONSUMER_AL_RESEARCH_SLASH_SEARCH_BROWSER 0x1C6 // HID type SEL +#define HID_CONSUMER_AL_AUDIO_PLAYER 0x1C7 // HID type SEL +// Reserved 0x1C8-1FF +#define HID_CONSUMER_GENERIC_GUI_APPLICATION_CONTROLS 0x200 // HID type NARY +#define HID_CONSUMER_AC_NEW 0x201 // HID type SEL +#define HID_CONSUMER_AC_OPEN 0x202 // HID type SEL +#define HID_CONSUMER_AC_CLOSE 0x203 // HID type SEL +#define HID_CONSUMER_AC_EXIT 0x204 // HID type SEL +#define HID_CONSUMER_AC_MAXIMIZE 0x205 // HID type SEL +#define HID_CONSUMER_AC_MINIMIZE 0x206 // HID type SEL +#define HID_CONSUMER_AC_SAVE 0x207 // HID type SEL +#define HID_CONSUMER_AC_PRINT 0x208 // HID type SEL +#define HID_CONSUMER_AC_PROPERTIES 0x209 // HID type SEL +#define HID_CONSUMER_AC_UNDO 0x21A // HID type SEL +#define HID_CONSUMER_AC_COPY 0x21B // HID type SEL +#define HID_CONSUMER_AC_CUT 0x21C // HID type SEL +#define HID_CONSUMER_AC_PASTE 0x21D // HID type SEL +#define HID_CONSUMER_AC_SELECT_ALL 0x21E // HID type SEL +#define HID_CONSUMER_AC_FIND 0x21F // HID type SEL +#define HID_CONSUMER_AC_FIND_AND_REPLACE 0x220 // HID type SEL +#define HID_CONSUMER_AC_SEARCH 0x221 // HID type SEL +#define HID_CONSUMER_AC_GO_TO 0x222 // HID type SEL +#define HID_CONSUMER_AC_HOME 0x223 // HID type SEL +#define HID_CONSUMER_AC_BACK 0x224 // HID type SEL +#define HID_CONSUMER_AC_FORWARD 0x225 // HID type SEL +#define HID_CONSUMER_AC_STOP 0x226 // HID type SEL +#define HID_CONSUMER_AC_REFRESH 0x227 // HID type SEL +#define HID_CONSUMER_AC_PREVIOUS_LINK 0x228 // HID type SEL +#define HID_CONSUMER_AC_NEXT_LINK 0x229 // HID type SEL +#define HID_CONSUMER_AC_BOOKMARKS 0x22A // HID type SEL +#define HID_CONSUMER_AC_HISTORY 0x22B // HID type SEL +#define HID_CONSUMER_AC_SUBSCRIPTIONS 0x22C // HID type SEL +#define HID_CONSUMER_AC_ZOOM_IN 0x22D // HID type SEL +#define HID_CONSUMER_AC_ZOOM_OUT 0x22E // HID type SEL +#define HID_CONSUMER_AC_ZOOM 0x22F // HID type LC +#define HID_CONSUMER_AC_FULL_SCREEN_VIEW 0x230 // HID type SEL +#define HID_CONSUMER_AC_NORMAL_VIEW 0x231 // HID type SEL +#define HID_CONSUMER_AC_VIEW_TOGGLE 0x232 // HID type SEL +#define HID_CONSUMER_AC_SCROLL_UP 0x233 // HID type SEL +#define HID_CONSUMER_AC_SCROLL_DOWN 0x234 // HID type SEL +#define HID_CONSUMER_AC_SCROLL 0x235 // HID type LC +#define HID_CONSUMER_AC_PAN_LEFT 0x236 // HID type SEL +#define HID_CONSUMER_AC_PAN_RIGHT 0x237 // HID type SEL +#define HID_CONSUMER_AC_PAN 0x238 // HID type LC +#define HID_CONSUMER_AC_NEW_WINDOW 0x239 // HID type SEL +#define HID_CONSUMER_AC_TILE_HORIZONTALLY 0x23A // HID type SEL +#define HID_CONSUMER_AC_TILE_VERTICALLY 0x23B // HID type SEL +#define HID_CONSUMER_AC_FORMAT 0x23C // HID type SEL +#define HID_CONSUMER_AC_EDIT 0x23D // HID type SEL +#define HID_CONSUMER_AC_BOLD 0x23E // HID type SEL +#define HID_CONSUMER_AC_ITALICS 0x23F // HID type SEL +#define HID_CONSUMER_AC_UNDERLINE 0x240 // HID type SEL +#define HID_CONSUMER_AC_STRIKETHROUGH 0x241 // HID type SEL +#define HID_CONSUMER_AC_SUBSCRIPT 0x242 // HID type SEL +#define HID_CONSUMER_AC_SUPERSCRIPT 0x243 // HID type SEL +#define HID_CONSUMER_AC_ALL_CAPS 0x244 // HID type SEL +#define HID_CONSUMER_AC_ROTATE 0x245 // HID type SEL +#define HID_CONSUMER_AC_RESIZE 0x246 // HID type SEL +#define HID_CONSUMER_AC_FLIP_HORIZONTAL 0x247 // HID type SEL +#define HID_CONSUMER_AC_FLIP_VERTICAL 0x248 // HID type SEL +#define HID_CONSUMER_AC_MIRROR_HORIZONTAL 0x249 // HID type SEL +#define HID_CONSUMER_AC_MIRROR_VERTICAL 0x24A // HID type SEL +#define HID_CONSUMER_AC_FONT_SELECT 0x24B // HID type SEL +#define HID_CONSUMER_AC_FONT_COLOR 0x24C // HID type SEL +#define HID_CONSUMER_AC_FONT_SIZE 0x24D // HID type SEL +#define HID_CONSUMER_AC_JUSTIFY_LEFT 0x24E // HID type SEL +#define HID_CONSUMER_AC_JUSTIFY_CENTER_H 0x24F // HID type SEL +#define HID_CONSUMER_AC_JUSTIFY_RIGHT 0x250 // HID type SEL +#define HID_CONSUMER_AC_JUSTIFY_BLOCK_H 0x251 // HID type SEL +#define HID_CONSUMER_AC_JUSTIFY_TOP 0x252 // HID type SEL +#define HID_CONSUMER_AC_JUSTIFY_CENTER_V 0x253 // HID type SEL +#define HID_CONSUMER_AC_JUSTIFY_BOTTOM 0x254 // HID type SEL +#define HID_CONSUMER_AC_JUSTIFY_BLOCK_V 0x255 // HID type SEL +#define HID_CONSUMER_AC_INDENT_DECREASE 0x256 // HID type SEL +#define HID_CONSUMER_AC_INDENT_INCREASE 0x257 // HID type SEL +#define HID_CONSUMER_AC_NUMBERED_LIST 0x258 // HID type SEL +#define HID_CONSUMER_AC_RESTART_NUMBERING 0x259 // HID type SEL +#define HID_CONSUMER_AC_BULLETED_LIST 0x25A // HID type SEL +#define HID_CONSUMER_AC_PROMOTE 0x25B // HID type SEL +#define HID_CONSUMER_AC_DEMOTE 0x25C // HID type SEL +#define HID_CONSUMER_AC_YES 0x25D // HID type SEL +#define HID_CONSUMER_AC_NO 0x25E // HID type SEL +#define HID_CONSUMER_AC_CANCEL 0x25F // HID type SEL +#define HID_CONSUMER_AC_CATALOG 0x260 // HID type SEL +#define HID_CONSUMER_AC_BUY_SLASH_CHECKOUT 0x261 // HID type SEL +#define HID_CONSUMER_AC_ADD_TO_CART 0x262 // HID type SEL +#define HID_CONSUMER_AC_EXPAND 0x263 // HID type SEL +#define HID_CONSUMER_AC_EXPAND_ALL 0x264 // HID type SEL +#define HID_CONSUMER_AC_COLLAPSE 0x265 // HID type SEL +#define HID_CONSUMER_AC_COLLAPSE_ALL 0x266 // HID type SEL +#define HID_CONSUMER_AC_PRINT_PREVIEW 0x267 // HID type SEL +#define HID_CONSUMER_AC_PASTE_SPECIAL 0x268 // HID type SEL +#define HID_CONSUMER_AC_INSERT_MODE 0x269 // HID type SEL +#define HID_CONSUMER_AC_DELETE 0x26A // HID type SEL +#define HID_CONSUMER_AC_LOCK 0x26B // HID type SEL +#define HID_CONSUMER_AC_UNLOCK 0x26C // HID type SEL +#define HID_CONSUMER_AC_PROTECT 0x26D // HID type SEL +#define HID_CONSUMER_AC_UNPROTECT 0x26E // HID type SEL +#define HID_CONSUMER_AC_ATTACH_COMMENT 0x26F // HID type SEL +#define HID_CONSUMER_AC_DELETE_COMMENT 0x270 // HID type SEL +#define HID_CONSUMER_AC_VIEW_COMMENT 0x271 // HID type SEL +#define HID_CONSUMER_AC_SELECT_WORD 0x272 // HID type SEL +#define HID_CONSUMER_AC_SELECT_SENTENCE 0x273 // HID type SEL +#define HID_CONSUMER_AC_SELECT_PARAGRAPH 0x274 // HID type SEL +#define HID_CONSUMER_AC_SELECT_COLUMN 0x275 // HID type SEL +#define HID_CONSUMER_AC_SELECT_ROW 0x276 // HID type SEL +#define HID_CONSUMER_AC_SELECT_TABLE 0x277 // HID type SEL +#define HID_CONSUMER_AC_SELECT_OBJECT 0x278 // HID type SEL +#define HID_CONSUMER_AC_REDO_SLASH_REPEAT 0x279 // HID type SEL +#define HID_CONSUMER_AC_SORT 0x27A // HID type SEL +#define HID_CONSUMER_AC_SORT_ASCENDING 0x27B // HID type SEL +#define HID_CONSUMER_AC_SORT_DESCENDING 0x27C // HID type SEL +#define HID_CONSUMER_AC_FILTER 0x27D // HID type SEL +#define HID_CONSUMER_AC_SET_CLOCK 0x27E // HID type SEL +#define HID_CONSUMER_AC_VIEW_CLOCK 0x27F // HID type SEL +#define HID_CONSUMER_AC_SELECT_TIME_ZONE 0x280 // HID type SEL +#define HID_CONSUMER_AC_EDIT_TIME_ZONES 0x281 // HID type SEL +#define HID_CONSUMER_AC_SET_ALARM 0x282 // HID type SEL +#define HID_CONSUMER_AC_CLEAR_ALARM 0x283 // HID type SEL +#define HID_CONSUMER_AC_SNOOZE_ALARM 0x284 // HID type SEL +#define HID_CONSUMER_AC_RESET_ALARM 0x285 // HID type SEL +#define HID_CONSUMER_AC_SYNCHRONIZE 0x286 // HID type SEL +#define HID_CONSUMER_AC_SEND_SLASH_RECEIVE 0x287 // HID type SEL +#define HID_CONSUMER_AC_SEND_TO 0x288 // HID type SEL +#define HID_CONSUMER_AC_REPLY 0x289 // HID type SEL +#define HID_CONSUMER_AC_REPLY_ALL 0x28A // HID type SEL +#define HID_CONSUMER_AC_FORWARD_MSG 0x28B // HID type SEL +#define HID_CONSUMER_AC_SEND 0x28C // HID type SEL +#define HID_CONSUMER_AC_ATTACH_FILE 0x28D // HID type SEL +#define HID_CONSUMER_AC_UPLOAD 0x28E // HID type SEL +#define HID_CONSUMER_AC_DOWNLOAD_(SAVE_TARGET_AS) 0x28F // HID type SEL +#define HID_CONSUMER_AC_SET_BORDERS 0x290 // HID type SEL +#define HID_CONSUMER_AC_INSERT_ROW 0x291 // HID type SEL +#define HID_CONSUMER_AC_INSERT_COLUMN 0x292 // HID type SEL +#define HID_CONSUMER_AC_INSERT_FILE 0x293 // HID type SEL +#define HID_CONSUMER_AC_INSERT_PICTURE 0x294 // HID type SEL +#define HID_CONSUMER_AC_INSERT_OBJECT 0x295 // HID type SEL +#define HID_CONSUMER_AC_INSERT_SYMBOL 0x296 // HID type SEL +#define HID_CONSUMER_AC_SAVE_AND_CLOSE 0x297 // HID type SEL +#define HID_CONSUMER_AC_RENAME 0x298 // HID type SEL +#define HID_CONSUMER_AC_MERGE 0x299 // HID type SEL +#define HID_CONSUMER_AC_SPLIT 0x29A // HID type SEL +#define HID_CONSUMER_AC_DISRIBUTE_HORIZONTALLY 0x29B // HID type SEL +#define HID_CONSUMER_AC_DISTRIBUTE_VERTICALLY 0x29C // HID type SEL + +#endif // __HIDTables__ \ No newline at end of file diff --git a/libraries/CompleteHID/examples/AbsoluteMouse/AbsoluteMouse.ino b/libraries/CompleteHID/examples/AbsoluteMouse/AbsoluteMouse.ino new file mode 100644 index 00000000000..7eaafa1a422 --- /dev/null +++ b/libraries/CompleteHID/examples/AbsoluteMouse/AbsoluteMouse.ino @@ -0,0 +1,28 @@ +/* AbsoluteMouse.ino + + For ATmega32U4 based boards (like the Leonardo and Micro) + * This code is an API demo for the USB HID Absolute Mouse positioning API. + It does not require any circut external to your Arduino + Created 12 Jan 2014 + by Jesse Vincent + This sample code is in the public domain. +*/ + + +void setup() { + Mouse.begin(); +} + +void loop() { + + Mouse.moveAbsolute(16384,16384); // Jump to the center of the screen + delay(2500); + Mouse.moveAbsolute(0, 0); // X position, Y position + delay(2500); + Mouse.moveAbsolute(0, 32767); + delay(2500); + Mouse.moveAbsolute(32767, 32767); + delay(2500); + Mouse.moveAbsolute(32767,0); + delay(2500); +} diff --git a/libraries/CompleteHID/examples/ConsumerAndSystemControl/ConsumerAndSystemControl.ino b/libraries/CompleteHID/examples/ConsumerAndSystemControl/ConsumerAndSystemControl.ino new file mode 100644 index 00000000000..8ea259ff9b4 --- /dev/null +++ b/libraries/CompleteHID/examples/ConsumerAndSystemControl/ConsumerAndSystemControl.ino @@ -0,0 +1,47 @@ +/* ConsumerAndSystemControl.ino + Turns the computer's volume up, then turns it down. + + For ATmega32U4 based boards (like the Leonardo and Micro) + * This code is an API demo for the USB HID ConsumerControl and + SystemControl APIS. + It does not require any circut external to your Arduino + Created 12 Jan 2014 + by Jesse Vincent + This sample code is in the public domain. +*/ + + +void setup() { + Keyboard.begin(); + + // It can take a moment for the USB interface to be ready + // after setup. Delay for a second so we don't lose the first + // keypress. + delay(1000); +} + +void loop() { + + Keyboard.consumerControl(CONSUMER_CONTROL_VOLUME_UP); + delay(1000); + Keyboard.consumerControl(CONSUMER_CONTROL_VOLUME_DOWN); + delay(1000); + + + // Some other things the consumer control API can do: + + // Keyboard.consumerControl(CONSUMER_CONTROL_VOLUME_MUTE); + // Keyboard.consumerControl(CONSUMER_CONTROL_PLAY_PAUSE); + // Keyboard.consumerControl(CONSUMER_CONTROL_STOP); + // Keyboard.consumerControl(CONSUMER_CONTROL_PREV_TRACK); + // Keyboard.consumerControl(CONSUMER_CONTROL_NEXT_TRACK); + + + // If you uncomment this code, the Arduino will try to put your + // computer to sleep after waiting for 30 seconds. + // delay(30000); Keyboard.systemControl(SYSTEM_CONTROL_SLEEP); + + // For a complete list, of the currently supported ConsumerControl + // and SystemControl usages, look in cores/arduino/USBAPI.h + +} \ No newline at end of file From 9074b1ed182dc4ec19606d1dbe917bcb758c2c5a Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 26 Jun 2015 17:16:54 +0200 Subject: [PATCH 28/39] fix HID descriptors bigger than 127 bytes --- hardware/arduino/avr/cores/arduino/PluggableUSB.cpp | 8 ++++---- hardware/arduino/avr/cores/arduino/PluggableUSB.h | 8 ++++---- hardware/arduino/avr/libraries/HID/HID.cpp | 8 ++++---- hardware/arduino/avr/libraries/HID/HID.h | 4 ++-- libraries/MIDIUSB/MIDIUSB.cpp | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index 00f400d56b3..970c11eeb35 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -36,9 +36,9 @@ static u8 modules_count = 0; static PUSBListNode* rootNode = NULL; static PUSBListNode* lastNode = NULL; -int8_t PUSB_GetInterface(u8* interfaceNum) +int PUSB_GetInterface(u8* interfaceNum) { - int8_t ret = 0; + int ret = 0; PUSBListNode* node = rootNode; for (u8 i=0; icb->getInterface(interfaceNum); @@ -47,9 +47,9 @@ int8_t PUSB_GetInterface(u8* interfaceNum) return ret; } -int8_t PUSB_GetDescriptor(int8_t t) +int PUSB_GetDescriptor(int8_t t) { - int8_t ret = 0; + int ret = 0; PUSBListNode* node = rootNode; for (u8 i=0; icb->getDescriptor(t); diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index f729deb098f..b9a27c157fc 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -28,8 +28,8 @@ typedef struct { bool (*setup)(Setup& setup, u8 i); - int8_t (*getInterface)(u8* interfaceNum); - int8_t (*getDescriptor)(int8_t t); + int (*getInterface)(u8* interfaceNum); + int (*getDescriptor)(int8_t t); int8_t numEndpoints; int8_t numInterfaces; uint8_t *endpointType; @@ -50,9 +50,9 @@ class PUSBListNode { int8_t PUSB_AddFunction(PUSBListNode *node, u8 *interface); -int8_t PUSB_GetInterface(u8* interfaceNum); +int PUSB_GetInterface(u8* interfaceNum); -int8_t PUSB_GetDescriptor(int8_t t); +int PUSB_GetDescriptor(int8_t t); bool PUSB_Setup(Setup& setup, u8 i); diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index bd7d25c3d84..c1ac51a2f5c 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -51,13 +51,13 @@ HIDDescriptor _hidInterface; u8 _hid_protocol = 1; u8 _hid_idle = 1; -int8_t WEAK HID_GetInterface(u8* interfaceNum) +int HID_GetInterface(u8* interfaceNum) { interfaceNum[0] += 1; // uses 1 return USB_SendControl(0,&_hidInterface,sizeof(_hidInterface)); } -int8_t WEAK HID_GetDescriptor(int8_t t) +int HID_GetDescriptor(int8_t t) { if (HID_REPORT_DESCRIPTOR_TYPE == t) { return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,getsizeof_hidReportDescriptor()); @@ -66,13 +66,13 @@ int8_t WEAK HID_GetDescriptor(int8_t t) } } -void WEAK HID_SendReport(u8 id, const void* data, int len) +void HID_SendReport(u8 id, const void* data, int len) { USB_Send(HID_TX, &id, 1); USB_Send(HID_TX | TRANSFER_RELEASE,data,len); } -bool WEAK HID_Setup(Setup& setup, u8 i) +bool HID_Setup(Setup& setup, u8 i) { if (HID_INTERFACE != i) { return false; diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index a75774f7b91..fe8ee092a7c 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -39,8 +39,8 @@ class HID_ }; int8_t HID_Plug(void); -int8_t HID_GetInterface(u8* interfaceNum); -int8_t HID_GetDescriptor(int8_t t); +int HID_GetInterface(u8* interfaceNum); +int HID_GetDescriptor(int8_t t); bool HID_Setup(Setup& setup, u8 i); void HID_SendReport(uint8_t id, const void* data, int len); diff --git a/libraries/MIDIUSB/MIDIUSB.cpp b/libraries/MIDIUSB/MIDIUSB.cpp index 939ca6bf5fd..1c7c52d9d69 100644 --- a/libraries/MIDIUSB/MIDIUSB.cpp +++ b/libraries/MIDIUSB/MIDIUSB.cpp @@ -39,18 +39,18 @@ ring_bufferMIDI midi_rx_buffer = {{0,0,0,0 }, 0, 0}; static MIDIDescriptor _midiInterface; -int8_t WEAK MIDI_GetInterface(uint8_t* interfaceNum) +int MIDI_GetInterface(uint8_t* interfaceNum) { interfaceNum[0] += 2; // uses 2 return USB_SendControl(0,&_midiInterface,sizeof(_midiInterface)); } -bool WEAK MIDI_Setup(Setup& setup, u8 i) +bool MIDI_Setup(Setup& setup, u8 i) { //Support requests here if needed. Typically these are optional return false; } -int8_t WEAK MIDI_GetDescriptor(int8_t t) +int MIDI_GetDescriptor(int8_t t) { return 0; } From dee43a19d721fb0ea00a8888e1b9190554021c3f Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 1 Jul 2015 10:08:03 +0200 Subject: [PATCH 29/39] fix HID headers --- hardware/arduino/avr/cores/arduino/USBCore.h | 12 ------------ hardware/arduino/avr/libraries/HID/HID.h | 11 +++++++++++ libraries/CompleteHID/CompleteHID.cpp | 1 - libraries/CompleteHID/CompleteHID.h | 3 ++- libraries/CompleteHID/HIDTables.h | 8 ++++---- libraries/Keyboard/Keyboard.h | 3 +++ 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/USBCore.h b/hardware/arduino/avr/cores/arduino/USBCore.h index c19d68a4236..66f8c05f135 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.h +++ b/hardware/arduino/avr/cores/arduino/USBCore.h @@ -61,13 +61,6 @@ #define MSC_RESET 0xFF #define MSC_GET_MAX_LUN 0xFE -#define HID_GET_REPORT 0x01 -#define HID_GET_IDLE 0x02 -#define HID_GET_PROTOCOL 0x03 -#define HID_SET_REPORT 0x09 -#define HID_SET_IDLE 0x0A -#define HID_SET_PROTOCOL 0x0B - // Descriptors #define USB_DEVICE_DESC_SIZE 18 @@ -131,11 +124,6 @@ #define MSC_SUBCLASS_SCSI 0x06 #define MSC_PROTOCOL_BULK_ONLY 0x50 -#define HID_HID_DESCRIPTOR_TYPE 0x21 -#define HID_REPORT_DESCRIPTOR_TYPE 0x22 -#define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23 - - // Device typedef struct { u8 len; // 18 diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index fe8ee092a7c..5bd137cd600 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -31,6 +31,17 @@ //================================================================================ // HID 'Driver' +#define HID_GET_REPORT 0x01 +#define HID_GET_IDLE 0x02 +#define HID_GET_PROTOCOL 0x03 +#define HID_SET_REPORT 0x09 +#define HID_SET_IDLE 0x0A +#define HID_SET_PROTOCOL 0x0B + +#define HID_HID_DESCRIPTOR_TYPE 0x21 +#define HID_REPORT_DESCRIPTOR_TYPE 0x22 +#define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23 + class HID_ { public: diff --git a/libraries/CompleteHID/CompleteHID.cpp b/libraries/CompleteHID/CompleteHID.cpp index 7c427ad957f..b177adebea5 100644 --- a/libraries/CompleteHID/CompleteHID.cpp +++ b/libraries/CompleteHID/CompleteHID.cpp @@ -1,7 +1,6 @@ #if 1 //defined(USBCON) #include "CompleteHID.h" -#include "HIDTables.h" #include "HID.h" #define HID_MOUSE_ABS_ENABLED diff --git a/libraries/CompleteHID/CompleteHID.h b/libraries/CompleteHID/CompleteHID.h index bc6c949850f..fc55747caac 100644 --- a/libraries/CompleteHID/CompleteHID.h +++ b/libraries/CompleteHID/CompleteHID.h @@ -1,4 +1,5 @@ -#ifndef MOUSEANDKEYBOARD_h +#ifndef COMPLETEHID_h +#define COMPLETEHID_h #if defined(_USING_HID) diff --git a/libraries/CompleteHID/HIDTables.h b/libraries/CompleteHID/HIDTables.h index a00de5fafef..2e62c3d2ef2 100644 --- a/libraries/CompleteHID/HIDTables.h +++ b/libraries/CompleteHID/HIDTables.h @@ -1,5 +1,5 @@ #ifndef __HIDTables__ -#define HID___HIDTables__ +#define __HIDTables__ // These mappings were extracted and transcribed from @@ -453,9 +453,9 @@ #define HID_CONSUMER_CHANNEL_TOP 0x169 // HID type CL #define HID_CONSUMER_CHANNEL_UNKNOWN 0x16A // HID type CL // Reserved 0x16B-16F -#define HID_CONSUMER_SUB-CHANNEL 0x170 // HID type LC -#define HID_CONSUMER_SUB-CHANNEL_INCREMENT 0x171 // HID type OSC -#define HID_CONSUMER_SUB-CHANNEL_DECREMENT 0x172 // HID type OSC +#define HID_CONSUMER_SUB_CHANNEL 0x170 // HID type LC +#define HID_CONSUMER_SUB_CHANNEL_INCREMENT 0x171 // HID type OSC +#define HID_CONSUMER_SUB_CHANNEL_DECREMENT 0x172 // HID type OSC #define HID_CONSUMER_ALTERNATE_AUDIO_INCREMENT 0x173 // HID type OSC #define HID_CONSUMER_ALTERNATE_AUDIO_DECREMENT 0x174 // HID type OSC // Reserved 0x175-17F diff --git a/libraries/Keyboard/Keyboard.h b/libraries/Keyboard/Keyboard.h index 6bfa0b8535e..475b3c168dc 100644 --- a/libraries/Keyboard/Keyboard.h +++ b/libraries/Keyboard/Keyboard.h @@ -19,6 +19,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef KEYBOARD_h +#define KEYBOARD_h + #if defined(_USING_HID) #error "Can only attach one submodule to HID module" From 97a377177260c4ecc5b20513056a39007b3297c4 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 1 Jul 2015 16:56:14 +0200 Subject: [PATCH 30/39] rename Setup typedef struct to USBSetup was really too common --- hardware/arduino/avr/cores/arduino/CDC.cpp | 4 ++-- hardware/arduino/avr/cores/arduino/PluggableUSB.cpp | 2 +- hardware/arduino/avr/cores/arduino/PluggableUSB.h | 4 ++-- hardware/arduino/avr/cores/arduino/USBAPI.h | 6 +++--- hardware/arduino/avr/cores/arduino/USBCore.cpp | 6 +++--- hardware/arduino/avr/libraries/HID/HID.cpp | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/CDC.cpp b/hardware/arduino/avr/cores/arduino/CDC.cpp index 2ea1353d28b..22f3591d8c7 100644 --- a/hardware/arduino/avr/cores/arduino/CDC.cpp +++ b/hardware/arduino/avr/cores/arduino/CDC.cpp @@ -53,13 +53,13 @@ const CDCDescriptor _cdcInterface = D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,0x40,0) }; -int WEAK CDC_GetInterface(u8* interfaceNum) +int CDC_GetInterface(u8* interfaceNum) { interfaceNum[0] += 2; // uses 2 return USB_SendControl(TRANSFER_PGM,&_cdcInterface,sizeof(_cdcInterface)); } -bool WEAK CDC_Setup(Setup& setup) +bool CDC_Setup(USBSetup& setup) { u8 r = setup.bRequest; u8 requestType = setup.bmRequestType; diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index 970c11eeb35..68a6c8af125 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -58,7 +58,7 @@ int PUSB_GetDescriptor(int8_t t) return ret; } -bool PUSB_Setup(Setup& setup, u8 j) +bool PUSB_Setup(USBSetup& setup, u8 j) { bool ret = false; PUSBListNode* node = rootNode; diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index b9a27c157fc..647980b850c 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -27,7 +27,7 @@ typedef struct { - bool (*setup)(Setup& setup, u8 i); + bool (*setup)(USBSetup& setup, u8 i); int (*getInterface)(u8* interfaceNum); int (*getDescriptor)(int8_t t); int8_t numEndpoints; @@ -54,7 +54,7 @@ int PUSB_GetInterface(u8* interfaceNum); int PUSB_GetDescriptor(int8_t t); -bool PUSB_Setup(Setup& setup, u8 i); +bool PUSB_Setup(USBSetup& setup, u8 i); void PUSB_Begin(); diff --git a/hardware/arduino/avr/cores/arduino/USBAPI.h b/hardware/arduino/avr/cores/arduino/USBAPI.h index 251e4b9577f..4abd9616f33 100644 --- a/hardware/arduino/avr/cores/arduino/USBAPI.h +++ b/hardware/arduino/avr/cores/arduino/USBAPI.h @@ -118,7 +118,7 @@ typedef struct uint8_t wValueH; uint16_t wIndex; uint16_t wLength; -} Setup; +} USBSetup; //================================================================================ //================================================================================ @@ -126,7 +126,7 @@ typedef struct int MSC_GetInterface(uint8_t* interfaceNum); int MSC_GetDescriptor(int i); -bool MSC_Setup(Setup& setup); +bool MSC_Setup(USBSetup& setup); bool MSC_Data(uint8_t rx,uint8_t tx); //================================================================================ @@ -135,7 +135,7 @@ bool MSC_Data(uint8_t rx,uint8_t tx); int CDC_GetInterface(uint8_t* interfaceNum); int CDC_GetDescriptor(int i); -bool CDC_Setup(Setup& setup); +bool CDC_Setup(USBSetup& setup); //================================================================================ //================================================================================ diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index 9095d79b970..8237ccb2c47 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -352,7 +352,7 @@ void InitEndpoints() // Handle CLASS_INTERFACE requests static -bool ClassInterfaceRequest(Setup& setup) +bool ClassInterfaceRequest(USBSetup& setup) { u8 i = setup.wIndex; @@ -465,7 +465,7 @@ bool SendConfiguration(int maxlen) u8 _cdcComposite = 0; static -bool SendDescriptor(Setup& setup) +bool SendDescriptor(USBSetup& setup) { int ret; u8 t = setup.wValueH; @@ -517,7 +517,7 @@ ISR(USB_COM_vect) if (!ReceivedSetupInt()) return; - Setup setup; + USBSetup setup; Recv((u8*)&setup,8); ClearSetupInt(); diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index c1ac51a2f5c..e75a6f53da5 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -72,7 +72,7 @@ void HID_SendReport(u8 id, const void* data, int len) USB_Send(HID_TX | TRANSFER_RELEASE,data,len); } -bool HID_Setup(Setup& setup, u8 i) +bool HID_Setup(USBSetup& setup, u8 i) { if (HID_INTERFACE != i) { return false; From 5defaeaa97a7a823d27941207d2e09fa30b49a73 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 1 Jul 2015 16:58:26 +0200 Subject: [PATCH 31/39] rework HID class functions scopes --- hardware/arduino/avr/libraries/HID/HID.cpp | 2 +- hardware/arduino/avr/libraries/HID/HID.h | 7 +------ libraries/Keyboard/Keyboard.cpp | 2 +- libraries/Keyboard/Keyboard.h | 1 + libraries/Mouse/Mouse.cpp | 2 +- libraries/Mouse/Mouse.h | 1 + 6 files changed, 6 insertions(+), 9 deletions(-) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index e75a6f53da5..f18e069d7e4 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -66,7 +66,7 @@ int HID_GetDescriptor(int8_t t) } } -void HID_SendReport(u8 id, const void* data, int len) +void HID_::SendReport(u8 id, const void* data, int len) { USB_Send(HID_TX, &id, 1); USB_Send(HID_TX | TRANSFER_RELEASE,data,len); diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index 5bd137cd600..d3a9982552b 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -47,14 +47,9 @@ class HID_ public: HID_(void); int begin(void); + void SendReport(uint8_t id, const void* data, int len); }; -int8_t HID_Plug(void); -int HID_GetInterface(u8* interfaceNum); -int HID_GetDescriptor(int8_t t); -bool HID_Setup(Setup& setup, u8 i); -void HID_SendReport(uint8_t id, const void* data, int len); - extern HID_ HID; typedef struct diff --git a/libraries/Keyboard/Keyboard.cpp b/libraries/Keyboard/Keyboard.cpp index a331d75da77..26772a45ba6 100644 --- a/libraries/Keyboard/Keyboard.cpp +++ b/libraries/Keyboard/Keyboard.cpp @@ -44,7 +44,7 @@ void Keyboard_::end(void) void Keyboard_::sendReport(KeyReport* keys) { - HID_SendReport(2,keys,sizeof(KeyReport)); + HID.SendReport(2,keys,sizeof(KeyReport)); } const u8 _hidReportDescriptor[] PROGMEM = { diff --git a/libraries/Keyboard/Keyboard.h b/libraries/Keyboard/Keyboard.h index 475b3c168dc..daa3d80192e 100644 --- a/libraries/Keyboard/Keyboard.h +++ b/libraries/Keyboard/Keyboard.h @@ -96,5 +96,6 @@ class Keyboard_ : public Print virtual void releaseAll(void); }; extern Keyboard_ Keyboard; +extern HID_ HID; #endif diff --git a/libraries/Mouse/Mouse.cpp b/libraries/Mouse/Mouse.cpp index aeeaae5dcf2..55dec7f9113 100644 --- a/libraries/Mouse/Mouse.cpp +++ b/libraries/Mouse/Mouse.cpp @@ -93,7 +93,7 @@ void Mouse_::move(signed char x, signed char y, signed char wheel) m[1] = x; m[2] = y; m[3] = wheel; - HID_SendReport(1,m,4); + HID.SendReport(1,m,4); } void Mouse_::buttons(uint8_t b) diff --git a/libraries/Mouse/Mouse.h b/libraries/Mouse/Mouse.h index 50f00a54896..73ca429b862 100644 --- a/libraries/Mouse/Mouse.h +++ b/libraries/Mouse/Mouse.h @@ -56,6 +56,7 @@ class Mouse_ bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default }; extern Mouse_ Mouse; +extern HID_ HID; #endif #endif \ No newline at end of file From 8a45883230919a3dd132d3c23d899241258b96b4 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 1 Jul 2015 17:00:14 +0200 Subject: [PATCH 32/39] save RAM content overridden by bootloader magic and restore it in case of aborted reboot use RAMEND-1 as suggested by @yyyc514 in PR #2474 of course it's not a real solution but we cannot force everyone to update the bootloader using an external programmer --- hardware/arduino/avr/cores/arduino/CDC.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hardware/arduino/avr/cores/arduino/CDC.cpp b/hardware/arduino/avr/cores/arduino/CDC.cpp index 22f3591d8c7..d694a2d2ca8 100644 --- a/hardware/arduino/avr/cores/arduino/CDC.cpp +++ b/hardware/arduino/avr/cores/arduino/CDC.cpp @@ -95,6 +95,7 @@ bool CDC_Setup(USBSetup& setup) // We check DTR state to determine if host port is open (bit 0 of lineState). if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01) == 0) { + *(uint16_t *)(RAMEND-1) = *(uint16_t *)0x0800; *(uint16_t *)0x0800 = 0x7777; wdt_enable(WDTO_120MS); } @@ -107,7 +108,7 @@ bool CDC_Setup(USBSetup& setup) wdt_disable(); wdt_reset(); - *(uint16_t *)0x0800 = 0x0; + *(uint16_t *)0x0800 = *(uint16_t *)(RAMEND-1); } } return true; From 6a9568d3e132f9b630c74010f1401fb8c06440dc Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 2 Jul 2015 12:08:53 +0200 Subject: [PATCH 33/39] fix pluggableUSB linked list --- hardware/arduino/avr/cores/arduino/PluggableUSB.cpp | 8 +++++--- hardware/arduino/avr/cores/arduino/PluggableUSB.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index 68a6c8af125..857a27fe9d7 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -34,7 +34,6 @@ extern u8 _initEndpoints[]; static u8 modules_count = 0; static PUSBListNode* rootNode = NULL; -static PUSBListNode* lastNode = NULL; int PUSB_GetInterface(u8* interfaceNum) { @@ -77,9 +76,12 @@ int8_t PUSB_AddFunction(PUSBListNode *node, u8* interface) if (modules_count == 0) { rootNode = node; - lastNode = node; } else { - lastNode->next = node; + PUSBListNode *current = rootNode; + while(current->next != NULL) { + current = current->next; + } + current->next = node; } *interface = lastIf; diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index 647980b850c..d89040eb41d 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -25,7 +25,7 @@ #if defined(USBCON) -typedef struct +typedef struct __attribute__((packed)) { bool (*setup)(USBSetup& setup, u8 i); int (*getInterface)(u8* interfaceNum); From e1a0350062534ccb84e8ceacfd5ad880d9e89f55 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 2 Jul 2015 12:12:15 +0200 Subject: [PATCH 34/39] allow HID submodules to create runtime descriptors with this PR you can add \#include Keyboard.h \#include Mouse.h \#include HID.h in the top of the sketch and you will expose a Mouse+Keyboard From the library pow, simply add static HID_Descriptor cb = { .length = sizeof(_hidReportDescriptor), .descriptor = _hidReportDescriptor, }; static HIDDescriptorListNode node(&cb); HID.AppendDescriptor(&node); in the class' constructor and you are done! --- hardware/arduino/avr/libraries/HID/HID.cpp | 39 ++++++++++++++---- hardware/arduino/avr/libraries/HID/HID.h | 20 +++++---- libraries/Keyboard/Keyboard.cpp | 48 +++++++++++----------- libraries/Keyboard/Keyboard.h | 10 ++--- libraries/Mouse/Mouse.cpp | 16 ++++---- libraries/Mouse/Mouse.h | 2 +- 6 files changed, 83 insertions(+), 52 deletions(-) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index f18e069d7e4..ba379c29d92 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -44,6 +44,9 @@ static u8 HID_INTERFACE; HIDDescriptor _hidInterface; +static HIDDescriptorListNode* rootNode = NULL; +static uint8_t sizeof_hidReportDescriptor = 0; +static uint8_t modules_count = 0; //================================================================================ //================================================================================ // Driver @@ -54,18 +57,45 @@ u8 _hid_idle = 1; int HID_GetInterface(u8* interfaceNum) { interfaceNum[0] += 1; // uses 1 + _hidInterface = + { + D_INTERFACE(HID_INTERFACE,1,3,0,0), + D_HIDREPORT(sizeof_hidReportDescriptor), + D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01) + }; return USB_SendControl(0,&_hidInterface,sizeof(_hidInterface)); } int HID_GetDescriptor(int8_t t) { if (HID_REPORT_DESCRIPTOR_TYPE == t) { - return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,getsizeof_hidReportDescriptor()); + HIDDescriptorListNode* current = rootNode; + int total = 0; + while(current != NULL) { + total += USB_SendControl(TRANSFER_PGM,current->cb->descriptor,current->cb->length); + current = current->next; + } + return total; } else { return 0; } } +void HID_::AppendDescriptor(HIDDescriptorListNode *node) +{ + if (modules_count == 0) { + rootNode = node; + } else { + HIDDescriptorListNode *current = rootNode; + while(current->next != NULL) { + current = current->next; + } + current->next = node; + } + modules_count++; + sizeof_hidReportDescriptor += node->cb->length; +} + void HID_::SendReport(u8 id, const void* data, int len) { USB_Send(HID_TX, &id, 1); @@ -129,13 +159,6 @@ HID_::HID_(void) static PUSBListNode node(&cb); HID_ENDPOINT_INT = PUSB_AddFunction(&node, &HID_INTERFACE); - - _hidInterface = - { - D_INTERFACE(HID_INTERFACE,1,3,0,0), - D_HIDREPORT(getsizeof_hidReportDescriptor()), - D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01) - }; } int HID_::begin(void) diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index d3a9982552b..c7608eb59b3 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -42,16 +42,27 @@ #define HID_REPORT_DESCRIPTOR_TYPE 0x22 #define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23 +typedef struct __attribute__((packed)) { + u8 length; + const void* descriptor; +} HID_Descriptor; + +class HIDDescriptorListNode { +public: + HIDDescriptorListNode *next = NULL; + const HID_Descriptor * cb; + HIDDescriptorListNode(const HID_Descriptor *ncb) {cb = ncb;} +}; + class HID_ { public: HID_(void); int begin(void); void SendReport(uint8_t id, const void* data, int len); + void AppendDescriptor(HIDDescriptorListNode* node); }; -extern HID_ HID; - typedef struct { u8 len; // 9 @@ -77,11 +88,6 @@ typedef struct #define D_HIDREPORT(_descriptorLength) \ { 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength, 0 } -extern const u8 _hidReportDescriptor[] PROGMEM; - -// MUST be declared by the module -size_t getsizeof_hidReportDescriptor(); - #define WEAK __attribute__ ((weak)) #endif diff --git a/libraries/Keyboard/Keyboard.cpp b/libraries/Keyboard/Keyboard.cpp index 26772a45ba6..571060e1e8c 100644 --- a/libraries/Keyboard/Keyboard.cpp +++ b/libraries/Keyboard/Keyboard.cpp @@ -21,33 +21,13 @@ #if 1 -#include "HID.h" #include "Keyboard.h" //================================================================================ //================================================================================ // Keyboard -Keyboard_ Keyboard; - -Keyboard_::Keyboard_(void) -{ -} - -void Keyboard_::begin(void) -{ -} - -void Keyboard_::end(void) -{ -} - -void Keyboard_::sendReport(KeyReport* keys) -{ - HID.SendReport(2,keys,sizeof(KeyReport)); -} - -const u8 _hidReportDescriptor[] PROGMEM = { +static const u8 _hidReportDescriptor[] PROGMEM = { // Keyboard 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47 @@ -80,6 +60,29 @@ const u8 _hidReportDescriptor[] PROGMEM = { 0xc0, // END_COLLECTION }; +Keyboard_::Keyboard_(void) +{ + static HID_Descriptor cb = { + .length = sizeof(_hidReportDescriptor), + .descriptor = _hidReportDescriptor, + }; + static HIDDescriptorListNode node(&cb); + HID.AppendDescriptor(&node); +} + +void Keyboard_::begin(void) +{ +} + +void Keyboard_::end(void) +{ +} + +void Keyboard_::sendReport(KeyReport* keys) +{ + HID.SendReport(2,keys,sizeof(KeyReport)); +} + extern const uint8_t _asciimap[128] PROGMEM; @@ -217,9 +220,6 @@ const uint8_t _asciimap[128] = 0 // DEL }; -size_t getsizeof_hidReportDescriptor() { - return sizeof(_hidReportDescriptor); -} uint8_t USBPutChar(uint8_t c); diff --git a/libraries/Keyboard/Keyboard.h b/libraries/Keyboard/Keyboard.h index daa3d80192e..9affa18d378 100644 --- a/libraries/Keyboard/Keyboard.h +++ b/libraries/Keyboard/Keyboard.h @@ -22,7 +22,7 @@ #ifndef KEYBOARD_h #define KEYBOARD_h -#if defined(_USING_HID) +#if 0 //defined(_USING_HID) #error "Can only attach one submodule to HID module" @@ -90,10 +90,10 @@ class Keyboard_ : public Print Keyboard_(void); void begin(void); void end(void); - virtual size_t write(uint8_t k); - virtual size_t press(uint8_t k); - virtual size_t release(uint8_t k); - virtual void releaseAll(void); + size_t write(uint8_t k); + size_t press(uint8_t k); + size_t release(uint8_t k); + void releaseAll(void); }; extern Keyboard_ Keyboard; extern HID_ HID; diff --git a/libraries/Mouse/Mouse.cpp b/libraries/Mouse/Mouse.cpp index 55dec7f9113..5001d6215e1 100644 --- a/libraries/Mouse/Mouse.cpp +++ b/libraries/Mouse/Mouse.cpp @@ -23,7 +23,7 @@ #include "Mouse.h" -const u8 _hidReportDescriptor[] PROGMEM = { +static const u8 _hidReportDescriptor[] PROGMEM = { // Mouse 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54 @@ -56,18 +56,18 @@ const u8 _hidReportDescriptor[] PROGMEM = { 0xc0, // END_COLLECTION }; -size_t getsizeof_hidReportDescriptor() { - return sizeof(_hidReportDescriptor); -} - -Mouse_ Mouse; - //================================================================================ //================================================================================ // Mouse Mouse_::Mouse_(void) : _buttons(0) { + const static HID_Descriptor cb = { + .length = sizeof(_hidReportDescriptor), + .descriptor = _hidReportDescriptor, + }; + static HIDDescriptorListNode node(&cb); + HID.AppendDescriptor(&node); } void Mouse_::begin(void) @@ -122,4 +122,6 @@ bool Mouse_::isPressed(uint8_t b) return false; } +Mouse_ Mouse; + #endif diff --git a/libraries/Mouse/Mouse.h b/libraries/Mouse/Mouse.h index 73ca429b862..ac1117c3c60 100644 --- a/libraries/Mouse/Mouse.h +++ b/libraries/Mouse/Mouse.h @@ -22,7 +22,7 @@ #ifndef MOUSE_h #define MOUSE_h -#if defined(_USING_HID) +#if 0 //defined(_USING_HID) #error "Can only attach one submodule to HID module" From efd329bb5e1e2575e00f0b3a7e4a106ce37f8abd Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 2 Jul 2015 12:27:33 +0200 Subject: [PATCH 35/39] fix MIDIUSB and adapt CompleteHID to PluggableHID --- libraries/CompleteHID/CompleteHID.cpp | 24 +- libraries/CompleteHID/CompleteHID.h | 26 +- libraries/MIDIUSB/MIDIUSB.cpp | 2 +- libraries/MIDIUSB/MIDIUSB.h | 12 +- .../MouseAndKeyboard/MouseAndKeyboard.cpp | 416 ------------------ libraries/MouseAndKeyboard/MouseAndKeyboard.h | 104 ----- 6 files changed, 34 insertions(+), 550 deletions(-) delete mode 100644 libraries/MouseAndKeyboard/MouseAndKeyboard.cpp delete mode 100644 libraries/MouseAndKeyboard/MouseAndKeyboard.h diff --git a/libraries/CompleteHID/CompleteHID.cpp b/libraries/CompleteHID/CompleteHID.cpp index b177adebea5..b533e63174b 100644 --- a/libraries/CompleteHID/CompleteHID.cpp +++ b/libraries/CompleteHID/CompleteHID.cpp @@ -1,7 +1,6 @@ #if 1 //defined(USBCON) #include "CompleteHID.h" -#include "HID.h" #define HID_MOUSE_ABS_ENABLED @@ -197,9 +196,6 @@ const u8 _hidReportDescriptor[] = { #endif }; -size_t getsizeof_hidReportDescriptor() { - return sizeof(_hidReportDescriptor); -} //================================================================================ //================================================================================ @@ -207,6 +203,12 @@ size_t getsizeof_hidReportDescriptor() { Mouse_::Mouse_(void) : _buttons(0) { + static HID_Descriptor cb = { + .length = sizeof(_hidReportDescriptor), + .descriptor = _hidReportDescriptor, + }; + static HIDDescriptorListNode node(&cb); + HID.AppendDescriptor(&node); } void Mouse_::begin(void) @@ -232,7 +234,7 @@ void Mouse_::move(signed char x, signed char y, signed char wheel) m[1] = x; m[2] = y; m[3] = wheel; - HID_SendReport(HID_REPORTID_MOUSE,m,sizeof(m)); + HID.SendReport(HID_REPORTID_MOUSE,m,sizeof(m)); } // X and Y have the range of 0 to 32767. @@ -261,7 +263,7 @@ void Mouse_::moveAbsolute(uint16_t x, uint16_t y) m[2] = MSB(x); m[3] = LSB(y); m[4] = MSB(y); - HID_SendReport(HID_REPORTID_MOUSE_ABS,m,sizeof(m)); + HID.SendReport(HID_REPORTID_MOUSE_ABS,m,sizeof(m)); } void Mouse_::buttons(uint8_t b) @@ -308,7 +310,7 @@ void Keyboard_::end(void) void Keyboard_::sendReport(KeyReport* keys) { - HID_SendReport(HID_REPORTID_KEYBOARD,keys,sizeof(*keys)); + HID.SendReport(HID_REPORTID_KEYBOARD,keys,sizeof(*keys)); } extern @@ -549,12 +551,12 @@ size_t Keyboard_::systemControl(uint8_t k) m[0] = LSB(mask); m[1] = MSB(mask); - HID_SendReport(HID_REPORTID_SYSTEMCONTROL,m,sizeof(m)); + HID.SendReport(HID_REPORTID_SYSTEMCONTROL,m,sizeof(m)); // these are all OSCs, so send a clear to make it possible to send it again later m[0] = 0; m[1] = 0; - HID_SendReport(HID_REPORTID_SYSTEMCONTROL,m,sizeof(m)); + HID.SendReport(HID_REPORTID_SYSTEMCONTROL,m,sizeof(m)); return 1; } else @@ -581,12 +583,12 @@ size_t Keyboard_::consumerControl(uint8_t k) m[0] = LSB(mask); m[1] = MSB(mask); - HID_SendReport(HID_REPORTID_CONSUMERCONTROL,m,sizeof(m)); + HID.SendReport(HID_REPORTID_CONSUMERCONTROL,m,sizeof(m)); // these are all OSCs, so send a clear to make it possible to send it again later m[0] = 0; m[1] = 0; - HID_SendReport(HID_REPORTID_CONSUMERCONTROL,m,sizeof(m)); + HID.SendReport(HID_REPORTID_CONSUMERCONTROL,m,sizeof(m)); return 1; } else diff --git a/libraries/CompleteHID/CompleteHID.h b/libraries/CompleteHID/CompleteHID.h index fc55747caac..467237f86b6 100644 --- a/libraries/CompleteHID/CompleteHID.h +++ b/libraries/CompleteHID/CompleteHID.h @@ -1,7 +1,7 @@ #ifndef COMPLETEHID_h #define COMPLETEHID_h -#if defined(_USING_HID) +#if 0 //defined(_USING_HID) #error "Can only attach one submodule to HID module" @@ -12,6 +12,8 @@ #include "HID.h" #include "HIDTables.h" +extern HID_ HID; + //================================================================================ //================================================================================ // Mouse @@ -98,17 +100,17 @@ class Keyboard_ : public Print Keyboard_(void); void begin(void); void end(void); - virtual size_t write(uint8_t k); - virtual size_t press(uint8_t k); - virtual size_t release(uint8_t k); - virtual size_t writeKeycode(uint8_t k); - virtual size_t pressKeycode(uint8_t k); - virtual size_t releaseKeycode(uint8_t k); - virtual size_t addKeycodeToReport(uint8_t k); - virtual size_t removeKeycodeFromReport(uint8_t k); - virtual void releaseAll(void); - virtual size_t systemControl(uint8_t k); - virtual size_t consumerControl(uint8_t k); + size_t write(uint8_t k); + size_t press(uint8_t k); + size_t release(uint8_t k); + size_t writeKeycode(uint8_t k); + size_t pressKeycode(uint8_t k); + size_t releaseKeycode(uint8_t k); + size_t addKeycodeToReport(uint8_t k); + size_t removeKeycodeFromReport(uint8_t k); + void releaseAll(void); + size_t systemControl(uint8_t k); + size_t consumerControl(uint8_t k); }; extern Keyboard_ Keyboard; diff --git a/libraries/MIDIUSB/MIDIUSB.cpp b/libraries/MIDIUSB/MIDIUSB.cpp index 1c7c52d9d69..9a1bfd79dce 100644 --- a/libraries/MIDIUSB/MIDIUSB.cpp +++ b/libraries/MIDIUSB/MIDIUSB.cpp @@ -44,7 +44,7 @@ int MIDI_GetInterface(uint8_t* interfaceNum) interfaceNum[0] += 2; // uses 2 return USB_SendControl(0,&_midiInterface,sizeof(_midiInterface)); } -bool MIDI_Setup(Setup& setup, u8 i) +bool MIDI_Setup(USBSetup& setup, u8 i) { //Support requests here if needed. Typically these are optional return false; diff --git a/libraries/MIDIUSB/MIDIUSB.h b/libraries/MIDIUSB/MIDIUSB.h index 7fad154730a..0776002dc12 100644 --- a/libraries/MIDIUSB/MIDIUSB.h +++ b/libraries/MIDIUSB/MIDIUSB.h @@ -30,12 +30,12 @@ class MIDI_ int8_t begin(); - virtual uint32_t available(void); - virtual void accept(void); - virtual midiEventPacket_t read(void); - virtual void flush(void); - virtual void sendMIDI(midiEventPacket_t event); - virtual size_t write(const uint8_t *buffer, size_t size); + uint32_t available(void); + void accept(void); + midiEventPacket_t read(void); + void flush(void); + void sendMIDI(midiEventPacket_t event); + size_t write(const uint8_t *buffer, size_t size); operator bool(); }; extern MIDI_ MidiUSB; diff --git a/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp b/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp deleted file mode 100644 index 809ff9d50bd..00000000000 --- a/libraries/MouseAndKeyboard/MouseAndKeyboard.cpp +++ /dev/null @@ -1,416 +0,0 @@ -#if 1 //defined(USBCON) - -#include "MouseAndKeyboard.h" -#include "HID.h" - -const u8 _hidReportDescriptor[] PROGMEM = { - - // Mouse - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54 - 0x09, 0x02, // USAGE (Mouse) - 0xa1, 0x01, // COLLECTION (Application) - 0x09, 0x01, // USAGE (Pointer) - 0xa1, 0x00, // COLLECTION (Physical) - 0x85, 0x01, // REPORT_ID (1) - 0x05, 0x09, // USAGE_PAGE (Button) - 0x19, 0x01, // USAGE_MINIMUM (Button 1) - 0x29, 0x03, // USAGE_MAXIMUM (Button 3) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x95, 0x03, // REPORT_COUNT (3) - 0x75, 0x01, // REPORT_SIZE (1) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x95, 0x01, // REPORT_COUNT (1) - 0x75, 0x05, // REPORT_SIZE (5) - 0x81, 0x03, // INPUT (Cnst,Var,Abs) - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x30, // USAGE (X) - 0x09, 0x31, // USAGE (Y) - 0x09, 0x38, // USAGE (Wheel) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x03, // REPORT_COUNT (3) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0xc0, // END_COLLECTION - 0xc0, // END_COLLECTION - - // Keyboard - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 47 - 0x09, 0x06, // USAGE (Keyboard) - 0xa1, 0x01, // COLLECTION (Application) - 0x85, 0x02, // REPORT_ID (2) - 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 (1) - 0x75, 0x08, // REPORT_SIZE (8) - 0x81, 0x03, // INPUT (Cnst,Var,Abs) - - 0x95, 0x06, // REPORT_COUNT (6) - 0x75, 0x08, // REPORT_SIZE (8) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x65, // LOGICAL_MAXIMUM (101) - 0x05, 0x07, // USAGE_PAGE (Keyboard) - - 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) - 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application) - 0x81, 0x00, // INPUT (Data,Ary,Abs) - 0xc0, // END_COLLECTION - -#ifdef RAWHID_ENABLED - // RAW HID - 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), // 30 - 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE), - - 0xA1, 0x01, // Collection 0x01 - 0x85, 0x03, // REPORT_ID (3) - 0x75, 0x08, // report size = 8 bits - 0x15, 0x00, // logical minimum = 0 - 0x26, 0xFF, 0x00, // logical maximum = 255 - - 0x95, 64, // report count TX - 0x09, 0x01, // usage - 0x81, 0x02, // Input (array) - - 0x95, 64, // report count RX - 0x09, 0x02, // usage - 0x91, 0x02, // Output (array) - 0xC0 // end collection -#endif -}; - -size_t getsizeof_hidReportDescriptor() { - return sizeof(_hidReportDescriptor); -} - -Mouse_ Mouse; - -//================================================================================ -//================================================================================ -// Mouse - -Mouse_::Mouse_(void) : _buttons(0) -{ -} - -void Mouse_::begin(void) -{ -} - -void Mouse_::end(void) -{ -} - -void Mouse_::click(uint8_t b) -{ - _buttons = b; - move(0,0,0); - _buttons = 0; - move(0,0,0); -} - -void Mouse_::move(signed char x, signed char y, signed char wheel) -{ - u8 m[4]; - m[0] = _buttons; - m[1] = x; - m[2] = y; - m[3] = wheel; - HID_SendReport(1,m,4); -} - -void Mouse_::buttons(uint8_t b) -{ - if (b != _buttons) - { - _buttons = b; - move(0,0,0); - } -} - -void Mouse_::press(uint8_t b) -{ - buttons(_buttons | b); -} - -void Mouse_::release(uint8_t b) -{ - buttons(_buttons & ~b); -} - -bool Mouse_::isPressed(uint8_t b) -{ - if ((b & _buttons) > 0) - return true; - return false; -} - -//================================================================================ -//================================================================================ -// Keyboard - -Keyboard_ Keyboard; - -Keyboard_::Keyboard_(void) -{ -} - -void Keyboard_::begin(void) -{ -} - -void Keyboard_::end(void) -{ -} - -void Keyboard_::sendReport(KeyReport* keys) -{ - HID_SendReport(2,keys,sizeof(KeyReport)); -} - -extern -const uint8_t _asciimap[128] PROGMEM; - -#define SHIFT 0x80 -const uint8_t _asciimap[128] = -{ - 0x00, // NUL - 0x00, // SOH - 0x00, // STX - 0x00, // ETX - 0x00, // EOT - 0x00, // ENQ - 0x00, // ACK - 0x00, // BEL - 0x2a, // BS Backspace - 0x2b, // TAB Tab - 0x28, // LF Enter - 0x00, // VT - 0x00, // FF - 0x00, // CR - 0x00, // SO - 0x00, // SI - 0x00, // DEL - 0x00, // DC1 - 0x00, // DC2 - 0x00, // DC3 - 0x00, // DC4 - 0x00, // NAK - 0x00, // SYN - 0x00, // ETB - 0x00, // CAN - 0x00, // EM - 0x00, // SUB - 0x00, // ESC - 0x00, // FS - 0x00, // GS - 0x00, // RS - 0x00, // US - - 0x2c, // ' ' - 0x1e|SHIFT, // ! - 0x34|SHIFT, // " - 0x20|SHIFT, // # - 0x21|SHIFT, // $ - 0x22|SHIFT, // % - 0x24|SHIFT, // & - 0x34, // ' - 0x26|SHIFT, // ( - 0x27|SHIFT, // ) - 0x25|SHIFT, // * - 0x2e|SHIFT, // + - 0x36, // , - 0x2d, // - - 0x37, // . - 0x38, // / - 0x27, // 0 - 0x1e, // 1 - 0x1f, // 2 - 0x20, // 3 - 0x21, // 4 - 0x22, // 5 - 0x23, // 6 - 0x24, // 7 - 0x25, // 8 - 0x26, // 9 - 0x33|SHIFT, // : - 0x33, // ; - 0x36|SHIFT, // < - 0x2e, // = - 0x37|SHIFT, // > - 0x38|SHIFT, // ? - 0x1f|SHIFT, // @ - 0x04|SHIFT, // A - 0x05|SHIFT, // B - 0x06|SHIFT, // C - 0x07|SHIFT, // D - 0x08|SHIFT, // E - 0x09|SHIFT, // F - 0x0a|SHIFT, // G - 0x0b|SHIFT, // H - 0x0c|SHIFT, // I - 0x0d|SHIFT, // J - 0x0e|SHIFT, // K - 0x0f|SHIFT, // L - 0x10|SHIFT, // M - 0x11|SHIFT, // N - 0x12|SHIFT, // O - 0x13|SHIFT, // P - 0x14|SHIFT, // Q - 0x15|SHIFT, // R - 0x16|SHIFT, // S - 0x17|SHIFT, // T - 0x18|SHIFT, // U - 0x19|SHIFT, // V - 0x1a|SHIFT, // W - 0x1b|SHIFT, // X - 0x1c|SHIFT, // Y - 0x1d|SHIFT, // Z - 0x2f, // [ - 0x31, // bslash - 0x30, // ] - 0x23|SHIFT, // ^ - 0x2d|SHIFT, // _ - 0x35, // ` - 0x04, // a - 0x05, // b - 0x06, // c - 0x07, // d - 0x08, // e - 0x09, // f - 0x0a, // g - 0x0b, // h - 0x0c, // i - 0x0d, // j - 0x0e, // k - 0x0f, // l - 0x10, // m - 0x11, // n - 0x12, // o - 0x13, // p - 0x14, // q - 0x15, // r - 0x16, // s - 0x17, // t - 0x18, // u - 0x19, // v - 0x1a, // w - 0x1b, // x - 0x1c, // y - 0x1d, // z - 0x2f|SHIFT, // - 0x31|SHIFT, // | - 0x30|SHIFT, // } - 0x35|SHIFT, // ~ - 0 // DEL -}; - -uint8_t USBPutChar(uint8_t c); - -// press() adds the specified key (printing, non-printing, or modifier) -// to the persistent key report and sends the report. Because of the way -// USB HID works, the host acts like the key remains pressed until we -// call release(), releaseAll(), or otherwise clear the report and resend. -size_t Keyboard_::press(uint8_t k) -{ - uint8_t i; - if (k >= 136) { // it's a non-printing key (not a modifier) - k = k - 136; - } else if (k >= 128) { // it's a modifier key - _keyReport.modifiers |= (1<<(k-128)); - k = 0; - } else { // it's a printing key - k = pgm_read_byte(_asciimap + k); - if (!k) { - setWriteError(); - return 0; - } - if (k & 0x80) { // it's a capital letter or other character reached with shift - _keyReport.modifiers |= 0x02; // the left shift modifier - k &= 0x7F; - } - } - - // Add k to the key report only if it's not already present - // and if there is an empty slot. - if (_keyReport.keys[0] != k && _keyReport.keys[1] != k && - _keyReport.keys[2] != k && _keyReport.keys[3] != k && - _keyReport.keys[4] != k && _keyReport.keys[5] != k) { - - for (i=0; i<6; i++) { - if (_keyReport.keys[i] == 0x00) { - _keyReport.keys[i] = k; - break; - } - } - if (i == 6) { - setWriteError(); - return 0; - } - } - sendReport(&_keyReport); - return 1; -} - -// release() takes the specified key out of the persistent key report and -// sends the report. This tells the OS the key is no longer pressed and that -// it shouldn't be repeated any more. -size_t Keyboard_::release(uint8_t k) -{ - uint8_t i; - if (k >= 136) { // it's a non-printing key (not a modifier) - k = k - 136; - } else if (k >= 128) { // it's a modifier key - _keyReport.modifiers &= ~(1<<(k-128)); - k = 0; - } else { // it's a printing key - k = pgm_read_byte(_asciimap + k); - if (!k) { - return 0; - } - if (k & 0x80) { // it's a capital letter or other character reached with shift - _keyReport.modifiers &= ~(0x02); // the left shift modifier - k &= 0x7F; - } - } - - // Test the key report to see if k is present. Clear it if it exists. - // Check all positions in case the key is present more than once (which it shouldn't be) - for (i=0; i<6; i++) { - if (0 != k && _keyReport.keys[i] == k) { - _keyReport.keys[i] = 0x00; - } - } - - sendReport(&_keyReport); - return 1; -} - -void Keyboard_::releaseAll(void) -{ - _keyReport.keys[0] = 0; - _keyReport.keys[1] = 0; - _keyReport.keys[2] = 0; - _keyReport.keys[3] = 0; - _keyReport.keys[4] = 0; - _keyReport.keys[5] = 0; - _keyReport.modifiers = 0; - sendReport(&_keyReport); -} - -size_t Keyboard_::write(uint8_t c) -{ - uint8_t p = press(c); // Keydown - release(c); // Keyup - return p; // just return the result of press() since release() almost always returns 1 -} - -#endif \ No newline at end of file diff --git a/libraries/MouseAndKeyboard/MouseAndKeyboard.h b/libraries/MouseAndKeyboard/MouseAndKeyboard.h deleted file mode 100644 index 0c67206a208..00000000000 --- a/libraries/MouseAndKeyboard/MouseAndKeyboard.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef MOUSEANDKEYBOARD_h - -#if defined(_USING_HID) - -#error "Can only attach one submodule to HID module" - -#else - -#define _USING_HID - -#include "HID.h" -//================================================================================ -//================================================================================ -// Mouse - -#define MOUSE_LEFT 1 -#define MOUSE_RIGHT 2 -#define MOUSE_MIDDLE 4 -#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE) - -class Mouse_ -{ -private: - uint8_t _buttons; - void buttons(uint8_t b); -public: - Mouse_(void); - void begin(void); - void end(void); - void click(uint8_t b = MOUSE_LEFT); - void move(signed char x, signed char y, signed char wheel = 0); - void press(uint8_t b = MOUSE_LEFT); // press LEFT by default - void release(uint8_t b = MOUSE_LEFT); // release LEFT by default - bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default -}; -extern Mouse_ Mouse; - -//================================================================================ -//================================================================================ -// Keyboard - -#define KEY_LEFT_CTRL 0x80 -#define KEY_LEFT_SHIFT 0x81 -#define KEY_LEFT_ALT 0x82 -#define KEY_LEFT_GUI 0x83 -#define KEY_RIGHT_CTRL 0x84 -#define KEY_RIGHT_SHIFT 0x85 -#define KEY_RIGHT_ALT 0x86 -#define KEY_RIGHT_GUI 0x87 - -#define KEY_UP_ARROW 0xDA -#define KEY_DOWN_ARROW 0xD9 -#define KEY_LEFT_ARROW 0xD8 -#define KEY_RIGHT_ARROW 0xD7 -#define KEY_BACKSPACE 0xB2 -#define KEY_TAB 0xB3 -#define KEY_RETURN 0xB0 -#define KEY_ESC 0xB1 -#define KEY_INSERT 0xD1 -#define KEY_DELETE 0xD4 -#define KEY_PAGE_UP 0xD3 -#define KEY_PAGE_DOWN 0xD6 -#define KEY_HOME 0xD2 -#define KEY_END 0xD5 -#define KEY_CAPS_LOCK 0xC1 -#define KEY_F1 0xC2 -#define KEY_F2 0xC3 -#define KEY_F3 0xC4 -#define KEY_F4 0xC5 -#define KEY_F5 0xC6 -#define KEY_F6 0xC7 -#define KEY_F7 0xC8 -#define KEY_F8 0xC9 -#define KEY_F9 0xCA -#define KEY_F10 0xCB -#define KEY_F11 0xCC -#define KEY_F12 0xCD - -// Low level key report: up to 6 keys and shift, ctrl etc at once -typedef struct -{ - uint8_t modifiers; - uint8_t reserved; - uint8_t keys[6]; -} KeyReport; - -class Keyboard_ : public Print -{ -private: - KeyReport _keyReport; - void sendReport(KeyReport* keys); -public: - Keyboard_(void); - void begin(void); - void end(void); - virtual size_t write(uint8_t k); - virtual size_t press(uint8_t k); - virtual size_t release(uint8_t k); - virtual void releaseAll(void); -}; -extern Keyboard_ Keyboard; - -#endif -#endif \ No newline at end of file From 8ebc5d0347ba3c5e3e672d4d2144c947cb6c03fb Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 15 Jul 2015 16:03:03 +0200 Subject: [PATCH 36/39] remove stub MIDIUSB library revert this commit when it's time to integrate this library --- libraries/MIDIUSB/MIDIUSB.cpp | 215 ---------------------------------- libraries/MIDIUSB/MIDIUSB.h | 157 ------------------------- 2 files changed, 372 deletions(-) delete mode 100644 libraries/MIDIUSB/MIDIUSB.cpp delete mode 100644 libraries/MIDIUSB/MIDIUSB.h diff --git a/libraries/MIDIUSB/MIDIUSB.cpp b/libraries/MIDIUSB/MIDIUSB.cpp deleted file mode 100644 index 9a1bfd79dce..00000000000 --- a/libraries/MIDIUSB/MIDIUSB.cpp +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright (c) 2015, Gary Grewal -/* -** Permission to use, copy, modify, and/or distribute this software for -** any purpose with or without fee is hereby granted, provided that the -** above copyright notice and this permission notice appear in all copies. -** -** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL -** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED -** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR -** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES -** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -** SOFTWARE. -*/ -#include "PluggableUSB.h" -#include "MIDIUSB.h" - -#define MIDI_BUFFER_SIZE 16 - - -static u8 MIDI_AC_INTERFACE; // MIDI AC Interface -static u8 MIDI_INTERFACE; -static u8 MIDI_FIRST_ENDPOINT; -static u8 MIDI_ENDPOINT_OUT; -static u8 MIDI_ENDPOINT_IN; - -#define MIDI_RX MIDI_ENDPOINT_OUT -#define MIDI_TX MIDI_ENDPOINT_IN - -struct ring_bufferMIDI -{ - midiEventPacket_t midiEvent[MIDI_BUFFER_SIZE]; - volatile uint32_t head; - volatile uint32_t tail; -}; - -ring_bufferMIDI midi_rx_buffer = {{0,0,0,0 }, 0, 0}; - -static MIDIDescriptor _midiInterface; - -int MIDI_GetInterface(uint8_t* interfaceNum) -{ - interfaceNum[0] += 2; // uses 2 - return USB_SendControl(0,&_midiInterface,sizeof(_midiInterface)); -} -bool MIDI_Setup(USBSetup& setup, u8 i) -{ - //Support requests here if needed. Typically these are optional - return false; -} - -int MIDI_GetDescriptor(int8_t t) -{ - return 0; -} - -void MIDI_::accept(void) -{ - // static uint32_t mguard = 0; - - // // synchronized access to guard - // do { - // if (__LDREXW(&mguard) != 0) { - // __CLREX(); - // return; // busy - // } - // } while (__STREXW(1, &mguard) != 0); // retry until write succeed - - // ring_bufferMIDI *buffer = &midi_rx_buffer; - // uint32_t i = (uint32_t)(buffer->head+1) % MIDI_BUFFER_SIZE; - - // // if we should be storing the received character into the location - // // just before the tail (meaning that the head would advance to the - // // current location of the tail), we're about to overflow the buffer - // // and so we don't write the character or advance the head. - // while (i != buffer->tail) { - // int c; - // midiEventPacket_t event; - // if (!USB_Available(MIDI_RX)) { - // udd_ack_fifocon(MIDI_RX); - // break; - // } - // c = USB_Recv(MIDI_RX, &event, sizeof(event) ); - - // //MIDI paacket has to be 4 bytes - // if(c < 4) - // return; - // buffer->midiEvent[buffer->head] = event; - // buffer->head = i; - - // i = (i + 1) % MIDI_BUFFER_SIZE; - // } - - // // release the guard - // mguard = 0; -} - -uint32_t MIDI_::available(void) -{ - - ring_bufferMIDI *buffer = &midi_rx_buffer; - return (uint32_t)(MIDI_BUFFER_SIZE + buffer->head - buffer->tail) % MIDI_BUFFER_SIZE; -} - - -midiEventPacket_t MIDI_::read(void) -{ - ring_bufferMIDI *buffer = &midi_rx_buffer; - midiEventPacket_t c = buffer->midiEvent[buffer->tail]; - c.header = 0; - c.byte1 = 0; - c.byte2 = 0; - c.byte3 = 0; - - // if the head isn't ahead of the tail, we don't have any characters - if (buffer->head == buffer->tail) - { - return c; - } - else - { - midiEventPacket_t c = buffer->midiEvent[buffer->tail]; - buffer->tail = (uint32_t)(buffer->tail + 1) % MIDI_BUFFER_SIZE; - if (USB_Available(MIDI_RX)) - accept(); - return c; - } -} - -void MIDI_::flush(void) -{ - USB_Flush(MIDI_TX); -} - -size_t MIDI_::write(const uint8_t *buffer, size_t size) -{ - /* only try to send bytes if the high-level MIDI connection itself - is open (not just the pipe) - the OS should set lineState when the port - is opened and clear lineState when the port is closed. - bytes sent before the user opens the connection or after - the connection is closed are lost - just like with a UART. */ - - // TODO - ZE - check behavior on different OSes and test what happens if an - // open connection isn't broken cleanly (cable is yanked out, host dies - // or locks up, or host virtual serial port hangs) - - int r = USB_Send(MIDI_TX, buffer, size); - - if (r > 0) - { - return r; - } else - { - return 0; - } - return 0; -} - -void MIDI_::sendMIDI(midiEventPacket_t event) -{ - uint8_t data[4]; - data[0] = event.header; - data[1] = event.byte1; - data[2] = event.byte2; - data[3] = event.byte3; - write(data, 4); -} - -MIDI_::MIDI_(void) -{ - static uint8_t endpointType[2]; - - endpointType[0] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT - endpointType[1] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN - - static PUSBCallbacks cb = { - .setup = &MIDI_Setup, - .getInterface = &MIDI_GetInterface, - .getDescriptor = &MIDI_GetDescriptor, - .numEndpoints = 1, - .numInterfaces = 2, - .endpointType = endpointType, - }; - - static PUSBListNode node(&cb); - - MIDI_ENDPOINT_OUT = PUSB_AddFunction(&node, &MIDI_AC_INTERFACE); - MIDI_ENDPOINT_IN = MIDI_ENDPOINT_OUT + 1; - MIDI_INTERFACE = MIDI_AC_INTERFACE + 1; - - _midiInterface = - { - D_IAD(MIDI_AC_INTERFACE, 2, MIDI_AUDIO, MIDI_AUDIO_CONTROL, 0), - D_INTERFACE(MIDI_AC_INTERFACE,0,MIDI_AUDIO,MIDI_AUDIO_CONTROL,0), - D_AC_INTERFACE(0x1, MIDI_INTERFACE), - D_INTERFACE(MIDI_INTERFACE,2, MIDI_AUDIO,MIDI_STREAMING,0), - D_AS_INTERFACE, - D_MIDI_INJACK(MIDI_JACK_EMD, 0x1), - D_MIDI_INJACK(MIDI_JACK_EXT, 0x2), - D_MIDI_OUTJACK(MIDI_JACK_EMD, 0x3, 1, 2, 1), - D_MIDI_OUTJACK(MIDI_JACK_EXT, 0x4, 1, 1, 1), - D_MIDI_JACK_EP(USB_ENDPOINT_OUT(MIDI_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,512), - D_MIDI_AC_JACK_EP(1, 1), - D_MIDI_JACK_EP(USB_ENDPOINT_IN(MIDI_ENDPOINT_IN),USB_ENDPOINT_TYPE_BULK,512), - D_MIDI_AC_JACK_EP (1, 3) - }; -} - -int8_t MIDI_::begin() -{ -} - - -MIDI_ MidiUSB; \ No newline at end of file diff --git a/libraries/MIDIUSB/MIDIUSB.h b/libraries/MIDIUSB/MIDIUSB.h deleted file mode 100644 index 0776002dc12..00000000000 --- a/libraries/MIDIUSB/MIDIUSB.h +++ /dev/null @@ -1,157 +0,0 @@ -//================================================================================ -//================================================================================ -// MIDI USB class - -#ifndef MIDIUSB_h -#define MIDIUSB_h - -#include -#include - -#if defined(USBCON) - -typedef struct -{ - uint8_t header; - uint8_t byte1; - uint8_t byte2; - uint8_t byte3; -}midiEventPacket_t; - -#define EP_TYPE_BULK_OUT_MIDI EP_TYPE_BULK_OUT -#define EP_TYPE_BULK_IN_MIDI EP_TYPE_BULK_IN - -class MIDI_ -{ -// private: -// RingBuffer *_midi_rx_buffer; -public: - MIDI_(void); - - int8_t begin(); - - uint32_t available(void); - void accept(void); - midiEventPacket_t read(void); - void flush(void); - void sendMIDI(midiEventPacket_t event); - size_t write(const uint8_t *buffer, size_t size); - operator bool(); -}; -extern MIDI_ MidiUSB; - -#define MIDI_AUDIO 0x01 -#define MIDI_AUDIO_CONTROL 0x01 -#define MIDI_CS_INTERFACE 0x24 -#define MIDI_CS_ENDPOINT 0x25 -#define MIDI_STREAMING 0x3 -#define MIDI_JACK_EMD 0x01 -#define MIDI_JACK_EXT 0X02 - -typedef struct -{ - uint8_t len; // 9 - uint8_t dtype; // 4 - uint8_t dsubType; - uint16_t bcdADc; - uint16_t wTotalLength; - uint8_t bInCollection; - uint8_t interfaceNumbers; -} MIDI_ACInterfaceDescriptor; - -typedef struct -{ - uint8_t len; // 9 - uint8_t dtype; // 4 - uint8_t dsubType; - uint8_t jackType; - uint8_t jackID; - uint8_t jackStrIndex; -} MIDIJackinDescriptor; - -typedef struct -{ - uint8_t len; // 9 - uint8_t dtype; // 4 - uint8_t dsubType; - uint8_t jackType; - uint8_t jackID; - uint8_t nPins; - uint8_t srcJackID; - uint8_t srcPinID; - uint8_t jackStrIndex; -} MIDIJackOutDescriptor; - -typedef struct -{ - EndpointDescriptor len; // 9 - uint8_t refresh; // 4 - uint8_t sync; -} MIDI_EPDescriptor; - -typedef struct -{ - uint8_t len; // 5 - uint8_t dtype; // 0x24 - uint8_t subtype; - uint8_t embJacks; - uint8_t jackID; -} MIDI_EP_ACDescriptor; - -typedef struct -{ - uint8_t len; // 9 - uint8_t dtype; // 4 - uint8_t dsubType; - uint16_t bcdADc; - uint16_t wTotalLength; -} MIDI_ASInterfaceDescriptor; - -typedef struct -{ - // IAD - IADDescriptor iad; - // MIDI Audio Control Interface - InterfaceDescriptor Audio_ControlInterface; - MIDI_ACInterfaceDescriptor Audio_ControlInterface_SPC; - - // MIDI Audio Streaming Interface - InterfaceDescriptor Audio_StreamInterface; - MIDI_ASInterfaceDescriptor Audio_StreamInterface_SPC; - - MIDIJackinDescriptor MIDI_In_Jack_Emb; - MIDIJackinDescriptor MIDI_In_Jack_Ext; - MIDIJackOutDescriptor MIDI_Out_Jack_Emb; - MIDIJackOutDescriptor MIDI_Out_Jack_Ext; - - MIDI_EPDescriptor MIDI_In_Jack_Endpoint; - MIDI_EP_ACDescriptor MIDI_In_Jack_Endpoint_SPC; - MIDI_EPDescriptor MIDI_Out_Jack_Endpoint; - MIDI_EP_ACDescriptor MIDI_Out_Jack_Endpoint_SPC; -} MIDIDescriptor; - -#define D_AC_INTERFACE(_streamingInterfaces, _MIDIInterface) \ - { 9, MIDI_CS_INTERFACE, 0x1, 0x0100, 0x0009, _streamingInterfaces, _MIDIInterface } - -#define D_AS_INTERFACE \ - { 0x7, MIDI_CS_INTERFACE, 0x01,0x0100, 0x0041} - -#define D_MIDI_INJACK(jackProp, _jackID) \ - { 0x06, MIDI_CS_INTERFACE, 0x02, jackProp, _jackID, 0 } - -#define D_MIDI_OUTJACK(jackProp, _jackID, _nPins, _srcID, _srcPin) \ - { 0x09, MIDI_CS_INTERFACE, 0x3, jackProp, _jackID, _nPins, _srcID, _srcPin, 0 } - -#define D_MIDI_JACK_EP(_addr,_attr,_packetSize) \ - { 9, 5, _addr,_attr,_packetSize, 0, 0, 0} - -#define D_MIDI_AC_JACK_EP(_nMIDI, _iDMIDI) \ - { 5, MIDI_CS_ENDPOINT, 0x1, _nMIDI, _iDMIDI} - -#define D_CDCCS(_subtype,_d0,_d1) { 5, 0x24, _subtype, _d0, _d1 } -#define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 } - -#define WEAK __attribute__ ((weak)) - -#endif -#endif \ No newline at end of file From 5cc7c1078f85c69b69b5692c58a1099cd31a85fd Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 15 Jul 2015 16:04:28 +0200 Subject: [PATCH 37/39] remove CompleteHID library expect way more interesting user-generated libraries --- libraries/CompleteHID/CompleteHID.cpp | 715 ------------------ libraries/CompleteHID/CompleteHID.h | 159 ---- libraries/CompleteHID/HIDTables.h | 677 ----------------- .../examples/AbsoluteMouse/AbsoluteMouse.ino | 28 - .../ConsumerAndSystemControl.ino | 47 -- 5 files changed, 1626 deletions(-) delete mode 100644 libraries/CompleteHID/CompleteHID.cpp delete mode 100644 libraries/CompleteHID/CompleteHID.h delete mode 100644 libraries/CompleteHID/HIDTables.h delete mode 100644 libraries/CompleteHID/examples/AbsoluteMouse/AbsoluteMouse.ino delete mode 100644 libraries/CompleteHID/examples/ConsumerAndSystemControl/ConsumerAndSystemControl.ino diff --git a/libraries/CompleteHID/CompleteHID.cpp b/libraries/CompleteHID/CompleteHID.cpp deleted file mode 100644 index b533e63174b..00000000000 --- a/libraries/CompleteHID/CompleteHID.cpp +++ /dev/null @@ -1,715 +0,0 @@ -#if 1 //defined(USBCON) - -#include "CompleteHID.h" - -#define HID_MOUSE_ABS_ENABLED - -Keyboard_ Keyboard; -Mouse_ Mouse; - -#define LSB(_x) ((_x) & 0xFF) -#define MSB(_x) ((_x) >> 8) - -#define RAWHID_USAGE_PAGE 0xFFC0 -#define RAWHID_USAGE 0x0C00 -#define RAWHID_TX_SIZE 64 -#define RAWHID_RX_SIZE 64 - -#define HID_REPORTID_KEYBOARD (1) -#define HID_REPORTID_MOUSE (2) -#define HID_REPORTID_MOUSE_ABS (3) -#define HID_REPORTID_SYSTEMCONTROL (4) -#define HID_REPORTID_CONSUMERCONTROL (5) -#define HID_REPORTID_RAWHID (6) - -#define HID_REPORT_KEYBOARD /* Keyboard */ \ - 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) 47 */ \ - 0x09, 0x06, /* USAGE (Keyboard) */ \ - 0xa1, 0x01, /* COLLECTION (Application) */ \ - 0x85, HID_REPORTID_KEYBOARD, /* REPORT_ID */ \ - 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ \ -\ - /* Keyboard Modifiers (shift, alt, ...) */ \ - 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 (1) */ \ - 0x75, 0x08, /* REPORT_SIZE (8) */ \ - 0x81, 0x03, /* INPUT (Cnst,Var,Abs) */ \ -\ - /* Keyboard keys */ \ - 0x95, 0x06, /* REPORT_COUNT (6) */ \ - 0x75, 0x08, /* REPORT_SIZE (8) */ \ - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \ - 0x26, 0xDF, 0x00, /* LOGICAL_MAXIMUM (239) */ \ - 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ \ - 0x19, 0x00, /* USAGE_MINIMUM (Reserved (no event indicated)) */ \ - 0x29, 0xDF, /* USAGE_MAXIMUM (Left Control - 1) */ \ - 0x81, 0x00, /* INPUT (Data,Ary,Abs) */ \ - 0xc0 /* END_COLLECTION */ - -#define HID_REPORT_MOUSE_ABSOLUTE /* Mouse absolute */ \ - 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \ - 0x09, 0x02, /* USAGE (Mouse) */ \ - 0xa1, 0x01, /* COLLECTION (Application) */ \ - 0x09, 0x01, /* USAGE (Pointer) */ \ - 0xa1, 0x00, /* COLLECTION (Physical) */ \ - 0x85, HID_REPORTID_MOUSE_ABS, /* REPORT_ID */ \ - 0x05, 0x09, /* USAGE_PAGE (Button) */ \ - 0x19, 0x01, /* USAGE_MINIMUM (Button 1) */ \ - 0x29, 0x03, /* USAGE_MAXIMUM (Button 3) */ \ - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \ - 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \ - 0x95, 0x03, /* REPORT_COUNT (3) */ \ - 0x75, 0x01, /* REPORT_SIZE (1) */ \ - 0x81, 0x02, /* INPUT (Data,Var,Abs) */ \ - 0x95, 0x01, /* REPORT_COUNT (1) */ \ - 0x75, 0x05, /* REPORT_SIZE (5) */ \ - 0x81, 0x03, /* INPUT (Cnst,Var,Abs) */ \ - 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \ - 0x09, 0x30, /* USAGE (X) */ \ - 0x09, 0x31, /* USAGE (Y) */ \ - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \ - 0x26, 0xff, 0x7f, /* LOGICAL_MAXIMUM (32767) */ \ - 0x75, 0x10, /* REPORT_SIZE (16) */ \ - 0x95, 0x02, /* REPORT_COUNT (2) */ \ - 0x81, 0x02, /* INPUT (Data,Var,Abs) */ \ - 0xc0, /* END_COLLECTION */ \ - 0xc0 /* END_COLLECTION */ - -#define HID_REPORT_MOUSE_RELATIVE /* Mouse relative */ \ - 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) 54 */ \ - 0x09, 0x02, /* USAGE (Mouse) */ \ - 0xa1, 0x01, /* COLLECTION (Application) */ \ - 0x09, 0x01, /* USAGE (Pointer) */ \ - 0xa1, 0x00, /* COLLECTION (Physical) */ \ - 0x85, HID_REPORTID_MOUSE, /* REPORT_ID */ \ - 0x05, 0x09, /* USAGE_PAGE (Button) */ \ - 0x19, 0x01, /* USAGE_MINIMUM (Button 1) */ \ - 0x29, 0x05, /* USAGE_MAXIMUM (Button 5) */ \ - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \ - 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \ - 0x95, 0x05, /* REPORT_COUNT (5) */ \ - 0x75, 0x01, /* REPORT_SIZE (1) */ \ - 0x81, 0x02, /* INPUT (Data,Var,Abs) */ \ - 0x95, 0x01, /* REPORT_COUNT (1) */ \ - 0x75, 0x03, /* REPORT_SIZE (3) */ \ - 0x81, 0x01, /* INPUT (Cnst,Var,Abs) */ \ - 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \ - 0x09, 0x30, /* USAGE (X) */ \ - 0x09, 0x31, /* USAGE (Y) */ \ - 0x09, 0x38, /* USAGE (Wheel) */ \ - 0x15, 0x81, /* LOGICAL_MINIMUM (-127) */ \ - 0x25, 0x7f, /* LOGICAL_MAXIMUM (127) */ \ - 0x75, 0x08, /* REPORT_SIZE (8) */ \ - 0x95, 0x03, /* REPORT_COUNT (3) */ \ - 0x81, 0x06, /* INPUT (Data,Var,Rel) */ \ - 0xc0, /* END_COLLECTION */ \ - 0xc0 /* END_COLLECTION */ - -#define HID_REPORT_SYSTEMCONTROL /* System Control (Power Down, Sleep, Wakeup, ...) */ \ - 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ \ - 0x09, 0x80, /* USAGE (System Control) */ \ - 0xa1, 0x01, /* COLLECTION (Application) */ \ - 0x85, HID_REPORTID_SYSTEMCONTROL, /* REPORT_ID */ \ - 0x09, 0x81, /* USAGE (System Power Down) */ \ - 0x09, 0x82, /* USAGE (System Sleep) */ \ - 0x09, 0x83, /* USAGE (System Wakeup) */ \ - 0x09, 0x8E, /* USAGE (System Cold Restart) */ \ - 0x09, 0x8F, /* USAGE (System Warm Restart) */ \ - 0x09, 0xA0, /* USAGE (System Dock) */ \ - 0x09, 0xA1, /* USAGE (System Undock) */ \ - 0x09, 0xA7, /* USAGE (System Speaker Mute) */ \ - 0x09, 0xA8, /* USAGE (System Hibernate) */ \ - /* although these display usages are not that important, they don't cost */ \ - /* much more than declaring the otherwise necessary constant fill bits */ \ - 0x09, 0xB0, /* USAGE (System Display Invert) */ \ - 0x09, 0xB1, /* USAGE (System Display Internal) */ \ - 0x09, 0xB2, /* USAGE (System Display External) */ \ - 0x09, 0xB3, /* USAGE (System Display Both) */ \ - 0x09, 0xB4, /* USAGE (System Display Dual) */ \ - 0x09, 0xB5, /* USAGE (System Display Toggle Intern/Extern) */ \ - 0x09, 0xB6, /* USAGE (System Display Swap) */ \ - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \ - 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \ - 0x75, 0x01, /* REPORT_SIZE (1) */ \ - 0x95, 0x10, /* REPORT_COUNT (16) */ \ - 0x81, 0x02, /* INPUT (Data,Var,Abs) */ \ - 0xc0 /* END_COLLECTION */ - -#define HID_REPORT_CONSUMERCONTROL /* Consumer Control (Sound/Media keys) */ \ - 0x05, 0x0c, /* USAGE_PAGE (Consumer Devices) */ \ - 0x09, 0x01, /* USAGE (Consumer Control) */ \ - 0xa1, 0x01, /* COLLECTION (Application) */ \ - 0x85, HID_REPORTID_CONSUMERCONTROL, /* REPORT_ID */ \ - 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \ - 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ \ - 0x75, 0x01, /* REPORT_SIZE (1) */ \ - 0x95, 0x08, /* REPORT_COUNT (8) */ \ - 0x09, 0xe2, /* USAGE (Mute) 0x01 */ \ - 0x09, 0xe9, /* USAGE (Volume Up) 0x02 */ \ - 0x09, 0xea, /* USAGE (Volume Down) 0x03 */ \ - 0x09, 0xcd, /* USAGE (Play/Pause) 0x04 */ \ - 0x09, 0xb7, /* USAGE (Stop) 0x05 */ \ - 0x09, 0xb6, /* USAGE (Scan Previous Track) 0x06 */ \ - 0x09, 0xb5, /* USAGE (Scan Next Track) 0x07 */ \ - 0x09, 0xb8, /* USAGE (Eject) 0x08 */ \ - 0x81, 0x02, /* INPUT (Data,Var,Abs) */ \ - 0xc0 - -#define HID_REPORT_RAWHID /* RAW HID */ \ - 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), /* 30 */ \ - 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE), \ -\ - 0xA1, 0x01, /* Collection 0x01 */ \ - 0x85, HID_REPORTID_RAWHID, /* REPORT_ID */ \ - 0x75, 0x08, /* report size = 8 bits */ \ - 0x15, 0x00, /* logical minimum = 0 */ \ - 0x26, 0xFF, 0x00, /* logical maximum = 255 */ \ -\ - 0x95, 64, /* report count TX */ \ - 0x09, 0x01, /* usage */ \ - 0x81, 0x02, /* Input (array) */ \ -\ - 0x95, 64, /* report count RX */ \ - 0x09, 0x02, /* usage */ \ - 0x91, 0x02, /* Output (array) */ \ - 0xC0 /* end collection */ - -extern const u8 _hidReportDescriptor[] PROGMEM; -const u8 _hidReportDescriptor[] = { - - HID_REPORT_KEYBOARD, - HID_REPORT_MOUSE_RELATIVE, -#ifdef HID_MOUSE_ABS_ENABLED - HID_REPORT_MOUSE_ABSOLUTE, -#endif - HID_REPORT_SYSTEMCONTROL, - HID_REPORT_CONSUMERCONTROL, -#if RAWHID_ENABLED - HID_REPORT_RAWHID -#endif -}; - - -//================================================================================ -//================================================================================ -// Mouse - -Mouse_::Mouse_(void) : _buttons(0) -{ - static HID_Descriptor cb = { - .length = sizeof(_hidReportDescriptor), - .descriptor = _hidReportDescriptor, - }; - static HIDDescriptorListNode node(&cb); - HID.AppendDescriptor(&node); -} - -void Mouse_::begin(void) -{ -} - -void Mouse_::end(void) -{ -} - -void Mouse_::click(uint8_t b) -{ - _buttons = b; - move(0,0,0); - _buttons = 0; - move(0,0,0); -} - -void Mouse_::move(signed char x, signed char y, signed char wheel) -{ - u8 m[4]; - m[0] = _buttons; - m[1] = x; - m[2] = y; - m[3] = wheel; - HID.SendReport(HID_REPORTID_MOUSE,m,sizeof(m)); -} - -// X and Y have the range of 0 to 32767. -// The USB Host will convert them to pixels on the screen. -// -// x=0,y=0 is top-left corner of the screen -// x=32767,y=0 is the top right corner -// x=32767,y=32767 is the bottom right corner -// x=0,y=32767 is the bottom left corner -// -// When converting these coordinates to pixels on screen, Mac OS X's -// default HID driver maps the inner 85% of the coordinate space to -// the screen's physical dimensions. This means that any value between -// 0 and 2293 or 30474 and 32767 will move the mouse to the screen -// edge on a Mac -// -// For details, see: -// http://lists.apple.com/archives/usb/2011/Jun/msg00032.html - - -void Mouse_::moveAbsolute(uint16_t x, uint16_t y) -{ - u8 m[5]; - m[0] = _buttons; - m[1] = LSB(x); - m[2] = MSB(x); - m[3] = LSB(y); - m[4] = MSB(y); - HID.SendReport(HID_REPORTID_MOUSE_ABS,m,sizeof(m)); -} - -void Mouse_::buttons(uint8_t b) -{ - if (b != _buttons) - { - _buttons = b; - move(0,0,0); - } -} - -void Mouse_::press(uint8_t b) -{ - buttons(_buttons | b); -} - -void Mouse_::release(uint8_t b) -{ - buttons(_buttons & ~b); -} - -bool Mouse_::isPressed(uint8_t b) -{ - if ((b & _buttons) > 0) - return true; - return false; -} - -//================================================================================ -//================================================================================ -// Keyboard - -Keyboard_::Keyboard_(void) -{ -} - -void Keyboard_::begin(void) -{ -} - -void Keyboard_::end(void) -{ -} - -void Keyboard_::sendReport(KeyReport* keys) -{ - HID.SendReport(HID_REPORTID_KEYBOARD,keys,sizeof(*keys)); -} - -extern -const uint8_t _asciimap[128] PROGMEM; - -#define SHIFT 0x80 -const uint8_t _asciimap[128] = -{ - 0x00, // NUL - 0x00, // SOH - 0x00, // STX - 0x00, // ETX - 0x00, // EOT - 0x00, // ENQ - 0x00, // ACK - 0x00, // BEL - 0x2a, // BS Backspace - 0x2b, // TAB Tab - 0x28, // LF Enter - 0x00, // VT - 0x00, // FF - 0x00, // CR - 0x00, // SO - 0x00, // SI - 0x00, // DEL - 0x00, // DC1 - 0x00, // DC2 - 0x00, // DC3 - 0x00, // DC4 - 0x00, // NAK - 0x00, // SYN - 0x00, // ETB - 0x00, // CAN - 0x00, // EM - 0x00, // SUB - 0x00, // ESC - 0x00, // FS - 0x00, // GS - 0x00, // RS - 0x00, // US - - 0x2c, // ' ' - 0x1e|SHIFT, // ! - 0x34|SHIFT, // " - 0x20|SHIFT, // # - 0x21|SHIFT, // $ - 0x22|SHIFT, // % - 0x24|SHIFT, // & - 0x34, // ' - 0x26|SHIFT, // ( - 0x27|SHIFT, // ) - 0x25|SHIFT, // * - 0x2e|SHIFT, // + - 0x36, // , - 0x2d, // - - 0x37, // . - 0x38, // / - 0x27, // 0 - 0x1e, // 1 - 0x1f, // 2 - 0x20, // 3 - 0x21, // 4 - 0x22, // 5 - 0x23, // 6 - 0x24, // 7 - 0x25, // 8 - 0x26, // 9 - 0x33|SHIFT, // : - 0x33, // ; - 0x36|SHIFT, // < - 0x2e, // = - 0x37|SHIFT, // > - 0x38|SHIFT, // ? - 0x1f|SHIFT, // @ - 0x04|SHIFT, // A - 0x05|SHIFT, // B - 0x06|SHIFT, // C - 0x07|SHIFT, // D - 0x08|SHIFT, // E - 0x09|SHIFT, // F - 0x0a|SHIFT, // G - 0x0b|SHIFT, // H - 0x0c|SHIFT, // I - 0x0d|SHIFT, // J - 0x0e|SHIFT, // K - 0x0f|SHIFT, // L - 0x10|SHIFT, // M - 0x11|SHIFT, // N - 0x12|SHIFT, // O - 0x13|SHIFT, // P - 0x14|SHIFT, // Q - 0x15|SHIFT, // R - 0x16|SHIFT, // S - 0x17|SHIFT, // T - 0x18|SHIFT, // U - 0x19|SHIFT, // V - 0x1a|SHIFT, // W - 0x1b|SHIFT, // X - 0x1c|SHIFT, // Y - 0x1d|SHIFT, // Z - 0x2f, // [ - 0x31, // bslash - 0x30, // ] - 0x23|SHIFT, // ^ - 0x2d|SHIFT, // _ - 0x35, // ` - 0x04, // a - 0x05, // b - 0x06, // c - 0x07, // d - 0x08, // e - 0x09, // f - 0x0a, // g - 0x0b, // h - 0x0c, // i - 0x0d, // j - 0x0e, // k - 0x0f, // l - 0x10, // m - 0x11, // n - 0x12, // o - 0x13, // p - 0x14, // q - 0x15, // r - 0x16, // s - 0x17, // t - 0x18, // u - 0x19, // v - 0x1a, // w - 0x1b, // x - 0x1c, // y - 0x1d, // z - 0x2f|SHIFT, // - 0x31|SHIFT, // | - 0x30|SHIFT, // } - 0x35|SHIFT, // ~ - 0 // DEL -}; - -uint8_t USBPutChar(uint8_t c); - - - // pressKeycode() adds the specified key (printing, non-printing, or modifier) - // to the persistent key report and sends the report. Because of the way - // USB HID works, the host acts like the key remains pressed until we - // call releaseKeycode(), releaseAll(), or otherwise clear the report and resend. - size_t Keyboard_::pressKeycode(uint8_t k) - { - if (!addKeycodeToReport(k)) { - return 0; - } - sendReport(&_keyReport); - } - - size_t Keyboard_::addKeycodeToReport(uint8_t k) - { - uint8_t index = 0; - uint8_t done = 0; - - if ((k >= HID_KEYBOARD_LEFT_CONTROL) && (k <= HID_KEYBOARD_RIGHT_GUI)) { - // it's a modifier key - _keyReport.modifiers |= (0x01 << (k - HID_KEYBOARD_LEFT_CONTROL)); - } else { - // it's some other key: - // Add k to the key report only if it's not already present - // and if there is an empty slot. - for (index = 0; index < KEYREPORT_KEYCOUNT; index++) { - if (_keyReport.keys[index] != k) { // is k already in list? - if (0 == _keyReport.keys[index]) { // have we found an empty slot? - _keyReport.keys[index] = k; - done = 1; - break; - } - } else { - done = 1; - break; - } - - } - - // use separate variable to check if slot was found - // for style reasons - we do not know how the compiler - // handles the for() index when it leaves the loop - if (0 == done) { - setWriteError(); - return 0; - } - } - - return 1; - } - - // press() transforms the given key to the actual keycode and calls - // pressKeycode() to actually press this key. - // - size_t Keyboard_::press(uint8_t k) - { - if (k >= KEY_RIGHT_GUI + 1) { - // it's a non-printing key (not a modifier) - k = k - (KEY_RIGHT_GUI + 1); - } else { - if (k >= KEY_LEFT_CTRL) { - // it's a modifier key - k = k - KEY_LEFT_CTRL + HID_KEYBOARD_LEFT_CONTROL; - } else { - k = pgm_read_byte(_asciimap + k); - if (k) { - if (k & SHIFT) { - // it's a capital letter or other character reached with shift - // the left shift modifier - addKeycodeToReport(HID_KEYBOARD_LEFT_SHIFT); - k = k ^ SHIFT; - } - } else { - return 0; - } - } - } - - pressKeycode(k); - return 1; - } - -// System Control -// k is one of the SYSTEM_CONTROL defines which come from the HID usage table "Generic Desktop Page (0x01)" -// in "HID Usage Tables" (HUT1_12v2.pdf) -size_t Keyboard_::systemControl(uint8_t k) -{ - if(k <= 16) - { - u16 mask = 0; - u8 m[2]; - - if(k > 0) - { - mask = 1 << (k - 1); - } - - m[0] = LSB(mask); - m[1] = MSB(mask); - HID.SendReport(HID_REPORTID_SYSTEMCONTROL,m,sizeof(m)); - - // these are all OSCs, so send a clear to make it possible to send it again later - m[0] = 0; - m[1] = 0; - HID.SendReport(HID_REPORTID_SYSTEMCONTROL,m,sizeof(m)); - return 1; - } - else - { - setWriteError(); - return 0; - } -} - -// Consumer Control -// k is one of the CONSUMER_CONTROL defines which come from the HID usage table "Consumer Devices Page (0x0c)" -// in "HID Usage Tables" (HUT1_12v2.pdf) -size_t Keyboard_::consumerControl(uint8_t k) -{ - if(k <= 8) - { - u16 mask = 0; - u8 m[2]; - - if(k > 0) - { - mask = 1 << (k - 1); - } - - m[0] = LSB(mask); - m[1] = MSB(mask); - HID.SendReport(HID_REPORTID_CONSUMERCONTROL,m,sizeof(m)); - - // these are all OSCs, so send a clear to make it possible to send it again later - m[0] = 0; - m[1] = 0; - HID.SendReport(HID_REPORTID_CONSUMERCONTROL,m,sizeof(m)); - return 1; - } - else - { - setWriteError(); - return 0; - } -} - -// releaseKeycode() takes the specified key out of the persistent key report and -// sends the report. This tells the OS the key is no longer pressed and that -// it shouldn't be repeated any more. -// When send is set to FALSE (= 0) no sendReport() is executed. This comes in -// handy when combining key releases (e.g. SHIFT+A). -size_t Keyboard_::releaseKeycode(uint8_t k) -{ - if (!removeKeycodeFromReport(k)) { - return 0; - } - sendReport(&_keyReport); -} - -size_t Keyboard_::removeKeycodeFromReport(uint8_t k) -{ - uint8_t indexA; - uint8_t indexB; - uint8_t count; - - if ((k >= HID_KEYBOARD_LEFT_CONTROL) && (k <= HID_KEYBOARD_RIGHT_GUI)) { - // it's a modifier key - _keyReport.modifiers = _keyReport.modifiers & (~(0x01 << (k - HID_KEYBOARD_LEFT_CONTROL))); - } else { - // it's some other key: - // Test the key report to see if k is present. Clear it if it exists. - // Check all positions in case the key is present more than once (which it shouldn't be) - for (indexA = 0; indexA < KEYREPORT_KEYCOUNT; indexA++) { - if (_keyReport.keys[indexA] == k) { - _keyReport.keys[indexA] = 0; - } - } - - // finally rearrange the keys list so that the free (= 0x00) are at the - // end of the keys list - some implementations stop for keys at the - // first occurence of an 0x00 in the keys list - // so (0x00)(0x01)(0x00)(0x03)(0x02)(0x00) becomes - // (0x01)(0x03)(0x02)(0x00)(0x00)(0x00) - count = 0; // holds the number of zeros we've found - indexA = 0; - while ((indexA + count) < KEYREPORT_KEYCOUNT) { - if (0 == _keyReport.keys[indexA]) { - count++; // one more zero - for (indexB = indexA; indexB < KEYREPORT_KEYCOUNT-count; indexB++) { - _keyReport.keys[indexB] = _keyReport.keys[indexB+1]; - } - _keyReport.keys[KEYREPORT_KEYCOUNT-count] = 0; - } else { - indexA++; // one more non-zero - } - } - } - - return 1; -} - -// release() transforms the given key to the actual keycode and calls -// releaseKeycode() to actually release this key. -// -size_t Keyboard_::release(uint8_t k) -{ - uint8_t i; - - if (k >= KEY_RIGHT_GUI + 1) { - // it's a non-printing key (not a modifier) - k = k - (KEY_RIGHT_GUI + 1); - } else { - if (k >= KEY_LEFT_CTRL) { - // it's a modifier key - k = k - KEY_LEFT_CTRL + HID_KEYBOARD_LEFT_CONTROL; - } else { - k = pgm_read_byte(_asciimap + k); - if (k) { - if ((k & SHIFT)) { - // it's a capital letter or other character reached with shift - // the left shift modifier - removeKeycodeFromReport(HID_KEYBOARD_LEFT_SHIFT); - k = k ^ SHIFT; - } - } else { - return 0; - } - } - } - - releaseKeycode(k); - return 1; -} - -void Keyboard_::releaseAll(void) -{ - _keyReport.keys[0] = 0; - _keyReport.keys[1] = 0; - _keyReport.keys[2] = 0; - _keyReport.keys[3] = 0; - _keyReport.keys[4] = 0; - _keyReport.keys[5] = 0; - _keyReport.modifiers = 0; - sendReport(&_keyReport); -} - -size_t Keyboard_::write(uint8_t c) -{ - uint8_t p = press(c); // Keydown - release(c); // Keyup - return p; // just return the result of press() since release() almost always returns 1 -} - -size_t Keyboard_::writeKeycode(uint8_t c) -{ - uint8_t p = pressKeycode(c); // Keydown - uint8_t r = releaseKeycode(c); // Keyup - return (p); // just return the result of pressKeycode() since release() almost always returns 1 -} - -#endif \ No newline at end of file diff --git a/libraries/CompleteHID/CompleteHID.h b/libraries/CompleteHID/CompleteHID.h deleted file mode 100644 index 467237f86b6..00000000000 --- a/libraries/CompleteHID/CompleteHID.h +++ /dev/null @@ -1,159 +0,0 @@ -#ifndef COMPLETEHID_h -#define COMPLETEHID_h - -#if 0 //defined(_USING_HID) - -#error "Can only attach one submodule to HID module" - -#else - -#define _USING_HID - -#include "HID.h" -#include "HIDTables.h" - -extern HID_ HID; - -//================================================================================ -//================================================================================ -// Mouse - -#define MOUSE_LEFT 1 -#define MOUSE_RIGHT 2 -#define MOUSE_MIDDLE 4 -#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE) - -class Mouse_ -{ -private: - uint8_t _buttons; - void buttons(uint8_t b); -public: - Mouse_(void); - void begin(void); - void end(void); - void click(uint8_t b = MOUSE_LEFT); - void move(signed char x, signed char y, signed char wheel = 0); - void moveAbsolute(uint16_t x, uint16_t y); - void press(uint8_t b = MOUSE_LEFT); // press LEFT by default - void release(uint8_t b = MOUSE_LEFT); // release LEFT by default - bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default -}; -extern Mouse_ Mouse; - -//================================================================================ -//================================================================================ -// Keyboard - -#define KEY_LEFT_CTRL 0x80 -#define KEY_LEFT_SHIFT 0x81 -#define KEY_LEFT_ALT 0x82 -#define KEY_LEFT_GUI 0x83 -#define KEY_RIGHT_CTRL 0x84 -#define KEY_RIGHT_SHIFT 0x85 -#define KEY_RIGHT_ALT 0x86 -#define KEY_RIGHT_GUI 0x87 - -#define KEY_UP_ARROW 0xDA -#define KEY_DOWN_ARROW 0xD9 -#define KEY_LEFT_ARROW 0xD8 -#define KEY_RIGHT_ARROW 0xD7 -#define KEY_BACKSPACE 0xB2 -#define KEY_TAB 0xB3 -#define KEY_RETURN 0xB0 -#define KEY_ESC 0xB1 -#define KEY_INSERT 0xD1 -#define KEY_DELETE 0xD4 -#define KEY_PAGE_UP 0xD3 -#define KEY_PAGE_DOWN 0xD6 -#define KEY_HOME 0xD2 -#define KEY_END 0xD5 -#define KEY_CAPS_LOCK 0xC1 -#define KEY_F1 0xC2 -#define KEY_F2 0xC3 -#define KEY_F3 0xC4 -#define KEY_F4 0xC5 -#define KEY_F5 0xC6 -#define KEY_F6 0xC7 -#define KEY_F7 0xC8 -#define KEY_F8 0xC9 -#define KEY_F9 0xCA -#define KEY_F10 0xCB -#define KEY_F11 0xCC -#define KEY_F12 0xCD - -// Low level key report: up to 6 keys and shift, ctrl etc at once -#define KEYREPORT_KEYCOUNT 0x06 -typedef struct -{ - uint8_t modifiers; - uint8_t reserved; - uint8_t keys[KEYREPORT_KEYCOUNT]; -} KeyReport; - -class Keyboard_ : public Print -{ -private: - KeyReport _keyReport; - void sendReport(KeyReport* keys); -public: - Keyboard_(void); - void begin(void); - void end(void); - size_t write(uint8_t k); - size_t press(uint8_t k); - size_t release(uint8_t k); - size_t writeKeycode(uint8_t k); - size_t pressKeycode(uint8_t k); - size_t releaseKeycode(uint8_t k); - size_t addKeycodeToReport(uint8_t k); - size_t removeKeycodeFromReport(uint8_t k); - void releaseAll(void); - size_t systemControl(uint8_t k); - size_t consumerControl(uint8_t k); -}; -extern Keyboard_ Keyboard; - -// System Control values for Keyboard_::systemControl() -// these defines come from the HID usage table "Generic Desktop Page (0x01)" -// in the USB standard document "HID Usage Tables" (HUT1_12v2.pdf) -// Currently this list contains only OSC (one shot control) values, -// the implementation of systemControl will have to be changed when -// adding OOC or RTC values. -#define SYSTEM_CONTROL_POWER_DOWN 1 -#define SYSTEM_CONTROL_SLEEP 2 -#define SYSTEM_CONTROL_WAKEUP 3 -#define SYSTEM_CONTROL_COLD_RESTART 4 -#define SYSTEM_CONTROL_WARM_RESTART 5 -#define SYSTEM_CONTROL_DOCK 6 -#define SYSTEM_CONTROL_UNDOCK 7 -#define SYSTEM_CONTROL_SPEAKER_MUTE 8 -#define SYSTEM_CONTROL_HIBERNATE 9 -#define SYSTEM_CONTROL_DISPLAY_INVERT 10 -#define SYSTEM_CONTROL_DISPLAY_INTERNAL 11 -#define SYSTEM_CONTROL_DISPLAY_EXTERNAL 12 -#define SYSTEM_CONTROL_DISPLAY_BOTH 13 -#define SYSTEM_CONTROL_DISPLAY_DUAL 14 -#define SYSTEM_CONTROL_DISPLAY_TOGGLE_INT_EXT 15 -#define SYSTEM_CONTROL_DISPLAY_SWAP 16 - - - -// Consumer Control values for Keyboard_::systemControl() -// these defines come from the HID usage table "Consumer Device Page (0x0c)" -// in the USB standard document "HID Usage Tables" (HUT1_12v2.pdf) -// Currently this list contains only OSC (one shot control) values, -// the implementation of systemControl will have to be changed when -// adding OOC or RTC values. - -#define CONSUMER_CONTROL_VOLUME_MUTE 1 -#define CONSUMER_CONTROL_VOLUME_UP 2 -#define CONSUMER_CONTROL_VOLUME_DOWN 3 -#define CONSUMER_CONTROL_PLAY_PAUSE 4 -#define CONSUMER_CONTROL_STOP 5 -#define CONSUMER_CONTROL_PREV_TRACK 6 -#define CONSUMER_CONTROL_NEXT_TRACK 7 -#define CONSUMER_CONTROL_EJECT 8 - -#endif -#endif \ No newline at end of file diff --git a/libraries/CompleteHID/HIDTables.h b/libraries/CompleteHID/HIDTables.h deleted file mode 100644 index 2e62c3d2ef2..00000000000 --- a/libraries/CompleteHID/HIDTables.h +++ /dev/null @@ -1,677 +0,0 @@ -#ifndef __HIDTables__ -#define __HIDTables__ - - -// These mappings were extracted and transcribed from -// http://www.usb.org_SLASH_developers_SLASH_devclass_docs_SLASH_Hut1_12v2.pdf -// -// In most cases, I've preserved the "official" USB Implementers forum -// "Usage Name", though I've standardized some abbreviations and spacing -// that were inconsistent in the original specification. Non alpha-numeric -// characters in symbol names were converted into those characters' names. -// -// To match Arduino code style, all hid usage names are fully upper case. -// -// Not every HID usage listed in this file is currently supported by Arduino -// In particular, any System Control or Consumer Control entry that doesn't -// have a comment indicating that it's "HID type OSC" will require additional -// code in the Arduino core to work. -// -// Non-working usages are listed here in the interest of not having to manually -// convert more usage names each and every time our HID stack gets a little bit -// better. -// -// -// -- Jesse Vincent , January 2014 - - - -// System control mappings - -#define HID_SYSTEM_POWER_DOWN 0x81 // HID type OSC -#define HID_SYSTEM_SLEEP 0x82 // HID type OSC -#define HID_SYSTEM_WAKE_UP 0x83 // HID type OSC -#define HID_SYSTEM_CONTEXT_MENU 0x84 // HID type OSC -#define HID_SYSTEM_MAIN_MENU 0x85 // HID type OSC -#define HID_SYSTEM_APP_MENU 0x86 // HID type OSC -#define HID_SYSTEM_MENU_HELP 0x87 // HID type OSC -#define HID_SYSTEM_MENU_EXIT 0x88 // HID type OSC -#define HID_SYSTEM_MENU_SELECT 0x89 // HID type OSC -#define HID_SYSTEM_MENU_RIGHT 0x8A // HID type RTC -#define HID_SYSTEM_MENU_LEFT 0x8B // HID type RTC -#define HID_SYSTEM_MENU_UP 0x8C // HID type RTC -#define HID_SYSTEM_MENU_DOWN 0x8D // HID type RTC -#define HID_SYSTEM_COLD_RESTART 0x8E // HID type OSC -#define HID_SYSTEM_WARM_RESTART 0x8F // HID type OSC -#define HID_D_PAD_UP 0x90 // HID type OOC -#define HID_D_PAD_DOWN 0x91 // HID type OOC -#define HID_D_PAD_RIGHT 0x92 // HID type OOC -#define HID_D_PAD_LEFT 0x93 // HID type OOC -// 0x94-0x9F are reserved -#define HID_SYSTEM_DOCK 0xA0 // HID type OSC -#define HID_SYSTEM_UNDOCK 0xA1 // HID type OSC -#define HID_SYSTEM_SETUP 0xA2 // HID type OSC -#define HID_SYSTEM_BREAK 0xA3 // HID type OSC -#define HID_SYSTEM_DEBUGGER_BREAK 0xA4 // HID type OSC -#define HID_APPLICATION_BREAK 0xA5 // HID type OSC -#define HID_APPLICATION_DEBUGGER_BREAK 0xA6 // HID type OSC -#define HID_SYSTEM_SPEAKER_MUTE 0xA7 // HID type OSC -#define HID_SYSTEM_HIBERNATE 0xA8 // HID type OSC -// 0xA9-0xAF are reserved -#define HID_SYSTEM_DISPLAY_INVERT 0xB0 // HID type OSC -#define HID_SYSTEM_DISPLAY_INTERNAL 0xB1 // HID type OSC -#define HID_SYSTEM_DISPLAY_EXTERNAL 0xB2 // HID type OSC -#define HID_SYSTEM_DISPLAY_BOTH 0xB3 // HID type OSC -#define HID_SYSTEM_DISPLAY_DUAL 0xB4 // HID type OSC -#define HID_SYSTEM_DISPLAY_TOGGLE_INT_SLASH_EXT 0xB5 // HID type OSC -#define HID_SYSTEM_DISPLAY_SWAP_PRIMARY_SLASH_SECONDARY 0xB6 // HID type OSC -#define HID_SYSTEM_DISPLAY_LCD_AUTOSCALE 0xB7 // HID type OSC - -// Keyboard HID mappings - -// Reserved (no_event_indicated) 0x00 -#define HID_KEYBOARD_ERROR_ROLLOVER 0x01 -#define HID_KEYBOARD_POST_FAIL 0x02 -#define HID_KEYBOARD_ERROR_UNDEFINED 0x03 -#define HID_KEYBOARD_A_AND_A 0x04 -#define HID_KEYBOARD_B_AND_B 0x05 -#define HID_KEYBOARD_C_AND_C 0x06 -#define HID_KEYBOARD_D_AND_D 0x07 -#define HID_KEYBOARD_E_AND_E 0x08 -#define HID_KEYBOARD_F_AND_F 0x09 -#define HID_KEYBOARD_G_AND_G 0x0A -#define HID_KEYBOARD_H_AND_H 0x0B -#define HID_KEYBOARD_I_AND_I 0x0C -#define HID_KEYBOARD_J_AND_J 0x0D -#define HID_KEYBOARD_K_AND_K 0x0E -#define HID_KEYBOARD_L_AND_L 0x0F -#define HID_KEYBOARD_M_AND_M 0x10 -#define HID_KEYBOARD_N_AND_N 0x11 -#define HID_KEYBOARD_O_AND_O 0x12 -#define HID_KEYBOARD_P_AND_P 0x13 -#define HID_KEYBOARD_Q_AND_Q 0x14 -#define HID_KEYBOARD_R_AND_R 0x15 -#define HID_KEYBOARD_S_AND_S 0x16 -#define HID_KEYBOARD_T_AND_T 0x17 -#define HID_KEYBOARD_U_AND_U 0x18 -#define HID_KEYBOARD_V_AND_V 0x19 -#define HID_KEYBOARD_W_AND_W 0x1A -#define HID_KEYBOARD_X_AND_X 0x1B -#define HID_KEYBOARD_Y_AND_Y 0x1C -#define HID_KEYBOARD_Z_AND_Z 0x1D -#define HID_KEYBOARD_1_AND_EXCLAMATION_POINT 0x1E -#define HID_KEYBOARD_2_AND_AT 0x1F -#define HID_KEYBOARD_3_AND_POUND 0x20 -#define HID_KEYBOARD_4_AND_DOLLAR 0x21 -#define HID_KEYBOARD_5_AND_PERCENT 0x22 -#define HID_KEYBOARD_6_AND_CARAT 0x23 -#define HID_KEYBOARD_7_AND_AMPERSAND 0x24 -#define HID_KEYBOARD_8_AND_ASTERISK 0x25 -#define HID_KEYBOARD_9_AND_LEFT_PAREN 0x26 -#define HID_KEYBOARD_0_AND_RIGHT_PAREN 0x27 -#define HID_KEYBOARD_ENTER 0x28 // (MARKED AS ENTER_SLASH_RETURN) -#define HID_KEYBOARD_ESCAPE 0x29 -#define HID_KEYBOARD_DELETE 0x2A // (BACKSPACE) -#define HID_KEYBOARD_TAB 0x2B -#define HID_KEYBOARD_SPACEBAR 0x2C -#define HID_KEYBOARD_MINUS_AND_UNDERSCORE 0x2D // (UNDERSCORE) -#define HID_KEYBOARD_EQUALS_AND_PLUS 0x2E -#define HID_KEYBOARD_LEFT_BRACKET_AND_LEFT_CURLY_BRACE 0x2F -#define HID_KEYBOARD_RIGHT_BRACKET_AND_RIGHT_CURLY_BRACE 0x30 -#define HID_KEYBOARD_BACKSLASH_AND_PIPE 0x31 -#define HID_KEYBOARD_NON_US_POUND_AND_TILDE 0x32 -#define HID_KEYBOARD_SEMICOLON_AND_COLON 0x33 -#define HID_KEYBOARD_QUOTE_AND_DOUBLEQUOTE 0x34 -#define HID_KEYBOARD_GRAVE_ACCENT_AND_TILDE 0x35 -#define HID_KEYBOARD_COMMA_AND_LESS_THAN 0x36 -#define HID_KEYBOARD_PERIOD_AND_GREATER_THAN 0x37 -#define HID_KEYBOARD_SLASH_AND_QUESTION_MARK 0x38 -#define HID_KEYBOARD_CAPS_LOCK 0x39 -#define HID_KEYBOARD_F1 0x3A -#define HID_KEYBOARD_F2 0x3B -#define HID_KEYBOARD_F3 0x3C -#define HID_KEYBOARD_F4 0x3D -#define HID_KEYBOARD_F5 0x3E -#define HID_KEYBOARD_F6 0x3F -#define HID_KEYBOARD_F7 0x40 -#define HID_KEYBOARD_F8 0x41 -#define HID_KEYBOARD_F9 0x42 -#define HID_KEYBOARD_F10 0x43 -#define HID_KEYBOARD_F11 0x44 -#define HID_KEYBOARD_F12 0x45 -#define HID_KEYBOARD_PRINTSCREEN 0x46 -#define HID_KEYBOARD_SCROLL_LOCK 0x47 -#define HID_KEYBOARD_PAUSE 0x48 -#define HID_KEYBOARD_INSERT 0x49 -#define HID_KEYBOARD_HOME 0x4A -#define HID_KEYBOARD_PAGE_UP 0x4B -#define HID_KEYBOARD_DELETE_FORWARD 0x4C -#define HID_KEYBOARD_END 0x4D -#define HID_KEYBOARD_PAGE_DOWN 0x4E -#define HID_KEYBOARD_RIGHTARROW 0x4F -#define HID_KEYBOARD_LEFTARROW 0x50 -#define HID_KEYBOARD_DOWNARROW 0x51 -#define HID_KEYBOARD_UPARROW 0x52 -#define HID_KEYPAD_NUM_LOCK_AND_CLEAR 0x53 -#define HID_KEYPAD_DIVIDE 0x54 -#define HID_KEYPAD_MULTIPLY 0x55 -#define HID_KEYPAD_SUBTRACT 0x56 -#define HID_KEYPAD_ADD 0x57 -#define HID_KEYPAD_ENTER 0x58 -#define HID_KEYPAD_1_AND_END 0x59 -#define HID_KEYPAD_2_AND_DOWN_ARROW 0x5A -#define HID_KEYPAD_3_AND_PAGE_DOWN 0x5B -#define HID_KEYPAD_4_AND_LEFT_ARROW 0x5C -#define HID_KEYPAD_5 0x5D -#define HID_KEYPAD_6_AND_RIGHT_ARROW 0x5E -#define HID_KEYPAD_7_AND_HOME 0x5F -#define HID_KEYPAD_8_AND_UP_ARROW 0x60 -#define HID_KEYPAD_9_AND_PAGE_UP 0x61 -#define HID_KEYPAD_0_AND_INSERT 0x62 -#define HID_KEYPAD_PERIOD_AND_DELETE 0x63 -#define HID_KEYBOARD_NON_US_BACKSLASH_AND_PIPE 0x64 -#define HID_KEYBOARD_APPLICATION 0x65 -#define HID_KEYBOARD_POWER 0x66 -#define HID_KEYPAD_EQUALS 0x67 -#define HID_KEYBOARD_F13 0x68 -#define HID_KEYBOARD_F14 0x69 -#define HID_KEYBOARD_F15 0x6A -#define HID_KEYBOARD_F16 0x6B -#define HID_KEYBOARD_F17 0x6C -#define HID_KEYBOARD_F18 0x6D -#define HID_KEYBOARD_F19 0x6E -#define HID_KEYBOARD_F20 0x6F -#define HID_KEYBOARD_F21 0x70 -#define HID_KEYBOARD_F22 0x71 -#define HID_KEYBOARD_F23 0x72 -#define HID_KEYBOARD_F24 0x73 -#define HID_KEYBOARD_EXECUTE 0x74 -#define HID_KEYBOARD_HELP 0x75 -#define HID_KEYBOARD_MENU 0x76 -#define HID_KEYBOARD_SELECT 0x77 -#define HID_KEYBOARD_STOP 0x78 -#define HID_KEYBOARD_AGAIN 0x79 -#define HID_KEYBOARD_UNDO 0x7A -#define HID_KEYBOARD_CUT 0x7B -#define HID_KEYBOARD_COPY 0x7C -#define HID_KEYBOARD_PASTE 0x7D -#define HID_KEYBOARD_FIND 0x7E -#define HID_KEYBOARD_MUTE 0x7F -#define HID_KEYBOARD_VOLUME_UP 0x80 -#define HID_KEYBOARD_VOLUME_DOWN 0x81 -#define HID_KEYBOARD_LOCKING_CAPS_LOCK 0x82 -#define HID_KEYBOARD_LOCKING_NUM_LOCK 0x83 -#define HID_KEYBOARD_LOCKING_SCROLL_LOCK 0x84 -#define HID_KEYPAD_COMMA 0x85 -#define HID_KEYPAD_EQUAL_SIGN 0x86 -#define HID_KEYBOARD_INTERNATIONAL1 0x87 -#define HID_KEYBOARD_INTERNATIONAL2 0x88 -#define HID_KEYBOARD_INTERNATIONAL3 0x89 -#define HID_KEYBOARD_INTERNATIONAL4 0x8A -#define HID_KEYBOARD_INTERNATIONAL5 0x8B -#define HID_KEYBOARD_INTERNATIONAL6 0x8C -#define HID_KEYBOARD_INTERNATIONAL7 0x8D -#define HID_KEYBOARD_INTERNATIONAL8 0x8E -#define HID_KEYBOARD_INTERNATIONAL9 0x8F -#define HID_KEYBOARD_LANG1 0x90 -#define HID_KEYBOARD_LANG2 0x91 -#define HID_KEYBOARD_LANG3 0x92 -#define HID_KEYBOARD_LANG4 0x93 -#define HID_KEYBOARD_LANG5 0x94 -#define HID_KEYBOARD_LANG6 0x95 -#define HID_KEYBOARD_LANG7 0x96 -#define HID_KEYBOARD_LANG8 0x97 -#define HID_KEYBOARD_LANG9 0x98 -#define HID_KEYBOARD_ALTERNATE_ERASE 0x99 -#define HID_KEYBOARD_SYSREQ_SLASH_ATTENTION 0x9A -#define HID_KEYBOARD_CANCEL 0x9B -#define HID_KEYBOARD_CLEAR 0x9C -#define HID_KEYBOARD_PRIOR 0x9D -#define HID_KEYBOARD_RETURN 0x9E -#define HID_KEYBOARD_SEPARATOR 0x9F -#define HID_KEYBOARD_OUT 0xA0 -#define HID_KEYBOARD_OPER 0xA1 -#define HID_KEYBOARD_CLEAR_SLASH_AGAIN 0xA2 -#define HID_KEYBOARD_CRSEL_SLASH_PROPS 0xA3 -#define HID_KEYBOARD_EXSEL 0xA4 -// Reserved 0xA5-AF -#define HID_KEYPAD_00 0xB0 -#define HID_KEYPAD_000 0xB1 -#define HID_THOUSANDS_SEPARATOR 0xB2 -#define HID_DECIMAL_SEPARATOR 0xB3 -#define HID_CURRENCY_UNIT 0xB4 -#define HID_CURRENCY_SUBUNIT 0xB5 -#define HID_KEYPAD_LEFT_PAREN 0xB6 -#define HID_KEYPAD_RIGHT_PAREN 0xB7 -#define HID_KEYPAD_LEFT_CURLY_BRACE 0xB8 -#define HID_KEYPAD_RIGHT_CURLY_BRACE 0xB9 -#define HID_KEYPAD_TAB 0xBA -#define HID_KEYPAD_BACKSPACE 0xBB -#define HID_KEYPAD_A 0xBC -#define HID_KEYPAD_B 0xBD -#define HID_KEYPAD_C 0xBE -#define HID_KEYPAD_D 0xBF -#define HID_KEYPAD_E 0xC0 -#define HID_KEYPAD_F 0xC1 -#define HID_KEYPAD_XOR 0xC2 -#define HID_KEYPAD_CARAT 0xC3 -#define HID_KEYPAD_PERCENT 0xC4 -#define HID_KEYPAD_LESS_THAN 0xC5 -#define HID_KEYPAD_GREATER_THAN 0xC6 -#define HID_KEYPAD_AMPERSAND 0xC7 -#define HID_KEYPAD_DOUBLEAMPERSAND 0xC8 -#define HID_KEYPAD_PIPE 0xC9 -#define HID_KEYPAD_DOUBLEPIPE 0xCA -#define HID_KEYPAD_COLON 0xCB -#define HID_KEYPAD_POUND_SIGN 0xCC -#define HID_KEYPAD_SPACE 0xCD -#define HID_KEYPAD_AT_SIGN 0xCE -#define HID_KEYPAD_EXCLAMATION_POINT 0xCF -#define HID_KEYPAD_MEMORY_STORE 0xD0 -#define HID_KEYPAD_MEMORY_RECALL 0xD1 -#define HID_KEYPAD_MEMORY_CLEAR 0xD2 -#define HID_KEYPAD_MEMORY_ADD 0xD3 -#define HID_KEYPAD_MEMORY_SUBTRACT 0xD4 -#define HID_KEYPAD_MEMORY_MULTIPLY 0xD5 -#define HID_KEYPAD_MEMORY_DIVIDE 0xD6 -#define HID_KEYPAD_PLUS_SLASH_MINUS 0xD7 -#define HID_KEYPAD_CLEAR 0xD8 -#define HID_KEYPAD_CLEAR_ENTRY 0xD9 -#define HID_KEYPAD_BINARY 0xDA -#define HID_KEYPAD_OCTAL 0xDB -#define HID_KEYPAD_DECIMAL 0xDC -#define HID_KEYPAD_HEXADECIMAL 0xDD - -// 0xDE-0xDF - RESERVED -#define HID_KEYBOARD_LEFT_CONTROL 0xE0 -#define HID_KEYBOARD_LEFT_SHIFT 0xE1 -#define HID_KEYBOARD_LEFT_ALT 0xE2 -#define HID_KEYBOARD_LEFT_GUI 0xE3 -#define HID_KEYBOARD_RIGHT_CONTROL 0xE4 -#define HID_KEYBOARD_RIGHT_SHIFT 0xE5 -#define HID_KEYBOARD_RIGHT_ALT 0xE6 -#define HID_KEYBOARD_RIGHT_GUI 0xE7 - - -// Consumer_Page_(0x0C) 0x15 -#define HID_CONSUMER_NUMERIC_KEY_PAD 0x02 // HID type NARY -#define HID_CONSUMER_PROGRAMMABLE_BUTTONS 0x03 // HID type NARY -#define HID_CONSUMER_MICROPHONE_CA 0x04 -#define HID_CONSUMER_HEADPHONE_CA 0x05 -#define HID_CONSUMER_GRAPHIC_EQUALIZER_CA 0x06 -// Reserved 0x07-1F -#define HID_CONSUMER_PLUS_10 0x20 // HID type OSC -#define HID_CONSUMER_PLUS_100 0x21 // HID type OSC -#define HID_CONSUMER_AM_SLASH_PM 0x22 // HID type OSC -// Reserved 0x23-3F -#define HID_CONSUMER_POWER 0x30 // HID type OOC -#define HID_CONSUMER_RESET 0x31 // HID type OSC -#define HID_CONSUMER_SLEEP 0x32 // HID type OSC -#define HID_CONSUMER_SLEEP_AFTER 0x33 // HID type OSC -#define HID_CONSUMER_SLEEP_MODE 0x34 // HID type RTC -#define HID_CONSUMER_ILLUMINATION 0x35 // HID type OOC -#define HID_CONSUMER_FUNCTION_BUTTONS 0x36 // HID type NARY -// Reserved 0x37-3F -#define HID_CONSUMER_MENU 0x40 // HID type OOC -#define HID_CONSUMER_MENU_PICK 0x41 // HID type OSC -#define HID_CONSUMER_MENU_UP 0x42 // HID type OSC -#define HID_CONSUMER_MENU_DOWN 0x43 // HID type OSC -#define HID_CONSUMER_MENU_LEFT 0x44 // HID type OSC -#define HID_CONSUMER_MENU_RIGHT 0x45 // HID type OSC -#define HID_CONSUMER_MENU_ESCAPE 0x46 // HID type OSC -#define HID_CONSUMER_MENU_VALUE_INCREASE 0x47 // HID type OSC -#define HID_CONSUMER_MENU_VALUE_DECREASE 0x48 // HID type OSC -// Reserved 0x49-5F -#define HID_CONSUMER_DATA_ON_SCREEN 0x60 // HID type OOC -#define HID_CONSUMER_CLOSED_CAPTION 0x61 // HID type OOC -#define HID_CONSUMER_CLOSED_CAPTION_SELECT 0x62 // HID type OSC -#define HID_CONSUMER_VCR_SLASH_TV 0x63 // HID type OOC -#define HID_CONSUMER_BROADCAST_MODE 0x64 // HID type OSC -#define HID_CONSUMER_SNAPSHOT 0x65 // HID type OSC -#define HID_CONSUMER_STILL 0x66 // HID type OSC -// Reserved 0x67-7F -#define HID_CONSUMER_SELECTION 0x80 // HID type NARY -#define HID_CONSUMER_ASSIGN_SELECTION 0x81 // HID type OSC -#define HID_CONSUMER_MODE_STEP 0x82 // HID type OSC -#define HID_CONSUMER_RECALL_LAST 0x83 // HID type OSC -#define HID_CONSUMER_ENTER_CHANNEL 0x84 // HID type OSC -#define HID_CONSUMER_ORDER_MOVIE 0x85 // HID type OSC -#define HID_CONSUMER_CHANNEL 0x86 // HID type LC -#define HID_CONSUMER_MEDIA_SELECTION 0x87 // HID type NARY -#define HID_CONSUMER_MEDIA_SELECT_COMPUTER 0x88 // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_TV 0x89 // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_WWW 0x8A // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_DVD 0x8B // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_TELEPHONE 0x8C // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_PROGRAM_GUIDE 0x8D // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_VIDEO_PHONE 0x8E // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_GAMES 0x8F // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_MESSAGES 0x90 // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_CD 0x91 // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_VCR 0x92 // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_TUNER 0x93 // HID type SEL -#define HID_CONSUMER_QUIT 0x94 // HID type OSC -#define HID_CONSUMER_HELP 0x95 // HID type OOC -#define HID_CONSUMER_MEDIA_SELECT_TAPE 0x96 // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_CABLE 0x97 // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_SATELLITE 0x98 // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_SECURITY 0x99 // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_HOME 0x9A // HID type SEL -#define HID_CONSUMER_MEDIA_SELECT_CALL 0x9B // HID type SEL -#define HID_CONSUMER_CHANNEL_INCREMENT 0x9C // HID type OSC -#define HID_CONSUMER_CHANNEL_DECREMENT 0x9D // HID type OSC -#define HID_CONSUMER_MEDIA_SELECT_SAP 0x9E // HID type SEL -// Reserved 0x9F -#define HID_CONSUMER_VCR_PLUS 0xA0 // HID type OSC -#define HID_CONSUMER_ONCE 0xA1 // HID type OSC -#define HID_CONSUMER_DAILY 0xA2 // HID type OSC -#define HID_CONSUMER_WEEKLY 0xA3 // HID type OSC -#define HID_CONSUMER_MONTHLY 0xA4 // HID type OSC -// Reserved 0xA5-AF -#define HID_CONSUMER_PLAY 0xB0 // HID type OOC -#define HID_CONSUMER_PAUSE 0xB1 // HID type OOC -#define HID_CONSUMER_RECORD 0xB2 // HID type OOC -#define HID_CONSUMER_FAST_FORWARD 0xB3 // HID type OOC -#define HID_CONSUMER_REWIND 0xB4 // HID type OOC -#define HID_CONSUMER_SCAN_NEXT_TRACK 0xB5 // HID type OSC -#define HID_CONSUMER_SCAN_PREVIOUS_TRACK 0xB6 // HID type OSC -#define HID_CONSUMER_STOP 0xB7 // HID type OSC -#define HID_CONSUMER_EJECT 0xB8 // HID type OSC -#define HID_CONSUMER_RANDOM_PLAY 0xB9 // HID type OOC -#define HID_CONSUMER_SELECT_DISC 0xBA // HID type NARY -#define HID_CONSUMER_ENTER_DISC_MC 0xBB -#define HID_CONSUMER_REPEAT 0xBC // HID type OSC -#define HID_CONSUMER_TRACKING 0xBD // HID type LC -#define HID_CONSUMER_TRACK_NORMAL 0xBE // HID type OSC -#define HID_CONSUMER_SLOW_TRACKING 0xBF // HID type LC -#define HID_CONSUMER_FRAME_FORWARD 0xC0 // HID type RTC -#define HID_CONSUMER_FRAME_BACK 0xC1 // HID type RTC -#define HID_CONSUMER_MARK 0xC2 // HID type OSC -#define HID_CONSUMER_CLEAR_MARK 0xC3 // HID type OSC -#define HID_CONSUMER_REPEAT_FROM_MARK 0xC4 // HID type OOC -#define HID_CONSUMER_RETURN_TO_MARK 0xC5 // HID type OSC -#define HID_CONSUMER_SEARCH_MARK_FORWARD 0xC6 // HID type OSC -#define HID_CONSUMER_SEARCH_MARK_BACKWARDS 0xC7 // HID type OSC -#define HID_CONSUMER_COUNTER_RESET 0xC8 // HID type OSC -#define HID_CONSUMER_SHOW_COUNTER 0xC9 // HID type OSC -#define HID_CONSUMER_TRACKING_INCREMENT 0xCA // HID type RTC -#define HID_CONSUMER_TRACKING_DECREMENT 0xCB // HID type RTC -#define HID_CONSUMER_STOP_SLASH_EJECT 0xCC // HID type OSC -#define HID_CONSUMER_PLAY_SLASH_PAUSE 0xCD // HID type OSC -#define HID_CONSUMER_PLAY_SLASH_SKIP 0xCE // HID type OSC -// Reserved 0xCF-DF -#define HID_CONSUMER_VOLUME 0xE0 // HID type LC -#define HID_CONSUMER_BALANCE 0xE1 // HID type LC -#define HID_CONSUMER_MUTE 0xE2 // HID type OOC -#define HID_CONSUMER_BASS 0xE3 // HID type LC -#define HID_CONSUMER_TREBLE 0xE4 // HID type LC -#define HID_CONSUMER_BASS_BOOST 0xE5 // HID type OOC -#define HID_CONSUMER_SURROUND_MODE 0xE6 // HID type OSC -#define HID_CONSUMER_LOUDNESS 0xE7 // HID type OOC -#define HID_CONSUMER_MPX 0xE8 // HID type OOC -#define HID_CONSUMER_VOLUME_INCREMENT 0xE9 // HID type RTC -#define HID_CONSUMER_VOLUME_DECREMENT 0xEA // HID type RTC -// Reserved 0xEB-EF -#define HID_CONSUMER_SPEED_SELECT 0xF0 // HID type OSC -#define HID_CONSUMER_PLAYBACK_SPEED 0xF1 // HID type NARY -#define HID_CONSUMER_STANDARD_PLAY 0xF2 // HID type SEL -#define HID_CONSUMER_LONG_PLAY 0xF3 // HID type SEL -#define HID_CONSUMER_EXTENDED_PLAY 0xF4 // HID type SEL -#define HID_CONSUMER_SLOW 0xF5 // HID type OSC -// Reserved 0xF6-FF -#define HID_CONSUMER_FAN_ENABLE 0x100 // HID type OOC -#define HID_CONSUMER_FAN_SPEED 0x101 // HID type LC -#define HID_CONSUMER_LIGHT_ENABLE 0x102 // HID type OOC -#define HID_CONSUMER_LIGHT_ILLUMINATION_LEVEL 0x103 // HID type LC -#define HID_CONSUMER_CLIMATE_CONTROL_ENABLE 0x104 // HID type OOC -#define HID_CONSUMER_ROOM_TEMPERATURE 0x105 // HID type LC -#define HID_CONSUMER_SECURITY_ENABLE 0x106 // HID type OOC -#define HID_CONSUMER_FIRE_ALARM 0x107 // HID type OSC -#define HID_CONSUMER_POLICE_ALARM 0x108 // HID type OSC -#define HID_CONSUMER_PROXIMITY 0x109 // HID type LC -#define HID_CONSUMER_MOTION 0x10A // HID type OSC -#define HID_CONSUMER_DURESS_ALARM 0x10B // HID type OSC -#define HID_CONSUMER_HOLDUP_ALARM 0x10C // HID type OSC -#define HID_CONSUMER_MEDICAL_ALARM 0x10D // HID type OSC -// Reserved 0x10E-14F -#define HID_CONSUMER_BALANCE_RIGHT 0x150 // HID type RTC -#define HID_CONSUMER_BALANCE_LEFT 0x151 // HID type RTC -#define HID_CONSUMER_BASS_INCREMENT 0x152 // HID type RTC -#define HID_CONSUMER_BASS_DECREMENT 0x153 // HID type RTC -#define HID_CONSUMER_TREBLE_INCREMENT 0x154 // HID type RTC -#define HID_CONSUMER_TREBLE_DECREMENT 0x155 // HID type RTC -// Reserved 0x156-15F -#define HID_CONSUMER_SPEAKER_SYSTEM 0x160 // HID type CL -#define HID_CONSUMER_CHANNEL_LEFT 0x161 // HID type CL -#define HID_CONSUMER_CHANNEL_RIGHT 0x162 // HID type CL -#define HID_CONSUMER_CHANNEL_CENTER 0x163 // HID type CL -#define HID_CONSUMER_CHANNEL_FRONT 0x164 // HID type CL -#define HID_CONSUMER_CHANNEL_CENTER_FRONT 0x165 // HID type CL -#define HID_CONSUMER_CHANNEL_SIDE 0x166 // HID type CL -#define HID_CONSUMER_CHANNEL_SURROUND 0x167 // HID type CL -#define HID_CONSUMER_CHANNEL_LOW_FREQUENCY_ENHANCEMENT 0x168 // HID type CL -#define HID_CONSUMER_CHANNEL_TOP 0x169 // HID type CL -#define HID_CONSUMER_CHANNEL_UNKNOWN 0x16A // HID type CL -// Reserved 0x16B-16F -#define HID_CONSUMER_SUB_CHANNEL 0x170 // HID type LC -#define HID_CONSUMER_SUB_CHANNEL_INCREMENT 0x171 // HID type OSC -#define HID_CONSUMER_SUB_CHANNEL_DECREMENT 0x172 // HID type OSC -#define HID_CONSUMER_ALTERNATE_AUDIO_INCREMENT 0x173 // HID type OSC -#define HID_CONSUMER_ALTERNATE_AUDIO_DECREMENT 0x174 // HID type OSC -// Reserved 0x175-17F -#define HID_CONSUMER_APPLICATION_LAUNCH_BUTTONS 0x180 // HID type NARY -#define HID_CONSUMER_AL_LAUNCH_BUTTON_CONFIGURATION_TOOL 0x181 // HID type SEL -#define HID_CONSUMER_AL_PROGRAMMABLE_BUTTON_CONFIGURATION 0x182 // HID type SEL -#define HID_CONSUMER_AL_CONSUMER_CONTROL_CONFIGURATION 0x183 // HID type SEL -#define HID_CONSUMER_AL_WORD_PROCESSOR 0x184 // HID type SEL -#define HID_CONSUMER_AL_TEXT_EDITOR 0x185 // HID type SEL -#define HID_CONSUMER_AL_SPREADSHEET 0x186 // HID type SEL -#define HID_CONSUMER_AL_GRAPHICS_EDITOR 0x187 // HID type SEL -#define HID_CONSUMER_AL_PRESENTATION_APP 0x188 // HID type SEL -#define HID_CONSUMER_AL_DATABASE_APP 0x189 // HID type SEL -#define HID_CONSUMER_AL_EMAIL_READER 0x18A // HID type SEL -#define HID_CONSUMER_AL_NEWSREADER 0x18B // HID type SEL -#define HID_CONSUMER_AL_VOICEMAIL 0x18C // HID type SEL -#define HID_CONSUMER_AL_CONTACTS_SLASH_ADDRESS_BOOK 0x18D // HID type SEL -#define HID_CONSUMER_AL_CALENDAR_SLASH_SCHEDULE 0x18E // HID type SEL -#define HID_CONSUMER_AL_TASK_SLASH_PROJECT_MANAGER 0x18F // HID type SEL -#define HID_CONSUMER_AL_LOG_SLASH_JOURNAL_SLASH_TIMECARD 0x190 // HID type SEL -#define HID_CONSUMER_AL_CHECKBOOK_SLASH_FINANCE 0x191 // HID type SEL -#define HID_CONSUMER_AL_CALCULATOR 0x192 // HID type SEL -#define HID_CONSUMER_AL_A_SLASH_V_CAPTURE_SLASH_PLAYBACK 0x193 // HID type SEL -#define HID_CONSUMER_AL_LOCAL_MACHINE_BROWSER 0x194 // HID type SEL -#define HID_CONSUMER_AL_LAN_SLASH_WAN_BROWSER 0x195 // HID type SEL -#define HID_CONSUMER_AL_INTERNET_BROWSER 0x196 // HID type SEL -#define HID_CONSUMER_AL_REMOTE_NETWORKING_SLASH_ISP_CONNECT 0x197 // HID type SEL -#define HID_CONSUMER_AL_NETWORK_CONFERENCE 0x198 // HID type SEL -#define HID_CONSUMER_AL_NETWORK_CHAT 0x199 // HID type SEL -#define HID_CONSUMER_AL_TELEPHONY_SLASH_DIALER 0x19A // HID type SEL -#define HID_CONSUMER_AL_LOGON 0x19B // HID type SEL -#define HID_CONSUMER_AL_LOGOFF 0x19C // HID type SEL -#define HID_CONSUMER_AL_LOGON_SLASH_LOGOFF 0x19D // HID type SEL -#define HID_CONSUMER_AL_TERMINAL_LOCK_SLASH_SCREENSAVER 0x19E // HID type SEL -#define HID_CONSUMER_AL_CONTROL_PANEL 0x19F // HID type SEL -#define HID_CONSUMER_AL_COMMAND_LINE_PROCESSOR_SLASH_RUN 0x1A0 // HID type SEL -#define HID_CONSUMER_AL_PROCESS_SLASH_TASK_MANAGER 0x1A1 // HID type SEL -#define HID_CONSUMER_AL_SELECT_TASK_SLASH_APPLICATION 0x1A2 // HID type SEL -#define HID_CONSUMER_AL_NEXT_TASK_SLASH_APPLICATION 0x1A3 // HID type SEL -#define HID_CONSUMER_AL_PREVIOUS_TASK_SLASH_APPLICATION 0x1A4 // HID type SEL -#define HID_CONSUMER_AL_PREEMPTIVE_HALT_TASK_SLASH_APPLICATION 0x1A5 // HID type SEL -#define HID_CONSUMER_AL_INTEGRATED_HELP_CENTER 0x1A6 // HID type SEL -#define HID_CONSUMER_AL_DOCUMENTS 0x1A7 // HID type SEL -#define HID_CONSUMER_AL_THESAURUS 0x1A8 // HID type SEL -#define HID_CONSUMER_AL_DICTIONARY 0x1A9 // HID type SEL -#define HID_CONSUMER_AL_DESKTOP 0x1AA // HID type SEL -#define HID_CONSUMER_AL_SPELL_CHECK 0x1AB // HID type SEL -#define HID_CONSUMER_AL_GRAMMAR_CHECK 0x1AC // HID type SEL -#define HID_CONSUMER_AL_WIRELESS_STATUS 0x1AD // HID type SEL -#define HID_CONSUMER_AL_KEYBOARD_LAYOUT 0x1AE // HID type SEL -#define HID_CONSUMER_AL_VIRUS_PROTECTION 0x1AF // HID type SEL -#define HID_CONSUMER_AL_ENCRYPTION 0x1B0 // HID type SEL -#define HID_CONSUMER_AL_SCREEN_SAVER 0x1B1 // HID type SEL -#define HID_CONSUMER_AL_ALARMS 0x1B2 // HID type SEL -#define HID_CONSUMER_AL_CLOCK 0x1B3 // HID type SEL -#define HID_CONSUMER_AL_FILE_BROWSER 0x1B4 // HID type SEL -#define HID_CONSUMER_AL_POWER_STATUS 0x1B5 // HID type SEL -#define HID_CONSUMER_AL_IMAGE_BROWSER 0x1B6 // HID type SEL -#define HID_CONSUMER_AL_AUDIO_BROWSER 0x1B7 // HID type SEL -#define HID_CONSUMER_AL_MOVIE_BROWSER 0x1B8 // HID type SEL -#define HID_CONSUMER_AL_DIGITAL_RIGHTS_MANAGER 0x1B9 // HID type SEL -#define HID_CONSUMER_AL_DIGITAL_WALLET 0x1BA // HID type SEL -// _Reserved 0x1BB -#define HID_CONSUMER_AL_INSTANT_MESSAGING 0x1BC // HID type SEL -#define HID_CONSUMER_AL_OEM_FEATURES_SLASH__TIPS_SLASH_TUTORIAL_BROWSER 0x1BD // HID type SEL -#define HID_CONSUMER_AL_OEM_HELP 0x1BE // HID type SEL -#define HID_CONSUMER_AL_ONLINE_COMMUNITY 0x1BF // HID type SEL -#define HID_CONSUMER_AL_ENTERTAINMENT_CONTENT_BROWSER 0x1C0 // HID type SEL -#define HID_CONSUMER_AL_ONLINE_SHOPPING_BROWSER 0x1C1 // HID type SEL -#define HID_CONSUMER_AL_SMARTCARD_INFORMATION_SLASH_HELP 0x1C2 // HID type SEL -#define HID_CONSUMER_AL_MARKET_MONITOR_SLASH_FINANCE_BROWSER 0x1C3 // HID type SEL -#define HID_CONSUMER_AL_CUSTOMIZED_CORPORATE_NEWS_BROWSER 0x1C4 // HID type SEL -#define HID_CONSUMER_AL_ONLINE_ACTIVITY_BROWSER 0x1C5 // HID type SEL -#define HID_CONSUMER_AL_RESEARCH_SLASH_SEARCH_BROWSER 0x1C6 // HID type SEL -#define HID_CONSUMER_AL_AUDIO_PLAYER 0x1C7 // HID type SEL -// Reserved 0x1C8-1FF -#define HID_CONSUMER_GENERIC_GUI_APPLICATION_CONTROLS 0x200 // HID type NARY -#define HID_CONSUMER_AC_NEW 0x201 // HID type SEL -#define HID_CONSUMER_AC_OPEN 0x202 // HID type SEL -#define HID_CONSUMER_AC_CLOSE 0x203 // HID type SEL -#define HID_CONSUMER_AC_EXIT 0x204 // HID type SEL -#define HID_CONSUMER_AC_MAXIMIZE 0x205 // HID type SEL -#define HID_CONSUMER_AC_MINIMIZE 0x206 // HID type SEL -#define HID_CONSUMER_AC_SAVE 0x207 // HID type SEL -#define HID_CONSUMER_AC_PRINT 0x208 // HID type SEL -#define HID_CONSUMER_AC_PROPERTIES 0x209 // HID type SEL -#define HID_CONSUMER_AC_UNDO 0x21A // HID type SEL -#define HID_CONSUMER_AC_COPY 0x21B // HID type SEL -#define HID_CONSUMER_AC_CUT 0x21C // HID type SEL -#define HID_CONSUMER_AC_PASTE 0x21D // HID type SEL -#define HID_CONSUMER_AC_SELECT_ALL 0x21E // HID type SEL -#define HID_CONSUMER_AC_FIND 0x21F // HID type SEL -#define HID_CONSUMER_AC_FIND_AND_REPLACE 0x220 // HID type SEL -#define HID_CONSUMER_AC_SEARCH 0x221 // HID type SEL -#define HID_CONSUMER_AC_GO_TO 0x222 // HID type SEL -#define HID_CONSUMER_AC_HOME 0x223 // HID type SEL -#define HID_CONSUMER_AC_BACK 0x224 // HID type SEL -#define HID_CONSUMER_AC_FORWARD 0x225 // HID type SEL -#define HID_CONSUMER_AC_STOP 0x226 // HID type SEL -#define HID_CONSUMER_AC_REFRESH 0x227 // HID type SEL -#define HID_CONSUMER_AC_PREVIOUS_LINK 0x228 // HID type SEL -#define HID_CONSUMER_AC_NEXT_LINK 0x229 // HID type SEL -#define HID_CONSUMER_AC_BOOKMARKS 0x22A // HID type SEL -#define HID_CONSUMER_AC_HISTORY 0x22B // HID type SEL -#define HID_CONSUMER_AC_SUBSCRIPTIONS 0x22C // HID type SEL -#define HID_CONSUMER_AC_ZOOM_IN 0x22D // HID type SEL -#define HID_CONSUMER_AC_ZOOM_OUT 0x22E // HID type SEL -#define HID_CONSUMER_AC_ZOOM 0x22F // HID type LC -#define HID_CONSUMER_AC_FULL_SCREEN_VIEW 0x230 // HID type SEL -#define HID_CONSUMER_AC_NORMAL_VIEW 0x231 // HID type SEL -#define HID_CONSUMER_AC_VIEW_TOGGLE 0x232 // HID type SEL -#define HID_CONSUMER_AC_SCROLL_UP 0x233 // HID type SEL -#define HID_CONSUMER_AC_SCROLL_DOWN 0x234 // HID type SEL -#define HID_CONSUMER_AC_SCROLL 0x235 // HID type LC -#define HID_CONSUMER_AC_PAN_LEFT 0x236 // HID type SEL -#define HID_CONSUMER_AC_PAN_RIGHT 0x237 // HID type SEL -#define HID_CONSUMER_AC_PAN 0x238 // HID type LC -#define HID_CONSUMER_AC_NEW_WINDOW 0x239 // HID type SEL -#define HID_CONSUMER_AC_TILE_HORIZONTALLY 0x23A // HID type SEL -#define HID_CONSUMER_AC_TILE_VERTICALLY 0x23B // HID type SEL -#define HID_CONSUMER_AC_FORMAT 0x23C // HID type SEL -#define HID_CONSUMER_AC_EDIT 0x23D // HID type SEL -#define HID_CONSUMER_AC_BOLD 0x23E // HID type SEL -#define HID_CONSUMER_AC_ITALICS 0x23F // HID type SEL -#define HID_CONSUMER_AC_UNDERLINE 0x240 // HID type SEL -#define HID_CONSUMER_AC_STRIKETHROUGH 0x241 // HID type SEL -#define HID_CONSUMER_AC_SUBSCRIPT 0x242 // HID type SEL -#define HID_CONSUMER_AC_SUPERSCRIPT 0x243 // HID type SEL -#define HID_CONSUMER_AC_ALL_CAPS 0x244 // HID type SEL -#define HID_CONSUMER_AC_ROTATE 0x245 // HID type SEL -#define HID_CONSUMER_AC_RESIZE 0x246 // HID type SEL -#define HID_CONSUMER_AC_FLIP_HORIZONTAL 0x247 // HID type SEL -#define HID_CONSUMER_AC_FLIP_VERTICAL 0x248 // HID type SEL -#define HID_CONSUMER_AC_MIRROR_HORIZONTAL 0x249 // HID type SEL -#define HID_CONSUMER_AC_MIRROR_VERTICAL 0x24A // HID type SEL -#define HID_CONSUMER_AC_FONT_SELECT 0x24B // HID type SEL -#define HID_CONSUMER_AC_FONT_COLOR 0x24C // HID type SEL -#define HID_CONSUMER_AC_FONT_SIZE 0x24D // HID type SEL -#define HID_CONSUMER_AC_JUSTIFY_LEFT 0x24E // HID type SEL -#define HID_CONSUMER_AC_JUSTIFY_CENTER_H 0x24F // HID type SEL -#define HID_CONSUMER_AC_JUSTIFY_RIGHT 0x250 // HID type SEL -#define HID_CONSUMER_AC_JUSTIFY_BLOCK_H 0x251 // HID type SEL -#define HID_CONSUMER_AC_JUSTIFY_TOP 0x252 // HID type SEL -#define HID_CONSUMER_AC_JUSTIFY_CENTER_V 0x253 // HID type SEL -#define HID_CONSUMER_AC_JUSTIFY_BOTTOM 0x254 // HID type SEL -#define HID_CONSUMER_AC_JUSTIFY_BLOCK_V 0x255 // HID type SEL -#define HID_CONSUMER_AC_INDENT_DECREASE 0x256 // HID type SEL -#define HID_CONSUMER_AC_INDENT_INCREASE 0x257 // HID type SEL -#define HID_CONSUMER_AC_NUMBERED_LIST 0x258 // HID type SEL -#define HID_CONSUMER_AC_RESTART_NUMBERING 0x259 // HID type SEL -#define HID_CONSUMER_AC_BULLETED_LIST 0x25A // HID type SEL -#define HID_CONSUMER_AC_PROMOTE 0x25B // HID type SEL -#define HID_CONSUMER_AC_DEMOTE 0x25C // HID type SEL -#define HID_CONSUMER_AC_YES 0x25D // HID type SEL -#define HID_CONSUMER_AC_NO 0x25E // HID type SEL -#define HID_CONSUMER_AC_CANCEL 0x25F // HID type SEL -#define HID_CONSUMER_AC_CATALOG 0x260 // HID type SEL -#define HID_CONSUMER_AC_BUY_SLASH_CHECKOUT 0x261 // HID type SEL -#define HID_CONSUMER_AC_ADD_TO_CART 0x262 // HID type SEL -#define HID_CONSUMER_AC_EXPAND 0x263 // HID type SEL -#define HID_CONSUMER_AC_EXPAND_ALL 0x264 // HID type SEL -#define HID_CONSUMER_AC_COLLAPSE 0x265 // HID type SEL -#define HID_CONSUMER_AC_COLLAPSE_ALL 0x266 // HID type SEL -#define HID_CONSUMER_AC_PRINT_PREVIEW 0x267 // HID type SEL -#define HID_CONSUMER_AC_PASTE_SPECIAL 0x268 // HID type SEL -#define HID_CONSUMER_AC_INSERT_MODE 0x269 // HID type SEL -#define HID_CONSUMER_AC_DELETE 0x26A // HID type SEL -#define HID_CONSUMER_AC_LOCK 0x26B // HID type SEL -#define HID_CONSUMER_AC_UNLOCK 0x26C // HID type SEL -#define HID_CONSUMER_AC_PROTECT 0x26D // HID type SEL -#define HID_CONSUMER_AC_UNPROTECT 0x26E // HID type SEL -#define HID_CONSUMER_AC_ATTACH_COMMENT 0x26F // HID type SEL -#define HID_CONSUMER_AC_DELETE_COMMENT 0x270 // HID type SEL -#define HID_CONSUMER_AC_VIEW_COMMENT 0x271 // HID type SEL -#define HID_CONSUMER_AC_SELECT_WORD 0x272 // HID type SEL -#define HID_CONSUMER_AC_SELECT_SENTENCE 0x273 // HID type SEL -#define HID_CONSUMER_AC_SELECT_PARAGRAPH 0x274 // HID type SEL -#define HID_CONSUMER_AC_SELECT_COLUMN 0x275 // HID type SEL -#define HID_CONSUMER_AC_SELECT_ROW 0x276 // HID type SEL -#define HID_CONSUMER_AC_SELECT_TABLE 0x277 // HID type SEL -#define HID_CONSUMER_AC_SELECT_OBJECT 0x278 // HID type SEL -#define HID_CONSUMER_AC_REDO_SLASH_REPEAT 0x279 // HID type SEL -#define HID_CONSUMER_AC_SORT 0x27A // HID type SEL -#define HID_CONSUMER_AC_SORT_ASCENDING 0x27B // HID type SEL -#define HID_CONSUMER_AC_SORT_DESCENDING 0x27C // HID type SEL -#define HID_CONSUMER_AC_FILTER 0x27D // HID type SEL -#define HID_CONSUMER_AC_SET_CLOCK 0x27E // HID type SEL -#define HID_CONSUMER_AC_VIEW_CLOCK 0x27F // HID type SEL -#define HID_CONSUMER_AC_SELECT_TIME_ZONE 0x280 // HID type SEL -#define HID_CONSUMER_AC_EDIT_TIME_ZONES 0x281 // HID type SEL -#define HID_CONSUMER_AC_SET_ALARM 0x282 // HID type SEL -#define HID_CONSUMER_AC_CLEAR_ALARM 0x283 // HID type SEL -#define HID_CONSUMER_AC_SNOOZE_ALARM 0x284 // HID type SEL -#define HID_CONSUMER_AC_RESET_ALARM 0x285 // HID type SEL -#define HID_CONSUMER_AC_SYNCHRONIZE 0x286 // HID type SEL -#define HID_CONSUMER_AC_SEND_SLASH_RECEIVE 0x287 // HID type SEL -#define HID_CONSUMER_AC_SEND_TO 0x288 // HID type SEL -#define HID_CONSUMER_AC_REPLY 0x289 // HID type SEL -#define HID_CONSUMER_AC_REPLY_ALL 0x28A // HID type SEL -#define HID_CONSUMER_AC_FORWARD_MSG 0x28B // HID type SEL -#define HID_CONSUMER_AC_SEND 0x28C // HID type SEL -#define HID_CONSUMER_AC_ATTACH_FILE 0x28D // HID type SEL -#define HID_CONSUMER_AC_UPLOAD 0x28E // HID type SEL -#define HID_CONSUMER_AC_DOWNLOAD_(SAVE_TARGET_AS) 0x28F // HID type SEL -#define HID_CONSUMER_AC_SET_BORDERS 0x290 // HID type SEL -#define HID_CONSUMER_AC_INSERT_ROW 0x291 // HID type SEL -#define HID_CONSUMER_AC_INSERT_COLUMN 0x292 // HID type SEL -#define HID_CONSUMER_AC_INSERT_FILE 0x293 // HID type SEL -#define HID_CONSUMER_AC_INSERT_PICTURE 0x294 // HID type SEL -#define HID_CONSUMER_AC_INSERT_OBJECT 0x295 // HID type SEL -#define HID_CONSUMER_AC_INSERT_SYMBOL 0x296 // HID type SEL -#define HID_CONSUMER_AC_SAVE_AND_CLOSE 0x297 // HID type SEL -#define HID_CONSUMER_AC_RENAME 0x298 // HID type SEL -#define HID_CONSUMER_AC_MERGE 0x299 // HID type SEL -#define HID_CONSUMER_AC_SPLIT 0x29A // HID type SEL -#define HID_CONSUMER_AC_DISRIBUTE_HORIZONTALLY 0x29B // HID type SEL -#define HID_CONSUMER_AC_DISTRIBUTE_VERTICALLY 0x29C // HID type SEL - -#endif // __HIDTables__ \ No newline at end of file diff --git a/libraries/CompleteHID/examples/AbsoluteMouse/AbsoluteMouse.ino b/libraries/CompleteHID/examples/AbsoluteMouse/AbsoluteMouse.ino deleted file mode 100644 index 7eaafa1a422..00000000000 --- a/libraries/CompleteHID/examples/AbsoluteMouse/AbsoluteMouse.ino +++ /dev/null @@ -1,28 +0,0 @@ -/* AbsoluteMouse.ino - - For ATmega32U4 based boards (like the Leonardo and Micro) - * This code is an API demo for the USB HID Absolute Mouse positioning API. - It does not require any circut external to your Arduino - Created 12 Jan 2014 - by Jesse Vincent - This sample code is in the public domain. -*/ - - -void setup() { - Mouse.begin(); -} - -void loop() { - - Mouse.moveAbsolute(16384,16384); // Jump to the center of the screen - delay(2500); - Mouse.moveAbsolute(0, 0); // X position, Y position - delay(2500); - Mouse.moveAbsolute(0, 32767); - delay(2500); - Mouse.moveAbsolute(32767, 32767); - delay(2500); - Mouse.moveAbsolute(32767,0); - delay(2500); -} diff --git a/libraries/CompleteHID/examples/ConsumerAndSystemControl/ConsumerAndSystemControl.ino b/libraries/CompleteHID/examples/ConsumerAndSystemControl/ConsumerAndSystemControl.ino deleted file mode 100644 index 8ea259ff9b4..00000000000 --- a/libraries/CompleteHID/examples/ConsumerAndSystemControl/ConsumerAndSystemControl.ino +++ /dev/null @@ -1,47 +0,0 @@ -/* ConsumerAndSystemControl.ino - Turns the computer's volume up, then turns it down. - - For ATmega32U4 based boards (like the Leonardo and Micro) - * This code is an API demo for the USB HID ConsumerControl and - SystemControl APIS. - It does not require any circut external to your Arduino - Created 12 Jan 2014 - by Jesse Vincent - This sample code is in the public domain. -*/ - - -void setup() { - Keyboard.begin(); - - // It can take a moment for the USB interface to be ready - // after setup. Delay for a second so we don't lose the first - // keypress. - delay(1000); -} - -void loop() { - - Keyboard.consumerControl(CONSUMER_CONTROL_VOLUME_UP); - delay(1000); - Keyboard.consumerControl(CONSUMER_CONTROL_VOLUME_DOWN); - delay(1000); - - - // Some other things the consumer control API can do: - - // Keyboard.consumerControl(CONSUMER_CONTROL_VOLUME_MUTE); - // Keyboard.consumerControl(CONSUMER_CONTROL_PLAY_PAUSE); - // Keyboard.consumerControl(CONSUMER_CONTROL_STOP); - // Keyboard.consumerControl(CONSUMER_CONTROL_PREV_TRACK); - // Keyboard.consumerControl(CONSUMER_CONTROL_NEXT_TRACK); - - - // If you uncomment this code, the Arduino will try to put your - // computer to sleep after waiting for 30 seconds. - // delay(30000); Keyboard.systemControl(SYSTEM_CONTROL_SLEEP); - - // For a complete list, of the currently supported ConsumerControl - // and SystemControl usages, look in cores/arduino/USBAPI.h - -} \ No newline at end of file From 99814355ecfb5cbc2b3e8e18f7a4e03a1db9079b Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 15 Jul 2015 16:05:28 +0200 Subject: [PATCH 38/39] add includes to USB examples --- .../09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino | 3 +++ .../09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino | 3 +++ .../09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino | 3 +++ .../09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino | 3 +++ .../KeyboardAndMouseControl/KeyboardAndMouseControl.ino | 4 ++++ .../09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino | 3 +++ .../Mouse/JoystickMouseControl/JoystickMouseControl.ino | 3 +++ 7 files changed, 22 insertions(+) diff --git a/build/shared/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino b/build/shared/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino index 9358ae8ff3b..1e468085341 100644 --- a/build/shared/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino +++ b/build/shared/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino @@ -29,6 +29,9 @@ #define WINDOWS 1 #define UBUNTU 2 +#include "Keyboard.h" +#include "HID.h" + // change this to match your platform: int platform = OSX; diff --git a/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino b/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino index 40a91abbec9..b6405bb9967 100644 --- a/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino +++ b/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino @@ -20,6 +20,9 @@ http://www.arduino.cc/en/Tutorial/KeyboardMessage */ +#include "Keyboard.h" +#include "HID.h" + const int buttonPin = 4; // input pin for pushbutton int previousButtonState = HIGH; // for checking the state of a pushButton int counter = 0; // button push counter diff --git a/build/shared/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino b/build/shared/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino index bc486a044e8..807480489a0 100644 --- a/build/shared/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino +++ b/build/shared/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino @@ -27,6 +27,9 @@ http://www.arduino.cc/en/Tutorial/KeyboardReprogram */ +#include "Keyboard.h" +#include "HID.h" + // use this option for OSX. // Comment it out if using Windows or Linux: char ctrlKey = KEY_LEFT_GUI; diff --git a/build/shared/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino b/build/shared/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino index 2f98c9116a0..3c2a6838d90 100644 --- a/build/shared/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino +++ b/build/shared/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino @@ -19,6 +19,9 @@ http://www.arduino.cc/en/Tutorial/KeyboardSerial */ +#include "Keyboard.h" +#include "HID.h" + void setup() { // open the serial port: Serial.begin(9600); diff --git a/build/shared/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino b/build/shared/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino index b41512ac3bc..01f60fe88fc 100644 --- a/build/shared/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino +++ b/build/shared/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino @@ -21,6 +21,10 @@ */ +#include "Keyboard.h" +#include "Mouse.h" +#include "HID.h" + // set pin numbers for the five buttons: const int upButton = 2; const int downButton = 3; diff --git a/build/shared/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino b/build/shared/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino index 3a5629fb167..9b9aef0337c 100644 --- a/build/shared/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino +++ b/build/shared/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino @@ -24,6 +24,9 @@ */ +#include "Mouse.h" +#include "HID.h" + // set pin numbers for the five buttons: const int upButton = 2; const int downButton = 3; diff --git a/build/shared/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino b/build/shared/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino index 1fcf269cd7f..b59b2b76ab3 100644 --- a/build/shared/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino +++ b/build/shared/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino @@ -28,6 +28,9 @@ */ +#include "Mouse.h" +#include "HID.h" + // set pin numbers for switch, joystick axes, and LED: const int switchPin = 2; // switch to turn on and off mouse control const int mouseButton = 3; // input pin for the mouse pushButton From af290fc5a35a694f06d84830d285f8667572b71f Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 15 Jul 2015 16:15:46 +0200 Subject: [PATCH 39/39] rework HID-based libraries and add Due fallback --- hardware/arduino/avr/libraries/HID/HID.cpp | 2 -- hardware/arduino/avr/libraries/HID/HID.h | 2 ++ .../arduino/avr/libraries/HID/keywords.txt | 21 ++++++++++++++++ .../avr/libraries/HID/library.properties | 8 ++++++ hardware/arduino/sam/libraries/HID/HID.h | 3 +++ libraries/Keyboard/README.adoc | 25 +++++++++++++++++++ libraries/Keyboard/keywords.txt | 24 ++++++++++++++++++ libraries/Keyboard/library.properties | 9 +++++++ libraries/Keyboard/{ => src}/Keyboard.cpp | 4 +-- libraries/Keyboard/{ => src}/Keyboard.h | 10 +++----- libraries/Mouse/README.adoc | 25 +++++++++++++++++++ libraries/Mouse/keywords.txt | 24 ++++++++++++++++++ libraries/Mouse/library.properties | 9 +++++++ libraries/Mouse/{ => src}/Mouse.cpp | 4 +-- libraries/Mouse/{ => src}/Mouse.h | 9 +++---- 15 files changed, 162 insertions(+), 17 deletions(-) create mode 100644 hardware/arduino/avr/libraries/HID/keywords.txt create mode 100644 hardware/arduino/avr/libraries/HID/library.properties create mode 100644 hardware/arduino/sam/libraries/HID/HID.h create mode 100644 libraries/Keyboard/README.adoc create mode 100644 libraries/Keyboard/keywords.txt create mode 100644 libraries/Keyboard/library.properties rename libraries/Keyboard/{ => src}/Keyboard.cpp (99%) rename libraries/Keyboard/{ => src}/Keyboard.h (96%) create mode 100644 libraries/Mouse/README.adoc create mode 100644 libraries/Mouse/keywords.txt create mode 100644 libraries/Mouse/library.properties rename libraries/Mouse/{ => src}/Mouse.cpp (99%) rename libraries/Mouse/{ => src}/Mouse.h (94%) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index ba379c29d92..0d2133ec799 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -21,8 +21,6 @@ #if defined(USBCON) -//#define RAWHID_ENABLED - HID_ HID; static u8 HID_ENDPOINT_INT; diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index c7608eb59b3..89832a9afef 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -27,6 +27,8 @@ #if defined(USBCON) +#define _USING_HID + //================================================================================ //================================================================================ // HID 'Driver' diff --git a/hardware/arduino/avr/libraries/HID/keywords.txt b/hardware/arduino/avr/libraries/HID/keywords.txt new file mode 100644 index 00000000000..32a9ba5f20c --- /dev/null +++ b/hardware/arduino/avr/libraries/HID/keywords.txt @@ -0,0 +1,21 @@ +####################################### +# Syntax Coloring Map HID +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +HID KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### +begin KEYWORD2 +SendReport KEYWORD2 +AppendDescriptor KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### +HID_TX LITERAL1 \ No newline at end of file diff --git a/hardware/arduino/avr/libraries/HID/library.properties b/hardware/arduino/avr/libraries/HID/library.properties new file mode 100644 index 00000000000..20a1e7f331f --- /dev/null +++ b/hardware/arduino/avr/libraries/HID/library.properties @@ -0,0 +1,8 @@ +name=HID +version=1.0 +author=Arduino +maintainer=Arduino +sentence=Module for PluggableUSB infrastructure. Exposes an API for devices like Keyboards, Mice and Gamepads +paragraph= +url=http://www.arduino.cc/en/Reference/HID +architectures=avr \ No newline at end of file diff --git a/hardware/arduino/sam/libraries/HID/HID.h b/hardware/arduino/sam/libraries/HID/HID.h new file mode 100644 index 00000000000..47ad936fa2f --- /dev/null +++ b/hardware/arduino/sam/libraries/HID/HID.h @@ -0,0 +1,3 @@ +// HID.h + +// placeholder waiting for HID library to be DUE compatible \ No newline at end of file diff --git a/libraries/Keyboard/README.adoc b/libraries/Keyboard/README.adoc new file mode 100644 index 00000000000..0d77d9a83d4 --- /dev/null +++ b/libraries/Keyboard/README.adoc @@ -0,0 +1,25 @@ += Keyboard Library for Arduino = + +This library allows an Arduino board with USB capabilites to act as a Keyboard. +Being based on HID library you need to include "HID.h" in your sketch. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/Keyboard + +== License == + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/libraries/Keyboard/keywords.txt b/libraries/Keyboard/keywords.txt new file mode 100644 index 00000000000..2078f032985 --- /dev/null +++ b/libraries/Keyboard/keywords.txt @@ -0,0 +1,24 @@ +####################################### +# Syntax Coloring Map For Keyboard +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Keyboard KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +write KEYWORD2 +press KEYWORD2 +release KEYWORD2 +releaseAll KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/libraries/Keyboard/library.properties b/libraries/Keyboard/library.properties new file mode 100644 index 00000000000..7d1c20c59b3 --- /dev/null +++ b/libraries/Keyboard/library.properties @@ -0,0 +1,9 @@ +name=Keyboard +version=1.0.0 +author=Arduino +maintainer=Arduino +sentence=Allows an Arduino board with USB capabilites to act as a Keyboard. For Leonardo/Micro only +paragraph=This library plugs on the HID library. It can be used with or without other HID-based libraries (Mouse, Gamepad etc) +category=USB +url=http://www.arduino.cc/en/Reference/Keyboard +architectures=* diff --git a/libraries/Keyboard/Keyboard.cpp b/libraries/Keyboard/src/Keyboard.cpp similarity index 99% rename from libraries/Keyboard/Keyboard.cpp rename to libraries/Keyboard/src/Keyboard.cpp index 571060e1e8c..73f4691193e 100644 --- a/libraries/Keyboard/Keyboard.cpp +++ b/libraries/Keyboard/src/Keyboard.cpp @@ -19,10 +19,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#if 1 - #include "Keyboard.h" +#if defined(_USING_HID) + //================================================================================ //================================================================================ // Keyboard diff --git a/libraries/Keyboard/Keyboard.h b/libraries/Keyboard/src/Keyboard.h similarity index 96% rename from libraries/Keyboard/Keyboard.h rename to libraries/Keyboard/src/Keyboard.h index 9affa18d378..761e8fa814a 100644 --- a/libraries/Keyboard/Keyboard.h +++ b/libraries/Keyboard/src/Keyboard.h @@ -22,15 +22,13 @@ #ifndef KEYBOARD_h #define KEYBOARD_h -#if 0 //defined(_USING_HID) - -#error "Can only attach one submodule to HID module" +#include "HID.h" -#else +#if !defined(_USING_HID) -#define _USING_HID +#warning "Using legacy HID core (non pluggable)" -#include "HID.h" +#else //================================================================================ //================================================================================ diff --git a/libraries/Mouse/README.adoc b/libraries/Mouse/README.adoc new file mode 100644 index 00000000000..3e61306c65b --- /dev/null +++ b/libraries/Mouse/README.adoc @@ -0,0 +1,25 @@ += Mouse Library for Arduino = + +This library allows an Arduino board with USB capabilites to act as a Mouse. +Being based on HID library you need to include "HID.h" in your sketch + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/Mouse + +== License == + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/libraries/Mouse/keywords.txt b/libraries/Mouse/keywords.txt new file mode 100644 index 00000000000..258c48eebaf --- /dev/null +++ b/libraries/Mouse/keywords.txt @@ -0,0 +1,24 @@ +####################################### +# Syntax Coloring Map For Keyboard +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Mouse KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +click KEYWORD2 +move KEYWORD2 +press KEYWORD2 +release KEYWORD2 +isPressed KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### diff --git a/libraries/Mouse/library.properties b/libraries/Mouse/library.properties new file mode 100644 index 00000000000..fe8e2c0b001 --- /dev/null +++ b/libraries/Mouse/library.properties @@ -0,0 +1,9 @@ +name=Mouse +version=1.0.0 +author=Arduino +maintainer=Arduino +sentence=Allows an Arduino board with USB capabilites to act as a Mouse. For Leonardo/Micro only +paragraph=This library plugs on the HID library. Can be used with or without other HID-based libraries (Keyboard, Gamepad etc) +category=USB +url=http://www.arduino.cc/en/Reference/Mouse +architectures=* diff --git a/libraries/Mouse/Mouse.cpp b/libraries/Mouse/src/Mouse.cpp similarity index 99% rename from libraries/Mouse/Mouse.cpp rename to libraries/Mouse/src/Mouse.cpp index 5001d6215e1..a0566811c28 100644 --- a/libraries/Mouse/Mouse.cpp +++ b/libraries/Mouse/src/Mouse.cpp @@ -19,10 +19,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#if 1 //defined(USBCON) - #include "Mouse.h" +#if defined(_USING_HID) + static const u8 _hidReportDescriptor[] PROGMEM = { // Mouse diff --git a/libraries/Mouse/Mouse.h b/libraries/Mouse/src/Mouse.h similarity index 94% rename from libraries/Mouse/Mouse.h rename to libraries/Mouse/src/Mouse.h index ac1117c3c60..3ab57a5eb1c 100644 --- a/libraries/Mouse/Mouse.h +++ b/libraries/Mouse/src/Mouse.h @@ -22,15 +22,14 @@ #ifndef MOUSE_h #define MOUSE_h -#if 0 //defined(_USING_HID) +#include "HID.h" -#error "Can only attach one submodule to HID module" +#if !defined(_USING_HID) -#else +#warning "Using legacy HID core (non pluggable)" -#define _USING_HID +#else -#include "HID.h" //================================================================================ //================================================================================ // Mouse