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