Pinscape Controller version 1 fork. This is a fork to allow for ongoing bug fixes to the original controller version, from before the major changes for the expansion board project.
Dependencies: FastIO FastPWM SimpleDMA mbed
Fork of Pinscape_Controller by
USBDevice/USBHID/USBKeyboard.h@68:edfecf67a931, 2016-02-15 (annotated)
- Committer:
- mjr
- Date:
- Mon Feb 15 23:03:55 2016 +0000
- Revision:
- 68:edfecf67a931
- Parent:
- 52:63f0a9b45f0c
Finalize USB library updates to fix compatibility problems introduced in USBHAL_KL25Z overhaul.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mjr | 52:63f0a9b45f0c | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
mjr | 52:63f0a9b45f0c | 2 | * |
mjr | 52:63f0a9b45f0c | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
mjr | 52:63f0a9b45f0c | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
mjr | 52:63f0a9b45f0c | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
mjr | 52:63f0a9b45f0c | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
mjr | 52:63f0a9b45f0c | 7 | * Software is furnished to do so, subject to the following conditions: |
mjr | 52:63f0a9b45f0c | 8 | * |
mjr | 52:63f0a9b45f0c | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
mjr | 52:63f0a9b45f0c | 10 | * substantial portions of the Software. |
mjr | 52:63f0a9b45f0c | 11 | * |
mjr | 52:63f0a9b45f0c | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
mjr | 52:63f0a9b45f0c | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
mjr | 52:63f0a9b45f0c | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
mjr | 52:63f0a9b45f0c | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
mjr | 52:63f0a9b45f0c | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
mjr | 52:63f0a9b45f0c | 17 | */ |
mjr | 52:63f0a9b45f0c | 18 | |
mjr | 52:63f0a9b45f0c | 19 | #ifndef USBKEYBOARD_H |
mjr | 52:63f0a9b45f0c | 20 | #define USBKEYBOARD_H |
mjr | 52:63f0a9b45f0c | 21 | |
mjr | 52:63f0a9b45f0c | 22 | #include "USBHID.h" |
mjr | 52:63f0a9b45f0c | 23 | #include "Stream.h" |
mjr | 52:63f0a9b45f0c | 24 | |
mjr | 52:63f0a9b45f0c | 25 | /* Modifiers */ |
mjr | 52:63f0a9b45f0c | 26 | enum MODIFIER_KEY { |
mjr | 52:63f0a9b45f0c | 27 | KEY_CTRL = 1, |
mjr | 52:63f0a9b45f0c | 28 | KEY_SHIFT = 2, |
mjr | 52:63f0a9b45f0c | 29 | KEY_ALT = 4, |
mjr | 52:63f0a9b45f0c | 30 | }; |
mjr | 52:63f0a9b45f0c | 31 | |
mjr | 52:63f0a9b45f0c | 32 | |
mjr | 52:63f0a9b45f0c | 33 | enum MEDIA_KEY { |
mjr | 52:63f0a9b45f0c | 34 | KEY_NEXT_TRACK, /*!< next Track Button */ |
mjr | 52:63f0a9b45f0c | 35 | KEY_PREVIOUS_TRACK, /*!< Previous track Button */ |
mjr | 52:63f0a9b45f0c | 36 | KEY_STOP, /*!< Stop Button */ |
mjr | 52:63f0a9b45f0c | 37 | KEY_PLAY_PAUSE, /*!< Play/Pause Button */ |
mjr | 52:63f0a9b45f0c | 38 | KEY_MUTE, /*!< Mute Button */ |
mjr | 52:63f0a9b45f0c | 39 | KEY_VOLUME_UP, /*!< Volume Up Button */ |
mjr | 52:63f0a9b45f0c | 40 | KEY_VOLUME_DOWN, /*!< Volume Down Button */ |
mjr | 52:63f0a9b45f0c | 41 | }; |
mjr | 52:63f0a9b45f0c | 42 | |
mjr | 52:63f0a9b45f0c | 43 | enum FUNCTION_KEY { |
mjr | 52:63f0a9b45f0c | 44 | KEY_F1 = 128, /* F1 key */ |
mjr | 52:63f0a9b45f0c | 45 | KEY_F2, /* F2 key */ |
mjr | 52:63f0a9b45f0c | 46 | KEY_F3, /* F3 key */ |
mjr | 52:63f0a9b45f0c | 47 | KEY_F4, /* F4 key */ |
mjr | 52:63f0a9b45f0c | 48 | KEY_F5, /* F5 key */ |
mjr | 52:63f0a9b45f0c | 49 | KEY_F6, /* F6 key */ |
mjr | 52:63f0a9b45f0c | 50 | KEY_F7, /* F7 key */ |
mjr | 52:63f0a9b45f0c | 51 | KEY_F8, /* F8 key */ |
mjr | 52:63f0a9b45f0c | 52 | KEY_F9, /* F9 key */ |
mjr | 52:63f0a9b45f0c | 53 | KEY_F10, /* F10 key */ |
mjr | 52:63f0a9b45f0c | 54 | KEY_F11, /* F11 key */ |
mjr | 52:63f0a9b45f0c | 55 | KEY_F12, /* F12 key */ |
mjr | 52:63f0a9b45f0c | 56 | |
mjr | 52:63f0a9b45f0c | 57 | KEY_PRINT_SCREEN, /* Print Screen key */ |
mjr | 52:63f0a9b45f0c | 58 | KEY_SCROLL_LOCK, /* Scroll lock */ |
mjr | 52:63f0a9b45f0c | 59 | KEY_CAPS_LOCK, /* caps lock */ |
mjr | 52:63f0a9b45f0c | 60 | KEY_NUM_LOCK, /* num lock */ |
mjr | 52:63f0a9b45f0c | 61 | KEY_INSERT, /* Insert key */ |
mjr | 52:63f0a9b45f0c | 62 | KEY_HOME, /* Home key */ |
mjr | 52:63f0a9b45f0c | 63 | KEY_PAGE_UP, /* Page Up key */ |
mjr | 52:63f0a9b45f0c | 64 | KEY_PAGE_DOWN, /* Page Down key */ |
mjr | 52:63f0a9b45f0c | 65 | |
mjr | 52:63f0a9b45f0c | 66 | RIGHT_ARROW, /* Right arrow */ |
mjr | 52:63f0a9b45f0c | 67 | LEFT_ARROW, /* Left arrow */ |
mjr | 52:63f0a9b45f0c | 68 | DOWN_ARROW, /* Down arrow */ |
mjr | 52:63f0a9b45f0c | 69 | UP_ARROW, /* Up arrow */ |
mjr | 52:63f0a9b45f0c | 70 | }; |
mjr | 52:63f0a9b45f0c | 71 | |
mjr | 52:63f0a9b45f0c | 72 | /** |
mjr | 52:63f0a9b45f0c | 73 | * USBKeyboard example |
mjr | 52:63f0a9b45f0c | 74 | * @code |
mjr | 52:63f0a9b45f0c | 75 | * |
mjr | 52:63f0a9b45f0c | 76 | * #include "mbed.h" |
mjr | 52:63f0a9b45f0c | 77 | * #include "USBKeyboard.h" |
mjr | 52:63f0a9b45f0c | 78 | * |
mjr | 52:63f0a9b45f0c | 79 | * USBKeyboard key; |
mjr | 52:63f0a9b45f0c | 80 | * |
mjr | 52:63f0a9b45f0c | 81 | * int main(void) |
mjr | 52:63f0a9b45f0c | 82 | * { |
mjr | 52:63f0a9b45f0c | 83 | * while (1) |
mjr | 52:63f0a9b45f0c | 84 | * { |
mjr | 52:63f0a9b45f0c | 85 | * key.printf("Hello World\r\n"); |
mjr | 52:63f0a9b45f0c | 86 | * wait(1); |
mjr | 52:63f0a9b45f0c | 87 | * } |
mjr | 52:63f0a9b45f0c | 88 | * } |
mjr | 52:63f0a9b45f0c | 89 | * |
mjr | 52:63f0a9b45f0c | 90 | * @endcode |
mjr | 52:63f0a9b45f0c | 91 | */ |
mjr | 52:63f0a9b45f0c | 92 | class USBKeyboard: public USBHID, public Stream { |
mjr | 52:63f0a9b45f0c | 93 | public: |
mjr | 52:63f0a9b45f0c | 94 | |
mjr | 52:63f0a9b45f0c | 95 | /** |
mjr | 52:63f0a9b45f0c | 96 | * Constructor |
mjr | 52:63f0a9b45f0c | 97 | * |
mjr | 52:63f0a9b45f0c | 98 | * |
mjr | 52:63f0a9b45f0c | 99 | * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK |
mjr | 52:63f0a9b45f0c | 100 | * @param vendor_id Your vendor_id (default: 0x1235) |
mjr | 52:63f0a9b45f0c | 101 | * @param product_id Your product_id (default: 0x0050) |
mjr | 52:63f0a9b45f0c | 102 | * @param product_release Your preoduct_release (default: 0x0001) |
mjr | 52:63f0a9b45f0c | 103 | * |
mjr | 52:63f0a9b45f0c | 104 | */ |
mjr | 52:63f0a9b45f0c | 105 | USBKeyboard(uint16_t vendor_id = 0x1235, uint16_t product_id = 0x0050, uint16_t product_release = 0x0001): |
mjr | 52:63f0a9b45f0c | 106 | USBHID(0, 0, vendor_id, product_id, product_release, false) { |
mjr | 52:63f0a9b45f0c | 107 | lock_status = 0; |
mjr | 52:63f0a9b45f0c | 108 | connect(); |
mjr | 52:63f0a9b45f0c | 109 | }; |
mjr | 52:63f0a9b45f0c | 110 | |
mjr | 52:63f0a9b45f0c | 111 | /** |
mjr | 52:63f0a9b45f0c | 112 | * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key |
mjr | 52:63f0a9b45f0c | 113 | * |
mjr | 52:63f0a9b45f0c | 114 | * @code |
mjr | 52:63f0a9b45f0c | 115 | * //To send CTRL + s (save) |
mjr | 52:63f0a9b45f0c | 116 | * keyboard.keyCode('s', KEY_CTRL); |
mjr | 52:63f0a9b45f0c | 117 | * @endcode |
mjr | 52:63f0a9b45f0c | 118 | * |
mjr | 52:63f0a9b45f0c | 119 | * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0) |
mjr | 52:63f0a9b45f0c | 120 | * @param key character to send |
mjr | 52:63f0a9b45f0c | 121 | * @returns true if there is no error, false otherwise |
mjr | 52:63f0a9b45f0c | 122 | */ |
mjr | 52:63f0a9b45f0c | 123 | bool keyCode(uint8_t key, uint8_t modifier = 0); |
mjr | 52:63f0a9b45f0c | 124 | |
mjr | 52:63f0a9b45f0c | 125 | /** |
mjr | 52:63f0a9b45f0c | 126 | * Send a character |
mjr | 52:63f0a9b45f0c | 127 | * |
mjr | 52:63f0a9b45f0c | 128 | * @param c character to be sent |
mjr | 52:63f0a9b45f0c | 129 | * @returns true if there is no error, false otherwise |
mjr | 52:63f0a9b45f0c | 130 | */ |
mjr | 52:63f0a9b45f0c | 131 | virtual int _putc(int c); |
mjr | 52:63f0a9b45f0c | 132 | |
mjr | 52:63f0a9b45f0c | 133 | /** |
mjr | 52:63f0a9b45f0c | 134 | * Control media keys |
mjr | 52:63f0a9b45f0c | 135 | * |
mjr | 52:63f0a9b45f0c | 136 | * @param key media key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN) |
mjr | 52:63f0a9b45f0c | 137 | * @returns true if there is no error, false otherwise |
mjr | 52:63f0a9b45f0c | 138 | */ |
mjr | 52:63f0a9b45f0c | 139 | bool mediaControl(MEDIA_KEY key); |
mjr | 52:63f0a9b45f0c | 140 | |
mjr | 52:63f0a9b45f0c | 141 | /* |
mjr | 52:63f0a9b45f0c | 142 | * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength. |
mjr | 52:63f0a9b45f0c | 143 | * |
mjr | 52:63f0a9b45f0c | 144 | * @returns pointer to the report descriptor |
mjr | 52:63f0a9b45f0c | 145 | */ |
mjr | 52:63f0a9b45f0c | 146 | virtual uint8_t * reportDesc(); |
mjr | 52:63f0a9b45f0c | 147 | |
mjr | 52:63f0a9b45f0c | 148 | /* |
mjr | 52:63f0a9b45f0c | 149 | * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys |
mjr | 52:63f0a9b45f0c | 150 | * |
mjr | 52:63f0a9b45f0c | 151 | * @returns if handle by subclass, return true |
mjr | 52:63f0a9b45f0c | 152 | */ |
mjr | 52:63f0a9b45f0c | 153 | virtual bool EP1_OUT_callback(); |
mjr | 52:63f0a9b45f0c | 154 | |
mjr | 52:63f0a9b45f0c | 155 | /** |
mjr | 52:63f0a9b45f0c | 156 | * Read status of lock keys. Useful to switch-on/off leds according to key pressed. Only the first three bits of the result is important: |
mjr | 52:63f0a9b45f0c | 157 | * - First bit: NUM_LOCK |
mjr | 52:63f0a9b45f0c | 158 | * - Second bit: CAPS_LOCK |
mjr | 52:63f0a9b45f0c | 159 | * - Third bit: SCROLL_LOCK |
mjr | 52:63f0a9b45f0c | 160 | * |
mjr | 52:63f0a9b45f0c | 161 | * @returns status of lock keys |
mjr | 52:63f0a9b45f0c | 162 | */ |
mjr | 52:63f0a9b45f0c | 163 | uint8_t lockStatus(); |
mjr | 52:63f0a9b45f0c | 164 | |
mjr | 52:63f0a9b45f0c | 165 | protected: |
mjr | 52:63f0a9b45f0c | 166 | /* |
mjr | 52:63f0a9b45f0c | 167 | * Get configuration descriptor |
mjr | 52:63f0a9b45f0c | 168 | * |
mjr | 52:63f0a9b45f0c | 169 | * @returns pointer to the configuration descriptor |
mjr | 52:63f0a9b45f0c | 170 | */ |
mjr | 52:63f0a9b45f0c | 171 | virtual uint8_t * configurationDesc(); |
mjr | 52:63f0a9b45f0c | 172 | |
mjr | 52:63f0a9b45f0c | 173 | private: |
mjr | 52:63f0a9b45f0c | 174 | //dummy otherwise it doesn,t compile (we must define all methods of an abstract class) |
mjr | 52:63f0a9b45f0c | 175 | virtual int _getc() { |
mjr | 52:63f0a9b45f0c | 176 | return -1; |
mjr | 52:63f0a9b45f0c | 177 | }; |
mjr | 52:63f0a9b45f0c | 178 | |
mjr | 52:63f0a9b45f0c | 179 | uint8_t lock_status; |
mjr | 52:63f0a9b45f0c | 180 | |
mjr | 52:63f0a9b45f0c | 181 | }; |
mjr | 52:63f0a9b45f0c | 182 | |
mjr | 52:63f0a9b45f0c | 183 | #endif |