2018.07.26

Dependencies:   FATFileSystem3 mbed-rtos

Fork of USBHost by mbed official

Committer:
sayzyas
Date:
Thu Jul 26 04:20:29 2018 +0000
Revision:
44:ef52682c423e
Parent:
43:1675750cca08
2018.07.26;

Who changed what in which revision?

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