EA BaseBoard, playing wav, PC see\'s SD-card through USB port.

Dependencies:   mbed

Committer:
Lerche
Date:
Tue Nov 22 05:45:58 2011 +0000
Revision:
0:fef366d2ed20
Thanks to those who provided EA_WavPlayer and USB_MSC

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Lerche 0:fef366d2ed20 1 // USB_MIDI.cpp
Lerche 0:fef366d2ed20 2 // MIDI edvice example
Lerche 0:fef366d2ed20 3 // Copyright (c) 2011 ARM Limited. All rights reserved.
Lerche 0:fef366d2ed20 4
Lerche 0:fef366d2ed20 5 #include "stdint.h"
Lerche 0:fef366d2ed20 6 #include "USBMIDI.h"
Lerche 0:fef366d2ed20 7 #include "USBBusInterface.h"
Lerche 0:fef366d2ed20 8
Lerche 0:fef366d2ed20 9
Lerche 0:fef366d2ed20 10 USBMIDI::USBMIDI(uint16_t vendor_id, uint16_t product_id, uint16_t product_release): USBDevice(vendor_id, product_id, product_release) {
Lerche 0:fef366d2ed20 11 midi_evt = NULL;
Lerche 0:fef366d2ed20 12 }
Lerche 0:fef366d2ed20 13
Lerche 0:fef366d2ed20 14 void USBMIDI::write(MIDIMessage m) {
Lerche 0:fef366d2ed20 15 USBDevice::write(EPBULK_IN, m.data, 4, MAX_PACKET_SIZE_EPBULK);
Lerche 0:fef366d2ed20 16 }
Lerche 0:fef366d2ed20 17
Lerche 0:fef366d2ed20 18
Lerche 0:fef366d2ed20 19 void USBMIDI::attach(void (*fptr)(MIDIMessage)) {
Lerche 0:fef366d2ed20 20 midi_evt = fptr;
Lerche 0:fef366d2ed20 21 }
Lerche 0:fef366d2ed20 22
Lerche 0:fef366d2ed20 23
Lerche 0:fef366d2ed20 24 bool USBMIDI::EPBULK_OUT_callback() {
Lerche 0:fef366d2ed20 25 uint8_t buf[64];
Lerche 0:fef366d2ed20 26 uint16_t len;
Lerche 0:fef366d2ed20 27 read(EPBULK_OUT, buf, &len, 64);
Lerche 0:fef366d2ed20 28
Lerche 0:fef366d2ed20 29 if (midi_evt != NULL) {
Lerche 0:fef366d2ed20 30 for (int i=0; i<len; i+=4) {
Lerche 0:fef366d2ed20 31 midi_evt(MIDIMessage(buf+i));
Lerche 0:fef366d2ed20 32 }
Lerche 0:fef366d2ed20 33 }
Lerche 0:fef366d2ed20 34
Lerche 0:fef366d2ed20 35 // We reactivate the endpoint to receive next characters
Lerche 0:fef366d2ed20 36 readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
Lerche 0:fef366d2ed20 37 return true;
Lerche 0:fef366d2ed20 38 }
Lerche 0:fef366d2ed20 39
Lerche 0:fef366d2ed20 40
Lerche 0:fef366d2ed20 41
Lerche 0:fef366d2ed20 42 bool USBMIDI::USBCallback_setConfiguration(uint8_t configuration) {
Lerche 0:fef366d2ed20 43 // Called in ISR context
Lerche 0:fef366d2ed20 44 // Set configuration. Return false if the
Lerche 0:fef366d2ed20 45 // configuration is not supported.
Lerche 0:fef366d2ed20 46 if (configuration != DEFAULT_CONFIGURATION) {
Lerche 0:fef366d2ed20 47 return false;
Lerche 0:fef366d2ed20 48 }
Lerche 0:fef366d2ed20 49
Lerche 0:fef366d2ed20 50 // Configure endpoints > 0
Lerche 0:fef366d2ed20 51 addEndpoint(EPBULK_IN, MAX_PACKET_SIZE_EPBULK);
Lerche 0:fef366d2ed20 52 addEndpoint(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
Lerche 0:fef366d2ed20 53
Lerche 0:fef366d2ed20 54 // We activate the endpoint to be able to receive data
Lerche 0:fef366d2ed20 55 readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
Lerche 0:fef366d2ed20 56 return true;
Lerche 0:fef366d2ed20 57 }
Lerche 0:fef366d2ed20 58
Lerche 0:fef366d2ed20 59
Lerche 0:fef366d2ed20 60 uint8_t * USBMIDI::stringIinterfaceDesc() {
Lerche 0:fef366d2ed20 61 static uint8_t stringIinterfaceDescriptor[] = {
Lerche 0:fef366d2ed20 62 0x0c, //bLength
Lerche 0:fef366d2ed20 63 STRING_DESCRIPTOR, //bDescriptorType 0x03
Lerche 0:fef366d2ed20 64 'A',0,'u',0,'d',0,'i',0,'o',0 //bString iInterface - Audio
Lerche 0:fef366d2ed20 65 };
Lerche 0:fef366d2ed20 66 return stringIinterfaceDescriptor;
Lerche 0:fef366d2ed20 67 }
Lerche 0:fef366d2ed20 68
Lerche 0:fef366d2ed20 69 uint8_t * USBMIDI::stringIproductDesc() {
Lerche 0:fef366d2ed20 70 static uint8_t stringIproductDescriptor[] = {
Lerche 0:fef366d2ed20 71 0x16, //bLength
Lerche 0:fef366d2ed20 72 STRING_DESCRIPTOR, //bDescriptorType 0x03
Lerche 0:fef366d2ed20 73 'M',0,'b',0,'e',0,'d',0,' ',0,'A',0,'u',0,'d',0,'i',0,'o',0 //bString iProduct - Mbed Audio
Lerche 0:fef366d2ed20 74 };
Lerche 0:fef366d2ed20 75 return stringIproductDescriptor;
Lerche 0:fef366d2ed20 76 }
Lerche 0:fef366d2ed20 77
Lerche 0:fef366d2ed20 78
Lerche 0:fef366d2ed20 79 uint8_t * USBMIDI::configurationDesc() {
Lerche 0:fef366d2ed20 80 static uint8_t configDescriptor[] = {
Lerche 0:fef366d2ed20 81 // configuration descriptor
Lerche 0:fef366d2ed20 82 0x09, 0x02, 0x65, 0x00, 0x02, 0x01, 0x00, 0xc0, 0x50,
Lerche 0:fef366d2ed20 83
Lerche 0:fef366d2ed20 84 // The Audio Interface Collection
Lerche 0:fef366d2ed20 85 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, // Standard AC Interface Descriptor
Lerche 0:fef366d2ed20 86 0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, // Class-specific AC Interface Descriptor
Lerche 0:fef366d2ed20 87 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, // MIDIStreaming Interface Descriptors
Lerche 0:fef366d2ed20 88 0x07, 0x24, 0x01, 0x00, 0x01, 0x41, 0x00, // Class-Specific MS Interface Header Descriptor
Lerche 0:fef366d2ed20 89
Lerche 0:fef366d2ed20 90 // MIDI IN JACKS
Lerche 0:fef366d2ed20 91 0x06, 0x24, 0x02, 0x01, 0x01, 0x00,
Lerche 0:fef366d2ed20 92 0x06, 0x24, 0x02, 0x02, 0x02, 0x00,
Lerche 0:fef366d2ed20 93
Lerche 0:fef366d2ed20 94 // MIDI OUT JACKS
Lerche 0:fef366d2ed20 95 0x09, 0x24, 0x03, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00,
Lerche 0:fef366d2ed20 96 0x09, 0x24, 0x03, 0x02, 0x06, 0x01, 0x01, 0x01, 0x00,
Lerche 0:fef366d2ed20 97
Lerche 0:fef366d2ed20 98 // OUT endpoint descriptor
Lerche 0:fef366d2ed20 99 0x09, 0x05, 0x02, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00,
Lerche 0:fef366d2ed20 100 0x05, 0x25, 0x01, 0x01, 0x01,
Lerche 0:fef366d2ed20 101
Lerche 0:fef366d2ed20 102 // IN endpoint descriptor
Lerche 0:fef366d2ed20 103 0x09, 0x05, 0x82, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00,
Lerche 0:fef366d2ed20 104 0x05, 0x25, 0x01, 0x01, 0x03,
Lerche 0:fef366d2ed20 105 };
Lerche 0:fef366d2ed20 106 return configDescriptor;
Lerche 0:fef366d2ed20 107 }