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