USBDevice for STM support

Dependents:   Nucleo_Usb_JoyMouse Nucleo_usbmouse ELEC350_1-referral-2018-usb-hid USBJoystick_HelloWorld2_wip ... more

This library contains all mbed usb device library (mbed-os\features\unsupported\USBDevice).

Committer:
frq08711@LMECWL0871.LME.ST.COM
Date:
Thu Dec 15 17:40:59 2016 +0100
Revision:
1:2a3ae13b45ef
copy of git hub directory unsupported/USBDevice

Who changed what in which revision?

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