USB device stack
Dependents: blinky_max32630fthr FTHR_USB_serial FTHR_OLED HSP_RPC_GUI_3_0_1 ... more
Fork of USBDevice by
USBMIDI.h
00001 /* Copyright (c) 2010-2011 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #ifndef USBMIDI_H 00020 #define USBMIDI_H 00021 00022 /* These headers are included for child class. */ 00023 #include "USBEndpoints.h" 00024 #include "USBDescriptor.h" 00025 #include "USBDevice_Types.h" 00026 00027 #include "USBDevice.h" 00028 #include "MIDIMessage.h" 00029 00030 #define DEFAULT_CONFIGURATION (1) 00031 00032 /** 00033 * USBMIDI example 00034 * 00035 * @code 00036 * #include "mbed.h" 00037 * #include "USBMIDI.h" 00038 * 00039 * USBMIDI midi; 00040 * 00041 * int main() { 00042 * while (1) { 00043 * for(int i=48; i<83; i++) { // send some messages! 00044 * midi.write(MIDIMessage::NoteOn(i)); 00045 * wait(0.25); 00046 * midi.write(MIDIMessage::NoteOff(i)); 00047 * wait(0.5); 00048 * } 00049 * } 00050 * } 00051 * @endcode 00052 */ 00053 class USBMIDI: public USBDevice { 00054 public: 00055 00056 /** 00057 * Constructor 00058 * 00059 * @param vendor_id Your vendor_id 00060 * @param product_id Your product_id 00061 * @param product_release Your preoduct_release 00062 */ 00063 USBMIDI(uint16_t vendor_id = 0x0700, uint16_t product_id = 0x0101, uint16_t product_release = 0x0001); 00064 00065 /** 00066 * Send a MIDIMessage 00067 * 00068 * @param m The MIDIMessage to send 00069 */ 00070 void write(MIDIMessage m); 00071 00072 /** 00073 * Attach a callback for when a MIDIEvent is received 00074 * 00075 * @param fptr function pointer 00076 */ 00077 void attach(void (*fptr)(MIDIMessage)); 00078 00079 00080 protected: 00081 virtual bool EPBULK_OUT_callback(); 00082 virtual bool USBCallback_setConfiguration(uint8_t configuration); 00083 /* 00084 * Get string product descriptor 00085 * 00086 * @returns pointer to the string product descriptor 00087 */ 00088 virtual uint8_t * stringIproductDesc(); 00089 00090 /* 00091 * Get string interface descriptor 00092 * 00093 * @returns pointer to the string interface descriptor 00094 */ 00095 virtual uint8_t * stringIinterfaceDesc(); 00096 00097 /* 00098 * Get configuration descriptor 00099 * 00100 * @returns pointer to the configuration descriptor 00101 */ 00102 virtual uint8_t * configurationDesc(); 00103 00104 private: 00105 uint8_t data[MAX_MIDI_MESSAGE_SIZE+1]; 00106 uint8_t cur_data; 00107 bool data_end; 00108 00109 void (*midi_evt)(MIDIMessage); 00110 }; 00111 00112 #endif
Generated on Wed Jul 13 2022 12:44:03 by 1.7.2