-
Notifications
You must be signed in to change notification settings - Fork 37
feature(tinyusb): Software VBUS monitoring feature on ESP32P4 (part1/2) (IEC-437) #305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
roma-jam
wants to merge
3
commits into
master
Choose a base branch
from
feature/vbus_monitor_esp32p4_part1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * 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 { | ||
| 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 config VBUS monitoring configuration | ||
| * | ||
| * @return | ||
| * - ESP_ERR_INVALID_ARG if config is NULL | ||
| * - ESP_OK if VBUS monitoring was initialized successfully | ||
| */ | ||
| 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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for myself: Why does tinyusb task need vbus_monitor_cfg?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we will start the VBUS monitor feature inside the dedicated task.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we start it from the dedicated task though? Is there any advantage I'm missing?
From what I can see we can init VBUS monitoring simply from
tinyusb_driver_install(). Instead of passing ittinyusb_driver_install -> tinyusb_task_start -> xTaskCreatePinnedToCore -> tinyusb_device_taskIt would also decouple VBUS monitoring from the task, as they are 2 separate things, aren't they?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there are couple of things that are not obvious from the first glance:
Making the VBUS monitor feature fully separate (rejected, as it creates the conflict with the access to GOTGCTL register). For ECO4 we need to drive the GOTGCTL register which is also might be changed in the
tusb_init(). So, enable the VBUS before thetusb_init()might not work, as the register will be modified in TinyUSB. Thus, we need to enable the feature after thetusb_init()call to control the state of GOTGCTL register and might be able to change it inesp_tinyusb, if necessary.Enable the feature after creating the
tusb_init()which is called after the dedicated task creation (rejected, as it creates the additional not-necessary logic in vbus monitor init error path). We can get the error during the VBUS monitoring initialization. In this way, we need to stop and delete the task and return the error for the upper layer. There is a dependency of the task from the feature -> the decision to move the feature inside the dedicated task was made. The same way as with descriptors config, which also should be available all the time, whiletud_task()is working.Including the vbus monitor configuration in the task config (rejected, as it creates the duplicate configuration in public structs). This will break the logic with ESP32-S2/S3 where we apply this config during the PHY initialization. Also, task config is public, so the change in there will add the same variables as we have in PHY-related config. Thus, the decision to keep the config in PHY and share it with dedicated task by adding another argument in the internal function was made.
Right now, there are three arguments, that we pass to the dedicated task in the non-publicly available call:
tinyusb_task_start(). If we want to simplify the process and not to forget anything, it might be simplified to the additional struct with refactoring, which doesn't break anything.