Kalibriersoftware Stromwerte

Dependencies:   Matrix mbed

Committer:
Racer01014
Date:
Mon Nov 23 16:09:54 2015 +0000
Revision:
0:5e35c180ed4a
-

Who changed what in which revision?

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