USB Serial application

Fork of USBSerial_HelloWorld by Samuel Mokrani

Committer:
Zaitsev
Date:
Sat Dec 16 10:26:48 2017 +0000
Revision:
11:b3f2a8bdac4d
Parent:
10:41552d038a69
A copy for D.S;

Who changed what in which revision?

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