mbed os with nrf51 internal bandgap enabled to read battery level

Dependents:   BLE_file_test BLE_Blink ExternalEncoder

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

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