diff --git a/src/HID-APIs/HID-Tables.h b/src/HID-APIs/HID-Tables.h new file mode 100644 index 0000000..bc56d52 --- /dev/null +++ b/src/HID-APIs/HID-Tables.h @@ -0,0 +1,671 @@ +// 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 + +#pragma once + +// 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 diff --git a/src/HID-APIs/ImprovedKeylayouts.h b/src/HID-APIs/ImprovedKeylayouts.h new file mode 100644 index 0000000..b512e64 --- /dev/null +++ b/src/HID-APIs/ImprovedKeylayouts.h @@ -0,0 +1,348 @@ +/* +Copyright (c) 2014-2015 NicoHood +See the readme for credit to other people. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +// Include guard +#pragma once + +//================================================================================ +// Key definitions +//================================================================================ + +// Modifiers +#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 + +// Normal keys +#define KEY_UP_ARROW (RAW_KEYBOARD_UP_ARROW + 136) +#define KEY_DOWN_ARROW (RAW_KEYBOARD_DOWN_ARROW + 136) +#define KEY_LEFT_ARROW (RAW_KEYBOARD_LEFT_ARROW + 136) +#define KEY_RIGHT_ARROW (RAW_KEYBOARD_RIGHT_ARROW + 136) +#define KEY_BACKSPACE (RAW_KEYBOARD_BACKSPACE + 136) +#define KEY_TAB (RAW_KEYBOARD_TAB + 136) +#define KEY_RETURN (RAW_KEYBOARD_RETURN + 136) +#define KEY_ENTER KEY_RETURN +#define KEY_ESC (RAW_KEYBOARD_ESC + 136) +#define KEY_INSERT (RAW_KEYBOARD_INSERT + 136) +#define KEY_DELETE (RAW_KEYBOARD_DELETE + 136) +#define KEY_PAGE_UP (RAW_KEYBOARD_PAGE_UP + 136) +#define KEY_PAGE_DOWN (RAW_KEYBOARD_PAGE_DOWN + 136) +#define KEY_HOME (RAW_KEYBOARD_HOME + 136) +#define KEY_END (RAW_KEYBOARD_END + 136) +#define KEY_CAPS_LOCK (RAW_KEYBOARD_CAPS_LOCK + 136) +#define KEY_F1 (RAW_KEYBOARD_F1 + 136) +#define KEY_F2 (RAW_KEYBOARD_F2 + 136) +#define KEY_F3 (RAW_KEYBOARD_F3 + 136) +#define KEY_F4 (RAW_KEYBOARD_F4 + 136) +#define KEY_F5 (RAW_KEYBOARD_F5 + 136) +#define KEY_F6 (RAW_KEYBOARD_F6 + 136) +#define KEY_F7 (RAW_KEYBOARD_F7 + 136) +#define KEY_F8 (RAW_KEYBOARD_F8 + 136) +#define KEY_F9 (RAW_KEYBOARD_F9 + 136) +#define KEY_F10 (RAW_KEYBOARD_F10 + 136) +#define KEY_F11 (RAW_KEYBOARD_F11 + 136) +#define KEY_F12 (RAW_KEYBOARD_F12 + 136) + + +// New key definitions +#define KEY_PRINT (RAW_KEYBOARD_PRINT + 136) +#define KEY_NUM_LOCK (RAW_KEYBOARD_NUM_LOCK + 136) +#define KEY_SCROLL_LOCK (RAW_KEYBOARD_SCROLL_LOCK + 136) +#define KEY_PAUSE (RAW_KEYBOARD_PAUSE + 136) +#define KEY_MENU (RAW_KEYBOARD_MENU + 136) +#define KEY_SPACE ' ' +#define KEY_LEFT_WINDOWS KEY_LEFT_GUI +#define KEY_RIGHT_WINDOWS KEY_RIGHT_GUI +#define KEY_PRINTSCREEN KEY_PRINT + +// Keyboard Leds +#define LED_NUM_LOCK 0x01 +#define LED_CAPS_LOCK 0x02 +#define LED_SCROLL_LOCK 0x04 + +//================================================================================ +// LAYOUT_US_ENGLISH +//================================================================================ + +#if !defined(LAYOUT_US_ENGLISH) && !defined(LAYOUT_UNITED_KINGDOM) +#error This API does not support non english layouts. Please select an US or UK Keyboard. +#endif + +#define RAW_KEYBOARD_LEFT_CTRL (1 << 0) +#define RAW_KEYBOARD_LEFT_SHIFT (1 << 1) +#define RAW_KEYBOARD_LEFT_ALT (1 << 2) +#define RAW_KEYBOARD_LEFT_GUI (1 << 3) +#define RAW_KEYBOARD_RIGHT_CTRL (1 << 4) +#define RAW_KEYBOARD_RIGHT_SHIFT (1 << 5) +#define RAW_KEYBOARD_RIGHT_ALT (1 << 6) +#define RAW_KEYBOARD_RIGHT_GUI (1 << 7) + +#define RAW_KEYBOARD_KEY(key) ((key>='a' && key<='z') ? (0x04 + key-'a') :\ +(key>='A' && key<='Z') ? (0x04 + key-'A') : (key>='1' && key<='9') ? (0x1E + key-'1') : 0x27) + +#define RAW_KEYBOARD_A ( 4 ) +#define RAW_KEYBOARD_B ( 5 ) +#define RAW_KEYBOARD_C ( 6 ) +#define RAW_KEYBOARD_D ( 7 ) +#define RAW_KEYBOARD_E ( 8 ) +#define RAW_KEYBOARD_F ( 9 ) +#define RAW_KEYBOARD_G ( 10 ) +#define RAW_KEYBOARD_H ( 11 ) +#define RAW_KEYBOARD_I ( 12 ) +#define RAW_KEYBOARD_J ( 13 ) +#define RAW_KEYBOARD_K ( 14 ) +#define RAW_KEYBOARD_L ( 15 ) +#define RAW_KEYBOARD_M ( 16 ) +#define RAW_KEYBOARD_N ( 17 ) +#define RAW_KEYBOARD_O ( 18 ) +#define RAW_KEYBOARD_P ( 19 ) +#define RAW_KEYBOARD_Q ( 20 ) +#define RAW_KEYBOARD_R ( 21 ) +#define RAW_KEYBOARD_S ( 22 ) +#define RAW_KEYBOARD_T ( 23 ) +#define RAW_KEYBOARD_U ( 24 ) +#define RAW_KEYBOARD_V ( 25 ) +#define RAW_KEYBOARD_W ( 26 ) +#define RAW_KEYBOARD_X ( 27 ) +#define RAW_KEYBOARD_Y ( 28 ) +#define RAW_KEYBOARD_Z ( 29 ) +#define RAW_KEYBOARD_1 ( 30 ) +#define RAW_KEYBOARD_2 ( 31 ) +#define RAW_KEYBOARD_3 ( 32 ) +#define RAW_KEYBOARD_4 ( 33 ) +#define RAW_KEYBOARD_5 ( 34 ) +#define RAW_KEYBOARD_6 ( 35 ) +#define RAW_KEYBOARD_7 ( 36 ) +#define RAW_KEYBOARD_8 ( 37 ) +#define RAW_KEYBOARD_9 ( 38 ) +#define RAW_KEYBOARD_0 ( 39 ) +#define RAW_KEYBOARD_ENTER ( 40 ) +#define RAW_KEYBOARD_ESC ( 41 ) +#define RAW_KEYBOARD_BACKSPACE ( 42 ) +#define RAW_KEYBOARD_TAB ( 43 ) +#define RAW_KEYBOARD_SPACE ( 44 ) +#define RAW_KEYBOARD_MINUS ( 45 ) +#define RAW_KEYBOARD_EQUAL ( 46 ) +#define RAW_KEYBOARD_LEFT_BRACE ( 47 ) +#define RAW_KEYBOARD_RIGHT_BRACE ( 48 ) +#define RAW_KEYBOARD_BACKSLASH ( 49 ) +#define RAW_KEYBOARD_NON_US_NUM ( 50 ) +#define RAW_KEYBOARD_SEMICOLON ( 51 ) +#define RAW_KEYBOARD_QUOTE ( 52 ) +#define RAW_KEYBOARD_TILDE ( 53 ) +#define RAW_KEYBOARD_COMMA ( 54 ) +#define RAW_KEYBOARD_PERIOD ( 55 ) +#define RAW_KEYBOARD_SLASH ( 56 ) + +#define RAW_KEYBOARD_CAPS_LOCK 0x39 +#define RAW_KEYBOARD_F1 0x3A +#define RAW_KEYBOARD_F2 0x3B +#define RAW_KEYBOARD_F3 0x3C +#define RAW_KEYBOARD_F4 0x3D +#define RAW_KEYBOARD_F5 0x3E +#define RAW_KEYBOARD_F6 0x3F +#define RAW_KEYBOARD_F7 0x40 +#define RAW_KEYBOARD_F8 0x41 +#define RAW_KEYBOARD_F9 0x42 +#define RAW_KEYBOARD_F10 0x43 +#define RAW_KEYBOARD_F11 0x44 +#define RAW_KEYBOARD_F12 0x45 +#define RAW_KEYBOARD_PRINT 0x46 +#define RAW_KEYBOARD_SCROLL_LOCK 0x47 +#define RAW_KEYBOARD_PAUSE 0x48 +#define RAW_KEYBOARD_INSERT 0x49 +#define RAW_KEYBOARD_HOME 0x4A +#define RAW_KEYBOARD_PAGE_UP 0x4B +#define RAW_KEYBOARD_DELETE 0x4C +#define RAW_KEYBOARD_END 0x4D +#define RAW_KEYBOARD_PAGE_DOWN 0x4E +#define RAW_KEYBOARD_RIGHT_ARROW 0x4F +#define RAW_KEYBOARD_LEFT_ARROW 0x50 +#define RAW_KEYBOARD_DOWN_ARROW 0x51 +#define RAW_KEYBOARD_UP_ARROW 0x52 +#define RAW_KEYBOARD_NUM_LOCK 0x53 +#define RAW_KEYBOARD_NON_US 0x64 +#define RAW_KEYBOARD_MENU 0x65 + +#define SHIFT 0x80 +static const uint8_t _asciimap[128] PROGMEM = +{ + 0x00, // NUL + 0x00, // SOH + 0x00, // STX + 0x00, // ETX + 0x00, // EOT + 0x00, // ENQ + 0x00, // ACK + 0x00, // BEL + RAW_KEYBOARD_BACKSPACE, // BS Backspace + RAW_KEYBOARD_TAB, // TAB Tab + RAW_KEYBOARD_ENTER, // 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 + + RAW_KEYBOARD_SPACE, // ' ' + RAW_KEYBOARD_1|SHIFT, // ! +#ifdef LAYOUT_UNITED_KINGDOM + RAW_KEYBOARD_2|SHIFT, // " +#else + RAW_KEYBOARD_QUOTE|SHIFT, // " +#endif +#ifdef LAYOUT_UNITED_KINGDOM + RAW_KEYBOARD_BACKSLASH +#else + RAW_KEYBOARD_3|SHIFT, // # +#endif + RAW_KEYBOARD_4|SHIFT, // $ + RAW_KEYBOARD_5|SHIFT, // % + RAW_KEYBOARD_7|SHIFT, // & + RAW_KEYBOARD_QUOTE, // ' + RAW_KEYBOARD_9|SHIFT, // ( + RAW_KEYBOARD_0|SHIFT, // ) + RAW_KEYBOARD_8|SHIFT, // * + RAW_KEYBOARD_EQUAL|SHIFT, // + + RAW_KEYBOARD_COMMA, // , + RAW_KEYBOARD_MINUS, // - + RAW_KEYBOARD_PERIOD, // . + RAW_KEYBOARD_SLASH, // / + RAW_KEYBOARD_0, // 0 + RAW_KEYBOARD_1, // 1 + RAW_KEYBOARD_2, // 2 + RAW_KEYBOARD_3, // 3 + RAW_KEYBOARD_4, // 4 + RAW_KEYBOARD_5, // 5 + RAW_KEYBOARD_6, // 6 + RAW_KEYBOARD_7, // 7 + RAW_KEYBOARD_8, // 8 + RAW_KEYBOARD_9, // 9 + RAW_KEYBOARD_SEMICOLON|SHIFT, // : + RAW_KEYBOARD_SEMICOLON, // ; + RAW_KEYBOARD_COMMA|SHIFT, // < + RAW_KEYBOARD_EQUAL, // = + RAW_KEYBOARD_PERIOD|SHIFT, // > + RAW_KEYBOARD_SLASH|SHIFT, // ? +#ifdef LAYOUT_UNITED_KINGDOM + RAW_KEYBOARD_QUOTE|SHIFT, // @ +#else + RAW_KEYBOARD_2|SHIFT, // @ +#endif + RAW_KEYBOARD_A|SHIFT, // A + RAW_KEYBOARD_B|SHIFT, // B + RAW_KEYBOARD_C|SHIFT, // C + RAW_KEYBOARD_D|SHIFT, // D + RAW_KEYBOARD_E|SHIFT, // E + RAW_KEYBOARD_F|SHIFT, // F + RAW_KEYBOARD_G|SHIFT, // G + RAW_KEYBOARD_H|SHIFT, // H + RAW_KEYBOARD_I|SHIFT, // I + RAW_KEYBOARD_J|SHIFT, // J + RAW_KEYBOARD_K|SHIFT, // K + RAW_KEYBOARD_L|SHIFT, // L + RAW_KEYBOARD_M|SHIFT, // M + RAW_KEYBOARD_N|SHIFT, // N + RAW_KEYBOARD_O|SHIFT, // O + RAW_KEYBOARD_P|SHIFT, // P + RAW_KEYBOARD_Q|SHIFT, // Q + RAW_KEYBOARD_R|SHIFT, // R + RAW_KEYBOARD_S|SHIFT, // S + RAW_KEYBOARD_T|SHIFT, // T + RAW_KEYBOARD_U|SHIFT, // U + RAW_KEYBOARD_V|SHIFT, // V + RAW_KEYBOARD_W|SHIFT, // W + RAW_KEYBOARD_X|SHIFT, // X + RAW_KEYBOARD_Y|SHIFT, // Y + RAW_KEYBOARD_Z|SHIFT, // Z + RAW_KEYBOARD_LEFT_BRACE, // [ +#ifdef LAYOUT_UNITED_KINGDOM + RAW_KEYBOARD_NON_US, // bslash +#else + RAW_KEYBOARD_BACKSLASH, // bslash +#endif + RAW_KEYBOARD_RIGHT_BRACE, // ] + RAW_KEYBOARD_6|SHIFT, // ^ + RAW_KEYBOARD_MINUS|SHIFT, // _ + RAW_KEYBOARD_TILDE, // ` + RAW_KEYBOARD_A, // a + RAW_KEYBOARD_B, // b + RAW_KEYBOARD_C, // c + RAW_KEYBOARD_D, // d + RAW_KEYBOARD_E, // e + RAW_KEYBOARD_F, // f + RAW_KEYBOARD_G, // g + RAW_KEYBOARD_H, // h + RAW_KEYBOARD_I, // i + RAW_KEYBOARD_J, // j + RAW_KEYBOARD_K, // k + RAW_KEYBOARD_L, // l + RAW_KEYBOARD_M, // m + RAW_KEYBOARD_N, // n + RAW_KEYBOARD_O, // o + RAW_KEYBOARD_P, // p + RAW_KEYBOARD_Q, // q + RAW_KEYBOARD_R, // r + RAW_KEYBOARD_S, // s + RAW_KEYBOARD_T, // t + RAW_KEYBOARD_U, // u + RAW_KEYBOARD_V, // v + RAW_KEYBOARD_W, // w + RAW_KEYBOARD_X, // x + RAW_KEYBOARD_Y, // y + RAW_KEYBOARD_Z, // z + RAW_KEYBOARD_LEFT_BRACE|SHIFT, // { +#ifdef LAYOUT_UNITED_KINGDOM + RAW_KEYBOARD_NON_US|SHIFT, // | +#else + RAW_KEYBOARD_BACKSLASH|SHIFT, // | +#endif + RAW_KEYBOARD_RIGHT_BRACE|SHIFT, // } +#ifdef LAYOUT_UNITED_KINGDOM + RAW_KEYBOARD_BACKSLASH|SHIFT, // ~ +#else + RAW_KEYBOARD_TILDE|SHIFT, // ~ +#endif + 0x00 // DEL +}; diff --git a/src/HID-APIs/KeyboardAPI.cpp b/src/HID-APIs/KeyboardAPI.cpp new file mode 100644 index 0000000..58cd476 --- /dev/null +++ b/src/HID-APIs/KeyboardAPI.cpp @@ -0,0 +1,279 @@ +/* +Copyright (c) 2014-2015 NicoHood +See the readme for credit to other people. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include "KeyboardAPI.h" + +const uint8_t _hidReportDescriptorKeyboard[] PROGMEM = { + HID_REPORT_KEYBOARD, +}; + +const uint8_t _hidMultiReportDescriptorKeyboard[] PROGMEM = { + HID_MULTIREPORT_KEYBOARD, +}; + +static_assert(sizeof _hidReportDescriptorKeyboard == HID_REPORT_KEYBOARD_SIZE, "Oops, sizes are not equal."); +static_assert(sizeof _hidMultiReportDescriptorKeyboard == HID_MULTIREPORT_KEYBOARD_SIZE, "Oops, sizes are not equal."); + + + +void KeyboardAPI::begin(void) +{ + releaseAll(); +} + + +void KeyboardAPI::end(void) +{ + releaseAll(); +} + + +void KeyboardAPI::send_now(void){ + sendReport(&_keyReport, sizeof(_keyReport)); +} + + +// 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 KeyboardAPI::press(uint8_t k) +{ + // TODO improve the whole mechanism + size_t ret = addKeyToReport(k); + if(ret){ + send_now(); + } + return ret; +} + +// 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 KeyboardAPI::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 & SHIFT) { // it's a capital letter or other character reached with shift + _keyReport.modifiers &= ~(0x02); // the left shift modifier + k = k ^ SHIFT; + } + } + + // 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; + } + } + + send_now(); + return 1; +} + +void KeyboardAPI::releaseAll(void) +{ + // release all keys + memset(&_keyReport, 0x00, sizeof(_keyReport)); + send_now(); +} + +size_t KeyboardAPI::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 +} + +// 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 KeyboardAPI::pressKeycode(uint8_t k) +{ + if (!addKeycodeToReport(k)) { + return 0; + } + send_now(); + return 1; +} + +size_t KeyboardAPI::addKeyToReport(uint8_t k) +{ + 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 & SHIFT) { // it's a capital letter or other character reached with shift + _keyReport.modifiers |= 0x02; // the left shift modifier + k = k ^ SHIFT; + } + } + + return addKeycodeToReport(k); +} + +size_t KeyboardAPI::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 < sizeof(_keyReport.keys); 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; +} + + +// 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 KeyboardAPI::releaseKeycode(uint8_t k) +{ + if (!removeKeycodeFromReport(k)) { + return 0; + } + send_now(); + return 1; +} + +size_t KeyboardAPI::removeKeyFromReport(uint8_t k) +{ + 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 & SHIFT) { // it's a capital letter or other character reached with shift + _keyReport.modifiers &= ~(0x02); // the left shift modifier + k = k ^ SHIFT; + } + } + + return removeKeycodeFromReport(k); +} + +size_t KeyboardAPI::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 < sizeof(_keyReport.keys); 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) < sizeof(_keyReport.keys)) { + if (0 == _keyReport.keys[indexA]) { + count++; // one more zero + for (indexB = indexA; indexB < sizeof(_keyReport.keys) - count; indexB++) { + _keyReport.keys[indexB] = _keyReport.keys[indexB + 1]; + } + _keyReport.keys[sizeof(_keyReport.keys) - count] = 0; + } + else { + indexA++; // one more non-zero + } + } + } + + return 1; +} + + +size_t KeyboardAPI::writeKeycode(uint8_t c) +{ + uint8_t p = pressKeycode(c); // Keydown + releaseKeycode(c); // Keyup + return (p); // just return the result of pressKeycode() since release() almost always returns 1 +} diff --git a/src/HID-APIs/KeyboardAPI.h b/src/HID-APIs/KeyboardAPI.h new file mode 100644 index 0000000..84bfe9a --- /dev/null +++ b/src/HID-APIs/KeyboardAPI.h @@ -0,0 +1,150 @@ +/* +Copyright (c) 2014-2015 NicoHood +See the readme for credit to other people. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +// Include guard +#pragma once + +#include +#include "HID-Settings.h" +#include "ImprovedKeylayouts.h" +#include "HID-Tables.h" //TODO + + +#define HID_REPORT_KEYBOARD_START \ + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) 47 */ \ + 0x09, 0x06, /* USAGE (Keyboard) */ \ + 0xa1, 0x01 /* COLLECTION (Application) */ + +#define HID_REPORT_KEYBOARD_REPORTID \ + 0x85, HID_REPORTID_KEYBOARD /* REPORT_ID TODO order important?*/ + +#define HID_REPORT_KEYBOARD_START2 \ + 0x05, 0x07 /* USAGE_PAGE (Keyboard) */ + +#define HID_REPORT_KEYBOARD_MODIFIERS \ + /* 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) */ + +#define HID_REPORT_KEYBOARD_RESERVED \ + /* Reserved byte TODO consumer and or system?*/ \ + 0x95, 0x01, /* REPORT_COUNT (1) */ \ + 0x75, 0x08, /* REPORT_SIZE (8) */ \ + 0x81, 0x03 /* INPUT (Cnst,Var,Abs) */ \ + +#define HID_REPORT_KEYBOARD_KEYS \ + /* 6 Keyboard keys */ \ + 0x95, 0x06, /* REPORT_COUNT (6) */ \ + 0x75, 0x08, /* REPORT_SIZE (8) */ \ + 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ \ + 0x26, 0xE7, 0x00, /* LOGICAL_MAXIMUM (231) */ \ + 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ \ + 0x19, 0x00, /* USAGE_MINIMUM (Reserved (no event indicated)) */ \ + 0x29, 0xE7, /* USAGE_MAXIMUM (Keyboard Right GUI) */ \ + 0x81, 0x00 /* INPUT (Data,Ary,Abs) */ + +#define HID_REPORT_KEYBOARD_LEDS \ + /* 5 LEDs for num lock etc */ \ + 0x05, 0x08, /* USAGE_PAGE (LEDs) */ \ + 0x19, 0x01, /* USAGE_MINIMUM (Num Lock) */ \ + 0x29, 0x05, /* USAGE_MAXIMUM (Kana) TODO */ \ + 0x95, 0x05, /* REPORT_COUNT (5) */ \ + 0x75, 0x01, /* REPORT_SIZE (1) */ \ + 0x91, 0x02, /* OUTPUT (Data,Var,Abs) */ \ + /* Reserved 3 bits TODO */ \ + 0x95, 0x01, /* REPORT_COUNT (1) */ \ + 0x75, 0x03, /* REPORT_SIZE (3) */ \ + 0x91, 0x03 /* OUTPUT (Cnst,Var,Abs) */ + +#define HID_REPORT_KEYBOARD_END \ + /* End */ \ + 0xc0 /* END_COLLECTION */ + +#define HID_REPORT_KEYBOARD \ +HID_REPORT_KEYBOARD_START, \ +HID_REPORT_KEYBOARD_START2, \ +HID_REPORT_KEYBOARD_MODIFIERS, \ +HID_REPORT_KEYBOARD_RESERVED, \ +HID_REPORT_KEYBOARD_KEYS, \ +HID_REPORT_KEYBOARD_LEDS, \ +HID_REPORT_KEYBOARD_END + +#define HID_MULTIREPORT_KEYBOARD \ +HID_REPORT_KEYBOARD_START, \ +HID_REPORT_KEYBOARD_REPORTID, \ +HID_REPORT_KEYBOARD_START2, \ +HID_REPORT_KEYBOARD_MODIFIERS, \ +HID_REPORT_KEYBOARD_RESERVED, \ +HID_REPORT_KEYBOARD_KEYS, \ +HID_REPORT_KEYBOARD_END + +#define HID_REPORT_KEYBOARD_SIZE sizeof ((uint8_t[]) {HID_REPORT_KEYBOARD}) +#define HID_MULTIREPORT_KEYBOARD_SIZE sizeof ((uint8_t[]) {HID_MULTIREPORT_KEYBOARD}) + +extern const uint8_t _hidReportDescriptorKeyboard[HID_REPORT_KEYBOARD_SIZE] PROGMEM; +extern const uint8_t _hidMultiReportDescriptorKeyboard[HID_MULTIREPORT_KEYBOARD_SIZE] PROGMEM; + + +typedef union{ + // Low level key report: up to 6 keys and shift, ctrl etc at once + uint8_t whole8[]; + uint16_t whole16[]; + uint32_t whole32[]; + struct{ + uint8_t modifiers; + uint8_t reserved; + uint8_t keys[6]; + }; +} HID_KeyboardReport_Data_t; + +class KeyboardAPI : public Print +{ +public: +//TODO nkro compatiblity, merge them + void begin(void); + void end(void); + size_t write(uint8_t k); + size_t press(uint8_t k); + size_t release(uint8_t k); + void releaseAll(void); + void send_now(void); + + size_t writeKeycode(uint8_t k); + size_t pressKeycode(uint8_t k); + size_t releaseKeycode(uint8_t k); + size_t addKeyToReport(uint8_t k); + size_t addKeycodeToReport(uint8_t k); + size_t removeKeyFromReport(uint8_t k); + size_t removeKeycodeFromReport(uint8_t k); + + // Sending is public in the base class for advanced users. + virtual void sendReport(void* data, int length) = 0; + +protected: + HID_KeyboardReport_Data_t _keyReport; +}; diff --git a/src/HID-Settings.h b/src/HID-Settings.h new file mode 100644 index 0000000..afa38be --- /dev/null +++ b/src/HID-Settings.h @@ -0,0 +1,112 @@ +/* +Copyright (c) 2014-2015 NicoHood +See the readme for credit to other people. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +// Include guard +#pragma once + +//================================================================================ +// Settings +//================================================================================ + +#define HID_KEYBOARD_LEDS_ENABLED + +//#define LAYOUT_US_ENGLISH +//#define LAYOUT_CANADIAN_FRENCH +//#define LAYOUT_CANADIAN_MULTILINGUAL +//#define LAYOUT_DANISH +//#define LAYOUT_FINNISH +//#define LAYOUT_FRENCH +//#define LAYOUT_FRENCH_BELGIAN +//#define LAYOUT_FRENCH_SWISS +//#define LAYOUT_GERMAN +//#define LAYOUT_GERMAN_MAC +//#define LAYOUT_GERMAN_SWISS +//#define LAYOUT_ICELANDIC +//#define LAYOUT_IRISH +//#define LAYOUT_ITALIAN +//#define LAYOUT_NORWEGIAN +//#define LAYOUT_PORTUGUESE +//#define LAYOUT_PORTUGUESE_BRAZILIAN +//#define LAYOUT_SPANISH +//#define LAYOUT_SPANISH_LATIN_AMERICA +//#define LAYOUT_SWEDISH +//#define LAYOUT_TURKISH +//#define LAYOUT_UNITED_KINGDOM +//#define LAYOUT_US_INTERNATIONAL + +//================================================================================ +// Definitions and Helpers +//================================================================================ + +// Default US keyboard layout +#if !defined(LAYOUT_CANADIAN_FRENCH) && !defined(LAYOUT_CANADIAN_MULTILINGUAL) \ +&& !defined(LAYOUT_DANISH) && !defined(LAYOUT_FINNISH) && !defined(LAYOUT_FRENCH) \ +&& !defined(LAYOUT_FRENCH_BELGIAN) && !defined(LAYOUT_FRENCH_SWISS) && !defined(LAYOUT_GERMAN) \ +&& !defined(LAYOUT_GERMAN_MAC) && !defined(LAYOUT_GERMAN_SWISS) && !defined(LAYOUT_ICELANDIC) \ +&& !defined(LAYOUT_IRISH) && !defined(LAYOUT_ITALIAN) && !defined(LAYOUT_NORWEGIAN) \ +&& !defined(LAYOUT_PORTUGUESE) && !defined(LAYOUT_PORTUGUESE_BRAZILIAN) \ +&& !defined(LAYOUT_SPANISH) && !defined(LAYOUT_SPANISH_LATIN_AMERICA) \ +&& !defined(LAYOUT_SWEDISH) && !defined(LAYOUT_TURKISH) && !defined(LAYOUT_UNITED_KINGDOM) \ +&& !defined(LAYOUT_US_INTERNATIONAL) && !defined(LAYOUT_US_ENGLISH) +#define LAYOUT_US_ENGLISH +#endif + +#define HID_REPORTID_NONE 0 + +#ifndef HID_REPORTID_MOUSE +#define HID_REPORTID_MOUSE 1 +#endif + +#ifndef HID_REPORTID_KEYBOARD +#define HID_REPORTID_KEYBOARD 2 +#endif + +#ifndef HID_REPORTID_RAWHID +// This will not work properly in most cases. +// The number is just kept from the old number counting. +#define HID_REPORTID_RAWHID 3 +#endif + +#ifndef HID_REPORTID_CONSUMERCONTROL +#define HID_REPORTID_CONSUMERCONTROL 4 +#endif + +#ifndef HID_REPORTID_SYSTEMCONTROL +#define HID_REPORTID_SYSTEMCONTROL 5 +#endif + +#ifndef HID_REPORTID_GAMEPAD +#define HID_REPORTID_GAMEPAD 6 +#endif + +#ifndef HID_REPORTID_MOUSE_ABSOLUTE +#define HID_REPORTID_MOUSE_ABSOLUTE 7 +#endif + +#ifndef HID_REPORTID_NKRO_KEYBOARD +#define HID_REPORTID_NKRO_KEYBOARD 8 +#endif + +#ifndef HID_REPORTID_TEENSY_KEYBOARD +#define HID_REPORTID_TEENSY_KEYBOARD 9 +#endif diff --git a/src/MultiReport/ImprovedKeyboard.cpp b/src/MultiReport/ImprovedKeyboard.cpp new file mode 100644 index 0000000..7e391a6 --- /dev/null +++ b/src/MultiReport/ImprovedKeyboard.cpp @@ -0,0 +1,38 @@ +/* +Copyright (c) 2014-2015 NicoHood +See the readme for credit to other people. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include "ImprovedKeyboard.h" + +Keyboard_::Keyboard_(void) +{ + static HIDDescriptorListNode node(_hidMultiReportDescriptorKeyboard, sizeof(_hidMultiReportDescriptorKeyboard)); + HID().AppendDescriptor(&node); +} + +void Keyboard_::sendReport(void* data, int length) +{ + HID().SendReport(HID_REPORTID_KEYBOARD, data, length); +} + +Keyboard_ Keyboard; + diff --git a/src/MultiReport/ImprovedKeyboard.h b/src/MultiReport/ImprovedKeyboard.h new file mode 100644 index 0000000..b6b9ab2 --- /dev/null +++ b/src/MultiReport/ImprovedKeyboard.h @@ -0,0 +1,43 @@ +/* +Copyright (c) 2014-2015 NicoHood +See the readme for credit to other people. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +// Include guard +#pragma once + +#include +#include "PluggableUSB.h" +#include "HID-Settings.h" +#include "HID.h" +#include "../HID-APIs/KeyboardAPI.h" + + +class Keyboard_ : public KeyboardAPI +{ +public: + Keyboard_(void); + +protected: + virtual inline void sendReport(void* data, int length) override; +}; +extern Keyboard_ Keyboard; + diff --git a/src/SingleReport/BootKeyboard.cpp b/src/SingleReport/BootKeyboard.cpp new file mode 100644 index 0000000..b67fd00 --- /dev/null +++ b/src/SingleReport/BootKeyboard.cpp @@ -0,0 +1,109 @@ +/* +Copyright (c) 2014-2015 NicoHood +See the readme for credit to other people. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include "BootKeyboard.h" +#include "HID-Driver.h" + +BootKeyboard_::BootKeyboard_(void) : PUSBListNode(1, 1, epType), protocol(1), idle(1), leds(0) +{ + epType[0] = EP_TYPE_INTERRUPT_IN; + PluggableUSB().plug(this); +} + +int BootKeyboard_::getInterface(uint8_t* interfaceCount) +{ + *interfaceCount += 1; // uses 1 + HIDDescriptor hidInterface = { + D_INTERFACE(pluggedInterface, 1, 3, 1, 1), // Boot compatible keyboard + D_HIDREPORT(sizeof(_hidReportDescriptorKeyboard)), + D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) + }; + return USB_SendControl(0, &hidInterface, sizeof(hidInterface)); +} + +int BootKeyboard_::getDescriptor(USBSetup& setup) +{ + // Check if this is a HID Class Descriptor request + if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0; } + if (setup.wValueH != HID_REPORT_DESCRIPTOR_TYPE) { return 0; } + + // In a HID Class Descriptor wIndex cointains the interface number + if (setup.wIndex != pluggedInterface) { return 0; } + + return USB_SendControl(TRANSFER_PGM, _hidReportDescriptorKeyboard, sizeof(_hidReportDescriptorKeyboard)); +} + +bool BootKeyboard_::setup(USBSetup& setup) +{ + // Check if this is a HID Class Descriptor request + if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return false; } + if (setup.wValueH != HID_REPORT_DESCRIPTOR_TYPE) { return false; } + + // In a HID Class Descriptor wIndex cointains the interface number + if (setup.wIndex != pluggedInterface) { return false; } + + uint8_t request = setup.bRequest; + uint8_t requestType = setup.bmRequestType; + + if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE) + { + if (request == HID_GET_REPORT) { + // TODO: HID_GetReport(); + return true; + } + if (request == HID_GET_PROTOCOL) { + // TODO: Send8(protocol); + return true; + } + } + + if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE) + { + if (request == HID_SET_PROTOCOL) { + protocol = setup.wValueL; + return true; + } + if (request == HID_SET_IDLE) { + idle = setup.wValueL; + return true; + } + if (request == HID_SET_REPORT) + { + //TODO + } + } + + return false; +} + +uint8_t BootKeyboard_::getLeds(void){ + return leds; +} + +void BootKeyboard_::sendReport(void* data, int length){ + USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, length); +} + +BootKeyboard_ BootKeyboard; + + diff --git a/src/SingleReport/BootKeyboard.h b/src/SingleReport/BootKeyboard.h new file mode 100644 index 0000000..01bcfcf --- /dev/null +++ b/src/SingleReport/BootKeyboard.h @@ -0,0 +1,55 @@ +/* +Copyright (c) 2014-2015 NicoHood +See the readme for credit to other people. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +// Include guard +#pragma once + +#include +#include "PluggableUSB.h" +#include "HID-Settings.h" +#include "../HID-APIs/KeyboardAPI.h" + + +class BootKeyboard_ : public PUSBListNode, public KeyboardAPI +{ +public: + BootKeyboard_(void); + uint8_t getLeds(void); + +protected: + // Implementation of the PUSBListNode + int getInterface(uint8_t* interfaceCount); + int getDescriptor(USBSetup& setup); + bool setup(USBSetup& setup); + + uint8_t epType[1]; + uint8_t protocol; + uint8_t idle; + + uint8_t leds; + + virtual void sendReport(void* data, int length) override; +}; +extern BootKeyboard_ BootKeyboard; + + diff --git a/src/SingleReport/HID-Driver.h b/src/SingleReport/HID-Driver.h new file mode 100644 index 0000000..9dcfd6a --- /dev/null +++ b/src/SingleReport/HID-Driver.h @@ -0,0 +1,61 @@ +/* +Copyright (c) 2014-2015 NicoHood +See the readme for credit to other people. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +// Include guard +#pragma once + +// 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 + +typedef struct +{ + uint8_t len; // 9 + uint8_t dtype; // 0x21 + uint8_t addr; + uint8_t versionL; // 0x101 + uint8_t versionH; // 0x101 + uint8_t country; + uint8_t desctype; // 0x22 report + uint8_t descLenL; + uint8_t descLenH; +} HIDDescDescriptor; + +typedef struct +{ + InterfaceDescriptor hid; + HIDDescDescriptor desc; + EndpointDescriptor in; +} HIDDescriptor; + +#define D_HIDREPORT(length) { 9, 0x21, 0x01, 0x01, 0, 1, 0x22, lowByte(length), highByte(length) } +