USBMSD SD card Hello World for Mbed platforms

Dependencies:   mbed USBMSD_SD USBDevice

Committer:
samux
Date:
Tue Dec 06 12:07:12 2011 +0000
Revision:
14:757226626acb
Parent:
11:a26e7b7a1221
protection enabled when usb cable plugged. filesystem has no access when plugged

Who changed what in which revision?

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