KL46Z-lab2

Dependencies:   SLCD- mbed TSI MMA8451Q USBDevice MAG3110

Committer:
Lokkus
Date:
Thu Feb 21 07:41:00 2019 +0000
Revision:
0:29277ae50860
KL46Z-lab2

Who changed what in which revision?

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