EA BaseBoard, playing wav, PC see\'s SD-card through USB port.

Dependencies:   mbed

Committer:
Lerche
Date:
Tue Nov 22 05:45:58 2011 +0000
Revision:
0:fef366d2ed20
Thanks to those who provided EA_WavPlayer and USB_MSC

Who changed what in which revision?

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