LPC11U35 ADC Tick & USBSerial

Dependencies:   mbed

Dependents:   SmallDoseMeter_SingleCH_AE_lpc11u35_V1_00

Committer:
H_Tsunemoto
Date:
Mon Feb 19 09:09:52 2018 +0000
Revision:
1:b1a3be5f48ab
Parent:
0:871ab6846b18
test

Who changed what in which revision?

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