Sensor reporting over USB CDC

Dependencies:   MAG3110 MMA8451Q SLCD- TSI USBDevice mbed

Committer:
wue
Date:
Wed Apr 16 12:20:12 2014 +0000
Revision:
0:7b58cdacf811
Sensor reporting over USB CDC

Who changed what in which revision?

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