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
USBHostHub/USBHostHub.cpp@8:3e7a33f81048, 2020-01-04 (annotated)
- Committer:
- kenjiArai
- Date:
- Sat Jan 04 23:30:59 2020 +0000
- Revision:
- 8:3e7a33f81048
- Parent:
- 5:fc157e6bd5a5
updated for STM32F4xx
Who changed what in which revision?
User | Revision | Line number | New 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 | #include "USBHostHub.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 18 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 19 | #if MAX_HUB_NB |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 20 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 21 | #include "USBHost.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 22 | #include "dbg.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 23 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 24 | #define GET_STATUS 0x00 |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 25 | #define CLEAR_FEATURE 0x01 |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 26 | #define GET_STATE 0x02 |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 27 | #define SET_FEATURE 0x03 |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 28 | #define GET_DESCRIPTOR 0x06 |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 29 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 30 | #define PORT_CONNECTION_FEATURE (0x00) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 31 | #define PORT_ENABLE_FEATURE (0x01) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 32 | #define PORT_RESET_FEATURE (0x04) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 33 | #define PORT_POWER_FEATURE (0x08) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 34 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 35 | #define C_PORT_CONNECTION_FEATURE (16) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 36 | #define C_PORT_ENABLE_FEATURE (17) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 37 | #define C_PORT_RESET_FEATURE (20) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 38 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 39 | #define PORT_CONNECTION (1 << 0) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 40 | #define PORT_ENABLE (1 << 1) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 41 | #define PORT_SUSPEND (1 << 2) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 42 | #define PORT_OVER_CURRENT (1 << 3) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 43 | #define PORT_RESET (1 << 4) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 44 | #define PORT_POWER (1 << 8) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 45 | #define PORT_LOW_SPEED (1 << 9) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 46 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 47 | #define C_PORT_CONNECTION (1 << 16) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 48 | #define C_PORT_ENABLE (1 << 17) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 49 | #define C_PORT_SUSPEND (1 << 18) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 50 | #define C_PORT_OVER_CURRENT (1 << 19) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 51 | #define C_PORT_RESET (1 << 20) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 52 | |
kenjiArai | 8:3e7a33f81048 | 53 | USBHostHub::USBHostHub() |
kenjiArai | 8:3e7a33f81048 | 54 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 55 | host = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 56 | init(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 57 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 58 | |
kenjiArai | 8:3e7a33f81048 | 59 | void USBHostHub::init() |
kenjiArai | 8:3e7a33f81048 | 60 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 61 | dev_connected = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 62 | dev = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 63 | int_in = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 64 | dev_connected = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 65 | hub_intf = -1; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 66 | hub_device_found = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 67 | nb_port = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 68 | hub_characteristics = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 69 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 70 | for (int i = 0; i < MAX_HUB_PORT; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 71 | device_children[i] = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 72 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 73 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 74 | |
kenjiArai | 8:3e7a33f81048 | 75 | void USBHostHub::setHost(USBHost * host_) |
kenjiArai | 8:3e7a33f81048 | 76 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 77 | host = host_; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 78 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 79 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 80 | bool USBHostHub::connected() |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 81 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 82 | return dev_connected; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 83 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 84 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 85 | bool USBHostHub::connect(USBDeviceConnected * dev) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 86 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 87 | if (dev_connected) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 88 | return true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 89 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 90 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 91 | if(host->enumerate(dev, this)) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 92 | init(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 93 | return false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 94 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 95 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 96 | if (hub_device_found) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 97 | this->dev = dev; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 98 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 99 | int_in = dev->getEndpoint(hub_intf, INTERRUPT_ENDPOINT, IN); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 100 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 101 | if (!int_in) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 102 | init(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 103 | return false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 104 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 105 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 106 | USB_INFO("New HUB: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, hub_intf); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 107 | dev->setName("Hub", hub_intf); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 108 | host->registerDriver(dev, hub_intf, this, &USBHostHub::disconnect); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 109 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 110 | int_in->attach(this, &USBHostHub::rxHandler); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 111 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 112 | // get HUB descriptor |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 113 | host->controlRead( dev, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 114 | USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 115 | GET_DESCRIPTOR, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 116 | 0x29 << 8, 0, buf, sizeof(HubDescriptor)); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 117 | nb_port = buf[2]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 118 | hub_characteristics = buf[3]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 119 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 120 | USB_DBG("Hub has %d port", nb_port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 121 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 122 | for (uint8_t j = 1; j <= nb_port; j++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 123 | setPortFeature(PORT_POWER_FEATURE, j); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 124 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 125 | wait_ms(buf[5]*2); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 126 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 127 | host->interruptRead(dev, int_in, buf, 1, false); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 128 | dev_connected = true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 129 | return true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 130 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 131 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 132 | return false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 133 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 134 | |
kenjiArai | 8:3e7a33f81048 | 135 | void USBHostHub::disconnect() |
kenjiArai | 8:3e7a33f81048 | 136 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 137 | init(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 138 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 139 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 140 | /*virtual*/ void USBHostHub::setVidPid(uint16_t vid, uint16_t pid) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 141 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 142 | // we don't check VID/PID for MSD driver |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 143 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 144 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 145 | /*virtual*/ bool USBHostHub::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 146 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 147 | if ((hub_intf == -1) && |
kenjiArai | 8:3e7a33f81048 | 148 | (intf_class == HUB_CLASS) && |
kenjiArai | 8:3e7a33f81048 | 149 | (intf_subclass == 0) && |
kenjiArai | 8:3e7a33f81048 | 150 | (intf_protocol == 0)) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 151 | hub_intf = intf_nb; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 152 | return true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 153 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 154 | return false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 155 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 156 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 157 | /*virtual*/ bool USBHostHub::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 158 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 159 | if (intf_nb == hub_intf) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 160 | if ((type == INTERRUPT_ENDPOINT) && (dir == IN)) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 161 | hub_device_found = true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 162 | return true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 163 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 164 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 165 | return false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 166 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 167 | |
kenjiArai | 8:3e7a33f81048 | 168 | void USBHostHub::deviceConnected(USBDeviceConnected * dev) |
kenjiArai | 8:3e7a33f81048 | 169 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 170 | device_children[dev->getPort() - 1] = dev; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 171 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 172 | |
kenjiArai | 8:3e7a33f81048 | 173 | void USBHostHub::deviceDisconnected(USBDeviceConnected * dev) |
kenjiArai | 8:3e7a33f81048 | 174 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 175 | device_children[dev->getPort() - 1] = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 176 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 177 | |
kenjiArai | 8:3e7a33f81048 | 178 | void USBHostHub::hubDisconnected() |
kenjiArai | 8:3e7a33f81048 | 179 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 180 | for (uint8_t i = 0; i < MAX_HUB_PORT; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 181 | if (device_children[i] != NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 182 | host->freeDevice(device_children[i]); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 183 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 184 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 185 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 186 | |
kenjiArai | 8:3e7a33f81048 | 187 | void USBHostHub::rxHandler() |
kenjiArai | 8:3e7a33f81048 | 188 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 189 | uint32_t status; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 190 | if (int_in) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 191 | if ((int_in->getLengthTransferred())&&(int_in->getState() == USB_TYPE_IDLE)) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 192 | for (int port = 1; port <= nb_port; port++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 193 | status = getPortStatus(port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 194 | USB_DBG("[hub handler hub: %d] status port %d [hub: %p]: 0x%X", dev->getHub(), port, dev, status); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 195 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 196 | // if connection status has changed |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 197 | if (status & C_PORT_CONNECTION) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 198 | if (status & PORT_CONNECTION) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 199 | USB_DBG("[hub handler hub: %d - port: %d] new device connected", dev->getHub(), port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 200 | host->deviceConnected(dev->getHub() + 1, port, status & PORT_LOW_SPEED, this); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 201 | } else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 202 | USB_DBG("[hub handler hub: %d - port: %d] device disconnected", dev->getHub(), port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 203 | host->deviceDisconnected(dev->getHub() + 1, port, this, 0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 204 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 205 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 206 | clearPortFeature(C_PORT_CONNECTION_FEATURE, port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 207 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 208 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 209 | if (status & C_PORT_RESET) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 210 | clearPortFeature(C_PORT_RESET_FEATURE, port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 211 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 212 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 213 | if (status & C_PORT_ENABLE) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 214 | clearPortFeature(C_PORT_ENABLE_FEATURE, port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 215 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 216 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 217 | if ((status & PORT_OVER_CURRENT)) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 218 | USB_ERR("OVER CURRENT DETECTED\r\n"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 219 | clearPortFeature(PORT_OVER_CURRENT, port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 220 | host->deviceDisconnected(dev->getHub() + 1, port, this, 0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 221 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 222 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 223 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 224 | host->interruptRead(dev, int_in, buf, 1, false); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 225 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 226 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 227 | |
kenjiArai | 8:3e7a33f81048 | 228 | void USBHostHub::portReset(uint8_t port) |
kenjiArai | 8:3e7a33f81048 | 229 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 230 | // reset port |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 231 | uint32_t status; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 232 | USB_DBG("reset port %d on hub: %p [this: %p]", port, dev, this) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 233 | setPortFeature(PORT_RESET_FEATURE, port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 234 | #if defined(TARGET_RZ_A1H) |
kenjiArai | 8:3e7a33f81048 | 235 | ThisThread::sleep_for(50); // Reset release waiting for Hi-Speed check. |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 236 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 237 | while(1) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 238 | status = getPortStatus(port); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 239 | /* disconnection since reset request */ |
kenjiArai | 8:3e7a33f81048 | 240 | if (!(status & PORT_CONNECTION)) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 241 | break; |
kenjiArai | 8:3e7a33f81048 | 242 | } |
kenjiArai | 8:3e7a33f81048 | 243 | if (status & (PORT_ENABLE | PORT_RESET)) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 244 | break; |
kenjiArai | 8:3e7a33f81048 | 245 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 246 | if (status & PORT_OVER_CURRENT) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 247 | USB_ERR("OVER CURRENT DETECTED\r\n"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 248 | clearPortFeature(PORT_OVER_CURRENT, port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 249 | host->deviceDisconnected(dev->getHub() + 1, port, this, 0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 250 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 251 | } |
kenjiArai | 8:3e7a33f81048 | 252 | ThisThread::sleep_for(10); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 253 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 254 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 255 | |
kenjiArai | 8:3e7a33f81048 | 256 | void USBHostHub::setPortFeature(uint32_t feature, uint8_t port) |
kenjiArai | 8:3e7a33f81048 | 257 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 258 | host->controlWrite( dev, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 259 | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 260 | SET_FEATURE, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 261 | feature, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 262 | port, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 263 | NULL, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 264 | 0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 265 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 266 | |
kenjiArai | 8:3e7a33f81048 | 267 | void USBHostHub::clearPortFeature(uint32_t feature, uint8_t port) |
kenjiArai | 8:3e7a33f81048 | 268 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 269 | host->controlWrite( dev, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 270 | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 271 | CLEAR_FEATURE, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 272 | feature, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 273 | port, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 274 | NULL, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 275 | 0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 276 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 277 | |
kenjiArai | 8:3e7a33f81048 | 278 | uint32_t USBHostHub::getPortStatus(uint8_t port) |
kenjiArai | 8:3e7a33f81048 | 279 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 280 | uint32_t st; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 281 | host->controlRead( dev, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 282 | USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 283 | GET_STATUS, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 284 | 0, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 285 | port, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 286 | (uint8_t *)&st, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 287 | 4); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 288 | return st; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 289 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 290 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 291 | #endif |