SD card interface

Committer:
lharoon
Date:
Mon Oct 08 11:14:07 2012 +0000
Revision:
0:22612ae617a0
1st edition

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lharoon 0:22612ae617a0 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
lharoon 0:22612ae617a0 2 *
lharoon 0:22612ae617a0 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
lharoon 0:22612ae617a0 4 * and associated documentation files (the "Software"), to deal in the Software without
lharoon 0:22612ae617a0 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
lharoon 0:22612ae617a0 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
lharoon 0:22612ae617a0 7 * Software is furnished to do so, subject to the following conditions:
lharoon 0:22612ae617a0 8 *
lharoon 0:22612ae617a0 9 * The above copyright notice and this permission notice shall be included in all copies or
lharoon 0:22612ae617a0 10 * substantial portions of the Software.
lharoon 0:22612ae617a0 11 *
lharoon 0:22612ae617a0 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
lharoon 0:22612ae617a0 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
lharoon 0:22612ae617a0 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
lharoon 0:22612ae617a0 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
lharoon 0:22612ae617a0 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
lharoon 0:22612ae617a0 17 */
lharoon 0:22612ae617a0 18
lharoon 0:22612ae617a0 19 #ifndef USBMOUSEKEYBOARD_H
lharoon 0:22612ae617a0 20 #define USBMOUSEKEYBOARD_H
lharoon 0:22612ae617a0 21
lharoon 0:22612ae617a0 22 #define REPORT_ID_KEYBOARD 1
lharoon 0:22612ae617a0 23 #define REPORT_ID_MOUSE 2
lharoon 0:22612ae617a0 24 #define REPORT_ID_VOLUME 3
lharoon 0:22612ae617a0 25
lharoon 0:22612ae617a0 26 #include "USBMouse.h"
lharoon 0:22612ae617a0 27 #include "USBKeyboard.h"
lharoon 0:22612ae617a0 28 #include "Stream.h"
lharoon 0:22612ae617a0 29 #include "USBHID.h"
lharoon 0:22612ae617a0 30
lharoon 0:22612ae617a0 31 /**
lharoon 0:22612ae617a0 32 * USBMouseKeyboard example
lharoon 0:22612ae617a0 33 * @code
lharoon 0:22612ae617a0 34 *
lharoon 0:22612ae617a0 35 * #include "mbed.h"
lharoon 0:22612ae617a0 36 * #include "USBMouseKeyboard.h"
lharoon 0:22612ae617a0 37 *
lharoon 0:22612ae617a0 38 * USBMouseKeyboard key_mouse;
lharoon 0:22612ae617a0 39 *
lharoon 0:22612ae617a0 40 * int main(void)
lharoon 0:22612ae617a0 41 * {
lharoon 0:22612ae617a0 42 * while(1)
lharoon 0:22612ae617a0 43 * {
lharoon 0:22612ae617a0 44 * key_mouse.move(20, 0);
lharoon 0:22612ae617a0 45 * key_mouse.printf("Hello From MBED\r\n");
lharoon 0:22612ae617a0 46 * wait(1);
lharoon 0:22612ae617a0 47 * }
lharoon 0:22612ae617a0 48 * }
lharoon 0:22612ae617a0 49 * @endcode
lharoon 0:22612ae617a0 50 *
lharoon 0:22612ae617a0 51 *
lharoon 0:22612ae617a0 52 * @code
lharoon 0:22612ae617a0 53 *
lharoon 0:22612ae617a0 54 * #include "mbed.h"
lharoon 0:22612ae617a0 55 * #include "USBMouseKeyboard.h"
lharoon 0:22612ae617a0 56 *
lharoon 0:22612ae617a0 57 * USBMouseKeyboard key_mouse(ABS_MOUSE);
lharoon 0:22612ae617a0 58 *
lharoon 0:22612ae617a0 59 * int main(void)
lharoon 0:22612ae617a0 60 * {
lharoon 0:22612ae617a0 61 * while(1)
lharoon 0:22612ae617a0 62 * {
lharoon 0:22612ae617a0 63 * key_mouse.move(X_MAX_ABS/2, Y_MAX_ABS/2);
lharoon 0:22612ae617a0 64 * key_mouse.printf("Hello from MBED\r\n");
lharoon 0:22612ae617a0 65 * wait(1);
lharoon 0:22612ae617a0 66 * }
lharoon 0:22612ae617a0 67 * }
lharoon 0:22612ae617a0 68 * @endcode
lharoon 0:22612ae617a0 69 */
lharoon 0:22612ae617a0 70 class USBMouseKeyboard: public USBHID, public Stream
lharoon 0:22612ae617a0 71 {
lharoon 0:22612ae617a0 72 public:
lharoon 0:22612ae617a0 73
lharoon 0:22612ae617a0 74 /**
lharoon 0:22612ae617a0 75 * Constructor
lharoon 0:22612ae617a0 76 *
lharoon 0:22612ae617a0 77 * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE)
lharoon 0:22612ae617a0 78 * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK
lharoon 0:22612ae617a0 79 * @param vendor_id Your vendor_id (default: 0x1234)
lharoon 0:22612ae617a0 80 * @param product_id Your product_id (default: 0x0001)
lharoon 0:22612ae617a0 81 * @param product_release Your preoduct_release (default: 0x0001)
lharoon 0:22612ae617a0 82 *
lharoon 0:22612ae617a0 83 */
lharoon 0:22612ae617a0 84 USBMouseKeyboard(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x0021, uint16_t product_id = 0x0011, uint16_t product_release = 0x0001):
lharoon 0:22612ae617a0 85 USBHID(0, 0, vendor_id, product_id, product_release, false)
lharoon 0:22612ae617a0 86 {
lharoon 0:22612ae617a0 87 lock_status = 0;
lharoon 0:22612ae617a0 88 button = 0;
lharoon 0:22612ae617a0 89 this->mouse_type = mouse_type;
lharoon 0:22612ae617a0 90 connect();
lharoon 0:22612ae617a0 91 };
lharoon 0:22612ae617a0 92
lharoon 0:22612ae617a0 93 /**
lharoon 0:22612ae617a0 94 * Write a state of the mouse
lharoon 0:22612ae617a0 95 *
lharoon 0:22612ae617a0 96 * @param x x-axis position
lharoon 0:22612ae617a0 97 * @param y y-axis position
lharoon 0:22612ae617a0 98 * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE)
lharoon 0:22612ae617a0 99 * @param z wheel state (>0 to scroll down, <0 to scroll up)
lharoon 0:22612ae617a0 100 * @returns true if there is no error, false otherwise
lharoon 0:22612ae617a0 101 */
lharoon 0:22612ae617a0 102 bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z);
lharoon 0:22612ae617a0 103
lharoon 0:22612ae617a0 104
lharoon 0:22612ae617a0 105 /**
lharoon 0:22612ae617a0 106 * Move the cursor to (x, y)
lharoon 0:22612ae617a0 107 *
lharoon 0:22612ae617a0 108 * @param x x-axis position
lharoon 0:22612ae617a0 109 * @param y y-axis position
lharoon 0:22612ae617a0 110 * @returns true if there is no error, false otherwise
lharoon 0:22612ae617a0 111 */
lharoon 0:22612ae617a0 112 bool move(int16_t x, int16_t y);
lharoon 0:22612ae617a0 113
lharoon 0:22612ae617a0 114 /**
lharoon 0:22612ae617a0 115 * Press one or several buttons
lharoon 0:22612ae617a0 116 *
lharoon 0:22612ae617a0 117 * @param button button state (ex: press(MOUSE_LEFT))
lharoon 0:22612ae617a0 118 * @returns true if there is no error, false otherwise
lharoon 0:22612ae617a0 119 */
lharoon 0:22612ae617a0 120 bool press(uint8_t button);
lharoon 0:22612ae617a0 121
lharoon 0:22612ae617a0 122 /**
lharoon 0:22612ae617a0 123 * Release one or several buttons
lharoon 0:22612ae617a0 124 *
lharoon 0:22612ae617a0 125 * @param button button state (ex: release(MOUSE_LEFT))
lharoon 0:22612ae617a0 126 * @returns true if there is no error, false otherwise
lharoon 0:22612ae617a0 127 */
lharoon 0:22612ae617a0 128 bool release(uint8_t button);
lharoon 0:22612ae617a0 129
lharoon 0:22612ae617a0 130 /**
lharoon 0:22612ae617a0 131 * Double click (MOUSE_LEFT)
lharoon 0:22612ae617a0 132 *
lharoon 0:22612ae617a0 133 * @returns true if there is no error, false otherwise
lharoon 0:22612ae617a0 134 */
lharoon 0:22612ae617a0 135 bool doubleClick();
lharoon 0:22612ae617a0 136
lharoon 0:22612ae617a0 137 /**
lharoon 0:22612ae617a0 138 * Click
lharoon 0:22612ae617a0 139 *
lharoon 0:22612ae617a0 140 * @param button state of the buttons ( ex: clic(MOUSE_LEFT))
lharoon 0:22612ae617a0 141 * @returns true if there is no error, false otherwise
lharoon 0:22612ae617a0 142 */
lharoon 0:22612ae617a0 143 bool click(uint8_t button);
lharoon 0:22612ae617a0 144
lharoon 0:22612ae617a0 145 /**
lharoon 0:22612ae617a0 146 * Scrolling
lharoon 0:22612ae617a0 147 *
lharoon 0:22612ae617a0 148 * @param z value of the wheel (>0 to go down, <0 to go up)
lharoon 0:22612ae617a0 149 * @returns true if there is no error, false otherwise
lharoon 0:22612ae617a0 150 */
lharoon 0:22612ae617a0 151 bool scroll(int8_t z);
lharoon 0:22612ae617a0 152
lharoon 0:22612ae617a0 153 /**
lharoon 0:22612ae617a0 154 * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key
lharoon 0:22612ae617a0 155 *
lharoon 0:22612ae617a0 156 * @code
lharoon 0:22612ae617a0 157 * //To send CTRL + s (save)
lharoon 0:22612ae617a0 158 * keyboard.keyCode('s', KEY_CTRL);
lharoon 0:22612ae617a0 159 * @endcode
lharoon 0:22612ae617a0 160 *
lharoon 0:22612ae617a0 161 * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0)
lharoon 0:22612ae617a0 162 * @param key character to send
lharoon 0:22612ae617a0 163 * @returns true if there is no error, false otherwise
lharoon 0:22612ae617a0 164 */
lharoon 0:22612ae617a0 165 bool keyCode(uint8_t key, uint8_t modifier = 0);
lharoon 0:22612ae617a0 166
lharoon 0:22612ae617a0 167 /**
lharoon 0:22612ae617a0 168 * Send a character
lharoon 0:22612ae617a0 169 *
lharoon 0:22612ae617a0 170 * @param c character to be sent
lharoon 0:22612ae617a0 171 * @returns true if there is no error, false otherwise
lharoon 0:22612ae617a0 172 */
lharoon 0:22612ae617a0 173 virtual int _putc(int c);
lharoon 0:22612ae617a0 174
lharoon 0:22612ae617a0 175 /**
lharoon 0:22612ae617a0 176 * Control media keys
lharoon 0:22612ae617a0 177 *
lharoon 0:22612ae617a0 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)
lharoon 0:22612ae617a0 179 * @returns true if there is no error, false otherwise
lharoon 0:22612ae617a0 180 */
lharoon 0:22612ae617a0 181 bool mediaControl(MEDIA_KEY key);
lharoon 0:22612ae617a0 182
lharoon 0:22612ae617a0 183 /**
lharoon 0:22612ae617a0 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:
lharoon 0:22612ae617a0 185 * - First bit: NUM_LOCK
lharoon 0:22612ae617a0 186 * - Second bit: CAPS_LOCK
lharoon 0:22612ae617a0 187 * - Third bit: SCROLL_LOCK
lharoon 0:22612ae617a0 188 *
lharoon 0:22612ae617a0 189 * @returns status of lock keys
lharoon 0:22612ae617a0 190 */
lharoon 0:22612ae617a0 191 uint8_t lockStatus();
lharoon 0:22612ae617a0 192
lharoon 0:22612ae617a0 193 /*
lharoon 0:22612ae617a0 194 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
lharoon 0:22612ae617a0 195 *
lharoon 0:22612ae617a0 196 * @returns pointer to the report descriptor
lharoon 0:22612ae617a0 197 */
lharoon 0:22612ae617a0 198 virtual uint8_t * reportDesc();
lharoon 0:22612ae617a0 199
lharoon 0:22612ae617a0 200 /*
lharoon 0:22612ae617a0 201 * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys
lharoon 0:22612ae617a0 202 *
lharoon 0:22612ae617a0 203 * @returns if handle by subclass, return true
lharoon 0:22612ae617a0 204 */
lharoon 0:22612ae617a0 205 virtual bool EP1_OUT_callback();
lharoon 0:22612ae617a0 206
lharoon 0:22612ae617a0 207
lharoon 0:22612ae617a0 208 private:
lharoon 0:22612ae617a0 209 bool mouseWrite(int8_t x, int8_t y, uint8_t buttons, int8_t z);
lharoon 0:22612ae617a0 210 MOUSE_TYPE mouse_type;
lharoon 0:22612ae617a0 211 uint8_t button;
lharoon 0:22612ae617a0 212 bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z);
lharoon 0:22612ae617a0 213
lharoon 0:22612ae617a0 214 uint8_t lock_status;
lharoon 0:22612ae617a0 215
lharoon 0:22612ae617a0 216 //dummy otherwise it doesn't compile (we must define all methods of an abstract class)
lharoon 0:22612ae617a0 217 virtual int _getc() { return -1;}
lharoon 0:22612ae617a0 218 };
lharoon 0:22612ae617a0 219
lharoon 0:22612ae617a0 220 #endif