2018.07.26

Dependencies:   FATFileSystem2 mbed-rtos

Fork of USBHost by mbed official

Committer:
sayzyas
Date:
Thu Jul 26 00:29:30 2018 +0000
Revision:
44:e437b1c7c61e
Parent:
43:78f328f311dc
2018.07.26

Who changed what in which revision?

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