Base station firmware

Committer:
Perijah
Date:
Tue May 24 13:16:55 2016 +0000
Revision:
0:ecc3925d3f8c
Base station firmware

Who changed what in which revision?

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