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