max4146x_comp

Dependencies:   MAX14690

Committer:
sdivarci
Date:
Sun Oct 25 20:10:02 2020 +0000
Revision:
0:0061165683ee
sdivarci

Who changed what in which revision?

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