Base station firmware

Committer:
Perijah
Date:
Tue May 24 13:16:55 2016 +0000
Revision:
0:ecc3925d3f8c
Base station firmware

Who changed what in which revision?

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