USBMSD SD card Hello World for Mbed platforms

Dependencies:   mbed USBMSD_SD USBDevice

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?

UserRevisionLine numberNew 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 USBMOUSEKEYBOARD_H
samux 14:757226626acb 20 #define USBMOUSEKEYBOARD_H
samux 14:757226626acb 21
samux 14:757226626acb 22 #define REPORT_ID_KEYBOARD 1
samux 14:757226626acb 23 #define REPORT_ID_MOUSE 2
samux 14:757226626acb 24 #define REPORT_ID_VOLUME 3
samux 14:757226626acb 25
samux 14:757226626acb 26 #include "USBMouse.h"
samux 14:757226626acb 27 #include "USBKeyboard.h"
samux 14:757226626acb 28 #include "Stream.h"
samux 14:757226626acb 29 #include "USBHID.h"
samux 14:757226626acb 30
samux 14:757226626acb 31 /**
samux 14:757226626acb 32 * USBMouseKeyboard example
samux 14:757226626acb 33 * @code
samux 14:757226626acb 34 *
samux 14:757226626acb 35 * #include "mbed.h"
samux 14:757226626acb 36 * #include "USBMouseKeyboard.h"
samux 14:757226626acb 37 *
samux 14:757226626acb 38 * USBMouseKeyboard key_mouse;
samux 14:757226626acb 39 *
samux 14:757226626acb 40 * int main(void)
samux 14:757226626acb 41 * {
samux 14:757226626acb 42 * while(1)
samux 14:757226626acb 43 * {
samux 14:757226626acb 44 * key_mouse.move(20, 0);
samux 14:757226626acb 45 * key_mouse.printf("Hello From MBED\r\n");
samux 14:757226626acb 46 * wait(1);
samux 14:757226626acb 47 * }
samux 14:757226626acb 48 * }
samux 14:757226626acb 49 * @endcode
samux 14:757226626acb 50 *
samux 14:757226626acb 51 *
samux 14:757226626acb 52 * @code
samux 14:757226626acb 53 *
samux 14:757226626acb 54 * #include "mbed.h"
samux 14:757226626acb 55 * #include "USBMouseKeyboard.h"
samux 14:757226626acb 56 *
samux 14:757226626acb 57 * USBMouseKeyboard key_mouse(ABS_MOUSE);
samux 14:757226626acb 58 *
samux 14:757226626acb 59 * int main(void)
samux 14:757226626acb 60 * {
samux 14:757226626acb 61 * while(1)
samux 14:757226626acb 62 * {
samux 14:757226626acb 63 * key_mouse.move(X_MAX_ABS/2, Y_MAX_ABS/2);
samux 14:757226626acb 64 * key_mouse.printf("Hello from MBED\r\n");
samux 14:757226626acb 65 * wait(1);
samux 14:757226626acb 66 * }
samux 14:757226626acb 67 * }
samux 14:757226626acb 68 * @endcode
samux 14:757226626acb 69 */
samux 14:757226626acb 70 class USBMouseKeyboard: public USBHID, public Stream
samux 14:757226626acb 71 {
samux 14:757226626acb 72 public:
samux 14:757226626acb 73
samux 14:757226626acb 74 /**
samux 14:757226626acb 75 * Constructor
samux 14:757226626acb 76 *
samux 14:757226626acb 77 * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE)
samux 14:757226626acb 78 * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK
samux 14:757226626acb 79 * @param vendor_id Your vendor_id (default: 0x1234)
samux 14:757226626acb 80 * @param product_id Your product_id (default: 0x0001)
samux 14:757226626acb 81 * @param product_release Your preoduct_release (default: 0x0001)
samux 14:757226626acb 82 *
samux 14:757226626acb 83 */
samux 14:757226626acb 84 USBMouseKeyboard(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x0021, uint16_t product_id = 0x0011, uint16_t product_release = 0x0001):
samux 14:757226626acb 85 USBHID(0, 0, vendor_id, product_id, product_release, false)
samux 14:757226626acb 86 {
samux 14:757226626acb 87 lock_status = 0;
samux 14:757226626acb 88 button = 0;
samux 14:757226626acb 89 this->mouse_type = mouse_type;
samux 14:757226626acb 90 connect();
samux 14:757226626acb 91 };
samux 14:757226626acb 92
samux 14:757226626acb 93 /**
samux 14:757226626acb 94 * Write a state of the mouse
samux 14:757226626acb 95 *
samux 14:757226626acb 96 * @param x x-axis position
samux 14:757226626acb 97 * @param y y-axis position
samux 14:757226626acb 98 * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE)
samux 14:757226626acb 99 * @param z wheel state (>0 to scroll down, <0 to scroll up)
samux 14:757226626acb 100 * @returns true if there is no error, false otherwise
samux 14:757226626acb 101 */
samux 14:757226626acb 102 bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z);
samux 14:757226626acb 103
samux 14:757226626acb 104
samux 14:757226626acb 105 /**
samux 14:757226626acb 106 * Move the cursor to (x, y)
samux 14:757226626acb 107 *
samux 14:757226626acb 108 * @param x x-axis position
samux 14:757226626acb 109 * @param y y-axis position
samux 14:757226626acb 110 * @returns true if there is no error, false otherwise
samux 14:757226626acb 111 */
samux 14:757226626acb 112 bool move(int16_t x, int16_t y);
samux 14:757226626acb 113
samux 14:757226626acb 114 /**
samux 14:757226626acb 115 * Press one or several buttons
samux 14:757226626acb 116 *
samux 14:757226626acb 117 * @param button button state (ex: press(MOUSE_LEFT))
samux 14:757226626acb 118 * @returns true if there is no error, false otherwise
samux 14:757226626acb 119 */
samux 14:757226626acb 120 bool press(uint8_t button);
samux 14:757226626acb 121
samux 14:757226626acb 122 /**
samux 14:757226626acb 123 * Release one or several buttons
samux 14:757226626acb 124 *
samux 14:757226626acb 125 * @param button button state (ex: release(MOUSE_LEFT))
samux 14:757226626acb 126 * @returns true if there is no error, false otherwise
samux 14:757226626acb 127 */
samux 14:757226626acb 128 bool release(uint8_t button);
samux 14:757226626acb 129
samux 14:757226626acb 130 /**
samux 14:757226626acb 131 * Double click (MOUSE_LEFT)
samux 14:757226626acb 132 *
samux 14:757226626acb 133 * @returns true if there is no error, false otherwise
samux 14:757226626acb 134 */
samux 14:757226626acb 135 bool doubleClick();
samux 14:757226626acb 136
samux 14:757226626acb 137 /**
samux 14:757226626acb 138 * Click
samux 14:757226626acb 139 *
samux 14:757226626acb 140 * @param button state of the buttons ( ex: clic(MOUSE_LEFT))
samux 14:757226626acb 141 * @returns true if there is no error, false otherwise
samux 14:757226626acb 142 */
samux 14:757226626acb 143 bool click(uint8_t button);
samux 14:757226626acb 144
samux 14:757226626acb 145 /**
samux 14:757226626acb 146 * Scrolling
samux 14:757226626acb 147 *
samux 14:757226626acb 148 * @param z value of the wheel (>0 to go down, <0 to go up)
samux 14:757226626acb 149 * @returns true if there is no error, false otherwise
samux 14:757226626acb 150 */
samux 14:757226626acb 151 bool scroll(int8_t z);
samux 14:757226626acb 152
samux 14:757226626acb 153 /**
samux 14:757226626acb 154 * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key
samux 14:757226626acb 155 *
samux 14:757226626acb 156 * @code
samux 14:757226626acb 157 * //To send CTRL + s (save)
samux 14:757226626acb 158 * keyboard.keyCode('s', KEY_CTRL);
samux 14:757226626acb 159 * @endcode
samux 14:757226626acb 160 *
samux 14:757226626acb 161 * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0)
samux 14:757226626acb 162 * @param key character to send
samux 14:757226626acb 163 * @returns true if there is no error, false otherwise
samux 14:757226626acb 164 */
samux 14:757226626acb 165 bool keyCode(uint8_t key, uint8_t modifier = 0);
samux 14:757226626acb 166
samux 14:757226626acb 167 /**
samux 14:757226626acb 168 * Send a character
samux 14:757226626acb 169 *
samux 14:757226626acb 170 * @param c character to be sent
samux 14:757226626acb 171 * @returns true if there is no error, false otherwise
samux 14:757226626acb 172 */
samux 14:757226626acb 173 virtual int _putc(int c);
samux 14:757226626acb 174
samux 14:757226626acb 175 /**
samux 14:757226626acb 176 * Control media keys
samux 14:757226626acb 177 *
samux 14:757226626acb 178 * @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 179 * @returns true if there is no error, false otherwise
samux 14:757226626acb 180 */
samux 14:757226626acb 181 bool mediaControl(MEDIA_KEY key);
samux 14:757226626acb 182
samux 14:757226626acb 183 /**
samux 14:757226626acb 184 * 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 185 * - First bit: NUM_LOCK
samux 14:757226626acb 186 * - Second bit: CAPS_LOCK
samux 14:757226626acb 187 * - Third bit: SCROLL_LOCK
samux 14:757226626acb 188 *
samux 14:757226626acb 189 * @returns status of lock keys
samux 14:757226626acb 190 */
samux 14:757226626acb 191 uint8_t lockStatus();
samux 14:757226626acb 192
samux 14:757226626acb 193 /*
samux 14:757226626acb 194 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
samux 14:757226626acb 195 *
samux 14:757226626acb 196 * @returns pointer to the report descriptor
samux 14:757226626acb 197 */
samux 14:757226626acb 198 virtual uint8_t * reportDesc();
samux 14:757226626acb 199
samux 14:757226626acb 200 /*
samux 14:757226626acb 201 * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys
samux 14:757226626acb 202 *
samux 14:757226626acb 203 * @returns if handle by subclass, return true
samux 14:757226626acb 204 */
samux 14:757226626acb 205 virtual bool EP1_OUT_callback();
samux 14:757226626acb 206
samux 14:757226626acb 207
samux 14:757226626acb 208 private:
samux 14:757226626acb 209 bool mouseWrite(int8_t x, int8_t y, uint8_t buttons, int8_t z);
samux 14:757226626acb 210 MOUSE_TYPE mouse_type;
samux 14:757226626acb 211 uint8_t button;
samux 14:757226626acb 212 bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z);
samux 14:757226626acb 213
samux 14:757226626acb 214 uint8_t lock_status;
samux 14:757226626acb 215
samux 14:757226626acb 216 //dummy otherwise it doesn't compile (we must define all methods of an abstract class)
samux 14:757226626acb 217 virtual int _getc() { return -1;}
samux 14:757226626acb 218 };
samux 14:757226626acb 219
samux 14:757226626acb 220 #endif