USB CDC (serial) and USB MSC (strage) Composite Device. http://mbed.org/users/okini3939/notebook/USB_Device/

Dependencies:   ChaNFSSD mbed ChaNFS

Committer:
okini3939
Date:
Fri Dec 23 16:37:58 2011 +0000
Revision:
2:5db90410bb90
Parent:
0:9b1d17d54055

        

Who changed what in which revision?

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