Pinscape Controller version 1 fork. This is a fork to allow for ongoing bug fixes to the original controller version, from before the major changes for the expansion board project.

Dependencies:   FastIO FastPWM SimpleDMA mbed

Fork of Pinscape_Controller by Mike R

Committer:
mjr
Date:
Mon Feb 15 23:03:55 2016 +0000
Revision:
68:edfecf67a931
Parent:
52:63f0a9b45f0c
Finalize USB library updates to fix compatibility problems introduced in USBHAL_KL25Z overhaul.

Who changed what in which revision?

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