Skip to content
Draft
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
2 changes: 1 addition & 1 deletion device/esp_tinyusb/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ 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
version: '0.18.0~5'
public: true
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 @@ -6,4 +6,4 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
set(COMPONENTS main)

project(test_app_dconn_detection)
project(test_app_vbus_monitor)
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "unity.h"
#include "unity_test_runner.h"
#include "unity_test_utils_memory.h"

#include "test_vbus_monitor.h"

void app_main(void)
{
/*
Expand Down Expand Up @@ -53,10 +57,16 @@ void app_main(void)
void setUp(void)
{
unity_utils_record_free_mem();
test_device_event_queue_setup();
test_vbus_monitor_control_setup();
}

/* tearDown runs after every test */
void tearDown(void)
{
// Short delay to allow task to be cleaned up
vTaskDelay(10);
test_vbus_monitor_control_teardown();
test_device_event_queue_teardown();
unity_utils_evaluate_leaks();
}
Loading
Loading