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