Skip to content

Commit 70f222e

Browse files
committed
feat(ext_port): Added External Port driver
Closes #12554
1 parent bcfa928 commit 70f222e

File tree

11 files changed

+1723
-29
lines changed

11 files changed

+1723
-29
lines changed

Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,3 +678,5 @@ mainmenu "Espressif IoT Development Framework Configuration"
678678
- CONFIG_BOOTLOADER_CACHE_32BIT_ADDR_QUAD_FLASH
679679
- CONFIG_ESP_WIFI_EAP_TLS1_3
680680
- CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
681+
- CONFIG_USB_HOST_EXT_PORT_SUPPORT_LS
682+
- CONFIG_USB_HOST_EXT_PORT_RESET_ATTEMPTS

components/usb/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ if(CONFIG_SOC_USB_OTG_SUPPORTED)
3030
endif()
3131

3232
if(CONFIG_USB_HOST_HUBS_SUPPORTED)
33-
list(APPEND srcs "ext_hub.c")
33+
list(APPEND srcs "ext_hub.c"
34+
"ext_port.c")
3435
endif()
3536

3637
idf_component_register(SRCS ${srcs}

components/usb/Kconfig

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,51 @@ menu "USB-OTG"
112112
help
113113
Enables support for connecting multiple Hubs simultaneously.
114114

115+
menu "Downstream Port configuration"
116+
depends on USB_HOST_HUBS_SUPPORTED
117+
118+
config USB_HOST_EXT_PORT_SUPPORT_LS
119+
depends on IDF_EXPERIMENTAL_FEATURES
120+
bool "Support LS"
121+
default n
122+
help
123+
Enables support of Low-speed devices, connected through the external Hub.
124+
125+
config USB_HOST_EXT_PORT_RESET_ATTEMPTS
126+
depends on IDF_EXPERIMENTAL_FEATURES
127+
# Invisible config option
128+
# Todo: IDF-11283
129+
int
130+
default 1
131+
help
132+
Amount of attempts to reset the device.
133+
134+
The default value is 1.
135+
136+
config USB_HOST_EXT_PORT_CUSTOM_RESET_ENABLE
137+
bool "Custom bPwrOn2PwrGood value"
138+
default n
139+
help
140+
Enables the possibility to configure custom time for the power-on sequence on a port
141+
until power is good on that port.
142+
143+
When enabled, applies the custom PwrOn2PwrGood delay.
144+
When disabled, applies the PwrOn2PwrGood value from the Hub Descriptor.
145+
146+
config USB_HOST_EXT_PORT_CUSTOM_RESET_MS
147+
depends on USB_HOST_EXT_PORT_CUSTOM_RESET_ENABLE
148+
int "PwrOn2PwrGood delay in ms"
149+
default 100
150+
range 0 5000
151+
help
152+
Custom value of delay from the time the power-on sequence begins on a port
153+
until power is good on that port.
154+
Value 0 is used for a hub with no power switches.
155+
156+
The default value is 100 ms.
157+
158+
endmenu #Downstream Port configuration
159+
115160
endmenu #Hub Driver Configuration
116161

117162
config USB_HOST_ENABLE_ENUM_FILTER_CALLBACK

components/usb/ext_hub.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
*/
66
#include <string.h>
77
#include <stdint.h>
8+
#include "sdkconfig.h"
89
#include "esp_err.h"
910
#include "esp_log.h"
1011
#include "esp_heap_caps.h"
1112
#include "freertos/FreeRTOS.h"
1213
#include "freertos/task.h"
13-
#include "freertos/semphr.h"
1414
#include "usb_private.h"
1515
#include "ext_hub.h"
16+
#include "ext_port.h"
1617
#include "usb/usb_helpers.h"
1718

18-
typedef struct ext_port_s *ext_port_hdl_t; /* This will be implemented during ext_port driver implementation */
19-
2019
#define EXT_HUB_MAX_STATUS_BYTES_SIZE (sizeof(uint32_t))
2120
#define EXT_HUB_STATUS_CHANGE_FLAG (1 << 0)
2221
#define EXT_HUB_STATUS_PORT1_CHANGE_FLAG (1 << 1)
@@ -396,8 +395,15 @@ static void device_error(ext_hub_dev_t *ext_hub_dev)
396395

397396
static esp_err_t device_port_new(ext_hub_dev_t *ext_hub_dev, uint8_t port_idx)
398397
{
398+
ext_port_config_t port_config = {
399+
.ext_hub_hdl = (ext_hub_handle_t) ext_hub_dev,
400+
.parent_dev_hdl = ext_hub_dev->constant.dev_hdl,
401+
.parent_port_num = port_idx + 1,
402+
.port_power_delay_ms = ext_hub_dev->constant.hub_desc->bPwrOn2PwrGood * 2,
403+
};
404+
399405
assert(p_ext_hub_driver->constant.port_driver);
400-
esp_err_t ret = p_ext_hub_driver->constant.port_driver->new (NULL, (void**) &ext_hub_dev->constant.ports[port_idx]);
406+
esp_err_t ret = p_ext_hub_driver->constant.port_driver->new (&port_config, (void**) &ext_hub_dev->constant.ports[port_idx]);
401407
if (ret != ESP_OK) {
402408
ESP_LOGE(EXT_HUB_TAG, "[%d:%d] Port allocation error: %s", ext_hub_dev->constant.dev_addr, port_idx + 1, esp_err_to_name(ret));
403409
goto fail;
@@ -418,7 +424,7 @@ static esp_err_t device_port_free(ext_hub_dev_t *ext_hub_dev, uint8_t port_idx)
418424

419425
assert(ext_hub_dev->single_thread.maxchild != 0);
420426
assert(p_ext_hub_driver->constant.port_driver);
421-
esp_err_t ret = p_ext_hub_driver->constant.port_driver->free(ext_hub_dev->constant.ports[port_idx]);
427+
esp_err_t ret = p_ext_hub_driver->constant.port_driver->del(ext_hub_dev->constant.ports[port_idx]);
422428

423429
if (ret != ESP_OK) {
424430
ESP_LOGE(EXT_HUB_TAG, "[%d:%d] Unable to free port: %s", ext_hub_dev->constant.dev_addr, port_idx + 1, esp_err_to_name(ret));
@@ -1038,6 +1044,7 @@ static void handle_device(ext_hub_dev_t *ext_hub_dev)
10381044
// FSM for external Hub
10391045
switch (ext_hub_dev->single_thread.stage) {
10401046
case EXT_HUB_STAGE_IDLE:
1047+
stage_pass = true;
10411048
break;
10421049
case EXT_HUB_STAGE_GET_DEVICE_STATUS:
10431050
case EXT_HUB_STAGE_GET_HUB_DESCRIPTOR:
@@ -1118,8 +1125,7 @@ esp_err_t ext_hub_install(const ext_hub_config_t *config)
11181125
{
11191126
esp_err_t ret;
11201127
ext_hub_driver_t *ext_hub_drv = heap_caps_calloc(1, sizeof(ext_hub_driver_t), MALLOC_CAP_DEFAULT);
1121-
SemaphoreHandle_t mux_lock = xSemaphoreCreateMutex();
1122-
if (ext_hub_drv == NULL || mux_lock == NULL) {
1128+
if (ext_hub_drv == NULL) {
11231129
ret = ESP_ERR_NO_MEM;
11241130
goto err;
11251131
}
@@ -1151,9 +1157,6 @@ esp_err_t ext_hub_install(const ext_hub_config_t *config)
11511157
return ESP_OK;
11521158

11531159
err:
1154-
if (mux_lock != NULL) {
1155-
vSemaphoreDelete(mux_lock);
1156-
}
11571160
heap_caps_free(ext_hub_drv);
11581161
return ret;
11591162
}
@@ -1672,7 +1675,7 @@ esp_err_t ext_hub_port_get_speed(ext_hub_handle_t ext_hub_hdl, uint8_t port_num,
16721675
esp_err_t ext_hub_set_port_feature(ext_hub_handle_t ext_hub_hdl, uint8_t port_num, uint8_t feature)
16731676
{
16741677
EXT_HUB_ENTER_CRITICAL();
1675-
EXT_HUB_CHECK_FROM_CRIT(p_ext_hub_driver != NULL, ESP_ERR_INVALID_STATE);
1678+
EXT_HUB_CHECK_FROM_CRIT(p_ext_hub_driver != NULL, ESP_ERR_NOT_ALLOWED);
16761679
EXT_HUB_EXIT_CRITICAL();
16771680

16781681
esp_err_t ret;
@@ -1701,7 +1704,7 @@ esp_err_t ext_hub_set_port_feature(ext_hub_handle_t ext_hub_hdl, uint8_t port_nu
17011704
esp_err_t ext_hub_clear_port_feature(ext_hub_handle_t ext_hub_hdl, uint8_t port_num, uint8_t feature)
17021705
{
17031706
EXT_HUB_ENTER_CRITICAL();
1704-
EXT_HUB_CHECK_FROM_CRIT(p_ext_hub_driver != NULL, ESP_ERR_INVALID_STATE);
1707+
EXT_HUB_CHECK_FROM_CRIT(p_ext_hub_driver != NULL, ESP_ERR_NOT_ALLOWED);
17051708
EXT_HUB_EXIT_CRITICAL();
17061709

17071710
esp_err_t ret;
@@ -1730,7 +1733,7 @@ esp_err_t ext_hub_clear_port_feature(ext_hub_handle_t ext_hub_hdl, uint8_t port_
17301733
esp_err_t ext_hub_get_port_status(ext_hub_handle_t ext_hub_hdl, uint8_t port_num)
17311734
{
17321735
EXT_HUB_ENTER_CRITICAL();
1733-
EXT_HUB_CHECK_FROM_CRIT(p_ext_hub_driver != NULL, ESP_ERR_INVALID_STATE);
1736+
EXT_HUB_CHECK_FROM_CRIT(p_ext_hub_driver != NULL, ESP_ERR_NOT_ALLOWED);
17341737
EXT_HUB_EXIT_CRITICAL();
17351738

17361739
esp_err_t ret;

0 commit comments

Comments
 (0)