Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions device/esp_tinyusb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
idf_build_get_property(target IDF_TARGET)

set(srcs
"descriptors_control.c"
"tinyusb.c"
Expand Down Expand Up @@ -43,6 +45,13 @@ if(CONFIG_TINYUSB_NET_MODE_NCM)
)
endif() # CONFIG_TINYUSB_NET_MODE_NCM

# Software VBUS monitoring is available only on esp32p4
if(${target} STREQUAL "esp32p4")
list(APPEND srcs
"tinyusb_vbus_monitor.c"
)
endif() # esp32p4

idf_component_register(SRCS ${srcs}
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "include_private"
Expand Down
4 changes: 3 additions & 1 deletion device/esp_tinyusb/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ targets:
dependencies:
idf: '>=5.0' # IDF 4.x contains TinyUSB as submodule
tinyusb:
version: '>=0.17.0~2' # 0.17.0~2 is the first version that supports deinit
# TODO: Revert after IEC-403
# version: '>=0.17.0~2' # 0.17.0~2 is the first version that supports deinit
version: '^0.18.0'
public: true
1 change: 1 addition & 0 deletions device/esp_tinyusb/include/tinyusb.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef struct {
The voltage divider output should be (0.75 * Vdd) if VBUS is 4.4V (lowest valid voltage at device port).
The comparator thresholds should be set with hysteresis: 4.35V (falling edge) and 4.75V (raising edge). */
int vbus_monitor_io; /*!< GPIO for VBUS monitoring, 3.3 V tolerant (use a comparator or a resistior divider to detect the VBUS valid condition). Ignored if not self_powered. */
uint32_t vbus_monitor_debounce_ms; /*!< Debounce delay for VBUS monitoring in milliseconds. Default is 250 ms. Relevant only for ESP32P4 and ignored if not self_powered. */
} tinyusb_phy_config_t;

/**
Expand Down
90 changes: 47 additions & 43 deletions device/esp_tinyusb/include/tinyusb_default_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,54 +63,58 @@ extern "C" {
#define TINYUSB_DEFAULT_TASK_SIZE 4096
// Default priority for task used in TinyUSB task creation
#define TINYUSB_DEFAULT_TASK_PRIO 5
// Default VBUS debounce time in milliseconds
#define TINYUSB_DEFAULT_DEBOUNCE_MS 250

#define TINYUSB_CONFIG_FULL_SPEED(event_hdl, arg) \
(tinyusb_config_t) { \
.port = TINYUSB_PORT_FULL_SPEED_0, \
.phy = { \
.skip_setup = false, \
.self_powered = false, \
.vbus_monitor_io = -1, \
}, \
.task = TINYUSB_TASK_DEFAULT(), \
.descriptor = { \
.device = NULL, \
.qualifier = NULL, \
.string = NULL, \
.string_count = 0, \
.full_speed_config = NULL, \
.high_speed_config = NULL, \
}, \
.event_cb = (event_hdl), \
.event_arg = (arg), \
#define TINYUSB_CONFIG_FULL_SPEED(event_hdl, arg) \
(tinyusb_config_t) { \
.port = TINYUSB_PORT_FULL_SPEED_0, \
.phy = { \
.skip_setup = false, \
.self_powered = false, \
.vbus_monitor_io = -1, \
.vbus_monitor_debounce_ms = TINYUSB_DEFAULT_DEBOUNCE_MS, \
}, \
.task = TINYUSB_TASK_DEFAULT(), \
.descriptor = { \
.device = NULL, \
.qualifier = NULL, \
.string = NULL, \
.string_count = 0, \
.full_speed_config = NULL, \
.high_speed_config = NULL, \
}, \
.event_cb = (event_hdl), \
.event_arg = (arg), \
}

#define TINYUSB_CONFIG_HIGH_SPEED(event_hdl, arg) \
(tinyusb_config_t) { \
.port = TINYUSB_PORT_HIGH_SPEED_0, \
.phy = { \
.skip_setup = false, \
.self_powered = false, \
.vbus_monitor_io = -1, \
}, \
.task = TINYUSB_TASK_DEFAULT(), \
.descriptor = { \
.device = NULL, \
.qualifier = NULL, \
.string = NULL, \
.string_count = 0, \
.full_speed_config = NULL, \
.high_speed_config = NULL, \
}, \
.event_cb = (event_hdl), \
.event_arg = (arg), \
#define TINYUSB_CONFIG_HIGH_SPEED(event_hdl, arg) \
(tinyusb_config_t) { \
.port = TINYUSB_PORT_HIGH_SPEED_0, \
.phy = { \
.skip_setup = false, \
.self_powered = false, \
.vbus_monitor_io = -1, \
.vbus_monitor_debounce_ms = TINYUSB_DEFAULT_DEBOUNCE_MS, \
}, \
.task = TINYUSB_TASK_DEFAULT(), \
.descriptor = { \
.device = NULL, \
.qualifier = NULL, \
.string = NULL, \
.string_count = 0, \
.full_speed_config = NULL, \
.high_speed_config = NULL, \
}, \
.event_cb = (event_hdl), \
.event_arg = (arg), \
}

#define TINYUSB_TASK_DEFAULT() \
(tinyusb_task_config_t) { \
.size = TINYUSB_DEFAULT_TASK_SIZE, \
.priority = TINYUSB_DEFAULT_TASK_PRIO, \
.xCoreID = TINYUSB_DEFAULT_TASK_AFFINITY, \
#define TINYUSB_TASK_DEFAULT() \
(tinyusb_task_config_t) { \
.size = TINYUSB_DEFAULT_TASK_SIZE, \
.priority = TINYUSB_DEFAULT_TASK_PRIO, \
.xCoreID = TINYUSB_DEFAULT_TASK_AFFINITY, \
}

/**
Expand Down
6 changes: 5 additions & 1 deletion device/esp_tinyusb/include_private/tinyusb_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "esp_err.h"
#include "tinyusb.h"
#include "tinyusb_vbus_monitor.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -42,7 +43,10 @@ esp_err_t tinyusb_task_check_config(const tinyusb_task_config_t *task_cfg);
* - ESP_ERR_NO_MEM if memory allocation failed
* - ESP_OK if TinyUSB Task initialized successfully
*/
esp_err_t tinyusb_task_start(tinyusb_port_t port, const tinyusb_task_config_t *task_cfg, const tinyusb_desc_config_t *desc_cfg);
esp_err_t tinyusb_task_start(tinyusb_port_t port,
const tinyusb_task_config_t *task_cfg,
const tinyusb_desc_config_t *desc_cfg,
const tinyusb_vbus_monitor_config_t *vbus_monitor_cfg);

/**
* @brief Stops TinyUSB Task
Expand Down
46 changes: 46 additions & 0 deletions device/esp_tinyusb/include_private/tinyusb_vbus_monitor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "esp_err.h"
#include "tinyusb.h"
#include "driver/gpio.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
bool enabled; /*!< Enable VBUS monitoring */
gpio_num_t gpio_num; /*!< GPIO number used for VBUS monitoring, 3.3 V tolerant */
uint32_t debounce_delay_ms; /*!< Debounce delay in milliseconds */
} tinyusb_vbus_monitor_config_t;

/**
* @brief Initialize VBUS monitoring on the specified GPIO
*
* Note:
* - This function should be called after tusb_init() when GOTGCTL register is initialized
* - This is a single-threaded implementation, so only one instance of VBUS monitoring is supported
*
* @param vbus_io_num GPIO number used for VBUS monitoring, 3.3 V tolerant (use a comparator or a resistor divider to detect the VBUS valid condition).
*
* @return
* - ESP_OK on success
* - ESP_ERR_NO_MEM if failed to create resources
* - ESP_ERR_INVALID_STATE if already initialized
*/
esp_err_t tinyusb_vbus_monitor_init(tinyusb_vbus_monitor_config_t *config);

/**
* @brief Deinitialize VBUS monitoring
*/
void tinyusb_vbus_monitor_deinit(void);

#ifdef __cplusplus
}
#endif

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ TEST_CASE("Config: Full-speed default (Full-speed)", "[runtime_config][full_spee
TEST_ASSERT_EQUAL_MESSAGE(false, tusb_cfg.phy.skip_setup, "Wrong default skip_setup value");
TEST_ASSERT_EQUAL_MESSAGE(false, tusb_cfg.phy.self_powered, "Wrong default self-powered flag");
TEST_ASSERT_EQUAL_MESSAGE(-1, tusb_cfg.phy.vbus_monitor_io, "Wrong default VBUS monitor IO");
TEST_ASSERT_EQUAL_MESSAGE(TINYUSB_DEFAULT_DEBOUNCE_MS, tusb_cfg.phy.vbus_monitor_debounce_ms, "Wrong default VBUS monitor debounce time");
TEST_ASSERT_EQUAL_MESSAGE(TINYUSB_DEFAULT_TASK_SIZE, tusb_cfg.task.size, "Wrong default task size");
TEST_ASSERT_EQUAL_MESSAGE(TINYUSB_DEFAULT_TASK_PRIO, tusb_cfg.task.priority, "Wrong default task priority");
#if CONFIG_FREERTOS_UNICORE
Expand All @@ -85,6 +86,7 @@ TEST_CASE("Config: Full-speed (High-speed)", "[runtime_config][full_speed]")
TEST_ASSERT_EQUAL_MESSAGE(false, tusb_cfg.phy.skip_setup, "Wrong default skip_setup value");
TEST_ASSERT_EQUAL_MESSAGE(false, tusb_cfg.phy.self_powered, "Wrong default self-powered flag");
TEST_ASSERT_EQUAL_MESSAGE(-1, tusb_cfg.phy.vbus_monitor_io, "Wrong default VBUS monitor IO");
TEST_ASSERT_EQUAL_MESSAGE(TINYUSB_DEFAULT_DEBOUNCE_MS, tusb_cfg.phy.vbus_monitor_debounce_ms, "Wrong default VBUS monitor debounce time");
TEST_ASSERT_EQUAL_MESSAGE(TINYUSB_DEFAULT_TASK_SIZE, tusb_cfg.task.size, "Wrong default task size");
TEST_ASSERT_EQUAL_MESSAGE(TINYUSB_DEFAULT_TASK_PRIO, tusb_cfg.task.priority, "Wrong default task priority");
TEST_ASSERT_EQUAL_MESSAGE(1, tusb_cfg.task.xCoreID, "Wrong default task affinity, should be 1 on multicore");
Expand All @@ -104,6 +106,7 @@ TEST_CASE("Config: High-speed default (High-speed)", "[runtime_config][high_spee
TEST_ASSERT_EQUAL_MESSAGE(false, tusb_cfg.phy.skip_setup, "Wrong default skip_setup value");
TEST_ASSERT_EQUAL_MESSAGE(false, tusb_cfg.phy.self_powered, "Wrong default self-powered flag");
TEST_ASSERT_EQUAL_MESSAGE(-1, tusb_cfg.phy.vbus_monitor_io, "Wrong default VBUS monitor IO");
TEST_ASSERT_EQUAL_MESSAGE(TINYUSB_DEFAULT_DEBOUNCE_MS, tusb_cfg.phy.vbus_monitor_debounce_ms, "Wrong default VBUS monitor debounce time");
TEST_ASSERT_EQUAL_MESSAGE(TINYUSB_DEFAULT_TASK_SIZE, tusb_cfg.task.size, "Wrong default task size");
TEST_ASSERT_EQUAL_MESSAGE(TINYUSB_DEFAULT_TASK_PRIO, tusb_cfg.task.priority, "Wrong default task priority");
TEST_ASSERT_EQUAL_MESSAGE(1, tusb_cfg.task.xCoreID, "Wrong default task affinity, should be 1 on multicore");
Expand Down
Loading
Loading