HID-over-GATT implementation with the BLE API. This library allows to create devices such as mouse, keyboard or joystick, over Bluetooth Low Energy.

Dependents:   BLENano_HID BLE_HID_MouseScrollDemo BLE_HID_KeyboardStreamDemo Shervs_TestKeyboard_TinyBLE ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Keyboard_types.h Source File

Keyboard_types.h

00001 /* Copyright (c) 2015 mbed.org, MIT License
00002  *
00003  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00004  * and associated documentation files (the "Software"), to deal in the Software without
00005  * restriction, including without limitation the rights to use, copy, modify, merge, publish,
00006  * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
00007  * Software is furnished to do so, subject to the following conditions:
00008  *
00009  * The above copyright notice and this permission notice shall be included in all copies or
00010  * substantial portions of the Software.
00011  *
00012  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00013  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00014  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00015  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00016  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017  *
00018  * Note: this file was pulled from different parts of the USBHID library, in mbed SDK
00019  */
00020 
00021 #ifndef KEYBOARD_DEFS_H
00022 #define KEYBOARD_DEFS_H
00023 
00024 #define REPORT_ID_KEYBOARD 1
00025 #define REPORT_ID_VOLUME   3
00026  
00027 /* Modifiers */
00028 enum MODIFIER_KEY {
00029     KEY_CTRL = 1,
00030     KEY_SHIFT = 2,
00031     KEY_ALT = 4,
00032 };
00033  
00034  
00035 enum MEDIA_KEY {
00036     KEY_NEXT_TRACK,     /*!< next Track Button */
00037     KEY_PREVIOUS_TRACK, /*!< Previous track Button */
00038     KEY_STOP,           /*!< Stop Button */
00039     KEY_PLAY_PAUSE,     /*!< Play/Pause Button */
00040     KEY_MUTE,           /*!< Mute Button */
00041     KEY_VOLUME_UP,      /*!< Volume Up Button */
00042     KEY_VOLUME_DOWN,    /*!< Volume Down Button */
00043 };
00044  
00045 enum FUNCTION_KEY {
00046     KEY_F1 = 128,   /* F1 key */
00047     KEY_F2,         /* F2 key */
00048     KEY_F3,         /* F3 key */
00049     KEY_F4,         /* F4 key */
00050     KEY_F5,         /* F5 key */
00051     KEY_F6,         /* F6 key */
00052     KEY_F7,         /* F7 key */
00053     KEY_F8,         /* F8 key */
00054     KEY_F9,         /* F9 key */
00055     KEY_F10,        /* F10 key */
00056     KEY_F11,        /* F11 key */
00057     KEY_F12,        /* F12 key */
00058  
00059     KEY_PRINT_SCREEN,   /* Print Screen key */
00060     KEY_SCROLL_LOCK,    /* Scroll lock */
00061     KEY_CAPS_LOCK,      /* caps lock */
00062     KEY_NUM_LOCK,       /* num lock */
00063     KEY_INSERT,         /* Insert key */
00064     KEY_HOME,           /* Home key */
00065     KEY_PAGE_UP,        /* Page Up key */
00066     KEY_PAGE_DOWN,      /* Page Down key */
00067  
00068     RIGHT_ARROW,        /* Right arrow */
00069     LEFT_ARROW,         /* Left arrow */
00070     DOWN_ARROW,         /* Down arrow */
00071     UP_ARROW,           /* Up arrow */
00072 };
00073  
00074 typedef struct {
00075     unsigned char usage;
00076     unsigned char modifier;
00077 } KEYMAP;
00078  
00079 #ifdef US_KEYBOARD
00080 /* US keyboard (as HID standard) */
00081 #define KEYMAP_SIZE (152)
00082 const KEYMAP keymap[KEYMAP_SIZE] = {
00083     {0, 0},             /* NUL */
00084     {0, 0},             /* SOH */
00085     {0, 0},             /* STX */
00086     {0, 0},             /* ETX */
00087     {0, 0},             /* EOT */
00088     {0, 0},             /* ENQ */
00089     {0, 0},             /* ACK */
00090     {0, 0},             /* BEL */
00091     {0x2a, 0},          /* BS  */  /* Keyboard Delete (Backspace) */
00092     {0x2b, 0},          /* TAB */  /* Keyboard Tab */
00093     {0x28, 0},          /* LF  */  /* Keyboard Return (Enter) */
00094     {0, 0},             /* VT  */
00095     {0, 0},             /* FF  */
00096     {0, 0},             /* CR  */
00097     {0, 0},             /* SO  */
00098     {0, 0},             /* SI  */
00099     {0, 0},             /* DEL */
00100     {0, 0},             /* DC1 */
00101     {0, 0},             /* DC2 */
00102     {0, 0},             /* DC3 */
00103     {0, 0},             /* DC4 */
00104     {0, 0},             /* NAK */
00105     {0, 0},             /* SYN */
00106     {0, 0},             /* ETB */
00107     {0, 0},             /* CAN */
00108     {0, 0},             /* EM  */
00109     {0, 0},             /* SUB */
00110     {0, 0},             /* ESC */
00111     {0, 0},             /* FS  */
00112     {0, 0},             /* GS  */
00113     {0, 0},             /* RS  */
00114     {0, 0},             /* US  */
00115     {0x2c, 0},          /*   */
00116     {0x1e, KEY_SHIFT},      /* ! */
00117     {0x34, KEY_SHIFT},      /* " */
00118     {0x20, KEY_SHIFT},      /* # */
00119     {0x21, KEY_SHIFT},      /* $ */
00120     {0x22, KEY_SHIFT},      /* % */
00121     {0x24, KEY_SHIFT},      /* & */
00122     {0x34, 0},          /* ' */
00123     {0x26, KEY_SHIFT},      /* ( */
00124     {0x27, KEY_SHIFT},      /* ) */
00125     {0x25, KEY_SHIFT},      /* * */
00126     {0x2e, KEY_SHIFT},      /* + */
00127     {0x36, 0},          /* , */
00128     {0x2d, 0},          /* - */
00129     {0x37, 0},          /* . */
00130     {0x38, 0},          /* / */
00131     {0x27, 0},          /* 0 */
00132     {0x1e, 0},          /* 1 */
00133     {0x1f, 0},          /* 2 */
00134     {0x20, 0},          /* 3 */
00135     {0x21, 0},          /* 4 */
00136     {0x22, 0},          /* 5 */
00137     {0x23, 0},          /* 6 */
00138     {0x24, 0},          /* 7 */
00139     {0x25, 0},          /* 8 */
00140     {0x26, 0},          /* 9 */
00141     {0x33, KEY_SHIFT},      /* : */
00142     {0x33, 0},          /* ; */
00143     {0x36, KEY_SHIFT},      /* < */
00144     {0x2e, 0},          /* = */
00145     {0x37, KEY_SHIFT},      /* > */
00146     {0x38, KEY_SHIFT},      /* ? */
00147     {0x1f, KEY_SHIFT},      /* @ */
00148     {0x04, KEY_SHIFT},      /* A */
00149     {0x05, KEY_SHIFT},      /* B */
00150     {0x06, KEY_SHIFT},      /* C */
00151     {0x07, KEY_SHIFT},      /* D */
00152     {0x08, KEY_SHIFT},      /* E */
00153     {0x09, KEY_SHIFT},      /* F */
00154     {0x0a, KEY_SHIFT},      /* G */
00155     {0x0b, KEY_SHIFT},      /* H */
00156     {0x0c, KEY_SHIFT},      /* I */
00157     {0x0d, KEY_SHIFT},      /* J */
00158     {0x0e, KEY_SHIFT},      /* K */
00159     {0x0f, KEY_SHIFT},      /* L */
00160     {0x10, KEY_SHIFT},      /* M */
00161     {0x11, KEY_SHIFT},      /* N */
00162     {0x12, KEY_SHIFT},      /* O */
00163     {0x13, KEY_SHIFT},      /* P */
00164     {0x14, KEY_SHIFT},      /* Q */
00165     {0x15, KEY_SHIFT},      /* R */
00166     {0x16, KEY_SHIFT},      /* S */
00167     {0x17, KEY_SHIFT},      /* T */
00168     {0x18, KEY_SHIFT},      /* U */
00169     {0x19, KEY_SHIFT},      /* V */
00170     {0x1a, KEY_SHIFT},      /* W */
00171     {0x1b, KEY_SHIFT},      /* X */
00172     {0x1c, KEY_SHIFT},      /* Y */
00173     {0x1d, KEY_SHIFT},      /* Z */
00174     {0x2f, 0},          /* [ */
00175     {0x31, 0},          /* \ */
00176     {0x30, 0},          /* ] */
00177     {0x23, KEY_SHIFT},      /* ^ */
00178     {0x2d, KEY_SHIFT},      /* _ */
00179     {0x35, 0},          /* ` */
00180     {0x04, 0},          /* a */
00181     {0x05, 0},          /* b */
00182     {0x06, 0},          /* c */
00183     {0x07, 0},          /* d */
00184     {0x08, 0},          /* e */
00185     {0x09, 0},          /* f */
00186     {0x0a, 0},          /* g */
00187     {0x0b, 0},          /* h */
00188     {0x0c, 0},          /* i */
00189     {0x0d, 0},          /* j */
00190     {0x0e, 0},          /* k */
00191     {0x0f, 0},          /* l */
00192     {0x10, 0},          /* m */
00193     {0x11, 0},          /* n */
00194     {0x12, 0},          /* o */
00195     {0x13, 0},          /* p */
00196     {0x14, 0},          /* q */
00197     {0x15, 0},          /* r */
00198     {0x16, 0},          /* s */
00199     {0x17, 0},          /* t */
00200     {0x18, 0},          /* u */
00201     {0x19, 0},          /* v */
00202     {0x1a, 0},          /* w */
00203     {0x1b, 0},          /* x */
00204     {0x1c, 0},          /* y */
00205     {0x1d, 0},          /* z */
00206     {0x2f, KEY_SHIFT},      /* { */
00207     {0x31, KEY_SHIFT},      /* | */
00208     {0x30, KEY_SHIFT},      /* } */
00209     {0x35, KEY_SHIFT},      /* ~ */
00210     {0,0},              /* DEL */
00211  
00212     {0x3a, 0},          /* F1 */
00213     {0x3b, 0},          /* F2 */
00214     {0x3c, 0},          /* F3 */
00215     {0x3d, 0},          /* F4 */
00216     {0x3e, 0},          /* F5 */
00217     {0x3f, 0},          /* F6 */
00218     {0x40, 0},          /* F7 */
00219     {0x41, 0},          /* F8 */
00220     {0x42, 0},          /* F9 */
00221     {0x43, 0},          /* F10 */
00222     {0x44, 0},          /* F11 */
00223     {0x45, 0},          /* F12 */
00224  
00225     {0x46, 0},          /* PRINT_SCREEN */
00226     {0x47, 0},          /* SCROLL_LOCK */
00227     {0x39, 0},          /* CAPS_LOCK */
00228     {0x53, 0},          /* NUM_LOCK */
00229     {0x49, 0},          /* INSERT */
00230     {0x4a, 0},          /* HOME */
00231     {0x4b, 0},          /* PAGE_UP */
00232     {0x4e, 0},          /* PAGE_DOWN */
00233  
00234     {0x4f, 0},          /* RIGHT_ARROW */
00235     {0x50, 0},          /* LEFT_ARROW */
00236     {0x51, 0},          /* DOWN_ARROW */
00237     {0x52, 0},          /* UP_ARROW */
00238 };
00239  
00240 #else
00241 /* UK keyboard */
00242 #define KEYMAP_SIZE (152)
00243 const KEYMAP keymap[KEYMAP_SIZE] = {
00244     {0, 0},             /* NUL */
00245     {0, 0},             /* SOH */
00246     {0, 0},             /* STX */
00247     {0, 0},             /* ETX */
00248     {0, 0},             /* EOT */
00249     {0, 0},             /* ENQ */
00250     {0, 0},             /* ACK */
00251     {0, 0},             /* BEL */
00252     {0x2a, 0},          /* BS  */  /* Keyboard Delete (Backspace) */
00253     {0x2b, 0},          /* TAB */  /* Keyboard Tab */
00254     {0x28, 0},          /* LF  */  /* Keyboard Return (Enter) */
00255     {0, 0},             /* VT  */
00256     {0, 0},             /* FF  */
00257     {0, 0},             /* CR  */
00258     {0, 0},             /* SO  */
00259     {0, 0},             /* SI  */
00260     {0, 0},             /* DEL */
00261     {0, 0},             /* DC1 */
00262     {0, 0},             /* DC2 */
00263     {0, 0},             /* DC3 */
00264     {0, 0},             /* DC4 */
00265     {0, 0},             /* NAK */
00266     {0, 0},             /* SYN */
00267     {0, 0},             /* ETB */
00268     {0, 0},             /* CAN */
00269     {0, 0},             /* EM  */
00270     {0, 0},             /* SUB */
00271     {0, 0},             /* ESC */
00272     {0, 0},             /* FS  */
00273     {0, 0},             /* GS  */
00274     {0, 0},             /* RS  */
00275     {0, 0},             /* US  */
00276     {0x2c, 0},          /*   */
00277     {0x1e, KEY_SHIFT},      /* ! */
00278     {0x1f, KEY_SHIFT},      /* " */
00279     {0x32, 0},          /* # */
00280     {0x21, KEY_SHIFT},      /* $ */
00281     {0x22, KEY_SHIFT},      /* % */
00282     {0x24, KEY_SHIFT},      /* & */
00283     {0x34, 0},          /* ' */
00284     {0x26, KEY_SHIFT},      /* ( */
00285     {0x27, KEY_SHIFT},      /* ) */
00286     {0x25, KEY_SHIFT},      /* * */
00287     {0x2e, KEY_SHIFT},      /* + */
00288     {0x36, 0},          /* , */
00289     {0x2d, 0},          /* - */
00290     {0x37, 0},          /* . */
00291     {0x38, 0},          /* / */
00292     {0x27, 0},          /* 0 */
00293     {0x1e, 0},          /* 1 */
00294     {0x1f, 0},          /* 2 */
00295     {0x20, 0},          /* 3 */
00296     {0x21, 0},          /* 4 */
00297     {0x22, 0},          /* 5 */
00298     {0x23, 0},          /* 6 */
00299     {0x24, 0},          /* 7 */
00300     {0x25, 0},          /* 8 */
00301     {0x26, 0},          /* 9 */
00302     {0x33, KEY_SHIFT},      /* : */
00303     {0x33, 0},          /* ; */
00304     {0x36, KEY_SHIFT},      /* < */
00305     {0x2e, 0},          /* = */
00306     {0x37, KEY_SHIFT},      /* > */
00307     {0x38, KEY_SHIFT},      /* ? */
00308     {0x34, KEY_SHIFT},      /* @ */
00309     {0x04, KEY_SHIFT},      /* A */
00310     {0x05, KEY_SHIFT},      /* B */
00311     {0x06, KEY_SHIFT},      /* C */
00312     {0x07, KEY_SHIFT},      /* D */
00313     {0x08, KEY_SHIFT},      /* E */
00314     {0x09, KEY_SHIFT},      /* F */
00315     {0x0a, KEY_SHIFT},      /* G */
00316     {0x0b, KEY_SHIFT},      /* H */
00317     {0x0c, KEY_SHIFT},      /* I */
00318     {0x0d, KEY_SHIFT},      /* J */
00319     {0x0e, KEY_SHIFT},      /* K */
00320     {0x0f, KEY_SHIFT},      /* L */
00321     {0x10, KEY_SHIFT},      /* M */
00322     {0x11, KEY_SHIFT},      /* N */
00323     {0x12, KEY_SHIFT},      /* O */
00324     {0x13, KEY_SHIFT},      /* P */
00325     {0x14, KEY_SHIFT},      /* Q */
00326     {0x15, KEY_SHIFT},      /* R */
00327     {0x16, KEY_SHIFT},      /* S */
00328     {0x17, KEY_SHIFT},      /* T */
00329     {0x18, KEY_SHIFT},      /* U */
00330     {0x19, KEY_SHIFT},      /* V */
00331     {0x1a, KEY_SHIFT},      /* W */
00332     {0x1b, KEY_SHIFT},      /* X */
00333     {0x1c, KEY_SHIFT},      /* Y */
00334     {0x1d, KEY_SHIFT},      /* Z */
00335     {0x2f, 0},          /* [ */
00336     {0x64, 0},          /* \ */
00337     {0x30, 0},          /* ] */
00338     {0x23, KEY_SHIFT},      /* ^ */
00339     {0x2d, KEY_SHIFT},      /* _ */
00340     {0x35, 0},          /* ` */
00341     {0x04, 0},          /* a */
00342     {0x05, 0},          /* b */
00343     {0x06, 0},          /* c */
00344     {0x07, 0},          /* d */
00345     {0x08, 0},          /* e */
00346     {0x09, 0},          /* f */
00347     {0x0a, 0},          /* g */
00348     {0x0b, 0},          /* h */
00349     {0x0c, 0},          /* i */
00350     {0x0d, 0},          /* j */
00351     {0x0e, 0},          /* k */
00352     {0x0f, 0},          /* l */
00353     {0x10, 0},          /* m */
00354     {0x11, 0},          /* n */
00355     {0x12, 0},          /* o */
00356     {0x13, 0},          /* p */
00357     {0x14, 0},          /* q */
00358     {0x15, 0},          /* r */
00359     {0x16, 0},          /* s */
00360     {0x17, 0},          /* t */
00361     {0x18, 0},          /* u */
00362     {0x19, 0},          /* v */
00363     {0x1a, 0},          /* w */
00364     {0x1b, 0},          /* x */
00365     {0x1c, 0},          /* y */
00366     {0x1d, 0},          /* z */
00367     {0x2f, KEY_SHIFT},      /* { */
00368     {0x64, KEY_SHIFT},      /* | */
00369     {0x30, KEY_SHIFT},      /* } */
00370     {0x32, KEY_SHIFT},      /* ~ */
00371     {0,0},             /* DEL */
00372  
00373     {0x3a, 0},          /* F1 */
00374     {0x3b, 0},          /* F2 */
00375     {0x3c, 0},          /* F3 */
00376     {0x3d, 0},          /* F4 */
00377     {0x3e, 0},          /* F5 */
00378     {0x3f, 0},          /* F6 */
00379     {0x40, 0},          /* F7 */
00380     {0x41, 0},          /* F8 */
00381     {0x42, 0},          /* F9 */
00382     {0x43, 0},          /* F10 */
00383     {0x44, 0},          /* F11 */
00384     {0x45, 0},          /* F12 */
00385  
00386     {0x46, 0},          /* PRINT_SCREEN */
00387     {0x47, 0},          /* SCROLL_LOCK */
00388     {0x39, 0},          /* CAPS_LOCK */
00389     {0x53, 0},          /* NUM_LOCK */
00390     {0x49, 0},          /* INSERT */
00391     {0x4a, 0},          /* HOME */
00392     {0x4b, 0},          /* PAGE_UP */
00393     {0x4e, 0},          /* PAGE_DOWN */
00394  
00395     {0x4f, 0},          /* RIGHT_ARROW */
00396     {0x50, 0},          /* LEFT_ARROW */
00397     {0x51, 0},          /* DOWN_ARROW */
00398     {0x52, 0},          /* UP_ARROW */
00399 };
00400 #endif
00401 
00402 #endif
00403