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