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 USBKEYBOARD_H
sdivarci 0:0061165683ee 20 #define USBKEYBOARD_H
sdivarci 0:0061165683ee 21
sdivarci 0:0061165683ee 22 #include "USBHID.h"
sdivarci 0:0061165683ee 23 #include "Stream.h"
sdivarci 0:0061165683ee 24
sdivarci 0:0061165683ee 25 /* Modifiers */
sdivarci 0:0061165683ee 26 enum MODIFIER_KEY {
sdivarci 0:0061165683ee 27 KEY_CTRL = 1,
sdivarci 0:0061165683ee 28 KEY_SHIFT = 2,
sdivarci 0:0061165683ee 29 KEY_ALT = 4,
sdivarci 0:0061165683ee 30 };
sdivarci 0:0061165683ee 31
sdivarci 0:0061165683ee 32
sdivarci 0:0061165683ee 33 enum MEDIA_KEY {
sdivarci 0:0061165683ee 34 KEY_NEXT_TRACK, /*!< next Track Button */
sdivarci 0:0061165683ee 35 KEY_PREVIOUS_TRACK, /*!< Previous track Button */
sdivarci 0:0061165683ee 36 KEY_STOP, /*!< Stop Button */
sdivarci 0:0061165683ee 37 KEY_PLAY_PAUSE, /*!< Play/Pause Button */
sdivarci 0:0061165683ee 38 KEY_MUTE, /*!< Mute Button */
sdivarci 0:0061165683ee 39 KEY_VOLUME_UP, /*!< Volume Up Button */
sdivarci 0:0061165683ee 40 KEY_VOLUME_DOWN, /*!< Volume Down Button */
sdivarci 0:0061165683ee 41 };
sdivarci 0:0061165683ee 42
sdivarci 0:0061165683ee 43 enum FUNCTION_KEY {
sdivarci 0:0061165683ee 44 KEY_F1 = 128, /* F1 key */
sdivarci 0:0061165683ee 45 KEY_F2, /* F2 key */
sdivarci 0:0061165683ee 46 KEY_F3, /* F3 key */
sdivarci 0:0061165683ee 47 KEY_F4, /* F4 key */
sdivarci 0:0061165683ee 48 KEY_F5, /* F5 key */
sdivarci 0:0061165683ee 49 KEY_F6, /* F6 key */
sdivarci 0:0061165683ee 50 KEY_F7, /* F7 key */
sdivarci 0:0061165683ee 51 KEY_F8, /* F8 key */
sdivarci 0:0061165683ee 52 KEY_F9, /* F9 key */
sdivarci 0:0061165683ee 53 KEY_F10, /* F10 key */
sdivarci 0:0061165683ee 54 KEY_F11, /* F11 key */
sdivarci 0:0061165683ee 55 KEY_F12, /* F12 key */
sdivarci 0:0061165683ee 56
sdivarci 0:0061165683ee 57 KEY_PRINT_SCREEN, /* Print Screen key */
sdivarci 0:0061165683ee 58 KEY_SCROLL_LOCK, /* Scroll lock */
sdivarci 0:0061165683ee 59 KEY_CAPS_LOCK, /* caps lock */
sdivarci 0:0061165683ee 60 KEY_NUM_LOCK, /* num lock */
sdivarci 0:0061165683ee 61 KEY_INSERT, /* Insert key */
sdivarci 0:0061165683ee 62 KEY_HOME, /* Home key */
sdivarci 0:0061165683ee 63 KEY_PAGE_UP, /* Page Up key */
sdivarci 0:0061165683ee 64 KEY_PAGE_DOWN, /* Page Down key */
sdivarci 0:0061165683ee 65
sdivarci 0:0061165683ee 66 RIGHT_ARROW, /* Right arrow */
sdivarci 0:0061165683ee 67 LEFT_ARROW, /* Left arrow */
sdivarci 0:0061165683ee 68 DOWN_ARROW, /* Down arrow */
sdivarci 0:0061165683ee 69 UP_ARROW, /* Up arrow */
sdivarci 0:0061165683ee 70 };
sdivarci 0:0061165683ee 71
sdivarci 0:0061165683ee 72 /**
sdivarci 0:0061165683ee 73 * USBKeyboard example
sdivarci 0:0061165683ee 74 * @code
sdivarci 0:0061165683ee 75 *
sdivarci 0:0061165683ee 76 * #include "mbed.h"
sdivarci 0:0061165683ee 77 * #include "USBKeyboard.h"
sdivarci 0:0061165683ee 78 *
sdivarci 0:0061165683ee 79 * USBKeyboard key;
sdivarci 0:0061165683ee 80 *
sdivarci 0:0061165683ee 81 * int main(void)
sdivarci 0:0061165683ee 82 * {
sdivarci 0:0061165683ee 83 * while (1)
sdivarci 0:0061165683ee 84 * {
sdivarci 0:0061165683ee 85 * key.printf("Hello World\r\n");
sdivarci 0:0061165683ee 86 * wait(1);
sdivarci 0:0061165683ee 87 * }
sdivarci 0:0061165683ee 88 * }
sdivarci 0:0061165683ee 89 *
sdivarci 0:0061165683ee 90 * @endcode
sdivarci 0:0061165683ee 91 */
sdivarci 0:0061165683ee 92 class USBKeyboard: public USBHID, public Stream {
sdivarci 0:0061165683ee 93 public:
sdivarci 0:0061165683ee 94
sdivarci 0:0061165683ee 95 /**
sdivarci 0:0061165683ee 96 * Constructor
sdivarci 0:0061165683ee 97 *
sdivarci 0:0061165683ee 98 *
sdivarci 0:0061165683ee 99 * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK
sdivarci 0:0061165683ee 100 * @param vendor_id Your vendor_id (default: 0x1235)
sdivarci 0:0061165683ee 101 * @param product_id Your product_id (default: 0x0050)
sdivarci 0:0061165683ee 102 * @param product_release Your preoduct_release (default: 0x0001)
sdivarci 0:0061165683ee 103 *
sdivarci 0:0061165683ee 104 */
sdivarci 0:0061165683ee 105 USBKeyboard(uint16_t vendor_id = 0x1235, uint16_t product_id = 0x0050, uint16_t product_release = 0x0001):
sdivarci 0:0061165683ee 106 USBHID(0, 0, vendor_id, product_id, product_release, false) {
sdivarci 0:0061165683ee 107 lock_status = 0;
sdivarci 0:0061165683ee 108 connect();
sdivarci 0:0061165683ee 109 };
sdivarci 0:0061165683ee 110
sdivarci 0:0061165683ee 111 /**
sdivarci 0:0061165683ee 112 * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key
sdivarci 0:0061165683ee 113 *
sdivarci 0:0061165683ee 114 * @code
sdivarci 0:0061165683ee 115 * //To send CTRL + s (save)
sdivarci 0:0061165683ee 116 * keyboard.keyCode('s', KEY_CTRL);
sdivarci 0:0061165683ee 117 * @endcode
sdivarci 0:0061165683ee 118 *
sdivarci 0:0061165683ee 119 * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0)
sdivarci 0:0061165683ee 120 * @param key character to send
sdivarci 0:0061165683ee 121 * @returns true if there is no error, false otherwise
sdivarci 0:0061165683ee 122 */
sdivarci 0:0061165683ee 123 bool keyCode(uint8_t key, uint8_t modifier = 0);
sdivarci 0:0061165683ee 124
sdivarci 0:0061165683ee 125 /**
sdivarci 0:0061165683ee 126 * Send a character
sdivarci 0:0061165683ee 127 *
sdivarci 0:0061165683ee 128 * @param c character to be sent
sdivarci 0:0061165683ee 129 * @returns true if there is no error, false otherwise
sdivarci 0:0061165683ee 130 */
sdivarci 0:0061165683ee 131 virtual int _putc(int c);
sdivarci 0:0061165683ee 132
sdivarci 0:0061165683ee 133 /**
sdivarci 0:0061165683ee 134 * Control media keys
sdivarci 0:0061165683ee 135 *
sdivarci 0:0061165683ee 136 * @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 137 * @returns true if there is no error, false otherwise
sdivarci 0:0061165683ee 138 */
sdivarci 0:0061165683ee 139 bool mediaControl(MEDIA_KEY key);
sdivarci 0:0061165683ee 140
sdivarci 0:0061165683ee 141 /*
sdivarci 0:0061165683ee 142 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
sdivarci 0:0061165683ee 143 *
sdivarci 0:0061165683ee 144 * @returns pointer to the report descriptor
sdivarci 0:0061165683ee 145 */
sdivarci 0:0061165683ee 146 virtual uint8_t * reportDesc();
sdivarci 0:0061165683ee 147
sdivarci 0:0061165683ee 148 /*
sdivarci 0:0061165683ee 149 * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys
sdivarci 0:0061165683ee 150 *
sdivarci 0:0061165683ee 151 * @returns if handle by subclass, return true
sdivarci 0:0061165683ee 152 */
sdivarci 0:0061165683ee 153 virtual bool EPINT_OUT_callback();
sdivarci 0:0061165683ee 154
sdivarci 0:0061165683ee 155 /**
sdivarci 0:0061165683ee 156 * 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 157 * - First bit: NUM_LOCK
sdivarci 0:0061165683ee 158 * - Second bit: CAPS_LOCK
sdivarci 0:0061165683ee 159 * - Third bit: SCROLL_LOCK
sdivarci 0:0061165683ee 160 *
sdivarci 0:0061165683ee 161 * @returns status of lock keys
sdivarci 0:0061165683ee 162 */
sdivarci 0:0061165683ee 163 uint8_t lockStatus();
sdivarci 0:0061165683ee 164
sdivarci 0:0061165683ee 165 protected:
sdivarci 0:0061165683ee 166 /*
sdivarci 0:0061165683ee 167 * Get configuration descriptor
sdivarci 0:0061165683ee 168 *
sdivarci 0:0061165683ee 169 * @returns pointer to the configuration descriptor
sdivarci 0:0061165683ee 170 */
sdivarci 0:0061165683ee 171 virtual uint8_t * configurationDesc();
sdivarci 0:0061165683ee 172
sdivarci 0:0061165683ee 173 private:
sdivarci 0:0061165683ee 174 //dummy otherwise it doesn,t compile (we must define all methods of an abstract class)
sdivarci 0:0061165683ee 175 virtual int _getc() {
sdivarci 0:0061165683ee 176 return -1;
sdivarci 0:0061165683ee 177 };
sdivarci 0:0061165683ee 178
sdivarci 0:0061165683ee 179 uint8_t lock_status;
sdivarci 0:0061165683ee 180
sdivarci 0:0061165683ee 181 };
sdivarci 0:0061165683ee 182
sdivarci 0:0061165683ee 183 #endif