Pinscape Controller version 1 fork. This is a fork to allow for ongoing bug fixes to the original controller version, from before the major changes for the expansion board project.

Dependencies:   FastIO FastPWM SimpleDMA mbed

Fork of Pinscape_Controller by Mike R

Committer:
mjr
Date:
Thu Feb 11 18:12:52 2016 +0000
Revision:
52:63f0a9b45f0c
Convert FastAnalogIn and USBDevice libraries to folders

Who changed what in which revision?

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