Added TARGET_DISCO_F469NI in USBHOST\USBHost\TARGET_STM\USBHALHost_STM_TARGET.h

Dependents:   DISCO-F469NI_USB_Disk STM32F4xx_USB_Memory

Fork of USBHOST by ST

Committer:
kenjiArai
Date:
Sat Jan 04 23:30:59 2020 +0000
Revision:
8:3e7a33f81048
Parent:
1:ab240722d7ef
updated for STM32F4xx

Who changed what in which revision?

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