Base station firmware

Committer:
Perijah
Date:
Tue May 24 13:16:55 2016 +0000
Revision:
0:ecc3925d3f8c
Base station firmware

Who changed what in which revision?

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