USB BARCODE READER
Fork of USBHOST by
USBHostHub/USBHostHub.cpp@7:ccd0ac9ae1c9, 2018-07-02 (annotated)
- Committer:
- shivanandgowdakr
- Date:
- Mon Jul 02 12:10:45 2018 +0000
- Revision:
- 7:ccd0ac9ae1c9
- Parent:
- 5:fc157e6bd5a5
USB BARCODE READER ;
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 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 53 | USBHostHub::USBHostHub() { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 54 | host = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 55 | init(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 56 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 57 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 58 | void USBHostHub::init() { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 59 | dev_connected = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 60 | dev = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 61 | int_in = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 62 | dev_connected = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 63 | hub_intf = -1; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 64 | hub_device_found = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 65 | nb_port = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 66 | hub_characteristics = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 67 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 68 | for (int i = 0; i < MAX_HUB_PORT; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 69 | device_children[i] = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 70 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 71 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 72 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 73 | void USBHostHub::setHost(USBHost * host_) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 74 | host = host_; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 75 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 76 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 77 | bool USBHostHub::connected() |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 78 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 79 | return dev_connected; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 80 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 81 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 82 | bool USBHostHub::connect(USBDeviceConnected * dev) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 83 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 84 | if (dev_connected) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 85 | return true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 86 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 87 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 88 | if(host->enumerate(dev, this)) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 89 | init(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 90 | return false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 91 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 92 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 93 | if (hub_device_found) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 94 | this->dev = dev; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 95 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 96 | int_in = dev->getEndpoint(hub_intf, INTERRUPT_ENDPOINT, IN); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 97 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 98 | if (!int_in) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 99 | init(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 100 | return false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 101 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 102 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 103 | 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 | 104 | dev->setName("Hub", hub_intf); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 105 | host->registerDriver(dev, hub_intf, this, &USBHostHub::disconnect); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 106 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 107 | int_in->attach(this, &USBHostHub::rxHandler); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 108 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 109 | // get HUB descriptor |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 110 | host->controlRead( dev, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 111 | USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 112 | GET_DESCRIPTOR, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 113 | 0x29 << 8, 0, buf, sizeof(HubDescriptor)); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 114 | nb_port = buf[2]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 115 | hub_characteristics = buf[3]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 116 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 117 | USB_DBG("Hub has %d port", nb_port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 118 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 119 | for (uint8_t j = 1; j <= nb_port; j++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 120 | setPortFeature(PORT_POWER_FEATURE, j); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 121 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 122 | wait_ms(buf[5]*2); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 123 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 124 | host->interruptRead(dev, int_in, buf, 1, false); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 125 | dev_connected = true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 126 | return true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 127 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 128 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 129 | return false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 130 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 131 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 132 | void USBHostHub::disconnect() { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 133 | init(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 134 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 135 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 136 | /*virtual*/ void USBHostHub::setVidPid(uint16_t vid, uint16_t pid) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 137 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 138 | // we don't check VID/PID for MSD driver |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 139 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 140 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 141 | /*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 | 142 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 143 | if ((hub_intf == -1) && |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 144 | (intf_class == HUB_CLASS) && |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 145 | (intf_subclass == 0) && |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 146 | (intf_protocol == 0)) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 147 | hub_intf = intf_nb; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 148 | return true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 149 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 150 | return false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 151 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 152 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 153 | /*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 | 154 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 155 | if (intf_nb == hub_intf) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 156 | if ((type == INTERRUPT_ENDPOINT) && (dir == IN)) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 157 | hub_device_found = true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 158 | return true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 159 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 160 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 161 | return false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 162 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 163 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 164 | void USBHostHub::deviceConnected(USBDeviceConnected * dev) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 165 | device_children[dev->getPort() - 1] = dev; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 166 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 167 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 168 | void USBHostHub::deviceDisconnected(USBDeviceConnected * dev) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 169 | device_children[dev->getPort() - 1] = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 170 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 171 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 172 | void USBHostHub::hubDisconnected() { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 173 | for (uint8_t i = 0; i < MAX_HUB_PORT; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 174 | if (device_children[i] != NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 175 | host->freeDevice(device_children[i]); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 176 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 177 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 178 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 179 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 180 | void USBHostHub::rxHandler() { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 181 | uint32_t status; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 182 | if (int_in) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 183 | if ((int_in->getLengthTransferred())&&(int_in->getState() == USB_TYPE_IDLE)) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 184 | for (int port = 1; port <= nb_port; port++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 185 | status = getPortStatus(port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 186 | 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 | 187 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 188 | // if connection status has changed |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 189 | if (status & C_PORT_CONNECTION) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 190 | if (status & PORT_CONNECTION) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 191 | USB_DBG("[hub handler hub: %d - port: %d] new device connected", dev->getHub(), port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 192 | host->deviceConnected(dev->getHub() + 1, port, status & PORT_LOW_SPEED, this); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 193 | } else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 194 | USB_DBG("[hub handler hub: %d - port: %d] device disconnected", dev->getHub(), port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 195 | host->deviceDisconnected(dev->getHub() + 1, port, this, 0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 196 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 197 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 198 | clearPortFeature(C_PORT_CONNECTION_FEATURE, port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 199 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 200 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 201 | if (status & C_PORT_RESET) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 202 | clearPortFeature(C_PORT_RESET_FEATURE, port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 203 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 204 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 205 | if (status & C_PORT_ENABLE) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 206 | clearPortFeature(C_PORT_ENABLE_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 & PORT_OVER_CURRENT)) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 210 | USB_ERR("OVER CURRENT DETECTED\r\n"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 211 | clearPortFeature(PORT_OVER_CURRENT, port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 212 | host->deviceDisconnected(dev->getHub() + 1, port, this, 0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 213 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 214 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 215 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 216 | host->interruptRead(dev, int_in, buf, 1, false); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 217 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 218 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 219 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 220 | void USBHostHub::portReset(uint8_t port) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 221 | // reset port |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 222 | uint32_t status; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 223 | USB_DBG("reset port %d on hub: %p [this: %p]", port, dev, this) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 224 | setPortFeature(PORT_RESET_FEATURE, port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 225 | #if defined(TARGET_RZ_A1H) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 226 | Thread::wait(50); // Reset release waiting for Hi-Speed check. |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 227 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 228 | while(1) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 229 | status = getPortStatus(port); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 230 | /* disconnection since reset request */ |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 231 | if (!(status & PORT_CONNECTION)) |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 232 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 233 | if (status & (PORT_ENABLE | PORT_RESET)) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 234 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 235 | if (status & PORT_OVER_CURRENT) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 236 | USB_ERR("OVER CURRENT DETECTED\r\n"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 237 | clearPortFeature(PORT_OVER_CURRENT, port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 238 | host->deviceDisconnected(dev->getHub() + 1, port, this, 0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 239 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 240 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 241 | Thread::wait(10); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 242 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 243 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 244 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 245 | void USBHostHub::setPortFeature(uint32_t feature, uint8_t port) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 246 | host->controlWrite( dev, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 247 | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 248 | SET_FEATURE, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 249 | feature, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 250 | port, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 251 | NULL, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 252 | 0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 253 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 254 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 255 | void USBHostHub::clearPortFeature(uint32_t feature, uint8_t port) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 256 | host->controlWrite( dev, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 257 | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 258 | CLEAR_FEATURE, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 259 | feature, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 260 | port, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 261 | NULL, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 262 | 0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 263 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 264 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 265 | uint32_t USBHostHub::getPortStatus(uint8_t port) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 266 | uint32_t st; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 267 | host->controlRead( dev, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 268 | USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 269 | GET_STATUS, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 270 | 0, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 271 | port, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 272 | (uint8_t *)&st, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 273 | 4); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 274 | return st; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 275 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 276 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 277 | #endif |