ram version see usbmsd_sd.cpp ram ok fs CANNOT be installed - too small use for illustrative purpose only

Dependencies:   USBDevice USBMSD_SD mbed

Fork of USBMSD_SD_HelloWorld_Mbed by Samuel Mokrani

Committer:
samux
Date:
Wed Nov 16 17:17:42 2011 +0000
Revision:
11:a26e7b7a1221
GOOD COMMIT: msd and hid work even on MAC...

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 #include "stdint.h"
samux 11:a26e7b7a1221 20 #include "USBMIDI.h"
samux 11:a26e7b7a1221 21 #include "USBBusInterface.h"
samux 11:a26e7b7a1221 22
samux 11:a26e7b7a1221 23
samux 11:a26e7b7a1221 24 USBMIDI::USBMIDI(uint16_t vendor_id, uint16_t product_id, uint16_t product_release): USBDevice(vendor_id, product_id, product_release) {
samux 11:a26e7b7a1221 25 midi_evt = NULL;
samux 11:a26e7b7a1221 26 USBDevice::connect();
samux 11:a26e7b7a1221 27 }
samux 11:a26e7b7a1221 28
samux 11:a26e7b7a1221 29 void USBMIDI::write(MIDIMessage m) {
samux 11:a26e7b7a1221 30 USBDevice::write(EPBULK_IN, m.data, 4, MAX_PACKET_SIZE_EPBULK);
samux 11:a26e7b7a1221 31 }
samux 11:a26e7b7a1221 32
samux 11:a26e7b7a1221 33
samux 11:a26e7b7a1221 34 void USBMIDI::attach(void (*fptr)(MIDIMessage)) {
samux 11:a26e7b7a1221 35 midi_evt = fptr;
samux 11:a26e7b7a1221 36 }
samux 11:a26e7b7a1221 37
samux 11:a26e7b7a1221 38
samux 11:a26e7b7a1221 39 bool USBMIDI::EP2_OUT_callback() {
samux 11:a26e7b7a1221 40 uint8_t buf[64];
samux 11:a26e7b7a1221 41 uint16_t len;
samux 11:a26e7b7a1221 42 read(EPBULK_OUT, buf, &len, 64);
samux 11:a26e7b7a1221 43
samux 11:a26e7b7a1221 44 if (midi_evt != NULL) {
samux 11:a26e7b7a1221 45 for (int i=0; i<len; i+=4) {
samux 11:a26e7b7a1221 46 midi_evt(MIDIMessage(buf+i));
samux 11:a26e7b7a1221 47 }
samux 11:a26e7b7a1221 48 }
samux 11:a26e7b7a1221 49
samux 11:a26e7b7a1221 50 // We reactivate the endpoint to receive next characters
samux 11:a26e7b7a1221 51 readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
samux 11:a26e7b7a1221 52 return true;
samux 11:a26e7b7a1221 53 }
samux 11:a26e7b7a1221 54
samux 11:a26e7b7a1221 55
samux 11:a26e7b7a1221 56
samux 11:a26e7b7a1221 57 // Called in ISR context
samux 11:a26e7b7a1221 58 // Set configuration. Return false if the
samux 11:a26e7b7a1221 59 // configuration is not supported.
samux 11:a26e7b7a1221 60 bool USBMIDI::USBCallback_setConfiguration(uint8_t configuration) {
samux 11:a26e7b7a1221 61 if (configuration != DEFAULT_CONFIGURATION) {
samux 11:a26e7b7a1221 62 return false;
samux 11:a26e7b7a1221 63 }
samux 11:a26e7b7a1221 64
samux 11:a26e7b7a1221 65 // Configure endpoints > 0
samux 11:a26e7b7a1221 66 addEndpoint(EPBULK_IN, MAX_PACKET_SIZE_EPBULK);
samux 11:a26e7b7a1221 67 addEndpoint(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
samux 11:a26e7b7a1221 68
samux 11:a26e7b7a1221 69 // We activate the endpoint to be able to receive data
samux 11:a26e7b7a1221 70 readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
samux 11:a26e7b7a1221 71 return true;
samux 11:a26e7b7a1221 72 }
samux 11:a26e7b7a1221 73
samux 11:a26e7b7a1221 74
samux 11:a26e7b7a1221 75 uint8_t * USBMIDI::stringIinterfaceDesc() {
samux 11:a26e7b7a1221 76 static uint8_t stringIinterfaceDescriptor[] = {
samux 11:a26e7b7a1221 77 0x0c, //bLength
samux 11:a26e7b7a1221 78 STRING_DESCRIPTOR, //bDescriptorType 0x03
samux 11:a26e7b7a1221 79 'A',0,'u',0,'d',0,'i',0,'o',0 //bString iInterface - Audio
samux 11:a26e7b7a1221 80 };
samux 11:a26e7b7a1221 81 return stringIinterfaceDescriptor;
samux 11:a26e7b7a1221 82 }
samux 11:a26e7b7a1221 83
samux 11:a26e7b7a1221 84 uint8_t * USBMIDI::stringIproductDesc() {
samux 11:a26e7b7a1221 85 static uint8_t stringIproductDescriptor[] = {
samux 11:a26e7b7a1221 86 0x16, //bLength
samux 11:a26e7b7a1221 87 STRING_DESCRIPTOR, //bDescriptorType 0x03
samux 11:a26e7b7a1221 88 'M',0,'b',0,'e',0,'d',0,' ',0,'A',0,'u',0,'d',0,'i',0,'o',0 //bString iProduct - Mbed Audio
samux 11:a26e7b7a1221 89 };
samux 11:a26e7b7a1221 90 return stringIproductDescriptor;
samux 11:a26e7b7a1221 91 }
samux 11:a26e7b7a1221 92
samux 11:a26e7b7a1221 93
samux 11:a26e7b7a1221 94 uint8_t * USBMIDI::configurationDesc() {
samux 11:a26e7b7a1221 95 static uint8_t configDescriptor[] = {
samux 11:a26e7b7a1221 96 // configuration descriptor
samux 11:a26e7b7a1221 97 0x09, 0x02, 0x65, 0x00, 0x02, 0x01, 0x00, 0xc0, 0x50,
samux 11:a26e7b7a1221 98
samux 11:a26e7b7a1221 99 // The Audio Interface Collection
samux 11:a26e7b7a1221 100 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, // Standard AC Interface Descriptor
samux 11:a26e7b7a1221 101 0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, // Class-specific AC Interface Descriptor
samux 11:a26e7b7a1221 102 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, // MIDIStreaming Interface Descriptors
samux 11:a26e7b7a1221 103 0x07, 0x24, 0x01, 0x00, 0x01, 0x41, 0x00, // Class-Specific MS Interface Header Descriptor
samux 11:a26e7b7a1221 104
samux 11:a26e7b7a1221 105 // MIDI IN JACKS
samux 11:a26e7b7a1221 106 0x06, 0x24, 0x02, 0x01, 0x01, 0x00,
samux 11:a26e7b7a1221 107 0x06, 0x24, 0x02, 0x02, 0x02, 0x00,
samux 11:a26e7b7a1221 108
samux 11:a26e7b7a1221 109 // MIDI OUT JACKS
samux 11:a26e7b7a1221 110 0x09, 0x24, 0x03, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00,
samux 11:a26e7b7a1221 111 0x09, 0x24, 0x03, 0x02, 0x06, 0x01, 0x01, 0x01, 0x00,
samux 11:a26e7b7a1221 112
samux 11:a26e7b7a1221 113 // OUT endpoint descriptor
samux 11:a26e7b7a1221 114 0x09, 0x05, 0x02, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00,
samux 11:a26e7b7a1221 115 0x05, 0x25, 0x01, 0x01, 0x01,
samux 11:a26e7b7a1221 116
samux 11:a26e7b7a1221 117 // IN endpoint descriptor
samux 11:a26e7b7a1221 118 0x09, 0x05, 0x82, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00,
samux 11:a26e7b7a1221 119 0x05, 0x25, 0x01, 0x01, 0x03,
samux 11:a26e7b7a1221 120 };
samux 11:a26e7b7a1221 121 return configDescriptor;
samux 11:a26e7b7a1221 122 }