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