Lucas Lim / Mbed 2 deprecated HSP_Temperature_Barometer_CS3237

Dependencies:   mbed

Committer:
lucaslwl
Date:
Mon Aug 26 08:11:41 2019 +0000
Revision:
22:5c07298d3383
add library folder

Who changed what in which revision?

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