Modified for PS3 Joystick

Dependents:   NiseKabuto

Fork of USBDevice by Samuel Mokrani

Committer:
sankichi
Date:
Sat Jul 27 14:05:26 2013 +0000
Revision:
1:ac5cca60029a
Parent:
0:140cdf8e2d60
First Release

Who changed what in which revision?

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