USBMSD SD card Hello World for Mbed platforms
Dependencies: mbed USBMSD_SD USBDevice
USBDevice/USBHID/USBMouseKeyboard.h@2:27a7e7f8d399, 2011-11-11 (annotated)
- Committer:
- samux
- Date:
- Fri Nov 11 15:22:53 2011 +0000
- Revision:
- 2:27a7e7f8d399
we have 2MB with the sdcard!!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux |
2:27a7e7f8d399 | 1 | /* USBMouseKeyboard.h */ |
samux |
2:27a7e7f8d399 | 2 | /* USB device example: Keyboard with a relative mouse */ |
samux |
2:27a7e7f8d399 | 3 | /* Copyright (c) 2011 ARM Limited. All rights reserved. */ |
samux |
2:27a7e7f8d399 | 4 | |
samux |
2:27a7e7f8d399 | 5 | #ifndef USBMOUSEKEYBOARD_H |
samux |
2:27a7e7f8d399 | 6 | #define USBMOUSEKEYBOARD_H |
samux |
2:27a7e7f8d399 | 7 | |
samux |
2:27a7e7f8d399 | 8 | #define REPORT_ID_KEYBOARD 1 |
samux |
2:27a7e7f8d399 | 9 | #define REPORT_ID_MOUSE 2 |
samux |
2:27a7e7f8d399 | 10 | #define REPORT_ID_VOLUME 3 |
samux |
2:27a7e7f8d399 | 11 | |
samux |
2:27a7e7f8d399 | 12 | #include "USBMouse.h" |
samux |
2:27a7e7f8d399 | 13 | #include "USBKeyboard.h" |
samux |
2:27a7e7f8d399 | 14 | #include "Stream.h" |
samux |
2:27a7e7f8d399 | 15 | #include "USBHID.h" |
samux |
2:27a7e7f8d399 | 16 | |
samux |
2:27a7e7f8d399 | 17 | /** |
samux |
2:27a7e7f8d399 | 18 | * USBMouseKeyboard example |
samux |
2:27a7e7f8d399 | 19 | * @code |
samux |
2:27a7e7f8d399 | 20 | * |
samux |
2:27a7e7f8d399 | 21 | * #include "mbed.h" |
samux |
2:27a7e7f8d399 | 22 | * #include "USBMouseKeyboard.h" |
samux |
2:27a7e7f8d399 | 23 | * |
samux |
2:27a7e7f8d399 | 24 | * USBMouseKeyboard key_mouse; |
samux |
2:27a7e7f8d399 | 25 | * |
samux |
2:27a7e7f8d399 | 26 | * int main(void) |
samux |
2:27a7e7f8d399 | 27 | * { |
samux |
2:27a7e7f8d399 | 28 | * while(1) |
samux |
2:27a7e7f8d399 | 29 | * { |
samux |
2:27a7e7f8d399 | 30 | * key_mouse.move(20, 0); |
samux |
2:27a7e7f8d399 | 31 | * key_mouse.printf("Hello From MBED\r\n"); |
samux |
2:27a7e7f8d399 | 32 | * wait(1); |
samux |
2:27a7e7f8d399 | 33 | * } |
samux |
2:27a7e7f8d399 | 34 | * } |
samux |
2:27a7e7f8d399 | 35 | * @endcode |
samux |
2:27a7e7f8d399 | 36 | * |
samux |
2:27a7e7f8d399 | 37 | * |
samux |
2:27a7e7f8d399 | 38 | * @code |
samux |
2:27a7e7f8d399 | 39 | * |
samux |
2:27a7e7f8d399 | 40 | * #include "mbed.h" |
samux |
2:27a7e7f8d399 | 41 | * #include "USBMouseKeyboard.h" |
samux |
2:27a7e7f8d399 | 42 | * |
samux |
2:27a7e7f8d399 | 43 | * USBMouseKeyboard key_mouse(ABS_MOUSE); |
samux |
2:27a7e7f8d399 | 44 | * |
samux |
2:27a7e7f8d399 | 45 | * int main(void) |
samux |
2:27a7e7f8d399 | 46 | * { |
samux |
2:27a7e7f8d399 | 47 | * while(1) |
samux |
2:27a7e7f8d399 | 48 | * { |
samux |
2:27a7e7f8d399 | 49 | * key_mouse.move(X_MAX_ABS/2, Y_MAX_ABS/2); |
samux |
2:27a7e7f8d399 | 50 | * key_mouse.printf("Hello from MBED\r\n"); |
samux |
2:27a7e7f8d399 | 51 | * wait(1); |
samux |
2:27a7e7f8d399 | 52 | * } |
samux |
2:27a7e7f8d399 | 53 | * } |
samux |
2:27a7e7f8d399 | 54 | * @endcode |
samux |
2:27a7e7f8d399 | 55 | */ |
samux |
2:27a7e7f8d399 | 56 | class USBMouseKeyboard: public USBHID, public Stream |
samux |
2:27a7e7f8d399 | 57 | { |
samux |
2:27a7e7f8d399 | 58 | public: |
samux |
2:27a7e7f8d399 | 59 | |
samux |
2:27a7e7f8d399 | 60 | /** |
samux |
2:27a7e7f8d399 | 61 | * Constructor |
samux |
2:27a7e7f8d399 | 62 | * |
samux |
2:27a7e7f8d399 | 63 | * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE) |
samux |
2:27a7e7f8d399 | 64 | * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK |
samux |
2:27a7e7f8d399 | 65 | * @param vendor_id Your vendor_id (default: 0x1234) |
samux |
2:27a7e7f8d399 | 66 | * @param product_id Your product_id (default: 0x0001) |
samux |
2:27a7e7f8d399 | 67 | * @param product_release Your preoduct_release (default: 0x0001) |
samux |
2:27a7e7f8d399 | 68 | * |
samux |
2:27a7e7f8d399 | 69 | */ |
samux |
2:27a7e7f8d399 | 70 | USBMouseKeyboard(MOUSE_TYPE mouse_type = REL_MOUSE, BusOut * leds = NULL, uint16_t vendor_id = 0x0021, uint16_t product_id = 0x0011, uint16_t product_release = 0x0001): |
samux |
2:27a7e7f8d399 | 71 | USBHID(0, 0, vendor_id, product_id, product_release) |
samux |
2:27a7e7f8d399 | 72 | { |
samux |
2:27a7e7f8d399 | 73 | this->leds = leds; |
samux |
2:27a7e7f8d399 | 74 | button = 0; |
samux |
2:27a7e7f8d399 | 75 | this->mouse_type = mouse_type; |
samux |
2:27a7e7f8d399 | 76 | }; |
samux |
2:27a7e7f8d399 | 77 | |
samux |
2:27a7e7f8d399 | 78 | /** |
samux |
2:27a7e7f8d399 | 79 | * Write a state of the mouse |
samux |
2:27a7e7f8d399 | 80 | * |
samux |
2:27a7e7f8d399 | 81 | * @param x x-axis position |
samux |
2:27a7e7f8d399 | 82 | * @param y y-axis position |
samux |
2:27a7e7f8d399 | 83 | * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE) |
samux |
2:27a7e7f8d399 | 84 | * @param z wheel state (>0 to scroll down, <0 to scroll up) |
samux |
2:27a7e7f8d399 | 85 | * @returns true if there is no error, false otherwise |
samux |
2:27a7e7f8d399 | 86 | */ |
samux |
2:27a7e7f8d399 | 87 | bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z); |
samux |
2:27a7e7f8d399 | 88 | |
samux |
2:27a7e7f8d399 | 89 | |
samux |
2:27a7e7f8d399 | 90 | /** |
samux |
2:27a7e7f8d399 | 91 | * Move the cursor to (x, y) |
samux |
2:27a7e7f8d399 | 92 | * |
samux |
2:27a7e7f8d399 | 93 | * @param x x-axis position |
samux |
2:27a7e7f8d399 | 94 | * @param y y-axis position |
samux |
2:27a7e7f8d399 | 95 | * @returns true if there is no error, false otherwise |
samux |
2:27a7e7f8d399 | 96 | */ |
samux |
2:27a7e7f8d399 | 97 | bool move(int16_t x, int16_t y); |
samux |
2:27a7e7f8d399 | 98 | |
samux |
2:27a7e7f8d399 | 99 | /** |
samux |
2:27a7e7f8d399 | 100 | * Press one or several buttons |
samux |
2:27a7e7f8d399 | 101 | * |
samux |
2:27a7e7f8d399 | 102 | * @param button button state (ex: press(MOUSE_LEFT)) |
samux |
2:27a7e7f8d399 | 103 | * @returns true if there is no error, false otherwise |
samux |
2:27a7e7f8d399 | 104 | */ |
samux |
2:27a7e7f8d399 | 105 | bool press(uint8_t button); |
samux |
2:27a7e7f8d399 | 106 | |
samux |
2:27a7e7f8d399 | 107 | /** |
samux |
2:27a7e7f8d399 | 108 | * Release one or several buttons |
samux |
2:27a7e7f8d399 | 109 | * |
samux |
2:27a7e7f8d399 | 110 | * @param button button state (ex: release(MOUSE_LEFT)) |
samux |
2:27a7e7f8d399 | 111 | * @returns true if there is no error, false otherwise |
samux |
2:27a7e7f8d399 | 112 | */ |
samux |
2:27a7e7f8d399 | 113 | bool release(uint8_t button); |
samux |
2:27a7e7f8d399 | 114 | |
samux |
2:27a7e7f8d399 | 115 | /** |
samux |
2:27a7e7f8d399 | 116 | * Double click (MOUSE_LEFT) |
samux |
2:27a7e7f8d399 | 117 | * |
samux |
2:27a7e7f8d399 | 118 | * @returns true if there is no error, false otherwise |
samux |
2:27a7e7f8d399 | 119 | */ |
samux |
2:27a7e7f8d399 | 120 | bool doubleClick(); |
samux |
2:27a7e7f8d399 | 121 | |
samux |
2:27a7e7f8d399 | 122 | /** |
samux |
2:27a7e7f8d399 | 123 | * Click |
samux |
2:27a7e7f8d399 | 124 | * |
samux |
2:27a7e7f8d399 | 125 | * @param button state of the buttons ( ex: clic(MOUSE_LEFT)) |
samux |
2:27a7e7f8d399 | 126 | * @returns true if there is no error, false otherwise |
samux |
2:27a7e7f8d399 | 127 | */ |
samux |
2:27a7e7f8d399 | 128 | bool click(uint8_t button); |
samux |
2:27a7e7f8d399 | 129 | |
samux |
2:27a7e7f8d399 | 130 | /** |
samux |
2:27a7e7f8d399 | 131 | * Scrolling |
samux |
2:27a7e7f8d399 | 132 | * |
samux |
2:27a7e7f8d399 | 133 | * @param z value of the wheel (>0 to go down, <0 to go up) |
samux |
2:27a7e7f8d399 | 134 | * @returns true if there is no error, false otherwise |
samux |
2:27a7e7f8d399 | 135 | */ |
samux |
2:27a7e7f8d399 | 136 | bool scroll(int8_t z); |
samux |
2:27a7e7f8d399 | 137 | |
samux |
2:27a7e7f8d399 | 138 | /** |
samux |
2:27a7e7f8d399 | 139 | * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key |
samux |
2:27a7e7f8d399 | 140 | * |
samux |
2:27a7e7f8d399 | 141 | * @code |
samux |
2:27a7e7f8d399 | 142 | * //To send CTRL + s (save) |
samux |
2:27a7e7f8d399 | 143 | * keyboard.keyCode('s', KEY_CTRL); |
samux |
2:27a7e7f8d399 | 144 | * @endcode |
samux |
2:27a7e7f8d399 | 145 | * |
samux |
2:27a7e7f8d399 | 146 | * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0) |
samux |
2:27a7e7f8d399 | 147 | * @param key character to send |
samux |
2:27a7e7f8d399 | 148 | * @returns true if there is no error, false otherwise |
samux |
2:27a7e7f8d399 | 149 | */ |
samux |
2:27a7e7f8d399 | 150 | bool keyCode(uint8_t key, uint8_t modifier = 0); |
samux |
2:27a7e7f8d399 | 151 | |
samux |
2:27a7e7f8d399 | 152 | /** |
samux |
2:27a7e7f8d399 | 153 | * Send a character |
samux |
2:27a7e7f8d399 | 154 | * |
samux |
2:27a7e7f8d399 | 155 | * @param c character to be sent |
samux |
2:27a7e7f8d399 | 156 | * @returns true if there is no error, false otherwise |
samux |
2:27a7e7f8d399 | 157 | */ |
samux |
2:27a7e7f8d399 | 158 | virtual int _putc(int c); |
samux |
2:27a7e7f8d399 | 159 | |
samux |
2:27a7e7f8d399 | 160 | /** |
samux |
2:27a7e7f8d399 | 161 | * Control media keys |
samux |
2:27a7e7f8d399 | 162 | * |
samux |
2:27a7e7f8d399 | 163 | * @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 |
2:27a7e7f8d399 | 164 | * @returns true if there is no error, false otherwise |
samux |
2:27a7e7f8d399 | 165 | */ |
samux |
2:27a7e7f8d399 | 166 | bool mediaControl(MEDIA_KEY key); |
samux |
2:27a7e7f8d399 | 167 | |
samux |
2:27a7e7f8d399 | 168 | /* |
samux |
2:27a7e7f8d399 | 169 | * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength. |
samux |
2:27a7e7f8d399 | 170 | * |
samux |
2:27a7e7f8d399 | 171 | * @returns pointer to the report descriptor |
samux |
2:27a7e7f8d399 | 172 | */ |
samux |
2:27a7e7f8d399 | 173 | virtual uint8_t * reportDesc(); |
samux |
2:27a7e7f8d399 | 174 | |
samux |
2:27a7e7f8d399 | 175 | /* |
samux |
2:27a7e7f8d399 | 176 | * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys |
samux |
2:27a7e7f8d399 | 177 | * |
samux |
2:27a7e7f8d399 | 178 | * @returns if handle by subclass, return true |
samux |
2:27a7e7f8d399 | 179 | */ |
samux |
2:27a7e7f8d399 | 180 | virtual bool EP1_OUT_callback(); |
samux |
2:27a7e7f8d399 | 181 | |
samux |
2:27a7e7f8d399 | 182 | |
samux |
2:27a7e7f8d399 | 183 | private: |
samux |
2:27a7e7f8d399 | 184 | bool mouseWrite(int8_t x, int8_t y, uint8_t buttons, int8_t z); |
samux |
2:27a7e7f8d399 | 185 | MOUSE_TYPE mouse_type; |
samux |
2:27a7e7f8d399 | 186 | uint8_t button; |
samux |
2:27a7e7f8d399 | 187 | bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z); |
samux |
2:27a7e7f8d399 | 188 | |
samux |
2:27a7e7f8d399 | 189 | // Switch on leds (CAPS LOCK,...) |
samux |
2:27a7e7f8d399 | 190 | BusOut * leds; |
samux |
2:27a7e7f8d399 | 191 | |
samux |
2:27a7e7f8d399 | 192 | //dummy otherwise it doesn,t compile (we must define all methods of an abstract class) |
samux |
2:27a7e7f8d399 | 193 | virtual int _getc() { return -1;} |
samux |
2:27a7e7f8d399 | 194 | }; |
samux |
2:27a7e7f8d399 | 195 | |
samux |
2:27a7e7f8d399 | 196 | #endif |