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