USBHost library with fixes

Dependencies:   mbed-rtos FATFileSystem

Dependents:   mbedica

Committer:
zrussell3
Date:
Thu Dec 13 19:24:21 2018 +0000
Revision:
0:b176d95bb38f
Modified USBHost library to fix modifier input

Who changed what in which revision?

UserRevisionLine numberNew contents of line
zrussell3 0:b176d95bb38f 1 /* mbed USBHost Library
zrussell3 0:b176d95bb38f 2 * Copyright (c) 2006-2013 ARM Limited
zrussell3 0:b176d95bb38f 3 *
zrussell3 0:b176d95bb38f 4 * Licensed under the Apache License, Version 2.0 (the "License");
zrussell3 0:b176d95bb38f 5 * you may not use this file except in compliance with the License.
zrussell3 0:b176d95bb38f 6 * You may obtain a copy of the License at
zrussell3 0:b176d95bb38f 7 *
zrussell3 0:b176d95bb38f 8 * http://www.apache.org/licenses/LICENSE-2.0
zrussell3 0:b176d95bb38f 9 *
zrussell3 0:b176d95bb38f 10 * Unless required by applicable law or agreed to in writing, software
zrussell3 0:b176d95bb38f 11 * distributed under the License is distributed on an "AS IS" BASIS,
zrussell3 0:b176d95bb38f 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
zrussell3 0:b176d95bb38f 13 * See the License for the specific language governing permissions and
zrussell3 0:b176d95bb38f 14 * limitations under the License.
zrussell3 0:b176d95bb38f 15 */
zrussell3 0:b176d95bb38f 16
zrussell3 0:b176d95bb38f 17 #ifndef USBHOST_H
zrussell3 0:b176d95bb38f 18 #define USBHOST_H
zrussell3 0:b176d95bb38f 19
zrussell3 0:b176d95bb38f 20 #include "USBHALHost.h"
zrussell3 0:b176d95bb38f 21 #include "USBDeviceConnected.h"
zrussell3 0:b176d95bb38f 22 #include "IUSBEnumerator.h"
zrussell3 0:b176d95bb38f 23 #include "USBHostConf.h"
zrussell3 0:b176d95bb38f 24 #include "rtos.h"
zrussell3 0:b176d95bb38f 25 #include "dbg.h"
zrussell3 0:b176d95bb38f 26 #include "USBHostHub.h"
zrussell3 0:b176d95bb38f 27
zrussell3 0:b176d95bb38f 28 /**
zrussell3 0:b176d95bb38f 29 * USBHost class
zrussell3 0:b176d95bb38f 30 * This class is a singleton. All drivers have a reference on the static USBHost instance
zrussell3 0:b176d95bb38f 31 */
zrussell3 0:b176d95bb38f 32 class USBHost : public USBHALHost {
zrussell3 0:b176d95bb38f 33 public:
zrussell3 0:b176d95bb38f 34 /**
zrussell3 0:b176d95bb38f 35 * Static method to create or retrieve the single USBHost instance
zrussell3 0:b176d95bb38f 36 */
zrussell3 0:b176d95bb38f 37 static USBHost * getHostInst();
zrussell3 0:b176d95bb38f 38
zrussell3 0:b176d95bb38f 39 /**
zrussell3 0:b176d95bb38f 40 * Control read: setup stage, data stage and status stage
zrussell3 0:b176d95bb38f 41 *
zrussell3 0:b176d95bb38f 42 * @param dev the control read will be done for this device
zrussell3 0:b176d95bb38f 43 * @param requestType request type
zrussell3 0:b176d95bb38f 44 * @param request request
zrussell3 0:b176d95bb38f 45 * @param value value
zrussell3 0:b176d95bb38f 46 * @param index index
zrussell3 0:b176d95bb38f 47 * @param buf pointer on a buffer where will be store the data received
zrussell3 0:b176d95bb38f 48 * @param len length of the transfer
zrussell3 0:b176d95bb38f 49 *
zrussell3 0:b176d95bb38f 50 * @returns status of the control read
zrussell3 0:b176d95bb38f 51 */
zrussell3 0:b176d95bb38f 52 USB_TYPE controlRead(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len);
zrussell3 0:b176d95bb38f 53
zrussell3 0:b176d95bb38f 54 /**
zrussell3 0:b176d95bb38f 55 * Control write: setup stage, data stage and status stage
zrussell3 0:b176d95bb38f 56 *
zrussell3 0:b176d95bb38f 57 * @param dev the control write will be done for this device
zrussell3 0:b176d95bb38f 58 * @param requestType request type
zrussell3 0:b176d95bb38f 59 * @param request request
zrussell3 0:b176d95bb38f 60 * @param value value
zrussell3 0:b176d95bb38f 61 * @param index index
zrussell3 0:b176d95bb38f 62 * @param buf pointer on a buffer which will be written
zrussell3 0:b176d95bb38f 63 * @param len length of the transfer
zrussell3 0:b176d95bb38f 64 *
zrussell3 0:b176d95bb38f 65 * @returns status of the control write
zrussell3 0:b176d95bb38f 66 */
zrussell3 0:b176d95bb38f 67 USB_TYPE controlWrite(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len);
zrussell3 0:b176d95bb38f 68
zrussell3 0:b176d95bb38f 69 /**
zrussell3 0:b176d95bb38f 70 * Bulk read
zrussell3 0:b176d95bb38f 71 *
zrussell3 0:b176d95bb38f 72 * @param dev the bulk transfer will be done for this device
zrussell3 0:b176d95bb38f 73 * @param ep USBEndpoint which will be used to read a packet
zrussell3 0:b176d95bb38f 74 * @param buf pointer on a buffer where will be store the data received
zrussell3 0:b176d95bb38f 75 * @param len length of the transfer
zrussell3 0:b176d95bb38f 76 * @param blocking if true, the read is blocking (wait for completion)
zrussell3 0:b176d95bb38f 77 *
zrussell3 0:b176d95bb38f 78 * @returns status of the bulk read
zrussell3 0:b176d95bb38f 79 */
zrussell3 0:b176d95bb38f 80 USB_TYPE bulkRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
zrussell3 0:b176d95bb38f 81
zrussell3 0:b176d95bb38f 82 /**
zrussell3 0:b176d95bb38f 83 * Bulk write
zrussell3 0:b176d95bb38f 84 *
zrussell3 0:b176d95bb38f 85 * @param dev the bulk transfer will be done for this device
zrussell3 0:b176d95bb38f 86 * @param ep USBEndpoint which will be used to write a packet
zrussell3 0:b176d95bb38f 87 * @param buf pointer on a buffer which will be written
zrussell3 0:b176d95bb38f 88 * @param len length of the transfer
zrussell3 0:b176d95bb38f 89 * @param blocking if true, the write is blocking (wait for completion)
zrussell3 0:b176d95bb38f 90 *
zrussell3 0:b176d95bb38f 91 * @returns status of the bulk write
zrussell3 0:b176d95bb38f 92 */
zrussell3 0:b176d95bb38f 93 USB_TYPE bulkWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
zrussell3 0:b176d95bb38f 94
zrussell3 0:b176d95bb38f 95 /**
zrussell3 0:b176d95bb38f 96 * Interrupt read
zrussell3 0:b176d95bb38f 97 *
zrussell3 0:b176d95bb38f 98 * @param dev the bulk transfer will be done for this device
zrussell3 0:b176d95bb38f 99 * @param ep USBEndpoint which will be used to write a packet
zrussell3 0:b176d95bb38f 100 * @param buf pointer on a buffer which will be written
zrussell3 0:b176d95bb38f 101 * @param len length of the transfer
zrussell3 0:b176d95bb38f 102 * @param blocking if true, the read is blocking (wait for completion)
zrussell3 0:b176d95bb38f 103 *
zrussell3 0:b176d95bb38f 104 * @returns status of the interrupt read
zrussell3 0:b176d95bb38f 105 */
zrussell3 0:b176d95bb38f 106 USB_TYPE interruptRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
zrussell3 0:b176d95bb38f 107
zrussell3 0:b176d95bb38f 108 /**
zrussell3 0:b176d95bb38f 109 * Interrupt write
zrussell3 0:b176d95bb38f 110 *
zrussell3 0:b176d95bb38f 111 * @param dev the bulk transfer will be done for this device
zrussell3 0:b176d95bb38f 112 * @param ep USBEndpoint which will be used to write a packet
zrussell3 0:b176d95bb38f 113 * @param buf pointer on a buffer which will be written
zrussell3 0:b176d95bb38f 114 * @param len length of the transfer
zrussell3 0:b176d95bb38f 115 * @param blocking if true, the write is blocking (wait for completion)
zrussell3 0:b176d95bb38f 116 *
zrussell3 0:b176d95bb38f 117 * @returns status of the interrupt write
zrussell3 0:b176d95bb38f 118 */
zrussell3 0:b176d95bb38f 119 USB_TYPE interruptWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
zrussell3 0:b176d95bb38f 120
zrussell3 0:b176d95bb38f 121 /**
zrussell3 0:b176d95bb38f 122 * Enumerate a device.
zrussell3 0:b176d95bb38f 123 *
zrussell3 0:b176d95bb38f 124 * @param dev device which will be enumerated
zrussell3 0:b176d95bb38f 125 *
zrussell3 0:b176d95bb38f 126 * @returns status of the enumeration
zrussell3 0:b176d95bb38f 127 */
zrussell3 0:b176d95bb38f 128 USB_TYPE enumerate(USBDeviceConnected * dev, IUSBEnumerator* pEnumerator);
zrussell3 0:b176d95bb38f 129
zrussell3 0:b176d95bb38f 130 /**
zrussell3 0:b176d95bb38f 131 * reset a specific device
zrussell3 0:b176d95bb38f 132 *
zrussell3 0:b176d95bb38f 133 * @param dev device which will be resetted
zrussell3 0:b176d95bb38f 134 */
zrussell3 0:b176d95bb38f 135 USB_TYPE resetDevice(USBDeviceConnected * dev);
zrussell3 0:b176d95bb38f 136
zrussell3 0:b176d95bb38f 137 /**
zrussell3 0:b176d95bb38f 138 * Get a device
zrussell3 0:b176d95bb38f 139 *
zrussell3 0:b176d95bb38f 140 * @param index index of the device which will be returned
zrussell3 0:b176d95bb38f 141 *
zrussell3 0:b176d95bb38f 142 * @returns pointer on the "index" device
zrussell3 0:b176d95bb38f 143 */
zrussell3 0:b176d95bb38f 144 USBDeviceConnected * getDevice(uint8_t index);
zrussell3 0:b176d95bb38f 145
zrussell3 0:b176d95bb38f 146 /*
zrussell3 0:b176d95bb38f 147 * If there is a HID device connected, the host stores the length of the report descriptor.
zrussell3 0:b176d95bb38f 148 * This avoid to the driver to re-ask the configuration descriptor to request the report descriptor
zrussell3 0:b176d95bb38f 149 *
zrussell3 0:b176d95bb38f 150 * @returns length of the report descriptor
zrussell3 0:b176d95bb38f 151 */
zrussell3 0:b176d95bb38f 152 inline uint16_t getLengthReportDescr() {
zrussell3 0:b176d95bb38f 153 return lenReportDescr;
zrussell3 0:b176d95bb38f 154 };
zrussell3 0:b176d95bb38f 155
zrussell3 0:b176d95bb38f 156 /**
zrussell3 0:b176d95bb38f 157 * register a driver into the host associated with a callback function called when the device is disconnected
zrussell3 0:b176d95bb38f 158 *
zrussell3 0:b176d95bb38f 159 * @param dev device
zrussell3 0:b176d95bb38f 160 * @param intf interface number
zrussell3 0:b176d95bb38f 161 * @param tptr pointer to the object to call the member function on
zrussell3 0:b176d95bb38f 162 * @param mptr pointer to the member function to be called
zrussell3 0:b176d95bb38f 163 */
zrussell3 0:b176d95bb38f 164 template<typename T>
zrussell3 0:b176d95bb38f 165 inline void registerDriver(USBDeviceConnected * dev, uint8_t intf, T* tptr, void (T::*mptr)(void)) {
zrussell3 0:b176d95bb38f 166 int index = findDevice(dev);
zrussell3 0:b176d95bb38f 167 if ((index != -1) && (mptr != NULL) && (tptr != NULL)) {
zrussell3 0:b176d95bb38f 168 USB_DBG("register driver for dev: %p on intf: %d", dev, intf);
zrussell3 0:b176d95bb38f 169 deviceAttachedDriver[index][intf] = true;
zrussell3 0:b176d95bb38f 170 dev->onDisconnect(intf, tptr, mptr);
zrussell3 0:b176d95bb38f 171 }
zrussell3 0:b176d95bb38f 172 }
zrussell3 0:b176d95bb38f 173
zrussell3 0:b176d95bb38f 174 /**
zrussell3 0:b176d95bb38f 175 * register a driver into the host associated with a callback function called when the device is disconnected
zrussell3 0:b176d95bb38f 176 *
zrussell3 0:b176d95bb38f 177 * @param dev device
zrussell3 0:b176d95bb38f 178 * @param intf interface number
zrussell3 0:b176d95bb38f 179 * @param fn callback called when the specified device has been disconnected
zrussell3 0:b176d95bb38f 180 */
zrussell3 0:b176d95bb38f 181 inline void registerDriver(USBDeviceConnected * dev, uint8_t intf, void (*fn)(void)) {
zrussell3 0:b176d95bb38f 182 int index = findDevice(dev);
zrussell3 0:b176d95bb38f 183 if ((index != -1) && (fn != NULL)) {
zrussell3 0:b176d95bb38f 184 USB_DBG("register driver for dev: %p on intf: %d", dev, intf);
zrussell3 0:b176d95bb38f 185 deviceAttachedDriver[index][intf] = true;
zrussell3 0:b176d95bb38f 186 dev->onDisconnect(intf, fn);
zrussell3 0:b176d95bb38f 187 }
zrussell3 0:b176d95bb38f 188 }
zrussell3 0:b176d95bb38f 189
zrussell3 0:b176d95bb38f 190 friend class USBHostHub;
zrussell3 0:b176d95bb38f 191
zrussell3 0:b176d95bb38f 192 protected:
zrussell3 0:b176d95bb38f 193
zrussell3 0:b176d95bb38f 194 /**
zrussell3 0:b176d95bb38f 195 * Virtual method called when a transfer has been completed
zrussell3 0:b176d95bb38f 196 *
zrussell3 0:b176d95bb38f 197 * @param addr list of the TDs which have been completed
zrussell3 0:b176d95bb38f 198 */
zrussell3 0:b176d95bb38f 199 virtual void transferCompleted(volatile uint32_t addr);
zrussell3 0:b176d95bb38f 200
zrussell3 0:b176d95bb38f 201 /**
zrussell3 0:b176d95bb38f 202 * Virtual method called when a device has been connected
zrussell3 0:b176d95bb38f 203 *
zrussell3 0:b176d95bb38f 204 * @param hub hub number of the device
zrussell3 0:b176d95bb38f 205 * @param port port number of the device
zrussell3 0:b176d95bb38f 206 * @param lowSpeed 1 if low speed, 0 otherwise
zrussell3 0:b176d95bb38f 207 * @param hub_parent reference on the parent hub
zrussell3 0:b176d95bb38f 208 */
zrussell3 0:b176d95bb38f 209 virtual void deviceConnected(int hub, int port, bool lowSpeed, USBHostHub * hub_parent = NULL);
zrussell3 0:b176d95bb38f 210
zrussell3 0:b176d95bb38f 211 /**
zrussell3 0:b176d95bb38f 212 * Virtuel method called when a device has been disconnected
zrussell3 0:b176d95bb38f 213 *
zrussell3 0:b176d95bb38f 214 * @param hub hub number of the device
zrussell3 0:b176d95bb38f 215 * @param port port number of the device
zrussell3 0:b176d95bb38f 216 * @param addr list of the TDs which have been completed to dequeue freed TDs
zrussell3 0:b176d95bb38f 217 */
zrussell3 0:b176d95bb38f 218 virtual void deviceDisconnected(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr);
zrussell3 0:b176d95bb38f 219
zrussell3 0:b176d95bb38f 220
zrussell3 0:b176d95bb38f 221 private:
zrussell3 0:b176d95bb38f 222 // singleton class -> constructor is private
zrussell3 0:b176d95bb38f 223 USBHost();
zrussell3 0:b176d95bb38f 224 static USBHost * instHost;
zrussell3 0:b176d95bb38f 225 uint16_t lenReportDescr;
zrussell3 0:b176d95bb38f 226
zrussell3 0:b176d95bb38f 227 // endpoints
zrussell3 0:b176d95bb38f 228 void unqueueEndpoint(USBEndpoint * ep) ;
zrussell3 0:b176d95bb38f 229 USBEndpoint endpoints[MAX_ENDPOINT];
zrussell3 0:b176d95bb38f 230 USBEndpoint* volatile control;
zrussell3 0:b176d95bb38f 231
zrussell3 0:b176d95bb38f 232 USBEndpoint* volatile headControlEndpoint;
zrussell3 0:b176d95bb38f 233 USBEndpoint* volatile headBulkEndpoint;
zrussell3 0:b176d95bb38f 234 USBEndpoint* volatile headInterruptEndpoint;
zrussell3 0:b176d95bb38f 235
zrussell3 0:b176d95bb38f 236 USBEndpoint* volatile tailControlEndpoint;
zrussell3 0:b176d95bb38f 237 USBEndpoint* volatile tailBulkEndpoint;
zrussell3 0:b176d95bb38f 238 USBEndpoint* volatile tailInterruptEndpoint;
zrussell3 0:b176d95bb38f 239
zrussell3 0:b176d95bb38f 240 bool controlEndpointAllocated;
zrussell3 0:b176d95bb38f 241
zrussell3 0:b176d95bb38f 242 // devices connected
zrussell3 0:b176d95bb38f 243 USBDeviceConnected devices[MAX_DEVICE_CONNECTED];
zrussell3 0:b176d95bb38f 244 bool deviceInUse[MAX_DEVICE_CONNECTED];
zrussell3 0:b176d95bb38f 245 bool deviceAttachedDriver[MAX_DEVICE_CONNECTED][MAX_INTF];
zrussell3 0:b176d95bb38f 246 bool deviceReset[MAX_DEVICE_CONNECTED];
zrussell3 0:b176d95bb38f 247 bool deviceInited[MAX_DEVICE_CONNECTED];
zrussell3 0:b176d95bb38f 248
zrussell3 0:b176d95bb38f 249 #if MAX_HUB_NB
zrussell3 0:b176d95bb38f 250 USBHostHub hubs[MAX_HUB_NB];
zrussell3 0:b176d95bb38f 251 bool hub_in_use[MAX_HUB_NB];
zrussell3 0:b176d95bb38f 252 #endif
zrussell3 0:b176d95bb38f 253
zrussell3 0:b176d95bb38f 254 // to store a setup packet
zrussell3 0:b176d95bb38f 255 uint8_t setupPacket[8];
zrussell3 0:b176d95bb38f 256
zrussell3 0:b176d95bb38f 257 typedef struct {
zrussell3 0:b176d95bb38f 258 uint8_t event_id;
zrussell3 0:b176d95bb38f 259 void * td_addr;
zrussell3 0:b176d95bb38f 260 uint8_t hub;
zrussell3 0:b176d95bb38f 261 uint8_t port;
zrussell3 0:b176d95bb38f 262 uint8_t lowSpeed;
zrussell3 0:b176d95bb38f 263 uint8_t td_state;
zrussell3 0:b176d95bb38f 264 void * hub_parent;
zrussell3 0:b176d95bb38f 265 } message_t;
zrussell3 0:b176d95bb38f 266
zrussell3 0:b176d95bb38f 267 Thread usbThread;
zrussell3 0:b176d95bb38f 268 void usb_process();
zrussell3 0:b176d95bb38f 269 static void usb_process_static(void const * arg);
zrussell3 0:b176d95bb38f 270 Mail<message_t, 10> mail_usb_event;
zrussell3 0:b176d95bb38f 271 Mutex usb_mutex;
zrussell3 0:b176d95bb38f 272 Mutex td_mutex;
zrussell3 0:b176d95bb38f 273
zrussell3 0:b176d95bb38f 274 // buffer for conf descriptor
zrussell3 0:b176d95bb38f 275 uint8_t data[415];
zrussell3 0:b176d95bb38f 276
zrussell3 0:b176d95bb38f 277 /**
zrussell3 0:b176d95bb38f 278 * Add a transfer on the TD linked list associated to an ED
zrussell3 0:b176d95bb38f 279 *
zrussell3 0:b176d95bb38f 280 * @param ed the transfer is associated to this ed
zrussell3 0:b176d95bb38f 281 * @param buf pointer on a buffer where will be read/write data to send or receive
zrussell3 0:b176d95bb38f 282 * @param len transfer length
zrussell3 0:b176d95bb38f 283 *
zrussell3 0:b176d95bb38f 284 * @return status of the transfer
zrussell3 0:b176d95bb38f 285 */
zrussell3 0:b176d95bb38f 286 USB_TYPE addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len) ;
zrussell3 0:b176d95bb38f 287
zrussell3 0:b176d95bb38f 288 /**
zrussell3 0:b176d95bb38f 289 * Link the USBEndpoint to the linked list and attach an USBEndpoint this USBEndpoint to a device
zrussell3 0:b176d95bb38f 290 *
zrussell3 0:b176d95bb38f 291 * @param dev pointer on a USBDeviceConnected object
zrussell3 0:b176d95bb38f 292 * @param ep pointer on the USBEndpoint which will be added
zrussell3 0:b176d95bb38f 293 *
zrussell3 0:b176d95bb38f 294 * return true if successful
zrussell3 0:b176d95bb38f 295 */
zrussell3 0:b176d95bb38f 296 bool addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint * ep) ;
zrussell3 0:b176d95bb38f 297
zrussell3 0:b176d95bb38f 298 /**
zrussell3 0:b176d95bb38f 299 * Create an USBEndpoint descriptor. Warning: the USBEndpoint is not linked.
zrussell3 0:b176d95bb38f 300 *
zrussell3 0:b176d95bb38f 301 * @param type USBEndpoint type (CONTROL_ENDPOINT, BULK_ENDPOINT, INTERRUPT_ENDPOINT)
zrussell3 0:b176d95bb38f 302 * @param dir USBEndpoint direction (no meaning for CONTROL_ENDPOINT)
zrussell3 0:b176d95bb38f 303 * @param size USBEndpoint max packet size
zrussell3 0:b176d95bb38f 304 * @param addr USBEndpoint address
zrussell3 0:b176d95bb38f 305 *
zrussell3 0:b176d95bb38f 306 * @returns pointer on the USBEndpoint created
zrussell3 0:b176d95bb38f 307 */
zrussell3 0:b176d95bb38f 308 USBEndpoint * newEndpoint(ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t addr) ;
zrussell3 0:b176d95bb38f 309
zrussell3 0:b176d95bb38f 310 /**
zrussell3 0:b176d95bb38f 311 * Request the device descriptor
zrussell3 0:b176d95bb38f 312 *
zrussell3 0:b176d95bb38f 313 * @param dev request the device descriptor on this device
zrussell3 0:b176d95bb38f 314 * @param buf buffer to store the device descriptor
zrussell3 0:b176d95bb38f 315 * @param max_len_buf maximum size of buf
zrussell3 0:b176d95bb38f 316 * @param len_dev_descr pointer to store the length of the packet transferred
zrussell3 0:b176d95bb38f 317 */
zrussell3 0:b176d95bb38f 318 USB_TYPE getDeviceDescriptor(USBDeviceConnected * dev, uint8_t * buf, uint16_t max_len_buf, uint16_t * len_dev_descr = NULL);
zrussell3 0:b176d95bb38f 319
zrussell3 0:b176d95bb38f 320 /**
zrussell3 0:b176d95bb38f 321 * Request the configuration descriptor
zrussell3 0:b176d95bb38f 322 *
zrussell3 0:b176d95bb38f 323 * @param dev request the configuration descriptor on this device
zrussell3 0:b176d95bb38f 324 * @param buf buffer to store the configuration descriptor
zrussell3 0:b176d95bb38f 325 * @param max_len_buf maximum size of buf
zrussell3 0:b176d95bb38f 326 * @param len_conf_descr pointer to store the length of the packet transferred
zrussell3 0:b176d95bb38f 327 */
zrussell3 0:b176d95bb38f 328 USB_TYPE getConfigurationDescriptor(USBDeviceConnected * dev, uint8_t * buf, uint16_t max_len_buf, uint16_t * len_conf_descr = NULL);
zrussell3 0:b176d95bb38f 329
zrussell3 0:b176d95bb38f 330 /**
zrussell3 0:b176d95bb38f 331 * Set the address of a specific device
zrussell3 0:b176d95bb38f 332 *
zrussell3 0:b176d95bb38f 333 * @param dev device to set the address
zrussell3 0:b176d95bb38f 334 * @param address address
zrussell3 0:b176d95bb38f 335 */
zrussell3 0:b176d95bb38f 336 USB_TYPE setAddress(USBDeviceConnected * dev, uint8_t address);
zrussell3 0:b176d95bb38f 337
zrussell3 0:b176d95bb38f 338 /**
zrussell3 0:b176d95bb38f 339 * Set the configuration of a device
zrussell3 0:b176d95bb38f 340 *
zrussell3 0:b176d95bb38f 341 * @param dev device on which the specified configuration will be activated
zrussell3 0:b176d95bb38f 342 * @param conf configuration number to activate (usually 1)
zrussell3 0:b176d95bb38f 343 */
zrussell3 0:b176d95bb38f 344 USB_TYPE setConfiguration(USBDeviceConnected * dev, uint8_t conf);
zrussell3 0:b176d95bb38f 345
zrussell3 0:b176d95bb38f 346 /**
zrussell3 0:b176d95bb38f 347 * Free a specific device
zrussell3 0:b176d95bb38f 348 *
zrussell3 0:b176d95bb38f 349 * @param dev device to be freed
zrussell3 0:b176d95bb38f 350 */
zrussell3 0:b176d95bb38f 351 void freeDevice(USBDeviceConnected * dev);
zrussell3 0:b176d95bb38f 352
zrussell3 0:b176d95bb38f 353 USB_TYPE controlTransfer( USBDeviceConnected * dev,
zrussell3 0:b176d95bb38f 354 uint8_t requestType,
zrussell3 0:b176d95bb38f 355 uint8_t request,
zrussell3 0:b176d95bb38f 356 uint32_t value,
zrussell3 0:b176d95bb38f 357 uint32_t index,
zrussell3 0:b176d95bb38f 358 uint8_t * buf,
zrussell3 0:b176d95bb38f 359 uint32_t len,
zrussell3 0:b176d95bb38f 360 bool write);
zrussell3 0:b176d95bb38f 361
zrussell3 0:b176d95bb38f 362 USB_TYPE generalTransfer( USBDeviceConnected * dev,
zrussell3 0:b176d95bb38f 363 USBEndpoint * ep,
zrussell3 0:b176d95bb38f 364 uint8_t * buf,
zrussell3 0:b176d95bb38f 365 uint32_t len,
zrussell3 0:b176d95bb38f 366 bool blocking,
zrussell3 0:b176d95bb38f 367 ENDPOINT_TYPE type,
zrussell3 0:b176d95bb38f 368 bool write) ;
zrussell3 0:b176d95bb38f 369
zrussell3 0:b176d95bb38f 370 void fillControlBuf(uint8_t requestType, uint8_t request, uint16_t value, uint16_t index, int len) ;
zrussell3 0:b176d95bb38f 371 void parseConfDescr(USBDeviceConnected * dev, uint8_t * conf_descr, uint32_t len, IUSBEnumerator* pEnumerator) ;
zrussell3 0:b176d95bb38f 372 int findDevice(USBDeviceConnected * dev) ;
zrussell3 0:b176d95bb38f 373 int findDevice(uint8_t hub, uint8_t port, USBHostHub * hub_parent = NULL) ;
zrussell3 0:b176d95bb38f 374 uint8_t numberDriverAttached(USBDeviceConnected * dev);
zrussell3 0:b176d95bb38f 375
zrussell3 0:b176d95bb38f 376 /////////////////////////
zrussell3 0:b176d95bb38f 377 /// FOR DEBUG
zrussell3 0:b176d95bb38f 378 /////////////////////////
zrussell3 0:b176d95bb38f 379 void printList(ENDPOINT_TYPE type);
zrussell3 0:b176d95bb38f 380
zrussell3 0:b176d95bb38f 381 };
zrussell3 0:b176d95bb38f 382
zrussell3 0:b176d95bb38f 383 #endif