max4146x_comp

Dependencies:   MAX14690

Committer:
sdivarci
Date:
Sun Oct 25 20:10:02 2020 +0000
Revision:
0:0061165683ee
sdivarci

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sdivarci 0:0061165683ee 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
sdivarci 0:0061165683ee 2 *
sdivarci 0:0061165683ee 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
sdivarci 0:0061165683ee 4 * and associated documentation files (the "Software"), to deal in the Software without
sdivarci 0:0061165683ee 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
sdivarci 0:0061165683ee 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
sdivarci 0:0061165683ee 7 * Software is furnished to do so, subject to the following conditions:
sdivarci 0:0061165683ee 8 *
sdivarci 0:0061165683ee 9 * The above copyright notice and this permission notice shall be included in all copies or
sdivarci 0:0061165683ee 10 * substantial portions of the Software.
sdivarci 0:0061165683ee 11 *
sdivarci 0:0061165683ee 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
sdivarci 0:0061165683ee 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
sdivarci 0:0061165683ee 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
sdivarci 0:0061165683ee 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
sdivarci 0:0061165683ee 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
sdivarci 0:0061165683ee 17 */
sdivarci 0:0061165683ee 18
sdivarci 0:0061165683ee 19 #ifndef USBDEVICE_H
sdivarci 0:0061165683ee 20 #define USBDEVICE_H
sdivarci 0:0061165683ee 21
sdivarci 0:0061165683ee 22 #include "mbed.h"
sdivarci 0:0061165683ee 23 #include "USBDevice_Types.h"
sdivarci 0:0061165683ee 24 #include "USBHAL.h"
sdivarci 0:0061165683ee 25
sdivarci 0:0061165683ee 26 class USBDevice: public USBHAL
sdivarci 0:0061165683ee 27 {
sdivarci 0:0061165683ee 28 public:
sdivarci 0:0061165683ee 29 USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
sdivarci 0:0061165683ee 30
sdivarci 0:0061165683ee 31 /*
sdivarci 0:0061165683ee 32 * Check if the device is configured
sdivarci 0:0061165683ee 33 *
sdivarci 0:0061165683ee 34 * @returns true if configured, false otherwise
sdivarci 0:0061165683ee 35 */
sdivarci 0:0061165683ee 36 bool configured(void);
sdivarci 0:0061165683ee 37
sdivarci 0:0061165683ee 38 /*
sdivarci 0:0061165683ee 39 * Connect a device
sdivarci 0:0061165683ee 40 *
sdivarci 0:0061165683ee 41 * @param blocking: block if not configured
sdivarci 0:0061165683ee 42 */
sdivarci 0:0061165683ee 43 void connect(bool blocking = true);
sdivarci 0:0061165683ee 44
sdivarci 0:0061165683ee 45 /*
sdivarci 0:0061165683ee 46 * Disconnect a device
sdivarci 0:0061165683ee 47 */
sdivarci 0:0061165683ee 48 void disconnect(void);
sdivarci 0:0061165683ee 49
sdivarci 0:0061165683ee 50 /*
sdivarci 0:0061165683ee 51 * Add an endpoint
sdivarci 0:0061165683ee 52 *
sdivarci 0:0061165683ee 53 * @param endpoint endpoint which will be added
sdivarci 0:0061165683ee 54 * @param maxPacket Maximum size of a packet which can be sent for this endpoint
sdivarci 0:0061165683ee 55 * @returns true if successful, false otherwise
sdivarci 0:0061165683ee 56 */
sdivarci 0:0061165683ee 57 bool addEndpoint(uint8_t endpoint, uint32_t maxPacket);
sdivarci 0:0061165683ee 58
sdivarci 0:0061165683ee 59 /*
sdivarci 0:0061165683ee 60 * Start a reading on a certain endpoint.
sdivarci 0:0061165683ee 61 * You can access the result of the reading by USBDevice_read
sdivarci 0:0061165683ee 62 *
sdivarci 0:0061165683ee 63 * @param endpoint endpoint which will be read
sdivarci 0:0061165683ee 64 * @param maxSize the maximum length that can be read
sdivarci 0:0061165683ee 65 * @return true if successful
sdivarci 0:0061165683ee 66 */
sdivarci 0:0061165683ee 67 bool readStart(uint8_t endpoint, uint32_t maxSize);
sdivarci 0:0061165683ee 68
sdivarci 0:0061165683ee 69 /*
sdivarci 0:0061165683ee 70 * Read a certain endpoint. Before calling this function, USBUSBDevice_readStart
sdivarci 0:0061165683ee 71 * must be called.
sdivarci 0:0061165683ee 72 *
sdivarci 0:0061165683ee 73 * Warning: blocking
sdivarci 0:0061165683ee 74 *
sdivarci 0:0061165683ee 75 * @param endpoint endpoint which will be read
sdivarci 0:0061165683ee 76 * @param buffer buffer will be filled with the data received
sdivarci 0:0061165683ee 77 * @param size the number of bytes read will be stored in *size
sdivarci 0:0061165683ee 78 * @param maxSize the maximum length that can be read
sdivarci 0:0061165683ee 79 * @returns true if successful
sdivarci 0:0061165683ee 80 */
sdivarci 0:0061165683ee 81 bool readEP(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);
sdivarci 0:0061165683ee 82
sdivarci 0:0061165683ee 83 /*
sdivarci 0:0061165683ee 84 * Read a certain endpoint.
sdivarci 0:0061165683ee 85 *
sdivarci 0:0061165683ee 86 * Warning: non blocking
sdivarci 0:0061165683ee 87 *
sdivarci 0:0061165683ee 88 * @param endpoint endpoint which will be read
sdivarci 0:0061165683ee 89 * @param buffer buffer will be filled with the data received (if data are available)
sdivarci 0:0061165683ee 90 * @param size the number of bytes read will be stored in *size
sdivarci 0:0061165683ee 91 * @param maxSize the maximum length that can be read
sdivarci 0:0061165683ee 92 * @returns true if successful
sdivarci 0:0061165683ee 93 */
sdivarci 0:0061165683ee 94 bool readEP_NB(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);
sdivarci 0:0061165683ee 95
sdivarci 0:0061165683ee 96 /*
sdivarci 0:0061165683ee 97 * Write a certain endpoint.
sdivarci 0:0061165683ee 98 *
sdivarci 0:0061165683ee 99 * Warning: blocking
sdivarci 0:0061165683ee 100 *
sdivarci 0:0061165683ee 101 * @param endpoint endpoint to write
sdivarci 0:0061165683ee 102 * @param buffer data contained in buffer will be write
sdivarci 0:0061165683ee 103 * @param size the number of bytes to write
sdivarci 0:0061165683ee 104 * @param maxSize the maximum length that can be written on this endpoint
sdivarci 0:0061165683ee 105 */
sdivarci 0:0061165683ee 106 bool write(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);
sdivarci 0:0061165683ee 107
sdivarci 0:0061165683ee 108
sdivarci 0:0061165683ee 109 /*
sdivarci 0:0061165683ee 110 * Write a certain endpoint.
sdivarci 0:0061165683ee 111 *
sdivarci 0:0061165683ee 112 * Warning: non blocking
sdivarci 0:0061165683ee 113 *
sdivarci 0:0061165683ee 114 * @param endpoint endpoint to write
sdivarci 0:0061165683ee 115 * @param buffer data contained in buffer will be write
sdivarci 0:0061165683ee 116 * @param size the number of bytes to write
sdivarci 0:0061165683ee 117 * @param maxSize the maximum length that can be written on this endpoint
sdivarci 0:0061165683ee 118 */
sdivarci 0:0061165683ee 119 bool writeNB(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);
sdivarci 0:0061165683ee 120
sdivarci 0:0061165683ee 121
sdivarci 0:0061165683ee 122 /*
sdivarci 0:0061165683ee 123 * Called by USBDevice layer on bus reset. Warning: Called in ISR context
sdivarci 0:0061165683ee 124 *
sdivarci 0:0061165683ee 125 * May be used to reset state
sdivarci 0:0061165683ee 126 */
sdivarci 0:0061165683ee 127 virtual void USBCallback_busReset(void) {};
sdivarci 0:0061165683ee 128
sdivarci 0:0061165683ee 129 /*
sdivarci 0:0061165683ee 130 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
sdivarci 0:0061165683ee 131 * This is used to handle extensions to standard requests
sdivarci 0:0061165683ee 132 * and class specific requests
sdivarci 0:0061165683ee 133 *
sdivarci 0:0061165683ee 134 * @returns true if class handles this request
sdivarci 0:0061165683ee 135 */
sdivarci 0:0061165683ee 136 virtual bool USBCallback_request() { return false; };
sdivarci 0:0061165683ee 137
sdivarci 0:0061165683ee 138 /*
sdivarci 0:0061165683ee 139 * Called by USBDevice on Endpoint0 request completion
sdivarci 0:0061165683ee 140 * if the 'notify' flag has been set to true. Warning: Called in ISR context
sdivarci 0:0061165683ee 141 *
sdivarci 0:0061165683ee 142 * In this case it is used to indicate that a HID report has
sdivarci 0:0061165683ee 143 * been received from the host on endpoint 0
sdivarci 0:0061165683ee 144 *
sdivarci 0:0061165683ee 145 * @param buf buffer received on endpoint 0
sdivarci 0:0061165683ee 146 * @param length length of this buffer
sdivarci 0:0061165683ee 147 */
sdivarci 0:0061165683ee 148 virtual void USBCallback_requestCompleted(uint8_t * buf, uint32_t length) {};
sdivarci 0:0061165683ee 149
sdivarci 0:0061165683ee 150 /*
sdivarci 0:0061165683ee 151 * Called by USBDevice layer. Set configuration of the device.
sdivarci 0:0061165683ee 152 * For instance, you can add all endpoints that you need on this function.
sdivarci 0:0061165683ee 153 *
sdivarci 0:0061165683ee 154 * @param configuration Number of the configuration
sdivarci 0:0061165683ee 155 */
sdivarci 0:0061165683ee 156 virtual bool USBCallback_setConfiguration(uint8_t configuration) { return false; };
sdivarci 0:0061165683ee 157
sdivarci 0:0061165683ee 158 /*
sdivarci 0:0061165683ee 159 * Called by USBDevice layer. Set interface/alternate of the device.
sdivarci 0:0061165683ee 160 *
sdivarci 0:0061165683ee 161 * @param interface Number of the interface to be configured
sdivarci 0:0061165683ee 162 * @param alternate Number of the alternate to be configured
sdivarci 0:0061165683ee 163 * @returns true if class handles this request
sdivarci 0:0061165683ee 164 */
sdivarci 0:0061165683ee 165 virtual bool USBCallback_setInterface(uint16_t interface, uint8_t alternate) { return false; };
sdivarci 0:0061165683ee 166
sdivarci 0:0061165683ee 167 /*
sdivarci 0:0061165683ee 168 * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
sdivarci 0:0061165683ee 169 *
sdivarci 0:0061165683ee 170 * @returns pointer to the device descriptor
sdivarci 0:0061165683ee 171 */
sdivarci 0:0061165683ee 172 virtual uint8_t * deviceDesc();
sdivarci 0:0061165683ee 173
sdivarci 0:0061165683ee 174 /*
sdivarci 0:0061165683ee 175 * Get configuration descriptor
sdivarci 0:0061165683ee 176 *
sdivarci 0:0061165683ee 177 * @returns pointer to the configuration descriptor
sdivarci 0:0061165683ee 178 */
sdivarci 0:0061165683ee 179 virtual uint8_t * configurationDesc(){return NULL;};
sdivarci 0:0061165683ee 180
sdivarci 0:0061165683ee 181 /*
sdivarci 0:0061165683ee 182 * Get string lang id descriptor
sdivarci 0:0061165683ee 183 *
sdivarci 0:0061165683ee 184 * @return pointer to the string lang id descriptor
sdivarci 0:0061165683ee 185 */
sdivarci 0:0061165683ee 186 virtual uint8_t * stringLangidDesc();
sdivarci 0:0061165683ee 187
sdivarci 0:0061165683ee 188 /*
sdivarci 0:0061165683ee 189 * Get string manufacturer descriptor
sdivarci 0:0061165683ee 190 *
sdivarci 0:0061165683ee 191 * @returns pointer to the string manufacturer descriptor
sdivarci 0:0061165683ee 192 */
sdivarci 0:0061165683ee 193 virtual uint8_t * stringImanufacturerDesc();
sdivarci 0:0061165683ee 194
sdivarci 0:0061165683ee 195 /*
sdivarci 0:0061165683ee 196 * Get string product descriptor
sdivarci 0:0061165683ee 197 *
sdivarci 0:0061165683ee 198 * @returns pointer to the string product descriptor
sdivarci 0:0061165683ee 199 */
sdivarci 0:0061165683ee 200 virtual uint8_t * stringIproductDesc();
sdivarci 0:0061165683ee 201
sdivarci 0:0061165683ee 202 /*
sdivarci 0:0061165683ee 203 * Get string serial descriptor
sdivarci 0:0061165683ee 204 *
sdivarci 0:0061165683ee 205 * @returns pointer to the string serial descriptor
sdivarci 0:0061165683ee 206 */
sdivarci 0:0061165683ee 207 virtual uint8_t * stringIserialDesc();
sdivarci 0:0061165683ee 208
sdivarci 0:0061165683ee 209 /*
sdivarci 0:0061165683ee 210 * Get string configuration descriptor
sdivarci 0:0061165683ee 211 *
sdivarci 0:0061165683ee 212 * @returns pointer to the string configuration descriptor
sdivarci 0:0061165683ee 213 */
sdivarci 0:0061165683ee 214 virtual uint8_t * stringIConfigurationDesc();
sdivarci 0:0061165683ee 215
sdivarci 0:0061165683ee 216 /*
sdivarci 0:0061165683ee 217 * Get string interface descriptor
sdivarci 0:0061165683ee 218 *
sdivarci 0:0061165683ee 219 * @returns pointer to the string interface descriptor
sdivarci 0:0061165683ee 220 */
sdivarci 0:0061165683ee 221 virtual uint8_t * stringIinterfaceDesc();
sdivarci 0:0061165683ee 222
sdivarci 0:0061165683ee 223 /*
sdivarci 0:0061165683ee 224 * Get the length of the report descriptor
sdivarci 0:0061165683ee 225 *
sdivarci 0:0061165683ee 226 * @returns length of the report descriptor
sdivarci 0:0061165683ee 227 */
sdivarci 0:0061165683ee 228 virtual uint16_t reportDescLength() { return 0; };
sdivarci 0:0061165683ee 229
sdivarci 0:0061165683ee 230
sdivarci 0:0061165683ee 231
sdivarci 0:0061165683ee 232 protected:
sdivarci 0:0061165683ee 233 virtual void busReset(void);
sdivarci 0:0061165683ee 234 virtual void EP0setupCallback(void);
sdivarci 0:0061165683ee 235 virtual void EP0out(void);
sdivarci 0:0061165683ee 236 virtual void EP0in(void);
sdivarci 0:0061165683ee 237 virtual void connectStateChanged(unsigned int connected);
sdivarci 0:0061165683ee 238 virtual void suspendStateChanged(unsigned int suspended);
sdivarci 0:0061165683ee 239 uint8_t * findDescriptor(uint8_t descriptorType);
sdivarci 0:0061165683ee 240 CONTROL_TRANSFER * getTransferPtr(void);
sdivarci 0:0061165683ee 241
sdivarci 0:0061165683ee 242 uint16_t VENDOR_ID;
sdivarci 0:0061165683ee 243 uint16_t PRODUCT_ID;
sdivarci 0:0061165683ee 244 uint16_t PRODUCT_RELEASE;
sdivarci 0:0061165683ee 245
sdivarci 0:0061165683ee 246 private:
sdivarci 0:0061165683ee 247 bool addRateFeedbackEndpoint(uint8_t endpoint, uint32_t maxPacket);
sdivarci 0:0061165683ee 248 bool requestGetDescriptor(void);
sdivarci 0:0061165683ee 249 bool controlOut(void);
sdivarci 0:0061165683ee 250 bool controlIn(void);
sdivarci 0:0061165683ee 251 bool requestSetAddress(void);
sdivarci 0:0061165683ee 252 bool requestSetConfiguration(void);
sdivarci 0:0061165683ee 253 bool requestSetFeature(void);
sdivarci 0:0061165683ee 254 bool requestClearFeature(void);
sdivarci 0:0061165683ee 255 bool requestGetStatus(void);
sdivarci 0:0061165683ee 256 bool requestSetup(void);
sdivarci 0:0061165683ee 257 bool controlSetup(void);
sdivarci 0:0061165683ee 258 void decodeSetupPacket(uint8_t *data, SETUP_PACKET *packet);
sdivarci 0:0061165683ee 259 bool requestGetConfiguration(void);
sdivarci 0:0061165683ee 260 bool requestGetInterface(void);
sdivarci 0:0061165683ee 261 bool requestSetInterface(void);
sdivarci 0:0061165683ee 262
sdivarci 0:0061165683ee 263 CONTROL_TRANSFER transfer;
sdivarci 0:0061165683ee 264 USB_DEVICE device;
sdivarci 0:0061165683ee 265
sdivarci 0:0061165683ee 266 uint16_t currentInterface;
sdivarci 0:0061165683ee 267 uint8_t currentAlternate;
sdivarci 0:0061165683ee 268 };
sdivarci 0:0061165683ee 269
sdivarci 0:0061165683ee 270
sdivarci 0:0061165683ee 271 #endif