USBAudio example using a microphone

Dependencies:   USBDevice mbed

Committer:
samux
Date:
Fri Dec 16 12:31:41 2011 +0000
Revision:
0:539ec61e1fbb
works with m0 and m3 (sinus) but the code is different to have the same result...

Who changed what in which revision?

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