USBMSD SD card Hello World for Mbed platforms
Dependencies: mbed USBMSD_SD USBDevice
USBDevice/USBHID/USBKeyboard.h@2:27a7e7f8d399, 2011-11-11 (annotated)
- Committer:
- samux
- Date:
- Fri Nov 11 15:22:53 2011 +0000
- Revision:
- 2:27a7e7f8d399
we have 2MB with the sdcard!!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux |
2:27a7e7f8d399 | 1 | /* USBKeyboard.h */ |
samux |
2:27a7e7f8d399 | 2 | /* USB device example: Standard keyboard */ |
samux |
2:27a7e7f8d399 | 3 | /* Copyright (c) 2011 ARM Limited. All rights reserved. */ |
samux |
2:27a7e7f8d399 | 4 | |
samux |
2:27a7e7f8d399 | 5 | #ifndef USBKEYBOARD_H |
samux |
2:27a7e7f8d399 | 6 | #define USBKEYBOARD_H |
samux |
2:27a7e7f8d399 | 7 | |
samux |
2:27a7e7f8d399 | 8 | #include "USBHID.h" |
samux |
2:27a7e7f8d399 | 9 | #include "Stream.h" |
samux |
2:27a7e7f8d399 | 10 | |
samux |
2:27a7e7f8d399 | 11 | /* Modifiers */ |
samux |
2:27a7e7f8d399 | 12 | enum MODIFIER_KEY |
samux |
2:27a7e7f8d399 | 13 | { |
samux |
2:27a7e7f8d399 | 14 | KEY_CTRL = 1, |
samux |
2:27a7e7f8d399 | 15 | KEY_SHIFT = 2, |
samux |
2:27a7e7f8d399 | 16 | KEY_ALT = 4, |
samux |
2:27a7e7f8d399 | 17 | }; |
samux |
2:27a7e7f8d399 | 18 | |
samux |
2:27a7e7f8d399 | 19 | |
samux |
2:27a7e7f8d399 | 20 | enum MEDIA_KEY |
samux |
2:27a7e7f8d399 | 21 | { |
samux |
2:27a7e7f8d399 | 22 | KEY_NEXT_TRACK, /*!< next Track Button */ |
samux |
2:27a7e7f8d399 | 23 | KEY_PREVIOUS_TRACK, /*!< Previous track Button */ |
samux |
2:27a7e7f8d399 | 24 | KEY_STOP, /*!< Stop Button */ |
samux |
2:27a7e7f8d399 | 25 | KEY_PLAY_PAUSE, /*!< Play/Pause Button */ |
samux |
2:27a7e7f8d399 | 26 | KEY_MUTE, /*!< Mute Button */ |
samux |
2:27a7e7f8d399 | 27 | KEY_VOLUME_UP, /*!< Volume Up Button */ |
samux |
2:27a7e7f8d399 | 28 | KEY_VOLUME_DOWN, /*!< Volume Down Button */ |
samux |
2:27a7e7f8d399 | 29 | }; |
samux |
2:27a7e7f8d399 | 30 | |
samux |
2:27a7e7f8d399 | 31 | enum FUNCTION_KEY |
samux |
2:27a7e7f8d399 | 32 | { |
samux |
2:27a7e7f8d399 | 33 | KEY_F1 = 128, /* F1 key */ |
samux |
2:27a7e7f8d399 | 34 | KEY_F2, /* F2 key */ |
samux |
2:27a7e7f8d399 | 35 | KEY_F3, /* F3 key */ |
samux |
2:27a7e7f8d399 | 36 | KEY_F4, /* F4 key */ |
samux |
2:27a7e7f8d399 | 37 | KEY_F5, /* F5 key */ |
samux |
2:27a7e7f8d399 | 38 | KEY_F6, /* F6 key */ |
samux |
2:27a7e7f8d399 | 39 | KEY_F7, /* F7 key */ |
samux |
2:27a7e7f8d399 | 40 | KEY_F8, /* F8 key */ |
samux |
2:27a7e7f8d399 | 41 | KEY_F9, /* F9 key */ |
samux |
2:27a7e7f8d399 | 42 | KEY_F10, /* F10 key */ |
samux |
2:27a7e7f8d399 | 43 | KEY_F11, /* F11 key */ |
samux |
2:27a7e7f8d399 | 44 | KEY_F12, /* F12 key */ |
samux |
2:27a7e7f8d399 | 45 | KEY_PRINT_SCREEN, /* Print Screen key */ |
samux |
2:27a7e7f8d399 | 46 | KEY_SCROLL_LOCK, /* Scroll lock */ |
samux |
2:27a7e7f8d399 | 47 | KEY_CAPS_LOCK, /* caps lock */ |
samux |
2:27a7e7f8d399 | 48 | KEY_NUM_LOCK, /* num lock */ |
samux |
2:27a7e7f8d399 | 49 | KEY_INSERT, /* Insert key */ |
samux |
2:27a7e7f8d399 | 50 | KEY_HOME, /* Home key */ |
samux |
2:27a7e7f8d399 | 51 | KEY_PAGE_UP, /* Page Up key */ |
samux |
2:27a7e7f8d399 | 52 | KEY_PAGE_DOWN, /* Page Down key */ |
samux |
2:27a7e7f8d399 | 53 | }; |
samux |
2:27a7e7f8d399 | 54 | |
samux |
2:27a7e7f8d399 | 55 | /** |
samux |
2:27a7e7f8d399 | 56 | * USBKeyboard example |
samux |
2:27a7e7f8d399 | 57 | * @code |
samux |
2:27a7e7f8d399 | 58 | * |
samux |
2:27a7e7f8d399 | 59 | * #include "mbed.h" |
samux |
2:27a7e7f8d399 | 60 | * #include "USBKeyboard.h" |
samux |
2:27a7e7f8d399 | 61 | * |
samux |
2:27a7e7f8d399 | 62 | * USBKeyboard key; |
samux |
2:27a7e7f8d399 | 63 | * |
samux |
2:27a7e7f8d399 | 64 | * int main(void) |
samux |
2:27a7e7f8d399 | 65 | * { |
samux |
2:27a7e7f8d399 | 66 | * while (1) |
samux |
2:27a7e7f8d399 | 67 | * { |
samux |
2:27a7e7f8d399 | 68 | * key.printf("Hello World\r\n"); |
samux |
2:27a7e7f8d399 | 69 | * wait(1); |
samux |
2:27a7e7f8d399 | 70 | * } |
samux |
2:27a7e7f8d399 | 71 | * } |
samux |
2:27a7e7f8d399 | 72 | * |
samux |
2:27a7e7f8d399 | 73 | * @endcode |
samux |
2:27a7e7f8d399 | 74 | */ |
samux |
2:27a7e7f8d399 | 75 | class USBKeyboard: public USBHID, public Stream |
samux |
2:27a7e7f8d399 | 76 | { |
samux |
2:27a7e7f8d399 | 77 | public: |
samux |
2:27a7e7f8d399 | 78 | |
samux |
2:27a7e7f8d399 | 79 | /** |
samux |
2:27a7e7f8d399 | 80 | * Constructor |
samux |
2:27a7e7f8d399 | 81 | * |
samux |
2:27a7e7f8d399 | 82 | * |
samux |
2:27a7e7f8d399 | 83 | * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK |
samux |
2:27a7e7f8d399 | 84 | * @param vendor_id Your vendor_id (default: 0x1234) |
samux |
2:27a7e7f8d399 | 85 | * @param product_id Your product_id (default: 0x0001) |
samux |
2:27a7e7f8d399 | 86 | * @param product_release Your preoduct_release (default: 0x0001) |
samux |
2:27a7e7f8d399 | 87 | * |
samux |
2:27a7e7f8d399 | 88 | */ |
samux |
2:27a7e7f8d399 | 89 | USBKeyboard(BusOut * leds = NULL, uint16_t vendor_id = 0x1235, uint16_t product_id = 0x0010, uint16_t product_release = 0x0001): |
samux |
2:27a7e7f8d399 | 90 | USBHID(0, 0, vendor_id, product_id, product_release){ |
samux |
2:27a7e7f8d399 | 91 | this->leds = leds; |
samux |
2:27a7e7f8d399 | 92 | }; |
samux |
2:27a7e7f8d399 | 93 | |
samux |
2:27a7e7f8d399 | 94 | /** |
samux |
2:27a7e7f8d399 | 95 | * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key |
samux |
2:27a7e7f8d399 | 96 | * |
samux |
2:27a7e7f8d399 | 97 | * @code |
samux |
2:27a7e7f8d399 | 98 | * //To send CTRL + s (save) |
samux |
2:27a7e7f8d399 | 99 | * keyboard.keyCode('s', KEY_CTRL); |
samux |
2:27a7e7f8d399 | 100 | * @endcode |
samux |
2:27a7e7f8d399 | 101 | * |
samux |
2:27a7e7f8d399 | 102 | * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0) |
samux |
2:27a7e7f8d399 | 103 | * @param key character to send |
samux |
2:27a7e7f8d399 | 104 | * @returns true if there is no error, false otherwise |
samux |
2:27a7e7f8d399 | 105 | */ |
samux |
2:27a7e7f8d399 | 106 | bool keyCode(uint8_t key, uint8_t modifier = 0); |
samux |
2:27a7e7f8d399 | 107 | |
samux |
2:27a7e7f8d399 | 108 | /** |
samux |
2:27a7e7f8d399 | 109 | * Send a character |
samux |
2:27a7e7f8d399 | 110 | * |
samux |
2:27a7e7f8d399 | 111 | * @param c character to be sent |
samux |
2:27a7e7f8d399 | 112 | * @returns true if there is no error, false otherwise |
samux |
2:27a7e7f8d399 | 113 | */ |
samux |
2:27a7e7f8d399 | 114 | virtual int _putc(int c); |
samux |
2:27a7e7f8d399 | 115 | |
samux |
2:27a7e7f8d399 | 116 | /** |
samux |
2:27a7e7f8d399 | 117 | * Control media keys |
samux |
2:27a7e7f8d399 | 118 | * |
samux |
2:27a7e7f8d399 | 119 | * @param key media key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN) |
samux |
2:27a7e7f8d399 | 120 | * @returns true if there is no error, false otherwise |
samux |
2:27a7e7f8d399 | 121 | */ |
samux |
2:27a7e7f8d399 | 122 | bool mediaControl(MEDIA_KEY key); |
samux |
2:27a7e7f8d399 | 123 | |
samux |
2:27a7e7f8d399 | 124 | /* |
samux |
2:27a7e7f8d399 | 125 | * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength. |
samux |
2:27a7e7f8d399 | 126 | * |
samux |
2:27a7e7f8d399 | 127 | * @returns pointer to the report descriptor |
samux |
2:27a7e7f8d399 | 128 | */ |
samux |
2:27a7e7f8d399 | 129 | virtual uint8_t * reportDesc(); |
samux |
2:27a7e7f8d399 | 130 | |
samux |
2:27a7e7f8d399 | 131 | /* |
samux |
2:27a7e7f8d399 | 132 | * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys |
samux |
2:27a7e7f8d399 | 133 | * |
samux |
2:27a7e7f8d399 | 134 | * @returns if handle by subclass, return true |
samux |
2:27a7e7f8d399 | 135 | */ |
samux |
2:27a7e7f8d399 | 136 | virtual bool EP1_OUT_callback(); |
samux |
2:27a7e7f8d399 | 137 | |
samux |
2:27a7e7f8d399 | 138 | private: |
samux |
2:27a7e7f8d399 | 139 | //dummy otherwise it doesn,t compile (we must define all methods of an abstract class) |
samux |
2:27a7e7f8d399 | 140 | virtual int _getc() { return -1;}; |
samux |
2:27a7e7f8d399 | 141 | |
samux |
2:27a7e7f8d399 | 142 | // Switch on leds (CAPS LOCK,...) |
samux |
2:27a7e7f8d399 | 143 | BusOut * leds; |
samux |
2:27a7e7f8d399 | 144 | }; |
samux |
2:27a7e7f8d399 | 145 | |
samux |
2:27a7e7f8d399 | 146 | #endif |
samux |
2:27a7e7f8d399 | 147 |