SD card interface

Committer:
lharoon
Date:
Mon Oct 08 11:14:07 2012 +0000
Revision:
0:22612ae617a0
1st edition

Who changed what in which revision?

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