USB Host Driver with Socket Modem support. Works with revision 323 of mbed-src but broken with any later version.
Dependencies: FATFileSystem
Fork of F401RE-USBHost by
USBHost/USBHost.h@10:40c7f6788902, 2014-02-05 (annotated)
- Committer:
- va009039
- Date:
- Wed Feb 05 13:34:37 2014 +0000
- Revision:
- 10:40c7f6788902
- Parent:
- 9:7f9f64cf5ded
fix endpoint callback.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 10:40c7f6788902 | 1 | /* mbed USBHost Library |
va009039 | 10:40c7f6788902 | 2 | * Copyright (c) 2006-2013 ARM Limited |
va009039 | 10:40c7f6788902 | 3 | * |
va009039 | 10:40c7f6788902 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
va009039 | 10:40c7f6788902 | 5 | * you may not use this file except in compliance with the License. |
va009039 | 10:40c7f6788902 | 6 | * You may obtain a copy of the License at |
va009039 | 10:40c7f6788902 | 7 | * |
va009039 | 10:40c7f6788902 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
va009039 | 10:40c7f6788902 | 9 | * |
va009039 | 10:40c7f6788902 | 10 | * Unless required by applicable law or agreed to in writing, software |
va009039 | 10:40c7f6788902 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
va009039 | 10:40c7f6788902 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
va009039 | 10:40c7f6788902 | 13 | * See the License for the specific language governing permissions and |
va009039 | 10:40c7f6788902 | 14 | * limitations under the License. |
va009039 | 10:40c7f6788902 | 15 | */ |
va009039 | 10:40c7f6788902 | 16 | |
va009039 | 7:9a20482c9a7a | 17 | #pragma once |
va009039 | 7:9a20482c9a7a | 18 | #include "mbed.h" |
va009039 | 7:9a20482c9a7a | 19 | #include "USBHALHost.h" |
va009039 | 7:9a20482c9a7a | 20 | #include "USBDeviceConnected.h" |
va009039 | 8:6463cd1964c0 | 21 | #include "IUSBEnumerator.h" |
va009039 | 8:6463cd1964c0 | 22 | #include "USBHostConf.h" |
va009039 | 9:7f9f64cf5ded | 23 | #include "dbg.h" |
va009039 | 10:40c7f6788902 | 24 | #include "myvector.h" |
va009039 | 7:9a20482c9a7a | 25 | |
va009039 | 10:40c7f6788902 | 26 | /** |
va009039 | 10:40c7f6788902 | 27 | * USBHost class |
va009039 | 10:40c7f6788902 | 28 | * This class is a singleton. All drivers have a reference on the static USBHost instance |
va009039 | 10:40c7f6788902 | 29 | */ |
va009039 | 7:9a20482c9a7a | 30 | class USBHost : public USBHALHost { |
va009039 | 7:9a20482c9a7a | 31 | public: |
va009039 | 7:9a20482c9a7a | 32 | /** |
va009039 | 7:9a20482c9a7a | 33 | * Static method to create or retrieve the single USBHost instance |
va009039 | 7:9a20482c9a7a | 34 | */ |
va009039 | 7:9a20482c9a7a | 35 | static USBHost* getHostInst(); |
va009039 | 7:9a20482c9a7a | 36 | |
va009039 | 7:9a20482c9a7a | 37 | /** |
va009039 | 7:9a20482c9a7a | 38 | * Control read: setup stage, data stage and status stage |
va009039 | 7:9a20482c9a7a | 39 | * |
va009039 | 7:9a20482c9a7a | 40 | * @param dev the control read will be done for this device |
va009039 | 7:9a20482c9a7a | 41 | * @param requestType request type |
va009039 | 7:9a20482c9a7a | 42 | * @param request request |
va009039 | 7:9a20482c9a7a | 43 | * @param value value |
va009039 | 7:9a20482c9a7a | 44 | * @param index index |
va009039 | 7:9a20482c9a7a | 45 | * @param buf pointer on a buffer where will be store the data received |
va009039 | 7:9a20482c9a7a | 46 | * @param len length of the transfer |
va009039 | 7:9a20482c9a7a | 47 | * |
va009039 | 7:9a20482c9a7a | 48 | * @returns status of the control read |
va009039 | 7:9a20482c9a7a | 49 | */ |
va009039 | 7:9a20482c9a7a | 50 | USB_TYPE controlRead(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len); |
va009039 | 7:9a20482c9a7a | 51 | |
va009039 | 7:9a20482c9a7a | 52 | /** |
va009039 | 7:9a20482c9a7a | 53 | * Control write: setup stage, data stage and status stage |
va009039 | 7:9a20482c9a7a | 54 | * |
va009039 | 7:9a20482c9a7a | 55 | * @param dev the control write will be done for this device |
va009039 | 7:9a20482c9a7a | 56 | * @param requestType request type |
va009039 | 7:9a20482c9a7a | 57 | * @param request request |
va009039 | 7:9a20482c9a7a | 58 | * @param value value |
va009039 | 7:9a20482c9a7a | 59 | * @param index index |
va009039 | 7:9a20482c9a7a | 60 | * @param buf pointer on a buffer which will be written |
va009039 | 7:9a20482c9a7a | 61 | * @param len length of the transfer |
va009039 | 7:9a20482c9a7a | 62 | * |
va009039 | 7:9a20482c9a7a | 63 | * @returns status of the control write |
va009039 | 7:9a20482c9a7a | 64 | */ |
va009039 | 7:9a20482c9a7a | 65 | USB_TYPE controlWrite(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len); |
va009039 | 9:7f9f64cf5ded | 66 | |
va009039 | 7:9a20482c9a7a | 67 | /** |
va009039 | 7:9a20482c9a7a | 68 | * Bulk read |
va009039 | 7:9a20482c9a7a | 69 | * |
va009039 | 7:9a20482c9a7a | 70 | * @param dev the bulk transfer will be done for this device |
va009039 | 7:9a20482c9a7a | 71 | * @param ep USBEndpoint which will be used to read a packet |
va009039 | 7:9a20482c9a7a | 72 | * @param buf pointer on a buffer where will be store the data received |
va009039 | 7:9a20482c9a7a | 73 | * @param len length of the transfer |
va009039 | 7:9a20482c9a7a | 74 | * @param blocking if true, the read is blocking (wait for completion) |
va009039 | 7:9a20482c9a7a | 75 | * |
va009039 | 7:9a20482c9a7a | 76 | * @returns status of the bulk read |
va009039 | 7:9a20482c9a7a | 77 | */ |
va009039 | 7:9a20482c9a7a | 78 | USB_TYPE bulkRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true); |
va009039 | 7:9a20482c9a7a | 79 | |
va009039 | 7:9a20482c9a7a | 80 | /** |
va009039 | 7:9a20482c9a7a | 81 | * Bulk write |
va009039 | 7:9a20482c9a7a | 82 | * |
va009039 | 7:9a20482c9a7a | 83 | * @param dev the bulk transfer will be done for this device |
va009039 | 7:9a20482c9a7a | 84 | * @param ep USBEndpoint which will be used to write a packet |
va009039 | 7:9a20482c9a7a | 85 | * @param buf pointer on a buffer which will be written |
va009039 | 7:9a20482c9a7a | 86 | * @param len length of the transfer |
va009039 | 7:9a20482c9a7a | 87 | * @param blocking if true, the write is blocking (wait for completion) |
va009039 | 7:9a20482c9a7a | 88 | * |
va009039 | 7:9a20482c9a7a | 89 | * @returns status of the bulk write |
va009039 | 7:9a20482c9a7a | 90 | */ |
va009039 | 7:9a20482c9a7a | 91 | USB_TYPE bulkWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true); |
va009039 | 7:9a20482c9a7a | 92 | |
va009039 | 7:9a20482c9a7a | 93 | /** |
va009039 | 7:9a20482c9a7a | 94 | * Interrupt read |
va009039 | 7:9a20482c9a7a | 95 | * |
va009039 | 7:9a20482c9a7a | 96 | * @param dev the interrupt transfer will be done for this device |
va009039 | 7:9a20482c9a7a | 97 | * @param ep USBEndpoint which will be used to write a packet |
va009039 | 7:9a20482c9a7a | 98 | * @param buf pointer on a buffer which will be written |
va009039 | 7:9a20482c9a7a | 99 | * @param len length of the transfer |
va009039 | 7:9a20482c9a7a | 100 | * @param blocking if true, the read is blocking (wait for completion) |
va009039 | 7:9a20482c9a7a | 101 | * |
va009039 | 7:9a20482c9a7a | 102 | * @returns status of the interrupt read |
va009039 | 7:9a20482c9a7a | 103 | */ |
va009039 | 7:9a20482c9a7a | 104 | USB_TYPE interruptRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true); |
va009039 | 7:9a20482c9a7a | 105 | |
va009039 | 7:9a20482c9a7a | 106 | /** |
va009039 | 7:9a20482c9a7a | 107 | * Interrupt write |
va009039 | 7:9a20482c9a7a | 108 | * |
va009039 | 7:9a20482c9a7a | 109 | * @param dev the interrupt transfer will be done for this device |
va009039 | 7:9a20482c9a7a | 110 | * @param ep USBEndpoint which will be used to write a packet |
va009039 | 7:9a20482c9a7a | 111 | * @param buf pointer on a buffer which will be written |
va009039 | 7:9a20482c9a7a | 112 | * @param len length of the transfer |
va009039 | 7:9a20482c9a7a | 113 | * @param blocking if true, the write is blocking (wait for completion) |
va009039 | 7:9a20482c9a7a | 114 | * |
va009039 | 7:9a20482c9a7a | 115 | * @returns status of the interrupt write |
va009039 | 7:9a20482c9a7a | 116 | */ |
va009039 | 7:9a20482c9a7a | 117 | USB_TYPE interruptWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true); |
va009039 | 7:9a20482c9a7a | 118 | |
va009039 | 8:6463cd1964c0 | 119 | /** |
va009039 | 9:7f9f64cf5ded | 120 | * Isochronous read |
va009039 | 9:7f9f64cf5ded | 121 | * |
va009039 | 9:7f9f64cf5ded | 122 | * @param dev the isochronous transfer will be done for this device |
va009039 | 9:7f9f64cf5ded | 123 | * @param ep USBEndpoint which will be used to write a packet |
va009039 | 9:7f9f64cf5ded | 124 | * @param buf pointer on a buffer which will be written |
va009039 | 9:7f9f64cf5ded | 125 | * @param len length of the transfer |
va009039 | 9:7f9f64cf5ded | 126 | * @param blocking if true, the read is blocking (wait for completion) |
va009039 | 9:7f9f64cf5ded | 127 | * |
va009039 | 9:7f9f64cf5ded | 128 | * @returns status of the interrupt read |
va009039 | 9:7f9f64cf5ded | 129 | */ |
va009039 | 9:7f9f64cf5ded | 130 | USB_TYPE isochronousRead(USBDeviceConnected* dev, USBEndpoint* ep, uint8_t* buf, uint32_t len, bool blocking = true); |
va009039 | 9:7f9f64cf5ded | 131 | |
va009039 | 9:7f9f64cf5ded | 132 | /** |
va009039 | 8:6463cd1964c0 | 133 | * Enumerate a device. |
va009039 | 8:6463cd1964c0 | 134 | * |
va009039 | 8:6463cd1964c0 | 135 | * @param dev device which will be enumerated |
va009039 | 8:6463cd1964c0 | 136 | * |
va009039 | 8:6463cd1964c0 | 137 | * @returns status of the enumeration |
va009039 | 8:6463cd1964c0 | 138 | */ |
va009039 | 8:6463cd1964c0 | 139 | USB_TYPE enumerate(USBDeviceConnected * dev, IUSBEnumerator* pEnumerator); |
va009039 | 8:6463cd1964c0 | 140 | |
va009039 | 8:6463cd1964c0 | 141 | /** |
va009039 | 8:6463cd1964c0 | 142 | * Get a device |
va009039 | 8:6463cd1964c0 | 143 | * |
va009039 | 8:6463cd1964c0 | 144 | * @param index index of the device which will be returned |
va009039 | 8:6463cd1964c0 | 145 | * |
va009039 | 8:6463cd1964c0 | 146 | * @returns pointer on the "index" device |
va009039 | 8:6463cd1964c0 | 147 | */ |
va009039 | 8:6463cd1964c0 | 148 | USBDeviceConnected * getDevice(uint8_t index) { |
va009039 | 10:40c7f6788902 | 149 | return index < DeviceLists.size() ? DeviceLists[index] : NULL; |
va009039 | 8:6463cd1964c0 | 150 | } |
va009039 | 8:6463cd1964c0 | 151 | |
va009039 | 8:6463cd1964c0 | 152 | /** |
va009039 | 8:6463cd1964c0 | 153 | * register a driver into the host associated with a callback function called when the device is disconnected |
va009039 | 8:6463cd1964c0 | 154 | * |
va009039 | 8:6463cd1964c0 | 155 | * @param dev device |
va009039 | 8:6463cd1964c0 | 156 | * @param intf interface number |
va009039 | 8:6463cd1964c0 | 157 | * @param tptr pointer to the object to call the member function on |
va009039 | 8:6463cd1964c0 | 158 | * @param mptr pointer to the member function to be called |
va009039 | 8:6463cd1964c0 | 159 | */ |
va009039 | 8:6463cd1964c0 | 160 | template<typename T> |
va009039 | 8:6463cd1964c0 | 161 | void registerDriver(USBDeviceConnected * dev, uint8_t intf, T* tptr, void (T::*mptr)(void)) { |
va009039 | 8:6463cd1964c0 | 162 | } |
va009039 | 8:6463cd1964c0 | 163 | |
va009039 | 9:7f9f64cf5ded | 164 | // KL46Z-USBHost extensions |
va009039 | 9:7f9f64cf5ded | 165 | int interruptReadNB(USBEndpoint* ep, uint8_t* data, int size); |
va009039 | 9:7f9f64cf5ded | 166 | int interruptWriteNB(USBEndpoint* ep, const uint8_t* data, int size); |
va009039 | 9:7f9f64cf5ded | 167 | int bulkReadNB(USBEndpoint*ep, uint8_t* data, int size); |
va009039 | 9:7f9f64cf5ded | 168 | int bulkWriteNB(USBEndpoint*ep, const uint8_t* data, int size); |
va009039 | 9:7f9f64cf5ded | 169 | int isochronousReadNB(USBEndpoint*ep, uint8_t* data, int size); |
va009039 | 9:7f9f64cf5ded | 170 | static void poll(); |
va009039 | 7:9a20482c9a7a | 171 | |
va009039 | 7:9a20482c9a7a | 172 | private: |
va009039 | 7:9a20482c9a7a | 173 | USBHost(); |
va009039 | 7:9a20482c9a7a | 174 | static USBHost* inst; |
va009039 | 10:40c7f6788902 | 175 | virtual bool addDevice(USBDeviceConnected* parent, int port, bool lowSpeed); |
va009039 | 8:6463cd1964c0 | 176 | void root_enumeration(USBDeviceConnected* dev); |
va009039 | 8:6463cd1964c0 | 177 | void parseConfDescr(USBDeviceConnected* dev, uint8_t* conf_descr, uint32_t len, IUSBEnumerator* pEnumerator); |
va009039 | 10:40c7f6788902 | 178 | myvector<USBDeviceConnected*>DeviceLists; |
va009039 | 8:6463cd1964c0 | 179 | |
va009039 | 8:6463cd1964c0 | 180 | int ControlRead(USBDeviceConnected* dev, SETUP_PACKET* setup, uint8_t* data, int size); |
va009039 | 8:6463cd1964c0 | 181 | int ControlWrite(USBDeviceConnected* dev, SETUP_PACKET* setup, uint8_t* data = NULL, int size = 0); |
va009039 | 9:7f9f64cf5ded | 182 | int bulkReadBLOCK(USBEndpoint*ep, uint8_t* data, int size, int timeout_ms); |
va009039 | 9:7f9f64cf5ded | 183 | void task(); |
va009039 | 10:40c7f6788902 | 184 | EndpointQueue ep_queue; |
va009039 | 8:6463cd1964c0 | 185 | |
va009039 | 8:6463cd1964c0 | 186 | // USB HUB |
va009039 | 8:6463cd1964c0 | 187 | bool Hub(USBDeviceConnected* dev); |
va009039 | 8:6463cd1964c0 | 188 | int SetPortPower(USBDeviceConnected* dev, int port); |
va009039 | 8:6463cd1964c0 | 189 | int ClearPortPower(USBDeviceConnected* dev, int port); |
va009039 | 8:6463cd1964c0 | 190 | int PortReset(USBDeviceConnected* dev, int port); |
va009039 | 8:6463cd1964c0 | 191 | int SetPortFeature(USBDeviceConnected* dev, int feature, int index); |
va009039 | 8:6463cd1964c0 | 192 | int ClearPortFeature(USBDeviceConnected* dev, int feature, int index); |
va009039 | 8:6463cd1964c0 | 193 | int SetPortReset(USBDeviceConnected* dev, int port); |
va009039 | 8:6463cd1964c0 | 194 | int GetPortStatus(USBDeviceConnected* dev, int port, uint32_t* status); |
va009039 | 7:9a20482c9a7a | 195 | }; |
va009039 | 7:9a20482c9a7a | 196 |