Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:27:58 2016 +0000
Revision:
0:6c56fb4bc5f0
Moving to library for sharing updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 0:6c56fb4bc5f0 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
nexpaq 0:6c56fb4bc5f0 2 *
nexpaq 0:6c56fb4bc5f0 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
nexpaq 0:6c56fb4bc5f0 4 * and associated documentation files (the "Software"), to deal in the Software without
nexpaq 0:6c56fb4bc5f0 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
nexpaq 0:6c56fb4bc5f0 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
nexpaq 0:6c56fb4bc5f0 7 * Software is furnished to do so, subject to the following conditions:
nexpaq 0:6c56fb4bc5f0 8 *
nexpaq 0:6c56fb4bc5f0 9 * The above copyright notice and this permission notice shall be included in all copies or
nexpaq 0:6c56fb4bc5f0 10 * substantial portions of the Software.
nexpaq 0:6c56fb4bc5f0 11 *
nexpaq 0:6c56fb4bc5f0 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
nexpaq 0:6c56fb4bc5f0 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
nexpaq 0:6c56fb4bc5f0 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
nexpaq 0:6c56fb4bc5f0 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
nexpaq 0:6c56fb4bc5f0 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
nexpaq 0:6c56fb4bc5f0 17 */
nexpaq 0:6c56fb4bc5f0 18
nexpaq 0:6c56fb4bc5f0 19 #ifndef USBMIDI_H
nexpaq 0:6c56fb4bc5f0 20 #define USBMIDI_H
nexpaq 0:6c56fb4bc5f0 21
nexpaq 0:6c56fb4bc5f0 22 /* These headers are included for child class. */
nexpaq 0:6c56fb4bc5f0 23 #include "USBEndpoints.h"
nexpaq 0:6c56fb4bc5f0 24 #include "USBDescriptor.h"
nexpaq 0:6c56fb4bc5f0 25 #include "USBDevice_Types.h"
nexpaq 0:6c56fb4bc5f0 26
nexpaq 0:6c56fb4bc5f0 27 #include "USBDevice.h"
nexpaq 0:6c56fb4bc5f0 28 #include "MIDIMessage.h"
nexpaq 0:6c56fb4bc5f0 29
nexpaq 0:6c56fb4bc5f0 30 #define DEFAULT_CONFIGURATION (1)
nexpaq 0:6c56fb4bc5f0 31
nexpaq 0:6c56fb4bc5f0 32 /**
nexpaq 0:6c56fb4bc5f0 33 * USBMIDI example
nexpaq 0:6c56fb4bc5f0 34 *
nexpaq 0:6c56fb4bc5f0 35 * @code
nexpaq 0:6c56fb4bc5f0 36 * #include "mbed.h"
nexpaq 0:6c56fb4bc5f0 37 * #include "USBMIDI.h"
nexpaq 0:6c56fb4bc5f0 38 *
nexpaq 0:6c56fb4bc5f0 39 * USBMIDI midi;
nexpaq 0:6c56fb4bc5f0 40 *
nexpaq 0:6c56fb4bc5f0 41 * int main() {
nexpaq 0:6c56fb4bc5f0 42 * while (1) {
nexpaq 0:6c56fb4bc5f0 43 * for(int i=48; i<83; i++) { // send some messages!
nexpaq 0:6c56fb4bc5f0 44 * midi.write(MIDIMessage::NoteOn(i));
nexpaq 0:6c56fb4bc5f0 45 * wait(0.25);
nexpaq 0:6c56fb4bc5f0 46 * midi.write(MIDIMessage::NoteOff(i));
nexpaq 0:6c56fb4bc5f0 47 * wait(0.5);
nexpaq 0:6c56fb4bc5f0 48 * }
nexpaq 0:6c56fb4bc5f0 49 * }
nexpaq 0:6c56fb4bc5f0 50 * }
nexpaq 0:6c56fb4bc5f0 51 * @endcode
nexpaq 0:6c56fb4bc5f0 52 */
nexpaq 0:6c56fb4bc5f0 53 class USBMIDI: public USBDevice {
nexpaq 0:6c56fb4bc5f0 54 public:
nexpaq 0:6c56fb4bc5f0 55
nexpaq 0:6c56fb4bc5f0 56 /**
nexpaq 0:6c56fb4bc5f0 57 * Constructor
nexpaq 0:6c56fb4bc5f0 58 *
nexpaq 0:6c56fb4bc5f0 59 * @param vendor_id Your vendor_id
nexpaq 0:6c56fb4bc5f0 60 * @param product_id Your product_id
nexpaq 0:6c56fb4bc5f0 61 * @param product_release Your preoduct_release
nexpaq 0:6c56fb4bc5f0 62 */
nexpaq 0:6c56fb4bc5f0 63 USBMIDI(uint16_t vendor_id = 0x0700, uint16_t product_id = 0x0101, uint16_t product_release = 0x0001);
nexpaq 0:6c56fb4bc5f0 64
nexpaq 0:6c56fb4bc5f0 65 /**
nexpaq 0:6c56fb4bc5f0 66 * Send a MIDIMessage
nexpaq 0:6c56fb4bc5f0 67 *
nexpaq 0:6c56fb4bc5f0 68 * @param m The MIDIMessage to send
nexpaq 0:6c56fb4bc5f0 69 */
nexpaq 0:6c56fb4bc5f0 70 void write(MIDIMessage m);
nexpaq 0:6c56fb4bc5f0 71
nexpaq 0:6c56fb4bc5f0 72 /**
nexpaq 0:6c56fb4bc5f0 73 * Attach a callback for when a MIDIEvent is received
nexpaq 0:6c56fb4bc5f0 74 *
nexpaq 0:6c56fb4bc5f0 75 * @param fptr function pointer
nexpaq 0:6c56fb4bc5f0 76 */
nexpaq 0:6c56fb4bc5f0 77 void attach(void (*fptr)(MIDIMessage));
nexpaq 0:6c56fb4bc5f0 78
nexpaq 0:6c56fb4bc5f0 79
nexpaq 0:6c56fb4bc5f0 80 protected:
nexpaq 0:6c56fb4bc5f0 81 virtual bool EPBULK_OUT_callback();
nexpaq 0:6c56fb4bc5f0 82 virtual bool USBCallback_setConfiguration(uint8_t configuration);
nexpaq 0:6c56fb4bc5f0 83 /*
nexpaq 0:6c56fb4bc5f0 84 * Get string product descriptor
nexpaq 0:6c56fb4bc5f0 85 *
nexpaq 0:6c56fb4bc5f0 86 * @returns pointer to the string product descriptor
nexpaq 0:6c56fb4bc5f0 87 */
nexpaq 0:6c56fb4bc5f0 88 virtual uint8_t * stringIproductDesc();
nexpaq 0:6c56fb4bc5f0 89
nexpaq 0:6c56fb4bc5f0 90 /*
nexpaq 0:6c56fb4bc5f0 91 * Get string interface descriptor
nexpaq 0:6c56fb4bc5f0 92 *
nexpaq 0:6c56fb4bc5f0 93 * @returns pointer to the string interface descriptor
nexpaq 0:6c56fb4bc5f0 94 */
nexpaq 0:6c56fb4bc5f0 95 virtual uint8_t * stringIinterfaceDesc();
nexpaq 0:6c56fb4bc5f0 96
nexpaq 0:6c56fb4bc5f0 97 /*
nexpaq 0:6c56fb4bc5f0 98 * Get configuration descriptor
nexpaq 0:6c56fb4bc5f0 99 *
nexpaq 0:6c56fb4bc5f0 100 * @returns pointer to the configuration descriptor
nexpaq 0:6c56fb4bc5f0 101 */
nexpaq 0:6c56fb4bc5f0 102 virtual uint8_t * configurationDesc();
nexpaq 0:6c56fb4bc5f0 103
nexpaq 0:6c56fb4bc5f0 104 private:
nexpaq 0:6c56fb4bc5f0 105 uint8_t data[MAX_MIDI_MESSAGE_SIZE+1];
nexpaq 0:6c56fb4bc5f0 106 uint8_t cur_data;
nexpaq 0:6c56fb4bc5f0 107 bool data_end;
nexpaq 0:6c56fb4bc5f0 108
nexpaq 0:6c56fb4bc5f0 109 void (*midi_evt)(MIDIMessage);
nexpaq 0:6c56fb4bc5f0 110 };
nexpaq 0:6c56fb4bc5f0 111
nexpaq 0:6c56fb4bc5f0 112 #endif