ryou sato / Mbed 2 deprecated LPC11U35_CTswitch_relay

Dependencies:   mbed LPC11U35_MCP41HV51-503EST

Committer:
ryousato
Date:
Tue Mar 09 05:40:47 2021 +0000
Revision:
9:0b3a7a9eed3e
Parent:
0:df1e1f84ded8
20210309

Who changed what in which revision?

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