The preloaded firmware shipped on the mBot.

Dependencies:   mbed

Fork of Official_mBot by Fred Parker

Committer:
jeffknaggs
Date:
Tue Nov 25 14:49:40 2014 +0000
Revision:
1:ffd9a51e7d35
Parent:
0:865d42c46692
Initial commit.

Who changed what in which revision?

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