Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UsbHostMAX3421E_Hello
usbhub.h@0:84353c479782, 2020-07-12 (annotated)
- Committer:
- hudakz
- Date:
- Sun Jul 12 20:39:26 2020 +0000
- Revision:
- 0:84353c479782
- Child:
- 1:2263e77400e9
MAX3421E-based USB Host Shield Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 0:84353c479782 | 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. |
hudakz | 0:84353c479782 | 2 | |
hudakz | 0:84353c479782 | 3 | This software may be distributed and modified under the terms of the GNU |
hudakz | 0:84353c479782 | 4 | General Public License version 2 (GPL2) as published by the Free Software |
hudakz | 0:84353c479782 | 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of |
hudakz | 0:84353c479782 | 6 | this file. Please note that GPL2 Section 2[b] requires that all works based |
hudakz | 0:84353c479782 | 7 | on this software must also be made publicly available under the terms of |
hudakz | 0:84353c479782 | 8 | the GPL2 ("Copyleft"). |
hudakz | 0:84353c479782 | 9 | |
hudakz | 0:84353c479782 | 10 | Contact information |
hudakz | 0:84353c479782 | 11 | ------------------- |
hudakz | 0:84353c479782 | 12 | |
hudakz | 0:84353c479782 | 13 | Circuits At Home, LTD |
hudakz | 0:84353c479782 | 14 | Web : http://www.circuitsathome.com |
hudakz | 0:84353c479782 | 15 | e-mail : support@circuitsathome.com |
hudakz | 0:84353c479782 | 16 | */ |
hudakz | 0:84353c479782 | 17 | #if !defined(__USBHUB_H__) |
hudakz | 0:84353c479782 | 18 | #define __USBHUB_H__ |
hudakz | 0:84353c479782 | 19 | |
hudakz | 0:84353c479782 | 20 | #include "Usb.h" |
hudakz | 0:84353c479782 | 21 | |
hudakz | 0:84353c479782 | 22 | #define USB_DESCRIPTOR_HUB 0x09 // Hub descriptor type |
hudakz | 0:84353c479782 | 23 | |
hudakz | 0:84353c479782 | 24 | // Hub Requests |
hudakz | 0:84353c479782 | 25 | #define bmREQ_CLEAR_HUB_FEATURE USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE |
hudakz | 0:84353c479782 | 26 | #define bmREQ_CLEAR_PORT_FEATURE USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER |
hudakz | 0:84353c479782 | 27 | #define bmREQ_CLEAR_TT_BUFFER USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER |
hudakz | 0:84353c479782 | 28 | #define bmREQ_GET_HUB_DESCRIPTOR USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE |
hudakz | 0:84353c479782 | 29 | #define bmREQ_GET_HUB_STATUS USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE |
hudakz | 0:84353c479782 | 30 | #define bmREQ_GET_PORT_STATUS USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER |
hudakz | 0:84353c479782 | 31 | #define bmREQ_RESET_TT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER |
hudakz | 0:84353c479782 | 32 | #define bmREQ_SET_HUB_DESCRIPTOR USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE |
hudakz | 0:84353c479782 | 33 | #define bmREQ_SET_HUB_FEATURE USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE |
hudakz | 0:84353c479782 | 34 | #define bmREQ_SET_PORT_FEATURE USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER |
hudakz | 0:84353c479782 | 35 | #define bmREQ_GET_TT_STATE USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER |
hudakz | 0:84353c479782 | 36 | #define bmREQ_STOP_TT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER |
hudakz | 0:84353c479782 | 37 | |
hudakz | 0:84353c479782 | 38 | // Hub Class Requests |
hudakz | 0:84353c479782 | 39 | #define HUB_REQUEST_CLEAR_TT_BUFFER 8 |
hudakz | 0:84353c479782 | 40 | #define HUB_REQUEST_RESET_TT 9 |
hudakz | 0:84353c479782 | 41 | #define HUB_REQUEST_GET_TT_STATE 10 |
hudakz | 0:84353c479782 | 42 | #define HUB_REQUEST_STOP_TT 11 |
hudakz | 0:84353c479782 | 43 | |
hudakz | 0:84353c479782 | 44 | // Hub Features |
hudakz | 0:84353c479782 | 45 | #define HUB_FEATURE_C_HUB_LOCAL_POWER 0 |
hudakz | 0:84353c479782 | 46 | #define HUB_FEATURE_C_HUB_OVER_CURRENT 1 |
hudakz | 0:84353c479782 | 47 | #define HUB_FEATURE_PORT_CONNECTION 0 |
hudakz | 0:84353c479782 | 48 | #define HUB_FEATURE_PORT_ENABLE 1 |
hudakz | 0:84353c479782 | 49 | #define HUB_FEATURE_PORT_SUSPEND 2 |
hudakz | 0:84353c479782 | 50 | #define HUB_FEATURE_PORT_OVER_CURRENT 3 |
hudakz | 0:84353c479782 | 51 | #define HUB_FEATURE_PORT_RESET 4 |
hudakz | 0:84353c479782 | 52 | #define HUB_FEATURE_PORT_POWER 8 |
hudakz | 0:84353c479782 | 53 | #define HUB_FEATURE_PORT_LOW_SPEED 9 |
hudakz | 0:84353c479782 | 54 | #define HUB_FEATURE_C_PORT_CONNECTION 16 |
hudakz | 0:84353c479782 | 55 | #define HUB_FEATURE_C_PORT_ENABLE 17 |
hudakz | 0:84353c479782 | 56 | #define HUB_FEATURE_C_PORT_SUSPEND 18 |
hudakz | 0:84353c479782 | 57 | #define HUB_FEATURE_C_PORT_OVER_CURRENT 19 |
hudakz | 0:84353c479782 | 58 | #define HUB_FEATURE_C_PORT_RESET 20 |
hudakz | 0:84353c479782 | 59 | #define HUB_FEATURE_PORT_TEST 21 |
hudakz | 0:84353c479782 | 60 | #define HUB_FEATURE_PORT_INDICATOR 22 |
hudakz | 0:84353c479782 | 61 | |
hudakz | 0:84353c479782 | 62 | // Hub Port Test Modes |
hudakz | 0:84353c479782 | 63 | #define HUB_PORT_TEST_MODE_J 1 |
hudakz | 0:84353c479782 | 64 | #define HUB_PORT_TEST_MODE_K 2 |
hudakz | 0:84353c479782 | 65 | #define HUB_PORT_TEST_MODE_SE0_NAK 3 |
hudakz | 0:84353c479782 | 66 | #define HUB_PORT_TEST_MODE_PACKET 4 |
hudakz | 0:84353c479782 | 67 | #define HUB_PORT_TEST_MODE_FORCE_ENABLE 5 |
hudakz | 0:84353c479782 | 68 | |
hudakz | 0:84353c479782 | 69 | // Hub Port Indicator Color |
hudakz | 0:84353c479782 | 70 | #define HUB_PORT_INDICATOR_AUTO 0 |
hudakz | 0:84353c479782 | 71 | #define HUB_PORT_INDICATOR_AMBER 1 |
hudakz | 0:84353c479782 | 72 | #define HUB_PORT_INDICATOR_GREEN 2 |
hudakz | 0:84353c479782 | 73 | #define HUB_PORT_INDICATOR_OFF 3 |
hudakz | 0:84353c479782 | 74 | |
hudakz | 0:84353c479782 | 75 | // Hub Port Status Bitmasks |
hudakz | 0:84353c479782 | 76 | #define bmHUB_PORT_STATUS_PORT_CONNECTION 0x0001 |
hudakz | 0:84353c479782 | 77 | #define bmHUB_PORT_STATUS_PORT_ENABLE 0x0002 |
hudakz | 0:84353c479782 | 78 | #define bmHUB_PORT_STATUS_PORT_SUSPEND 0x0004 |
hudakz | 0:84353c479782 | 79 | #define bmHUB_PORT_STATUS_PORT_OVER_CURRENT 0x0008 |
hudakz | 0:84353c479782 | 80 | #define bmHUB_PORT_STATUS_PORT_RESET 0x0010 |
hudakz | 0:84353c479782 | 81 | #define bmHUB_PORT_STATUS_PORT_POWER 0x0100 |
hudakz | 0:84353c479782 | 82 | #define bmHUB_PORT_STATUS_PORT_LOW_SPEED 0x0200 |
hudakz | 0:84353c479782 | 83 | #define bmHUB_PORT_STATUS_PORT_HIGH_SPEED 0x0400 |
hudakz | 0:84353c479782 | 84 | #define bmHUB_PORT_STATUS_PORT_TEST 0x0800 |
hudakz | 0:84353c479782 | 85 | #define bmHUB_PORT_STATUS_PORT_INDICATOR 0x1000 |
hudakz | 0:84353c479782 | 86 | |
hudakz | 0:84353c479782 | 87 | // Hub Port Status Change Bitmasks (used one byte instead of two) |
hudakz | 0:84353c479782 | 88 | #define bmHUB_PORT_STATUS_C_PORT_CONNECTION 0x0001 |
hudakz | 0:84353c479782 | 89 | #define bmHUB_PORT_STATUS_C_PORT_ENABLE 0x0002 |
hudakz | 0:84353c479782 | 90 | #define bmHUB_PORT_STATUS_C_PORT_SUSPEND 0x0004 |
hudakz | 0:84353c479782 | 91 | #define bmHUB_PORT_STATUS_C_PORT_OVER_CURRENT 0x0008 |
hudakz | 0:84353c479782 | 92 | #define bmHUB_PORT_STATUS_C_PORT_RESET 0x0010 |
hudakz | 0:84353c479782 | 93 | |
hudakz | 0:84353c479782 | 94 | // Hub Status Bitmasks (used one byte instead of two) |
hudakz | 0:84353c479782 | 95 | #define bmHUB_STATUS_LOCAL_POWER_SOURCE 0x01 |
hudakz | 0:84353c479782 | 96 | #define bmHUB_STATUS_OVER_CURRENT 0x12 |
hudakz | 0:84353c479782 | 97 | |
hudakz | 0:84353c479782 | 98 | // Hub Status Change Bitmasks (used one byte instead of two) |
hudakz | 0:84353c479782 | 99 | #define bmHUB_STATUS_C_LOCAL_POWER_SOURCE 0x01 |
hudakz | 0:84353c479782 | 100 | #define bmHUB_STATUS_C_OVER_CURRENT 0x12 |
hudakz | 0:84353c479782 | 101 | |
hudakz | 0:84353c479782 | 102 | |
hudakz | 0:84353c479782 | 103 | // Hub Port Configuring Substates |
hudakz | 0:84353c479782 | 104 | #define USB_STATE_HUB_PORT_CONFIGURING 0xb0 |
hudakz | 0:84353c479782 | 105 | #define USB_STATE_HUB_PORT_POWERED_OFF 0xb1 |
hudakz | 0:84353c479782 | 106 | #define USB_STATE_HUB_PORT_WAIT_FOR_POWER_GOOD 0xb2 |
hudakz | 0:84353c479782 | 107 | #define USB_STATE_HUB_PORT_DISCONNECTED 0xb3 |
hudakz | 0:84353c479782 | 108 | #define USB_STATE_HUB_PORT_DISABLED 0xb4 |
hudakz | 0:84353c479782 | 109 | #define USB_STATE_HUB_PORT_RESETTING 0xb5 |
hudakz | 0:84353c479782 | 110 | #define USB_STATE_HUB_PORT_ENABLED 0xb6 |
hudakz | 0:84353c479782 | 111 | |
hudakz | 0:84353c479782 | 112 | // Additional Error Codes |
hudakz | 0:84353c479782 | 113 | #define HUB_ERROR_PORT_HAS_BEEN_RESET 0xb1 |
hudakz | 0:84353c479782 | 114 | |
hudakz | 0:84353c479782 | 115 | // The bit mask to check for all necessary state bits |
hudakz | 0:84353c479782 | 116 | #define bmHUB_PORT_STATUS_ALL_MAIN ((0UL | bmHUB_PORT_STATUS_C_PORT_CONNECTION | bmHUB_PORT_STATUS_C_PORT_ENABLE | bmHUB_PORT_STATUS_C_PORT_SUSPEND | bmHUB_PORT_STATUS_C_PORT_RESET) << 16) | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_ENABLE | bmHUB_PORT_STATUS_PORT_CONNECTION | bmHUB_PORT_STATUS_PORT_SUSPEND) |
hudakz | 0:84353c479782 | 117 | |
hudakz | 0:84353c479782 | 118 | // Bit mask to check for DISABLED state in HubEvent::bmStatus field |
hudakz | 0:84353c479782 | 119 | #define bmHUB_PORT_STATE_CHECK_DISABLED (0x0000 | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_ENABLE | bmHUB_PORT_STATUS_PORT_CONNECTION | bmHUB_PORT_STATUS_PORT_SUSPEND) |
hudakz | 0:84353c479782 | 120 | |
hudakz | 0:84353c479782 | 121 | // Hub Port States |
hudakz | 0:84353c479782 | 122 | #define bmHUB_PORT_STATE_DISABLED (0x0000 | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_CONNECTION) |
hudakz | 0:84353c479782 | 123 | |
hudakz | 0:84353c479782 | 124 | // Hub Port Events |
hudakz | 0:84353c479782 | 125 | #define bmHUB_PORT_EVENT_CONNECT (((0UL | bmHUB_PORT_STATUS_C_PORT_CONNECTION) << 16) | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_CONNECTION) |
hudakz | 0:84353c479782 | 126 | #define bmHUB_PORT_EVENT_DISCONNECT (((0UL | bmHUB_PORT_STATUS_C_PORT_CONNECTION) << 16) | bmHUB_PORT_STATUS_PORT_POWER) |
hudakz | 0:84353c479782 | 127 | #define bmHUB_PORT_EVENT_RESET_COMPLETE (((0UL | bmHUB_PORT_STATUS_C_PORT_RESET) << 16) | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_ENABLE | bmHUB_PORT_STATUS_PORT_CONNECTION) |
hudakz | 0:84353c479782 | 128 | |
hudakz | 0:84353c479782 | 129 | #define bmHUB_PORT_EVENT_LS_CONNECT (((0UL | bmHUB_PORT_STATUS_C_PORT_CONNECTION) << 16) | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_CONNECTION | bmHUB_PORT_STATUS_PORT_LOW_SPEED) |
hudakz | 0:84353c479782 | 130 | #define bmHUB_PORT_EVENT_LS_RESET_COMPLETE (((0UL | bmHUB_PORT_STATUS_C_PORT_RESET) << 16) | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_ENABLE | bmHUB_PORT_STATUS_PORT_CONNECTION | bmHUB_PORT_STATUS_PORT_LOW_SPEED) |
hudakz | 0:84353c479782 | 131 | #define bmHUB_PORT_EVENT_LS_PORT_ENABLED (((0UL | bmHUB_PORT_STATUS_C_PORT_CONNECTION | bmHUB_PORT_STATUS_C_PORT_ENABLE) << 16) | bmHUB_PORT_STATUS_PORT_POWER | bmHUB_PORT_STATUS_PORT_ENABLE | bmHUB_PORT_STATUS_PORT_CONNECTION | bmHUB_PORT_STATUS_PORT_LOW_SPEED) |
hudakz | 0:84353c479782 | 132 | |
hudakz | 0:84353c479782 | 133 | struct HubDescriptor { |
hudakz | 0:84353c479782 | 134 | uint8_t bDescLength; // descriptor length |
hudakz | 0:84353c479782 | 135 | uint8_t bDescriptorType; // descriptor type |
hudakz | 0:84353c479782 | 136 | uint8_t bNbrPorts; // number of ports a hub equiped with |
hudakz | 0:84353c479782 | 137 | |
hudakz | 0:84353c479782 | 138 | struct { |
hudakz | 0:84353c479782 | 139 | uint16_t LogPwrSwitchMode : 2; |
hudakz | 0:84353c479782 | 140 | uint16_t CompoundDevice : 1; |
hudakz | 0:84353c479782 | 141 | uint16_t OverCurrentProtectMode : 2; |
hudakz | 0:84353c479782 | 142 | uint16_t TTThinkTime : 2; |
hudakz | 0:84353c479782 | 143 | uint16_t PortIndicatorsSupported : 1; |
hudakz | 0:84353c479782 | 144 | uint16_t Reserved : 8; |
hudakz | 0:84353c479782 | 145 | } __attribute__((packed)); |
hudakz | 0:84353c479782 | 146 | |
hudakz | 0:84353c479782 | 147 | uint8_t bPwrOn2PwrGood; |
hudakz | 0:84353c479782 | 148 | uint8_t bHubContrCurrent; |
hudakz | 0:84353c479782 | 149 | } __attribute__((packed)); |
hudakz | 0:84353c479782 | 150 | |
hudakz | 0:84353c479782 | 151 | struct HubEvent { |
hudakz | 0:84353c479782 | 152 | |
hudakz | 0:84353c479782 | 153 | union { |
hudakz | 0:84353c479782 | 154 | |
hudakz | 0:84353c479782 | 155 | struct { |
hudakz | 0:84353c479782 | 156 | uint16_t bmStatus; // port status bits |
hudakz | 0:84353c479782 | 157 | uint16_t bmChange; // port status change bits |
hudakz | 0:84353c479782 | 158 | } __attribute__((packed)); |
hudakz | 0:84353c479782 | 159 | uint32_t bmEvent; |
hudakz | 0:84353c479782 | 160 | uint8_t evtBuff[4]; |
hudakz | 0:84353c479782 | 161 | }; |
hudakz | 0:84353c479782 | 162 | } __attribute__((packed)); |
hudakz | 0:84353c479782 | 163 | |
hudakz | 0:84353c479782 | 164 | class USBHub : USBDeviceConfig { |
hudakz | 0:84353c479782 | 165 | static bool bResetInitiated; // True when reset is triggered |
hudakz | 0:84353c479782 | 166 | |
hudakz | 0:84353c479782 | 167 | USB *pUsb; // USB class instance pointer |
hudakz | 0:84353c479782 | 168 | |
hudakz | 0:84353c479782 | 169 | EpInfo epInfo[2]; // interrupt endpoint info structure |
hudakz | 0:84353c479782 | 170 | |
hudakz | 0:84353c479782 | 171 | uint8_t bAddress; // address |
hudakz | 0:84353c479782 | 172 | uint8_t bNbrPorts; // number of ports |
hudakz | 0:84353c479782 | 173 | // uint8_t bInitState; // initialization state variable |
hudakz | 0:84353c479782 | 174 | uint32_t qNextPollTime; // next poll time |
hudakz | 0:84353c479782 | 175 | bool bPollEnable; // poll enable flag |
hudakz | 0:84353c479782 | 176 | |
hudakz | 0:84353c479782 | 177 | uint8_t CheckHubStatus(); |
hudakz | 0:84353c479782 | 178 | uint8_t PortStatusChange(uint8_t port, HubEvent &evt); |
hudakz | 0:84353c479782 | 179 | |
hudakz | 0:84353c479782 | 180 | public: |
hudakz | 0:84353c479782 | 181 | USBHub(USB *p); |
hudakz | 0:84353c479782 | 182 | |
hudakz | 0:84353c479782 | 183 | uint8_t ClearHubFeature(uint8_t fid); |
hudakz | 0:84353c479782 | 184 | uint8_t ClearPortFeature(uint8_t fid, uint8_t port, uint8_t sel = 0); |
hudakz | 0:84353c479782 | 185 | uint8_t GetHubDescriptor(uint8_t index, uint16_t nbytes, uint8_t *dataptr); |
hudakz | 0:84353c479782 | 186 | uint8_t GetHubStatus(uint16_t nbytes, uint8_t* dataptr); |
hudakz | 0:84353c479782 | 187 | uint8_t GetPortStatus(uint8_t port, uint16_t nbytes, uint8_t* dataptr); |
hudakz | 0:84353c479782 | 188 | uint8_t SetHubDescriptor(uint8_t port, uint16_t nbytes, uint8_t* dataptr); |
hudakz | 0:84353c479782 | 189 | uint8_t SetHubFeature(uint8_t fid); |
hudakz | 0:84353c479782 | 190 | uint8_t SetPortFeature(uint8_t fid, uint8_t port, uint8_t sel = 0); |
hudakz | 0:84353c479782 | 191 | |
hudakz | 0:84353c479782 | 192 | void PrintHubStatus(); |
hudakz | 0:84353c479782 | 193 | |
hudakz | 0:84353c479782 | 194 | uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); |
hudakz | 0:84353c479782 | 195 | uint8_t Release(); |
hudakz | 0:84353c479782 | 196 | uint8_t Poll(); |
hudakz | 0:84353c479782 | 197 | void ResetHubPort(uint8_t port); |
hudakz | 0:84353c479782 | 198 | |
hudakz | 0:84353c479782 | 199 | virtual uint8_t GetAddress() { |
hudakz | 0:84353c479782 | 200 | return bAddress; |
hudakz | 0:84353c479782 | 201 | }; |
hudakz | 0:84353c479782 | 202 | |
hudakz | 0:84353c479782 | 203 | virtual bool DEVCLASSOK(uint8_t klass) { |
hudakz | 0:84353c479782 | 204 | return (klass == 0x09); |
hudakz | 0:84353c479782 | 205 | } |
hudakz | 0:84353c479782 | 206 | |
hudakz | 0:84353c479782 | 207 | }; |
hudakz | 0:84353c479782 | 208 | |
hudakz | 0:84353c479782 | 209 | // Clear Hub Feature |
hudakz | 0:84353c479782 | 210 | |
hudakz | 0:84353c479782 | 211 | inline uint8_t USBHub::ClearHubFeature(uint8_t fid) { |
hudakz | 0:84353c479782 | 212 | return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CLEAR_HUB_FEATURE, USB_REQUEST_CLEAR_FEATURE, fid, 0, 0, 0, 0, NULL, NULL)); |
hudakz | 0:84353c479782 | 213 | } |
hudakz | 0:84353c479782 | 214 | // Clear Port Feature |
hudakz | 0:84353c479782 | 215 | |
hudakz | 0:84353c479782 | 216 | inline uint8_t USBHub::ClearPortFeature(uint8_t fid, uint8_t port, uint8_t sel) { |
hudakz | 0:84353c479782 | 217 | return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CLEAR_PORT_FEATURE, USB_REQUEST_CLEAR_FEATURE, fid, 0, ((0x0000 | port) | (sel << 8)), 0, 0, NULL, NULL)); |
hudakz | 0:84353c479782 | 218 | } |
hudakz | 0:84353c479782 | 219 | // Get Hub Descriptor |
hudakz | 0:84353c479782 | 220 | |
hudakz | 0:84353c479782 | 221 | inline uint8_t USBHub::GetHubDescriptor(uint8_t index, uint16_t nbytes, uint8_t *dataptr) { |
hudakz | 0:84353c479782 | 222 | return ( pUsb->ctrlReq(bAddress, 0, bmREQ_GET_HUB_DESCRIPTOR, USB_REQUEST_GET_DESCRIPTOR, index, 0x29, 0, nbytes, nbytes, dataptr, NULL)); |
hudakz | 0:84353c479782 | 223 | } |
hudakz | 0:84353c479782 | 224 | // Get Hub Status |
hudakz | 0:84353c479782 | 225 | |
hudakz | 0:84353c479782 | 226 | inline uint8_t USBHub::GetHubStatus(uint16_t nbytes, uint8_t* dataptr) { |
hudakz | 0:84353c479782 | 227 | return ( pUsb->ctrlReq(bAddress, 0, bmREQ_GET_HUB_STATUS, USB_REQUEST_GET_STATUS, 0, 0, 0x0000, nbytes, nbytes, dataptr, NULL)); |
hudakz | 0:84353c479782 | 228 | } |
hudakz | 0:84353c479782 | 229 | // Get Port Status |
hudakz | 0:84353c479782 | 230 | |
hudakz | 0:84353c479782 | 231 | inline uint8_t USBHub::GetPortStatus(uint8_t port, uint16_t nbytes, uint8_t* dataptr) { |
hudakz | 0:84353c479782 | 232 | return ( pUsb->ctrlReq(bAddress, 0, bmREQ_GET_PORT_STATUS, USB_REQUEST_GET_STATUS, 0, 0, port, nbytes, nbytes, dataptr, NULL)); |
hudakz | 0:84353c479782 | 233 | } |
hudakz | 0:84353c479782 | 234 | // Set Hub Descriptor |
hudakz | 0:84353c479782 | 235 | |
hudakz | 0:84353c479782 | 236 | inline uint8_t USBHub::SetHubDescriptor(uint8_t port, uint16_t nbytes, uint8_t* dataptr) { |
hudakz | 0:84353c479782 | 237 | return ( pUsb->ctrlReq(bAddress, 0, bmREQ_SET_HUB_DESCRIPTOR, USB_REQUEST_SET_DESCRIPTOR, 0, 0, port, nbytes, nbytes, dataptr, NULL)); |
hudakz | 0:84353c479782 | 238 | } |
hudakz | 0:84353c479782 | 239 | // Set Hub Feature |
hudakz | 0:84353c479782 | 240 | |
hudakz | 0:84353c479782 | 241 | inline uint8_t USBHub::SetHubFeature(uint8_t fid) { |
hudakz | 0:84353c479782 | 242 | return ( pUsb->ctrlReq(bAddress, 0, bmREQ_SET_HUB_FEATURE, USB_REQUEST_SET_FEATURE, fid, 0, 0, 0, 0, NULL, NULL)); |
hudakz | 0:84353c479782 | 243 | } |
hudakz | 0:84353c479782 | 244 | // Set Port Feature |
hudakz | 0:84353c479782 | 245 | |
hudakz | 0:84353c479782 | 246 | inline uint8_t USBHub::SetPortFeature(uint8_t fid, uint8_t port, uint8_t sel) { |
hudakz | 0:84353c479782 | 247 | return ( pUsb->ctrlReq(bAddress, 0, bmREQ_SET_PORT_FEATURE, USB_REQUEST_SET_FEATURE, fid, 0, (((0x0000 | sel) << 8) | port), 0, 0, NULL, NULL)); |
hudakz | 0:84353c479782 | 248 | } |
hudakz | 0:84353c479782 | 249 | |
hudakz | 0:84353c479782 | 250 | void PrintHubPortStatus(USB *usbptr, uint8_t addr, uint8_t port, bool print_changes = false); |
hudakz | 0:84353c479782 | 251 | |
hudakz | 0:84353c479782 | 252 | #endif // __USBHUB_H__ |