USBDevice

Dependents:   QEI_X1_LCD_test3 macnica_test

Committer:
toucyy
Date:
Thu Apr 18 07:49:37 2013 +0000
Revision:
0:2d8d0b73e1ff
[mbed] converted /QEI_HelloWorld/USBDevice

Who changed what in which revision?

UserRevisionLine numberNew contents of line
toucyy 0:2d8d0b73e1ff 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
toucyy 0:2d8d0b73e1ff 2 *
toucyy 0:2d8d0b73e1ff 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
toucyy 0:2d8d0b73e1ff 4 * and associated documentation files (the "Software"), to deal in the Software without
toucyy 0:2d8d0b73e1ff 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
toucyy 0:2d8d0b73e1ff 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
toucyy 0:2d8d0b73e1ff 7 * Software is furnished to do so, subject to the following conditions:
toucyy 0:2d8d0b73e1ff 8 *
toucyy 0:2d8d0b73e1ff 9 * The above copyright notice and this permission notice shall be included in all copies or
toucyy 0:2d8d0b73e1ff 10 * substantial portions of the Software.
toucyy 0:2d8d0b73e1ff 11 *
toucyy 0:2d8d0b73e1ff 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
toucyy 0:2d8d0b73e1ff 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
toucyy 0:2d8d0b73e1ff 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
toucyy 0:2d8d0b73e1ff 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
toucyy 0:2d8d0b73e1ff 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
toucyy 0:2d8d0b73e1ff 17 */
toucyy 0:2d8d0b73e1ff 18
toucyy 0:2d8d0b73e1ff 19 #ifndef USBMIDI_H
toucyy 0:2d8d0b73e1ff 20 #define USBMIDI_H
toucyy 0:2d8d0b73e1ff 21
toucyy 0:2d8d0b73e1ff 22 /* These headers are included for child class. */
toucyy 0:2d8d0b73e1ff 23 #include "USBEndpoints.h"
toucyy 0:2d8d0b73e1ff 24 #include "USBDescriptor.h"
toucyy 0:2d8d0b73e1ff 25 #include "USBDevice_Types.h"
toucyy 0:2d8d0b73e1ff 26
toucyy 0:2d8d0b73e1ff 27 #include "USBDevice.h"
toucyy 0:2d8d0b73e1ff 28 #include "MIDIMessage.h"
toucyy 0:2d8d0b73e1ff 29
toucyy 0:2d8d0b73e1ff 30 #define DEFAULT_CONFIGURATION (1)
toucyy 0:2d8d0b73e1ff 31
toucyy 0:2d8d0b73e1ff 32 /**
toucyy 0:2d8d0b73e1ff 33 * USBMIDI example
toucyy 0:2d8d0b73e1ff 34 *
toucyy 0:2d8d0b73e1ff 35 * @code
toucyy 0:2d8d0b73e1ff 36 * #include "mbed.h"
toucyy 0:2d8d0b73e1ff 37 * #include "USBMIDI.h"
toucyy 0:2d8d0b73e1ff 38 *
toucyy 0:2d8d0b73e1ff 39 * USBMIDI midi;
toucyy 0:2d8d0b73e1ff 40 *
toucyy 0:2d8d0b73e1ff 41 * int main() {
toucyy 0:2d8d0b73e1ff 42 * while (1) {
toucyy 0:2d8d0b73e1ff 43 * for(int i=48; i<83; i++) { // send some messages!
toucyy 0:2d8d0b73e1ff 44 * midi.write(MIDIMessage::NoteOn(i));
toucyy 0:2d8d0b73e1ff 45 * wait(0.25);
toucyy 0:2d8d0b73e1ff 46 * midi.write(MIDIMessage::NoteOff(i));
toucyy 0:2d8d0b73e1ff 47 * wait(0.5);
toucyy 0:2d8d0b73e1ff 48 * }
toucyy 0:2d8d0b73e1ff 49 * }
toucyy 0:2d8d0b73e1ff 50 * }
toucyy 0:2d8d0b73e1ff 51 * @endcode
toucyy 0:2d8d0b73e1ff 52 */
toucyy 0:2d8d0b73e1ff 53 class USBMIDI: public USBDevice {
toucyy 0:2d8d0b73e1ff 54 public:
toucyy 0:2d8d0b73e1ff 55
toucyy 0:2d8d0b73e1ff 56 /**
toucyy 0:2d8d0b73e1ff 57 * Constructor
toucyy 0:2d8d0b73e1ff 58 *
toucyy 0:2d8d0b73e1ff 59 * @param vendor_id Your vendor_id
toucyy 0:2d8d0b73e1ff 60 * @param product_id Your product_id
toucyy 0:2d8d0b73e1ff 61 * @param product_release Your preoduct_release
toucyy 0:2d8d0b73e1ff 62 */
toucyy 0:2d8d0b73e1ff 63 USBMIDI(uint16_t vendor_id = 0x0700, uint16_t product_id = 0x0101, uint16_t product_release = 0x0001);
toucyy 0:2d8d0b73e1ff 64
toucyy 0:2d8d0b73e1ff 65 /**
toucyy 0:2d8d0b73e1ff 66 * Send a MIDIMessage
toucyy 0:2d8d0b73e1ff 67 *
toucyy 0:2d8d0b73e1ff 68 * @param m The MIDIMessage to send
toucyy 0:2d8d0b73e1ff 69 */
toucyy 0:2d8d0b73e1ff 70 void write(MIDIMessage m);
toucyy 0:2d8d0b73e1ff 71
toucyy 0:2d8d0b73e1ff 72 /**
toucyy 0:2d8d0b73e1ff 73 * Attach a callback for when a MIDIEvent is received
toucyy 0:2d8d0b73e1ff 74 *
toucyy 0:2d8d0b73e1ff 75 * @param fptr function pointer
toucyy 0:2d8d0b73e1ff 76 */
toucyy 0:2d8d0b73e1ff 77 void attach(void (*fptr)(MIDIMessage));
toucyy 0:2d8d0b73e1ff 78
toucyy 0:2d8d0b73e1ff 79
toucyy 0:2d8d0b73e1ff 80 protected:
toucyy 0:2d8d0b73e1ff 81 virtual bool EP2_OUT_callback();
toucyy 0:2d8d0b73e1ff 82 virtual bool USBCallback_setConfiguration(uint8_t configuration);
toucyy 0:2d8d0b73e1ff 83 /*
toucyy 0:2d8d0b73e1ff 84 * Get string product descriptor
toucyy 0:2d8d0b73e1ff 85 *
toucyy 0:2d8d0b73e1ff 86 * @returns pointer to the string product descriptor
toucyy 0:2d8d0b73e1ff 87 */
toucyy 0:2d8d0b73e1ff 88 virtual uint8_t * stringIproductDesc();
toucyy 0:2d8d0b73e1ff 89
toucyy 0:2d8d0b73e1ff 90 /*
toucyy 0:2d8d0b73e1ff 91 * Get string interface descriptor
toucyy 0:2d8d0b73e1ff 92 *
toucyy 0:2d8d0b73e1ff 93 * @returns pointer to the string interface descriptor
toucyy 0:2d8d0b73e1ff 94 */
toucyy 0:2d8d0b73e1ff 95 virtual uint8_t * stringIinterfaceDesc();
toucyy 0:2d8d0b73e1ff 96
toucyy 0:2d8d0b73e1ff 97 /*
toucyy 0:2d8d0b73e1ff 98 * Get configuration descriptor
toucyy 0:2d8d0b73e1ff 99 *
toucyy 0:2d8d0b73e1ff 100 * @returns pointer to the configuration descriptor
toucyy 0:2d8d0b73e1ff 101 */
toucyy 0:2d8d0b73e1ff 102 virtual uint8_t * configurationDesc();
toucyy 0:2d8d0b73e1ff 103
toucyy 0:2d8d0b73e1ff 104 private:
toucyy 0:2d8d0b73e1ff 105 void (*midi_evt)(MIDIMessage);
toucyy 0:2d8d0b73e1ff 106
toucyy 0:2d8d0b73e1ff 107 };
toucyy 0:2d8d0b73e1ff 108
toucyy 0:2d8d0b73e1ff 109 #endif
toucyy 0:2d8d0b73e1ff 110