The preloaded firmware shipped on the mBot.

Dependencies:   mbed

Fork of Official_mBot by Fred Parker

Committer:
jeffknaggs
Date:
Tue Nov 25 14:49:40 2014 +0000
Revision:
1:ffd9a51e7d35
Parent:
0:865d42c46692
Initial commit.

Who changed what in which revision?

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