final

Dependencies:   mbed FATFileSystem

Fork of KL46Z-USBHostMSD_HelloWorld by Norimasa Okamoto

Committer:
homzovam
Date:
Sat Apr 04 20:16:39 2015 +0000
Revision:
4:77d6450f34d7
prijimac-funkcni final

Who changed what in which revision?

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