blablabla

Dependencies:   MAG3110 MMA8451Q SLCD- TSI USBDevice mbed

Committer:
Osator
Date:
Wed Apr 16 12:20:00 2014 +0000
Revision:
0:339b7abfa147
blablabla

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Osator 0:339b7abfa147 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
Osator 0:339b7abfa147 2 *
Osator 0:339b7abfa147 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Osator 0:339b7abfa147 4 * and associated documentation files (the "Software"), to deal in the Software without
Osator 0:339b7abfa147 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
Osator 0:339b7abfa147 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Osator 0:339b7abfa147 7 * Software is furnished to do so, subject to the following conditions:
Osator 0:339b7abfa147 8 *
Osator 0:339b7abfa147 9 * The above copyright notice and this permission notice shall be included in all copies or
Osator 0:339b7abfa147 10 * substantial portions of the Software.
Osator 0:339b7abfa147 11 *
Osator 0:339b7abfa147 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Osator 0:339b7abfa147 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Osator 0:339b7abfa147 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Osator 0:339b7abfa147 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Osator 0:339b7abfa147 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Osator 0:339b7abfa147 17 */
Osator 0:339b7abfa147 18
Osator 0:339b7abfa147 19 #include "stdint.h"
Osator 0:339b7abfa147 20 #include "USBMIDI.h"
Osator 0:339b7abfa147 21
Osator 0:339b7abfa147 22
Osator 0:339b7abfa147 23 USBMIDI::USBMIDI(uint16_t vendor_id, uint16_t product_id, uint16_t product_release): USBDevice(vendor_id, product_id, product_release) {
Osator 0:339b7abfa147 24 midi_evt = NULL;
Osator 0:339b7abfa147 25 USBDevice::connect();
Osator 0:339b7abfa147 26 }
Osator 0:339b7abfa147 27
Osator 0:339b7abfa147 28 void USBMIDI::write(MIDIMessage m) {
Osator 0:339b7abfa147 29 USBDevice::write(EPBULK_IN, m.data, 4, MAX_PACKET_SIZE_EPBULK);
Osator 0:339b7abfa147 30 }
Osator 0:339b7abfa147 31
Osator 0:339b7abfa147 32
Osator 0:339b7abfa147 33 void USBMIDI::attach(void (*fptr)(MIDIMessage)) {
Osator 0:339b7abfa147 34 midi_evt = fptr;
Osator 0:339b7abfa147 35 }
Osator 0:339b7abfa147 36
Osator 0:339b7abfa147 37
Osator 0:339b7abfa147 38 bool USBMIDI::EP2_OUT_callback() {
Osator 0:339b7abfa147 39 uint8_t buf[64];
Osator 0:339b7abfa147 40 uint32_t len;
Osator 0:339b7abfa147 41 readEP(EPBULK_OUT, buf, &len, 64);
Osator 0:339b7abfa147 42
Osator 0:339b7abfa147 43 if (midi_evt != NULL) {
Osator 0:339b7abfa147 44 for (uint32_t i=0; i<len; i+=4) {
Osator 0:339b7abfa147 45 midi_evt(MIDIMessage(buf+i));
Osator 0:339b7abfa147 46 }
Osator 0:339b7abfa147 47 }
Osator 0:339b7abfa147 48
Osator 0:339b7abfa147 49 // We reactivate the endpoint to receive next characters
Osator 0:339b7abfa147 50 readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
Osator 0:339b7abfa147 51 return true;
Osator 0:339b7abfa147 52 }
Osator 0:339b7abfa147 53
Osator 0:339b7abfa147 54
Osator 0:339b7abfa147 55
Osator 0:339b7abfa147 56 // Called in ISR context
Osator 0:339b7abfa147 57 // Set configuration. Return false if the
Osator 0:339b7abfa147 58 // configuration is not supported.
Osator 0:339b7abfa147 59 bool USBMIDI::USBCallback_setConfiguration(uint8_t configuration) {
Osator 0:339b7abfa147 60 if (configuration != DEFAULT_CONFIGURATION) {
Osator 0:339b7abfa147 61 return false;
Osator 0:339b7abfa147 62 }
Osator 0:339b7abfa147 63
Osator 0:339b7abfa147 64 // Configure endpoints > 0
Osator 0:339b7abfa147 65 addEndpoint(EPBULK_IN, MAX_PACKET_SIZE_EPBULK);
Osator 0:339b7abfa147 66 addEndpoint(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
Osator 0:339b7abfa147 67
Osator 0:339b7abfa147 68 // We activate the endpoint to be able to receive data
Osator 0:339b7abfa147 69 readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
Osator 0:339b7abfa147 70 return true;
Osator 0:339b7abfa147 71 }
Osator 0:339b7abfa147 72
Osator 0:339b7abfa147 73
Osator 0:339b7abfa147 74 uint8_t * USBMIDI::stringIinterfaceDesc() {
Osator 0:339b7abfa147 75 static uint8_t stringIinterfaceDescriptor[] = {
Osator 0:339b7abfa147 76 0x0c, //bLength
Osator 0:339b7abfa147 77 STRING_DESCRIPTOR, //bDescriptorType 0x03
Osator 0:339b7abfa147 78 'A',0,'u',0,'d',0,'i',0,'o',0 //bString iInterface - Audio
Osator 0:339b7abfa147 79 };
Osator 0:339b7abfa147 80 return stringIinterfaceDescriptor;
Osator 0:339b7abfa147 81 }
Osator 0:339b7abfa147 82
Osator 0:339b7abfa147 83 uint8_t * USBMIDI::stringIproductDesc() {
Osator 0:339b7abfa147 84 static uint8_t stringIproductDescriptor[] = {
Osator 0:339b7abfa147 85 0x16, //bLength
Osator 0:339b7abfa147 86 STRING_DESCRIPTOR, //bDescriptorType 0x03
Osator 0:339b7abfa147 87 'M',0,'b',0,'e',0,'d',0,' ',0,'A',0,'u',0,'d',0,'i',0,'o',0 //bString iProduct - Mbed Audio
Osator 0:339b7abfa147 88 };
Osator 0:339b7abfa147 89 return stringIproductDescriptor;
Osator 0:339b7abfa147 90 }
Osator 0:339b7abfa147 91
Osator 0:339b7abfa147 92
Osator 0:339b7abfa147 93 uint8_t * USBMIDI::configurationDesc() {
Osator 0:339b7abfa147 94 static uint8_t configDescriptor[] = {
Osator 0:339b7abfa147 95 // configuration descriptor
Osator 0:339b7abfa147 96 0x09, 0x02, 0x65, 0x00, 0x02, 0x01, 0x00, 0xc0, 0x50,
Osator 0:339b7abfa147 97
Osator 0:339b7abfa147 98 // The Audio Interface Collection
Osator 0:339b7abfa147 99 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, // Standard AC Interface Descriptor
Osator 0:339b7abfa147 100 0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, // Class-specific AC Interface Descriptor
Osator 0:339b7abfa147 101 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, // MIDIStreaming Interface Descriptors
Osator 0:339b7abfa147 102 0x07, 0x24, 0x01, 0x00, 0x01, 0x41, 0x00, // Class-Specific MS Interface Header Descriptor
Osator 0:339b7abfa147 103
Osator 0:339b7abfa147 104 // MIDI IN JACKS
Osator 0:339b7abfa147 105 0x06, 0x24, 0x02, 0x01, 0x01, 0x00,
Osator 0:339b7abfa147 106 0x06, 0x24, 0x02, 0x02, 0x02, 0x00,
Osator 0:339b7abfa147 107
Osator 0:339b7abfa147 108 // MIDI OUT JACKS
Osator 0:339b7abfa147 109 0x09, 0x24, 0x03, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00,
Osator 0:339b7abfa147 110 0x09, 0x24, 0x03, 0x02, 0x06, 0x01, 0x01, 0x01, 0x00,
Osator 0:339b7abfa147 111
Osator 0:339b7abfa147 112 // OUT endpoint descriptor
Osator 0:339b7abfa147 113 0x09, 0x05, 0x02, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00,
Osator 0:339b7abfa147 114 0x05, 0x25, 0x01, 0x01, 0x01,
Osator 0:339b7abfa147 115
Osator 0:339b7abfa147 116 // IN endpoint descriptor
Osator 0:339b7abfa147 117 0x09, 0x05, 0x82, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00,
Osator 0:339b7abfa147 118 0x05, 0x25, 0x01, 0x01, 0x03,
Osator 0:339b7abfa147 119 };
Osator 0:339b7abfa147 120 return configDescriptor;
Osator 0:339b7abfa147 121 }