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 USB_HID_H
elessair 0:f269e3021894 20 #define USB_HID_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 "USBHID_Types.h"
elessair 0:f269e3021894 28 #include "USBDevice.h"
elessair 0:f269e3021894 29
elessair 0:f269e3021894 30
elessair 0:f269e3021894 31 /**
elessair 0:f269e3021894 32 * USBHID example
elessair 0:f269e3021894 33 * @code
elessair 0:f269e3021894 34 * #include "mbed.h"
elessair 0:f269e3021894 35 * #include "USBHID.h"
elessair 0:f269e3021894 36 *
elessair 0:f269e3021894 37 * USBHID hid;
elessair 0:f269e3021894 38 * HID_REPORT recv;
elessair 0:f269e3021894 39 * BusOut leds(LED1,LED2,LED3,LED4);
elessair 0:f269e3021894 40 *
elessair 0:f269e3021894 41 * int main(void) {
elessair 0:f269e3021894 42 * while (1) {
elessair 0:f269e3021894 43 * hid.read(&recv);
elessair 0:f269e3021894 44 * leds = recv.data[0];
elessair 0:f269e3021894 45 * }
elessair 0:f269e3021894 46 * }
elessair 0:f269e3021894 47 * @endcode
elessair 0:f269e3021894 48 */
elessair 0:f269e3021894 49
elessair 0:f269e3021894 50 class USBHID: public USBDevice {
elessair 0:f269e3021894 51 public:
elessair 0:f269e3021894 52
elessair 0:f269e3021894 53 /**
elessair 0:f269e3021894 54 * Constructor
elessair 0:f269e3021894 55 *
elessair 0:f269e3021894 56 * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes)
elessair 0:f269e3021894 57 * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes)
elessair 0:f269e3021894 58 * @param vendor_id Your vendor_id
elessair 0:f269e3021894 59 * @param product_id Your product_id
elessair 0:f269e3021894 60 * @param product_release Your preoduct_release
elessair 0:f269e3021894 61 * @param connect Connect the device
elessair 0:f269e3021894 62 */
elessair 0:f269e3021894 63 USBHID(uint8_t output_report_length = 64, uint8_t input_report_length = 64, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0006, uint16_t product_release = 0x0001, bool connect = true);
elessair 0:f269e3021894 64
elessair 0:f269e3021894 65
elessair 0:f269e3021894 66 /**
elessair 0:f269e3021894 67 * Send a Report. warning: blocking
elessair 0:f269e3021894 68 *
elessair 0:f269e3021894 69 * @param report Report which will be sent (a report is defined by all data and the length)
elessair 0:f269e3021894 70 * @returns true if successful
elessair 0:f269e3021894 71 */
elessair 0:f269e3021894 72 bool send(HID_REPORT *report);
elessair 0:f269e3021894 73
elessair 0:f269e3021894 74
elessair 0:f269e3021894 75 /**
elessair 0:f269e3021894 76 * Send a Report. warning: non blocking
elessair 0:f269e3021894 77 *
elessair 0:f269e3021894 78 * @param report Report which will be sent (a report is defined by all data and the length)
elessair 0:f269e3021894 79 * @returns true if successful
elessair 0:f269e3021894 80 */
elessair 0:f269e3021894 81 bool sendNB(HID_REPORT *report);
elessair 0:f269e3021894 82
elessair 0:f269e3021894 83 /**
elessair 0:f269e3021894 84 * Read a report: blocking
elessair 0:f269e3021894 85 *
elessair 0:f269e3021894 86 * @param report pointer to the report to fill
elessair 0:f269e3021894 87 * @returns true if successful
elessair 0:f269e3021894 88 */
elessair 0:f269e3021894 89 bool read(HID_REPORT * report);
elessair 0:f269e3021894 90
elessair 0:f269e3021894 91 /**
elessair 0:f269e3021894 92 * Read a report: non blocking
elessair 0:f269e3021894 93 *
elessair 0:f269e3021894 94 * @param report pointer to the report to fill
elessair 0:f269e3021894 95 * @returns true if successful
elessair 0:f269e3021894 96 */
elessair 0:f269e3021894 97 bool readNB(HID_REPORT * report);
elessair 0:f269e3021894 98
elessair 0:f269e3021894 99 protected:
elessair 0:f269e3021894 100 uint16_t reportLength;
elessair 0:f269e3021894 101
elessair 0:f269e3021894 102 /*
elessair 0:f269e3021894 103 * Get the Report descriptor
elessair 0:f269e3021894 104 *
elessair 0:f269e3021894 105 * @returns pointer to the report descriptor
elessair 0:f269e3021894 106 */
elessair 0:f269e3021894 107 virtual uint8_t * reportDesc();
elessair 0:f269e3021894 108
elessair 0:f269e3021894 109 /*
elessair 0:f269e3021894 110 * Get the length of the report descriptor
elessair 0:f269e3021894 111 *
elessair 0:f269e3021894 112 * @returns the length of the report descriptor
elessair 0:f269e3021894 113 */
elessair 0:f269e3021894 114 virtual uint16_t reportDescLength();
elessair 0:f269e3021894 115
elessair 0:f269e3021894 116 /*
elessair 0:f269e3021894 117 * Get string product descriptor
elessair 0:f269e3021894 118 *
elessair 0:f269e3021894 119 * @returns pointer to the string product descriptor
elessair 0:f269e3021894 120 */
elessair 0:f269e3021894 121 virtual uint8_t * stringIproductDesc();
elessair 0:f269e3021894 122
elessair 0:f269e3021894 123 /*
elessair 0:f269e3021894 124 * Get string interface descriptor
elessair 0:f269e3021894 125 *
elessair 0:f269e3021894 126 * @returns pointer to the string interface descriptor
elessair 0:f269e3021894 127 */
elessair 0:f269e3021894 128 virtual uint8_t * stringIinterfaceDesc();
elessair 0:f269e3021894 129
elessair 0:f269e3021894 130 /*
elessair 0:f269e3021894 131 * Get configuration descriptor
elessair 0:f269e3021894 132 *
elessair 0:f269e3021894 133 * @returns pointer to the configuration descriptor
elessair 0:f269e3021894 134 */
elessair 0:f269e3021894 135 virtual uint8_t * configurationDesc();
elessair 0:f269e3021894 136
elessair 0:f269e3021894 137
elessair 0:f269e3021894 138 /*
elessair 0:f269e3021894 139 * HID Report received by SET_REPORT request. Warning: Called in ISR context
elessair 0:f269e3021894 140 * First byte of data will be the report ID
elessair 0:f269e3021894 141 *
elessair 0:f269e3021894 142 * @param report Data and length received
elessair 0:f269e3021894 143 */
elessair 0:f269e3021894 144 virtual void HID_callbackSetReport(HID_REPORT *report){};
elessair 0:f269e3021894 145
elessair 0:f269e3021894 146
elessair 0:f269e3021894 147 /*
elessair 0:f269e3021894 148 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
elessair 0:f269e3021894 149 * This is used to handle extensions to standard requests
elessair 0:f269e3021894 150 * and class specific requests
elessair 0:f269e3021894 151 *
elessair 0:f269e3021894 152 * @returns true if class handles this request
elessair 0:f269e3021894 153 */
elessair 0:f269e3021894 154 virtual bool USBCallback_request();
elessair 0:f269e3021894 155
elessair 0:f269e3021894 156
elessair 0:f269e3021894 157 /*
elessair 0:f269e3021894 158 * Called by USBDevice layer. Set configuration of the device.
elessair 0:f269e3021894 159 * For instance, you can add all endpoints that you need on this function.
elessair 0:f269e3021894 160 *
elessair 0:f269e3021894 161 * @param configuration Number of the configuration
elessair 0:f269e3021894 162 * @returns true if class handles this request
elessair 0:f269e3021894 163 */
elessair 0:f269e3021894 164 virtual bool USBCallback_setConfiguration(uint8_t configuration);
elessair 0:f269e3021894 165
elessair 0:f269e3021894 166 private:
elessair 0:f269e3021894 167 HID_REPORT outputReport;
elessair 0:f269e3021894 168 uint8_t output_length;
elessair 0:f269e3021894 169 uint8_t input_length;
elessair 0:f269e3021894 170 };
elessair 0:f269e3021894 171
elessair 0:f269e3021894 172 #endif