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 USBDEVICE_H
lucaslwl 22:5c07298d3383 20 #define USBDEVICE_H
lucaslwl 22:5c07298d3383 21
lucaslwl 22:5c07298d3383 22 #include "mbed.h"
lucaslwl 22:5c07298d3383 23 #include "USBDevice_Types.h"
lucaslwl 22:5c07298d3383 24 #include "USBHAL.h"
lucaslwl 22:5c07298d3383 25
lucaslwl 22:5c07298d3383 26 class USBDevice: public USBHAL
lucaslwl 22:5c07298d3383 27 {
lucaslwl 22:5c07298d3383 28 public:
lucaslwl 22:5c07298d3383 29 USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
lucaslwl 22:5c07298d3383 30
lucaslwl 22:5c07298d3383 31 /*
lucaslwl 22:5c07298d3383 32 * Check if the device is configured
lucaslwl 22:5c07298d3383 33 *
lucaslwl 22:5c07298d3383 34 * @returns true if configured, false otherwise
lucaslwl 22:5c07298d3383 35 */
lucaslwl 22:5c07298d3383 36 bool configured(void);
lucaslwl 22:5c07298d3383 37
lucaslwl 22:5c07298d3383 38 /*
lucaslwl 22:5c07298d3383 39 * Connect a device
lucaslwl 22:5c07298d3383 40 *
lucaslwl 22:5c07298d3383 41 * @param blocking: block if not configured
lucaslwl 22:5c07298d3383 42 */
lucaslwl 22:5c07298d3383 43 void connect(bool blocking = true);
lucaslwl 22:5c07298d3383 44
lucaslwl 22:5c07298d3383 45 /*
lucaslwl 22:5c07298d3383 46 * Disconnect a device
lucaslwl 22:5c07298d3383 47 */
lucaslwl 22:5c07298d3383 48 void disconnect(void);
lucaslwl 22:5c07298d3383 49
lucaslwl 22:5c07298d3383 50 /*
lucaslwl 22:5c07298d3383 51 * Add an endpoint
lucaslwl 22:5c07298d3383 52 *
lucaslwl 22:5c07298d3383 53 * @param endpoint endpoint which will be added
lucaslwl 22:5c07298d3383 54 * @param maxPacket Maximum size of a packet which can be sent for this endpoint
lucaslwl 22:5c07298d3383 55 * @returns true if successful, false otherwise
lucaslwl 22:5c07298d3383 56 */
lucaslwl 22:5c07298d3383 57 bool addEndpoint(uint8_t endpoint, uint32_t maxPacket);
lucaslwl 22:5c07298d3383 58
lucaslwl 22:5c07298d3383 59 /*
lucaslwl 22:5c07298d3383 60 * Start a reading on a certain endpoint.
lucaslwl 22:5c07298d3383 61 * You can access the result of the reading by USBDevice_read
lucaslwl 22:5c07298d3383 62 *
lucaslwl 22:5c07298d3383 63 * @param endpoint endpoint which will be read
lucaslwl 22:5c07298d3383 64 * @param maxSize the maximum length that can be read
lucaslwl 22:5c07298d3383 65 * @return true if successful
lucaslwl 22:5c07298d3383 66 */
lucaslwl 22:5c07298d3383 67 bool readStart(uint8_t endpoint, uint32_t maxSize);
lucaslwl 22:5c07298d3383 68
lucaslwl 22:5c07298d3383 69 /*
lucaslwl 22:5c07298d3383 70 * Read a certain endpoint. Before calling this function, USBUSBDevice_readStart
lucaslwl 22:5c07298d3383 71 * must be called.
lucaslwl 22:5c07298d3383 72 *
lucaslwl 22:5c07298d3383 73 * Warning: blocking
lucaslwl 22:5c07298d3383 74 *
lucaslwl 22:5c07298d3383 75 * @param endpoint endpoint which will be read
lucaslwl 22:5c07298d3383 76 * @param buffer buffer will be filled with the data received
lucaslwl 22:5c07298d3383 77 * @param size the number of bytes read will be stored in *size
lucaslwl 22:5c07298d3383 78 * @param maxSize the maximum length that can be read
lucaslwl 22:5c07298d3383 79 * @returns true if successful
lucaslwl 22:5c07298d3383 80 */
lucaslwl 22:5c07298d3383 81 bool readEP(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);
lucaslwl 22:5c07298d3383 82
lucaslwl 22:5c07298d3383 83 /*
lucaslwl 22:5c07298d3383 84 * Read a certain endpoint.
lucaslwl 22:5c07298d3383 85 *
lucaslwl 22:5c07298d3383 86 * Warning: non blocking
lucaslwl 22:5c07298d3383 87 *
lucaslwl 22:5c07298d3383 88 * @param endpoint endpoint which will be read
lucaslwl 22:5c07298d3383 89 * @param buffer buffer will be filled with the data received (if data are available)
lucaslwl 22:5c07298d3383 90 * @param size the number of bytes read will be stored in *size
lucaslwl 22:5c07298d3383 91 * @param maxSize the maximum length that can be read
lucaslwl 22:5c07298d3383 92 * @returns true if successful
lucaslwl 22:5c07298d3383 93 */
lucaslwl 22:5c07298d3383 94 bool readEP_NB(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);
lucaslwl 22:5c07298d3383 95
lucaslwl 22:5c07298d3383 96 /*
lucaslwl 22:5c07298d3383 97 * Write a certain endpoint.
lucaslwl 22:5c07298d3383 98 *
lucaslwl 22:5c07298d3383 99 * Warning: blocking
lucaslwl 22:5c07298d3383 100 *
lucaslwl 22:5c07298d3383 101 * @param endpoint endpoint to write
lucaslwl 22:5c07298d3383 102 * @param buffer data contained in buffer will be write
lucaslwl 22:5c07298d3383 103 * @param size the number of bytes to write
lucaslwl 22:5c07298d3383 104 * @param maxSize the maximum length that can be written on this endpoint
lucaslwl 22:5c07298d3383 105 */
lucaslwl 22:5c07298d3383 106 bool write(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);
lucaslwl 22:5c07298d3383 107
lucaslwl 22:5c07298d3383 108
lucaslwl 22:5c07298d3383 109 /*
lucaslwl 22:5c07298d3383 110 * Write a certain endpoint.
lucaslwl 22:5c07298d3383 111 *
lucaslwl 22:5c07298d3383 112 * Warning: non blocking
lucaslwl 22:5c07298d3383 113 *
lucaslwl 22:5c07298d3383 114 * @param endpoint endpoint to write
lucaslwl 22:5c07298d3383 115 * @param buffer data contained in buffer will be write
lucaslwl 22:5c07298d3383 116 * @param size the number of bytes to write
lucaslwl 22:5c07298d3383 117 * @param maxSize the maximum length that can be written on this endpoint
lucaslwl 22:5c07298d3383 118 */
lucaslwl 22:5c07298d3383 119 bool writeNB(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);
lucaslwl 22:5c07298d3383 120
lucaslwl 22:5c07298d3383 121
lucaslwl 22:5c07298d3383 122 /*
lucaslwl 22:5c07298d3383 123 * Called by USBDevice layer on bus reset. Warning: Called in ISR context
lucaslwl 22:5c07298d3383 124 *
lucaslwl 22:5c07298d3383 125 * May be used to reset state
lucaslwl 22:5c07298d3383 126 */
lucaslwl 22:5c07298d3383 127 virtual void USBCallback_busReset(void) {};
lucaslwl 22:5c07298d3383 128
lucaslwl 22:5c07298d3383 129 /*
lucaslwl 22:5c07298d3383 130 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
lucaslwl 22:5c07298d3383 131 * This is used to handle extensions to standard requests
lucaslwl 22:5c07298d3383 132 * and class specific requests
lucaslwl 22:5c07298d3383 133 *
lucaslwl 22:5c07298d3383 134 * @returns true if class handles this request
lucaslwl 22:5c07298d3383 135 */
lucaslwl 22:5c07298d3383 136 virtual bool USBCallback_request() { return false; };
lucaslwl 22:5c07298d3383 137
lucaslwl 22:5c07298d3383 138 /*
lucaslwl 22:5c07298d3383 139 * Called by USBDevice on Endpoint0 request completion
lucaslwl 22:5c07298d3383 140 * if the 'notify' flag has been set to true. Warning: Called in ISR context
lucaslwl 22:5c07298d3383 141 *
lucaslwl 22:5c07298d3383 142 * In this case it is used to indicate that a HID report has
lucaslwl 22:5c07298d3383 143 * been received from the host on endpoint 0
lucaslwl 22:5c07298d3383 144 *
lucaslwl 22:5c07298d3383 145 * @param buf buffer received on endpoint 0
lucaslwl 22:5c07298d3383 146 * @param length length of this buffer
lucaslwl 22:5c07298d3383 147 */
lucaslwl 22:5c07298d3383 148 virtual void USBCallback_requestCompleted(uint8_t * buf, uint32_t length) {};
lucaslwl 22:5c07298d3383 149
lucaslwl 22:5c07298d3383 150 /*
lucaslwl 22:5c07298d3383 151 * Called by USBDevice layer. Set configuration of the device.
lucaslwl 22:5c07298d3383 152 * For instance, you can add all endpoints that you need on this function.
lucaslwl 22:5c07298d3383 153 *
lucaslwl 22:5c07298d3383 154 * @param configuration Number of the configuration
lucaslwl 22:5c07298d3383 155 */
lucaslwl 22:5c07298d3383 156 virtual bool USBCallback_setConfiguration(uint8_t configuration) { return false; };
lucaslwl 22:5c07298d3383 157
lucaslwl 22:5c07298d3383 158 /*
lucaslwl 22:5c07298d3383 159 * Called by USBDevice layer. Set interface/alternate of the device.
lucaslwl 22:5c07298d3383 160 *
lucaslwl 22:5c07298d3383 161 * @param interface Number of the interface to be configured
lucaslwl 22:5c07298d3383 162 * @param alternate Number of the alternate to be configured
lucaslwl 22:5c07298d3383 163 * @returns true if class handles this request
lucaslwl 22:5c07298d3383 164 */
lucaslwl 22:5c07298d3383 165 virtual bool USBCallback_setInterface(uint16_t interface, uint8_t alternate) { return false; };
lucaslwl 22:5c07298d3383 166
lucaslwl 22:5c07298d3383 167 /*
lucaslwl 22:5c07298d3383 168 * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
lucaslwl 22:5c07298d3383 169 *
lucaslwl 22:5c07298d3383 170 * @returns pointer to the device descriptor
lucaslwl 22:5c07298d3383 171 */
lucaslwl 22:5c07298d3383 172 virtual uint8_t * deviceDesc();
lucaslwl 22:5c07298d3383 173
lucaslwl 22:5c07298d3383 174 /*
lucaslwl 22:5c07298d3383 175 * Get configuration descriptor
lucaslwl 22:5c07298d3383 176 *
lucaslwl 22:5c07298d3383 177 * @returns pointer to the configuration descriptor
lucaslwl 22:5c07298d3383 178 */
lucaslwl 22:5c07298d3383 179 virtual uint8_t * configurationDesc(){return NULL;};
lucaslwl 22:5c07298d3383 180
lucaslwl 22:5c07298d3383 181 /*
lucaslwl 22:5c07298d3383 182 * Get string lang id descriptor
lucaslwl 22:5c07298d3383 183 *
lucaslwl 22:5c07298d3383 184 * @return pointer to the string lang id descriptor
lucaslwl 22:5c07298d3383 185 */
lucaslwl 22:5c07298d3383 186 virtual uint8_t * stringLangidDesc();
lucaslwl 22:5c07298d3383 187
lucaslwl 22:5c07298d3383 188 /*
lucaslwl 22:5c07298d3383 189 * Get string manufacturer descriptor
lucaslwl 22:5c07298d3383 190 *
lucaslwl 22:5c07298d3383 191 * @returns pointer to the string manufacturer descriptor
lucaslwl 22:5c07298d3383 192 */
lucaslwl 22:5c07298d3383 193 virtual uint8_t * stringImanufacturerDesc();
lucaslwl 22:5c07298d3383 194
lucaslwl 22:5c07298d3383 195 /*
lucaslwl 22:5c07298d3383 196 * Get string product descriptor
lucaslwl 22:5c07298d3383 197 *
lucaslwl 22:5c07298d3383 198 * @returns pointer to the string product descriptor
lucaslwl 22:5c07298d3383 199 */
lucaslwl 22:5c07298d3383 200 virtual uint8_t * stringIproductDesc();
lucaslwl 22:5c07298d3383 201
lucaslwl 22:5c07298d3383 202 /*
lucaslwl 22:5c07298d3383 203 * Get string serial descriptor
lucaslwl 22:5c07298d3383 204 *
lucaslwl 22:5c07298d3383 205 * @returns pointer to the string serial descriptor
lucaslwl 22:5c07298d3383 206 */
lucaslwl 22:5c07298d3383 207 virtual uint8_t * stringIserialDesc();
lucaslwl 22:5c07298d3383 208
lucaslwl 22:5c07298d3383 209 /*
lucaslwl 22:5c07298d3383 210 * Get string configuration descriptor
lucaslwl 22:5c07298d3383 211 *
lucaslwl 22:5c07298d3383 212 * @returns pointer to the string configuration descriptor
lucaslwl 22:5c07298d3383 213 */
lucaslwl 22:5c07298d3383 214 virtual uint8_t * stringIConfigurationDesc();
lucaslwl 22:5c07298d3383 215
lucaslwl 22:5c07298d3383 216 /*
lucaslwl 22:5c07298d3383 217 * Get string interface descriptor
lucaslwl 22:5c07298d3383 218 *
lucaslwl 22:5c07298d3383 219 * @returns pointer to the string interface descriptor
lucaslwl 22:5c07298d3383 220 */
lucaslwl 22:5c07298d3383 221 virtual uint8_t * stringIinterfaceDesc();
lucaslwl 22:5c07298d3383 222
lucaslwl 22:5c07298d3383 223 /*
lucaslwl 22:5c07298d3383 224 * Get the length of the report descriptor
lucaslwl 22:5c07298d3383 225 *
lucaslwl 22:5c07298d3383 226 * @returns length of the report descriptor
lucaslwl 22:5c07298d3383 227 */
lucaslwl 22:5c07298d3383 228 virtual uint16_t reportDescLength() { return 0; };
lucaslwl 22:5c07298d3383 229
lucaslwl 22:5c07298d3383 230
lucaslwl 22:5c07298d3383 231
lucaslwl 22:5c07298d3383 232 protected:
lucaslwl 22:5c07298d3383 233 virtual void busReset(void);
lucaslwl 22:5c07298d3383 234 virtual void EP0setupCallback(void);
lucaslwl 22:5c07298d3383 235 virtual void EP0out(void);
lucaslwl 22:5c07298d3383 236 virtual void EP0in(void);
lucaslwl 22:5c07298d3383 237 virtual void connectStateChanged(unsigned int connected);
lucaslwl 22:5c07298d3383 238 virtual void suspendStateChanged(unsigned int suspended);
lucaslwl 22:5c07298d3383 239 uint8_t * findDescriptor(uint8_t descriptorType);
lucaslwl 22:5c07298d3383 240 CONTROL_TRANSFER * getTransferPtr(void);
lucaslwl 22:5c07298d3383 241
lucaslwl 22:5c07298d3383 242 uint16_t VENDOR_ID;
lucaslwl 22:5c07298d3383 243 uint16_t PRODUCT_ID;
lucaslwl 22:5c07298d3383 244 uint16_t PRODUCT_RELEASE;
lucaslwl 22:5c07298d3383 245
lucaslwl 22:5c07298d3383 246 private:
lucaslwl 22:5c07298d3383 247 bool addRateFeedbackEndpoint(uint8_t endpoint, uint32_t maxPacket);
lucaslwl 22:5c07298d3383 248 bool requestGetDescriptor(void);
lucaslwl 22:5c07298d3383 249 bool controlOut(void);
lucaslwl 22:5c07298d3383 250 bool controlIn(void);
lucaslwl 22:5c07298d3383 251 bool requestSetAddress(void);
lucaslwl 22:5c07298d3383 252 bool requestSetConfiguration(void);
lucaslwl 22:5c07298d3383 253 bool requestSetFeature(void);
lucaslwl 22:5c07298d3383 254 bool requestClearFeature(void);
lucaslwl 22:5c07298d3383 255 bool requestGetStatus(void);
lucaslwl 22:5c07298d3383 256 bool requestSetup(void);
lucaslwl 22:5c07298d3383 257 bool controlSetup(void);
lucaslwl 22:5c07298d3383 258 void decodeSetupPacket(uint8_t *data, SETUP_PACKET *packet);
lucaslwl 22:5c07298d3383 259 bool requestGetConfiguration(void);
lucaslwl 22:5c07298d3383 260 bool requestGetInterface(void);
lucaslwl 22:5c07298d3383 261 bool requestSetInterface(void);
lucaslwl 22:5c07298d3383 262
lucaslwl 22:5c07298d3383 263 CONTROL_TRANSFER transfer;
lucaslwl 22:5c07298d3383 264 USB_DEVICE device;
lucaslwl 22:5c07298d3383 265
lucaslwl 22:5c07298d3383 266 uint16_t currentInterface;
lucaslwl 22:5c07298d3383 267 uint8_t currentAlternate;
lucaslwl 22:5c07298d3383 268 };
lucaslwl 22:5c07298d3383 269
lucaslwl 22:5c07298d3383 270
lucaslwl 22:5c07298d3383 271 #endif