Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Committer:
cyberjoey
Date:
Sat Oct 22 01:31:58 2016 +0000
Revision:
9:6bb35cef007d
Parent:
1:55a6170b404f
WORKING

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 1:55a6170b404f 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
nexpaq 1:55a6170b404f 2 *
nexpaq 1:55a6170b404f 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
nexpaq 1:55a6170b404f 4 * and associated documentation files (the "Software"), to deal in the Software without
nexpaq 1:55a6170b404f 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
nexpaq 1:55a6170b404f 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
nexpaq 1:55a6170b404f 7 * Software is furnished to do so, subject to the following conditions:
nexpaq 1:55a6170b404f 8 *
nexpaq 1:55a6170b404f 9 * The above copyright notice and this permission notice shall be included in all copies or
nexpaq 1:55a6170b404f 10 * substantial portions of the Software.
nexpaq 1:55a6170b404f 11 *
nexpaq 1:55a6170b404f 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
nexpaq 1:55a6170b404f 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
nexpaq 1:55a6170b404f 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
nexpaq 1:55a6170b404f 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
nexpaq 1:55a6170b404f 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
nexpaq 1:55a6170b404f 17 */
nexpaq 1:55a6170b404f 18
nexpaq 1:55a6170b404f 19 #ifndef USBKEYBOARD_H
nexpaq 1:55a6170b404f 20 #define USBKEYBOARD_H
nexpaq 1:55a6170b404f 21
nexpaq 1:55a6170b404f 22 #include "USBHID.h"
nexpaq 1:55a6170b404f 23 #include "Stream.h"
nexpaq 1:55a6170b404f 24
nexpaq 1:55a6170b404f 25 /* Modifiers */
nexpaq 1:55a6170b404f 26 enum MODIFIER_KEY {
nexpaq 1:55a6170b404f 27 KEY_CTRL = 1,
nexpaq 1:55a6170b404f 28 KEY_SHIFT = 2,
nexpaq 1:55a6170b404f 29 KEY_ALT = 4,
nexpaq 1:55a6170b404f 30 };
nexpaq 1:55a6170b404f 31
nexpaq 1:55a6170b404f 32
nexpaq 1:55a6170b404f 33 enum MEDIA_KEY {
nexpaq 1:55a6170b404f 34 KEY_NEXT_TRACK, /*!< next Track Button */
nexpaq 1:55a6170b404f 35 KEY_PREVIOUS_TRACK, /*!< Previous track Button */
nexpaq 1:55a6170b404f 36 KEY_STOP, /*!< Stop Button */
nexpaq 1:55a6170b404f 37 KEY_PLAY_PAUSE, /*!< Play/Pause Button */
nexpaq 1:55a6170b404f 38 KEY_MUTE, /*!< Mute Button */
nexpaq 1:55a6170b404f 39 KEY_VOLUME_UP, /*!< Volume Up Button */
nexpaq 1:55a6170b404f 40 KEY_VOLUME_DOWN, /*!< Volume Down Button */
nexpaq 1:55a6170b404f 41 };
nexpaq 1:55a6170b404f 42
nexpaq 1:55a6170b404f 43 enum FUNCTION_KEY {
nexpaq 1:55a6170b404f 44 KEY_F1 = 128, /* F1 key */
nexpaq 1:55a6170b404f 45 KEY_F2, /* F2 key */
nexpaq 1:55a6170b404f 46 KEY_F3, /* F3 key */
nexpaq 1:55a6170b404f 47 KEY_F4, /* F4 key */
nexpaq 1:55a6170b404f 48 KEY_F5, /* F5 key */
nexpaq 1:55a6170b404f 49 KEY_F6, /* F6 key */
nexpaq 1:55a6170b404f 50 KEY_F7, /* F7 key */
nexpaq 1:55a6170b404f 51 KEY_F8, /* F8 key */
nexpaq 1:55a6170b404f 52 KEY_F9, /* F9 key */
nexpaq 1:55a6170b404f 53 KEY_F10, /* F10 key */
nexpaq 1:55a6170b404f 54 KEY_F11, /* F11 key */
nexpaq 1:55a6170b404f 55 KEY_F12, /* F12 key */
nexpaq 1:55a6170b404f 56
nexpaq 1:55a6170b404f 57 KEY_PRINT_SCREEN, /* Print Screen key */
nexpaq 1:55a6170b404f 58 KEY_SCROLL_LOCK, /* Scroll lock */
nexpaq 1:55a6170b404f 59 KEY_CAPS_LOCK, /* caps lock */
nexpaq 1:55a6170b404f 60 KEY_NUM_LOCK, /* num lock */
nexpaq 1:55a6170b404f 61 KEY_INSERT, /* Insert key */
nexpaq 1:55a6170b404f 62 KEY_HOME, /* Home key */
nexpaq 1:55a6170b404f 63 KEY_PAGE_UP, /* Page Up key */
nexpaq 1:55a6170b404f 64 KEY_PAGE_DOWN, /* Page Down key */
nexpaq 1:55a6170b404f 65
nexpaq 1:55a6170b404f 66 RIGHT_ARROW, /* Right arrow */
nexpaq 1:55a6170b404f 67 LEFT_ARROW, /* Left arrow */
nexpaq 1:55a6170b404f 68 DOWN_ARROW, /* Down arrow */
nexpaq 1:55a6170b404f 69 UP_ARROW, /* Up arrow */
nexpaq 1:55a6170b404f 70 };
nexpaq 1:55a6170b404f 71
nexpaq 1:55a6170b404f 72 /**
nexpaq 1:55a6170b404f 73 * USBKeyboard example
nexpaq 1:55a6170b404f 74 * @code
nexpaq 1:55a6170b404f 75 *
nexpaq 1:55a6170b404f 76 * #include "mbed.h"
nexpaq 1:55a6170b404f 77 * #include "USBKeyboard.h"
nexpaq 1:55a6170b404f 78 *
nexpaq 1:55a6170b404f 79 * USBKeyboard key;
nexpaq 1:55a6170b404f 80 *
nexpaq 1:55a6170b404f 81 * int main(void)
nexpaq 1:55a6170b404f 82 * {
nexpaq 1:55a6170b404f 83 * while (1)
nexpaq 1:55a6170b404f 84 * {
nexpaq 1:55a6170b404f 85 * key.printf("Hello World\r\n");
nexpaq 1:55a6170b404f 86 * wait(1);
nexpaq 1:55a6170b404f 87 * }
nexpaq 1:55a6170b404f 88 * }
nexpaq 1:55a6170b404f 89 *
nexpaq 1:55a6170b404f 90 * @endcode
nexpaq 1:55a6170b404f 91 */
nexpaq 1:55a6170b404f 92 class USBKeyboard: public USBHID, public Stream {
nexpaq 1:55a6170b404f 93 public:
nexpaq 1:55a6170b404f 94
nexpaq 1:55a6170b404f 95 /**
nexpaq 1:55a6170b404f 96 * Constructor
nexpaq 1:55a6170b404f 97 *
nexpaq 1:55a6170b404f 98 *
nexpaq 1:55a6170b404f 99 * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK
nexpaq 1:55a6170b404f 100 * @param vendor_id Your vendor_id (default: 0x1235)
nexpaq 1:55a6170b404f 101 * @param product_id Your product_id (default: 0x0050)
nexpaq 1:55a6170b404f 102 * @param product_release Your preoduct_release (default: 0x0001)
nexpaq 1:55a6170b404f 103 *
nexpaq 1:55a6170b404f 104 */
nexpaq 1:55a6170b404f 105 USBKeyboard(uint16_t vendor_id = 0x1235, uint16_t product_id = 0x0050, uint16_t product_release = 0x0001):
nexpaq 1:55a6170b404f 106 USBHID(0, 0, vendor_id, product_id, product_release, false) {
nexpaq 1:55a6170b404f 107 lock_status = 0;
nexpaq 1:55a6170b404f 108 connect();
nexpaq 1:55a6170b404f 109 };
nexpaq 1:55a6170b404f 110
nexpaq 1:55a6170b404f 111 /**
nexpaq 1:55a6170b404f 112 * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key
nexpaq 1:55a6170b404f 113 *
nexpaq 1:55a6170b404f 114 * @code
nexpaq 1:55a6170b404f 115 * //To send CTRL + s (save)
nexpaq 1:55a6170b404f 116 * keyboard.keyCode('s', KEY_CTRL);
nexpaq 1:55a6170b404f 117 * @endcode
nexpaq 1:55a6170b404f 118 *
nexpaq 1:55a6170b404f 119 * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0)
nexpaq 1:55a6170b404f 120 * @param key character to send
nexpaq 1:55a6170b404f 121 * @returns true if there is no error, false otherwise
nexpaq 1:55a6170b404f 122 */
nexpaq 1:55a6170b404f 123 bool keyCode(uint8_t key, uint8_t modifier = 0);
nexpaq 1:55a6170b404f 124
nexpaq 1:55a6170b404f 125 /**
nexpaq 1:55a6170b404f 126 * Send a character
nexpaq 1:55a6170b404f 127 *
nexpaq 1:55a6170b404f 128 * @param c character to be sent
nexpaq 1:55a6170b404f 129 * @returns true if there is no error, false otherwise
nexpaq 1:55a6170b404f 130 */
nexpaq 1:55a6170b404f 131 virtual int _putc(int c);
nexpaq 1:55a6170b404f 132
nexpaq 1:55a6170b404f 133 /**
nexpaq 1:55a6170b404f 134 * Control media keys
nexpaq 1:55a6170b404f 135 *
nexpaq 1:55a6170b404f 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)
nexpaq 1:55a6170b404f 137 * @returns true if there is no error, false otherwise
nexpaq 1:55a6170b404f 138 */
nexpaq 1:55a6170b404f 139 bool mediaControl(MEDIA_KEY key);
nexpaq 1:55a6170b404f 140
nexpaq 1:55a6170b404f 141 /*
nexpaq 1:55a6170b404f 142 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
nexpaq 1:55a6170b404f 143 *
nexpaq 1:55a6170b404f 144 * @returns pointer to the report descriptor
nexpaq 1:55a6170b404f 145 */
nexpaq 1:55a6170b404f 146 virtual uint8_t * reportDesc();
nexpaq 1:55a6170b404f 147
nexpaq 1:55a6170b404f 148 /*
nexpaq 1:55a6170b404f 149 * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys
nexpaq 1:55a6170b404f 150 *
nexpaq 1:55a6170b404f 151 * @returns if handle by subclass, return true
nexpaq 1:55a6170b404f 152 */
nexpaq 1:55a6170b404f 153 virtual bool EPINT_OUT_callback();
nexpaq 1:55a6170b404f 154
nexpaq 1:55a6170b404f 155 /**
nexpaq 1:55a6170b404f 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:
nexpaq 1:55a6170b404f 157 * - First bit: NUM_LOCK
nexpaq 1:55a6170b404f 158 * - Second bit: CAPS_LOCK
nexpaq 1:55a6170b404f 159 * - Third bit: SCROLL_LOCK
nexpaq 1:55a6170b404f 160 *
nexpaq 1:55a6170b404f 161 * @returns status of lock keys
nexpaq 1:55a6170b404f 162 */
nexpaq 1:55a6170b404f 163 uint8_t lockStatus();
nexpaq 1:55a6170b404f 164
nexpaq 1:55a6170b404f 165 protected:
nexpaq 1:55a6170b404f 166 /*
nexpaq 1:55a6170b404f 167 * Get configuration descriptor
nexpaq 1:55a6170b404f 168 *
nexpaq 1:55a6170b404f 169 * @returns pointer to the configuration descriptor
nexpaq 1:55a6170b404f 170 */
nexpaq 1:55a6170b404f 171 virtual uint8_t * configurationDesc();
nexpaq 1:55a6170b404f 172
nexpaq 1:55a6170b404f 173 private:
nexpaq 1:55a6170b404f 174 //dummy otherwise it doesn,t compile (we must define all methods of an abstract class)
nexpaq 1:55a6170b404f 175 virtual int _getc() {
nexpaq 1:55a6170b404f 176 return -1;
nexpaq 1:55a6170b404f 177 };
nexpaq 1:55a6170b404f 178
nexpaq 1:55a6170b404f 179 uint8_t lock_status;
nexpaq 1:55a6170b404f 180
nexpaq 1:55a6170b404f 181 };
nexpaq 1:55a6170b404f 182
nexpaq 1:55a6170b404f 183 #endif