USBMSD test for GR-PEACH

Dependencies:   USBDevice USBMSD_SD mbed

Fork of USBMSD_SD_HelloWorld_Mbed by Samuel Mokrani

Committer:
samux
Date:
Wed Nov 16 17:17:42 2011 +0000
Revision:
11:a26e7b7a1221
GOOD COMMIT: msd and hid work even on MAC...

Who changed what in which revision?

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