library

Dependents:   USB_CDC_MSD_Hello

Committer:
sherckuith
Date:
Fri Aug 24 02:01:51 2012 +0000
Revision:
0:d5bb9a9c3e24
[mbed] converted /USB_CDC_MSD_Hello/USBDevice

Who changed what in which revision?

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