max4146x_comp

Dependencies:   MAX14690

Committer:
sdivarci
Date:
Sun Oct 25 20:10:02 2020 +0000
Revision:
0:0061165683ee
sdivarci

Who changed what in which revision?

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