This is a data logger program to be implemented with an instrument amplifier.

Dependencies:   mbed

Committer:
KISScientific
Date:
Tue Apr 04 18:01:11 2017 +0000
Revision:
0:d75ca4e39672
This is a data logger program.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
KISScientific 0:d75ca4e39672 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
KISScientific 0:d75ca4e39672 2 *
KISScientific 0:d75ca4e39672 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
KISScientific 0:d75ca4e39672 4 * and associated documentation files (the "Software"), to deal in the Software without
KISScientific 0:d75ca4e39672 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
KISScientific 0:d75ca4e39672 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
KISScientific 0:d75ca4e39672 7 * Software is furnished to do so, subject to the following conditions:
KISScientific 0:d75ca4e39672 8 *
KISScientific 0:d75ca4e39672 9 * The above copyright notice and this permission notice shall be included in all copies or
KISScientific 0:d75ca4e39672 10 * substantial portions of the Software.
KISScientific 0:d75ca4e39672 11 *
KISScientific 0:d75ca4e39672 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
KISScientific 0:d75ca4e39672 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
KISScientific 0:d75ca4e39672 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
KISScientific 0:d75ca4e39672 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
KISScientific 0:d75ca4e39672 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
KISScientific 0:d75ca4e39672 17 */
KISScientific 0:d75ca4e39672 18
KISScientific 0:d75ca4e39672 19 #ifndef USB_HID_H
KISScientific 0:d75ca4e39672 20 #define USB_HID_H
KISScientific 0:d75ca4e39672 21
KISScientific 0:d75ca4e39672 22 /* These headers are included for child class. */
KISScientific 0:d75ca4e39672 23 #include "USBEndpoints.h"
KISScientific 0:d75ca4e39672 24 #include "USBDescriptor.h"
KISScientific 0:d75ca4e39672 25 #include "USBDevice_Types.h"
KISScientific 0:d75ca4e39672 26
KISScientific 0:d75ca4e39672 27 #include "USBHID_Types.h"
KISScientific 0:d75ca4e39672 28 #include "USBDevice.h"
KISScientific 0:d75ca4e39672 29
KISScientific 0:d75ca4e39672 30
KISScientific 0:d75ca4e39672 31 /**
KISScientific 0:d75ca4e39672 32 * USBHID example
KISScientific 0:d75ca4e39672 33 * @code
KISScientific 0:d75ca4e39672 34 * #include "mbed.h"
KISScientific 0:d75ca4e39672 35 * #include "USBHID.h"
KISScientific 0:d75ca4e39672 36 *
KISScientific 0:d75ca4e39672 37 * USBHID hid;
KISScientific 0:d75ca4e39672 38 * HID_REPORT recv;
KISScientific 0:d75ca4e39672 39 * BusOut leds(LED1,LED2,LED3,LED4);
KISScientific 0:d75ca4e39672 40 *
KISScientific 0:d75ca4e39672 41 * int main(void) {
KISScientific 0:d75ca4e39672 42 * while (1) {
KISScientific 0:d75ca4e39672 43 * hid.read(&recv);
KISScientific 0:d75ca4e39672 44 * leds = recv.data[0];
KISScientific 0:d75ca4e39672 45 * }
KISScientific 0:d75ca4e39672 46 * }
KISScientific 0:d75ca4e39672 47 * @endcode
KISScientific 0:d75ca4e39672 48 */
KISScientific 0:d75ca4e39672 49
KISScientific 0:d75ca4e39672 50 class USBHID: public USBDevice {
KISScientific 0:d75ca4e39672 51 public:
KISScientific 0:d75ca4e39672 52
KISScientific 0:d75ca4e39672 53 /**
KISScientific 0:d75ca4e39672 54 * Constructor
KISScientific 0:d75ca4e39672 55 *
KISScientific 0:d75ca4e39672 56 * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes)
KISScientific 0:d75ca4e39672 57 * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes)
KISScientific 0:d75ca4e39672 58 * @param vendor_id Your vendor_id
KISScientific 0:d75ca4e39672 59 * @param product_id Your product_id
KISScientific 0:d75ca4e39672 60 * @param product_release Your preoduct_release
KISScientific 0:d75ca4e39672 61 * @param connect Connect the device
KISScientific 0:d75ca4e39672 62 */
KISScientific 0:d75ca4e39672 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);
KISScientific 0:d75ca4e39672 64
KISScientific 0:d75ca4e39672 65
KISScientific 0:d75ca4e39672 66 /**
KISScientific 0:d75ca4e39672 67 * Send a Report. warning: blocking
KISScientific 0:d75ca4e39672 68 *
KISScientific 0:d75ca4e39672 69 * @param report Report which will be sent (a report is defined by all data and the length)
KISScientific 0:d75ca4e39672 70 * @returns true if successful
KISScientific 0:d75ca4e39672 71 */
KISScientific 0:d75ca4e39672 72 bool send(HID_REPORT *report);
KISScientific 0:d75ca4e39672 73
KISScientific 0:d75ca4e39672 74
KISScientific 0:d75ca4e39672 75 /**
KISScientific 0:d75ca4e39672 76 * Send a Report. warning: non blocking
KISScientific 0:d75ca4e39672 77 *
KISScientific 0:d75ca4e39672 78 * @param report Report which will be sent (a report is defined by all data and the length)
KISScientific 0:d75ca4e39672 79 * @returns true if successful
KISScientific 0:d75ca4e39672 80 */
KISScientific 0:d75ca4e39672 81 bool sendNB(HID_REPORT *report);
KISScientific 0:d75ca4e39672 82
KISScientific 0:d75ca4e39672 83 /**
KISScientific 0:d75ca4e39672 84 * Read a report: blocking
KISScientific 0:d75ca4e39672 85 *
KISScientific 0:d75ca4e39672 86 * @param report pointer to the report to fill
KISScientific 0:d75ca4e39672 87 * @returns true if successful
KISScientific 0:d75ca4e39672 88 */
KISScientific 0:d75ca4e39672 89 bool read(HID_REPORT * report);
KISScientific 0:d75ca4e39672 90
KISScientific 0:d75ca4e39672 91 /**
KISScientific 0:d75ca4e39672 92 * Read a report: non blocking
KISScientific 0:d75ca4e39672 93 *
KISScientific 0:d75ca4e39672 94 * @param report pointer to the report to fill
KISScientific 0:d75ca4e39672 95 * @returns true if successful
KISScientific 0:d75ca4e39672 96 */
KISScientific 0:d75ca4e39672 97 bool readNB(HID_REPORT * report);
KISScientific 0:d75ca4e39672 98
KISScientific 0:d75ca4e39672 99 protected:
KISScientific 0:d75ca4e39672 100 uint16_t reportLength;
KISScientific 0:d75ca4e39672 101
KISScientific 0:d75ca4e39672 102 /*
KISScientific 0:d75ca4e39672 103 * Get the Report descriptor
KISScientific 0:d75ca4e39672 104 *
KISScientific 0:d75ca4e39672 105 * @returns pointer to the report descriptor
KISScientific 0:d75ca4e39672 106 */
KISScientific 0:d75ca4e39672 107 virtual uint8_t * reportDesc();
KISScientific 0:d75ca4e39672 108
KISScientific 0:d75ca4e39672 109 /*
KISScientific 0:d75ca4e39672 110 * Get the length of the report descriptor
KISScientific 0:d75ca4e39672 111 *
KISScientific 0:d75ca4e39672 112 * @returns the length of the report descriptor
KISScientific 0:d75ca4e39672 113 */
KISScientific 0:d75ca4e39672 114 virtual uint16_t reportDescLength();
KISScientific 0:d75ca4e39672 115
KISScientific 0:d75ca4e39672 116 /*
KISScientific 0:d75ca4e39672 117 * Get string product descriptor
KISScientific 0:d75ca4e39672 118 *
KISScientific 0:d75ca4e39672 119 * @returns pointer to the string product descriptor
KISScientific 0:d75ca4e39672 120 */
KISScientific 0:d75ca4e39672 121 virtual uint8_t * stringIproductDesc();
KISScientific 0:d75ca4e39672 122
KISScientific 0:d75ca4e39672 123 /*
KISScientific 0:d75ca4e39672 124 * Get string interface descriptor
KISScientific 0:d75ca4e39672 125 *
KISScientific 0:d75ca4e39672 126 * @returns pointer to the string interface descriptor
KISScientific 0:d75ca4e39672 127 */
KISScientific 0:d75ca4e39672 128 virtual uint8_t * stringIinterfaceDesc();
KISScientific 0:d75ca4e39672 129
KISScientific 0:d75ca4e39672 130 /*
KISScientific 0:d75ca4e39672 131 * Get configuration descriptor
KISScientific 0:d75ca4e39672 132 *
KISScientific 0:d75ca4e39672 133 * @returns pointer to the configuration descriptor
KISScientific 0:d75ca4e39672 134 */
KISScientific 0:d75ca4e39672 135 virtual uint8_t * configurationDesc();
KISScientific 0:d75ca4e39672 136
KISScientific 0:d75ca4e39672 137
KISScientific 0:d75ca4e39672 138 /*
KISScientific 0:d75ca4e39672 139 * HID Report received by SET_REPORT request. Warning: Called in ISR context
KISScientific 0:d75ca4e39672 140 * First byte of data will be the report ID
KISScientific 0:d75ca4e39672 141 *
KISScientific 0:d75ca4e39672 142 * @param report Data and length received
KISScientific 0:d75ca4e39672 143 */
KISScientific 0:d75ca4e39672 144 virtual void HID_callbackSetReport(HID_REPORT *report){};
KISScientific 0:d75ca4e39672 145
KISScientific 0:d75ca4e39672 146
KISScientific 0:d75ca4e39672 147 /*
KISScientific 0:d75ca4e39672 148 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
KISScientific 0:d75ca4e39672 149 * This is used to handle extensions to standard requests
KISScientific 0:d75ca4e39672 150 * and class specific requests
KISScientific 0:d75ca4e39672 151 *
KISScientific 0:d75ca4e39672 152 * @returns true if class handles this request
KISScientific 0:d75ca4e39672 153 */
KISScientific 0:d75ca4e39672 154 virtual bool USBCallback_request();
KISScientific 0:d75ca4e39672 155
KISScientific 0:d75ca4e39672 156
KISScientific 0:d75ca4e39672 157 /*
KISScientific 0:d75ca4e39672 158 * Called by USBDevice layer. Set configuration of the device.
KISScientific 0:d75ca4e39672 159 * For instance, you can add all endpoints that you need on this function.
KISScientific 0:d75ca4e39672 160 *
KISScientific 0:d75ca4e39672 161 * @param configuration Number of the configuration
KISScientific 0:d75ca4e39672 162 * @returns true if class handles this request
KISScientific 0:d75ca4e39672 163 */
KISScientific 0:d75ca4e39672 164 virtual bool USBCallback_setConfiguration(uint8_t configuration);
KISScientific 0:d75ca4e39672 165
KISScientific 0:d75ca4e39672 166 private:
KISScientific 0:d75ca4e39672 167 HID_REPORT outputReport;
KISScientific 0:d75ca4e39672 168 uint8_t output_length;
KISScientific 0:d75ca4e39672 169 uint8_t input_length;
KISScientific 0:d75ca4e39672 170 };
KISScientific 0:d75ca4e39672 171
KISScientific 0:d75ca4e39672 172 #endif