BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Committer:
gustavatmel
Date:
Tue May 01 15:55:34 2018 +0000
Revision:
2:798925c9e4a8
Parent:
1:9c5af431a1f1
bluetooth

Who changed what in which revision?

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