USBMSD SD card Hello World for Mbed platforms

Dependencies:   mbed USBMSD_SD USBDevice

Committer:
samux
Date:
Fri Nov 11 15:22:53 2011 +0000
Revision:
2:27a7e7f8d399
we have 2MB with the sdcard!!

Who changed what in which revision?

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