xd

Dependencies:   mbed

Fork of Simple_Touch_Sens by Veikko Kero

Committer:
Vekotin
Date:
Thu Jan 30 06:13:55 2014 +0000
Revision:
1:7ed7d128d225
egw

Who changed what in which revision?

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