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