Dependencies:   FATFileSystem

Committer:
nhiro3303
Date:
Tue Aug 22 06:18:15 2017 +0000
Revision:
0:42b8e1bc6235
ps3 test library

Who changed what in which revision?

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