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
ledc: Do not drive output during init if the output is inverted (IDFGH-6875) #8497
Conversation
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.
Shouldn't gpio_set_direction
be called before gpio_set_level
?
No.
If the output is inverted, and gpio_set_level() is called after
gpio_set_direction(), then the output will have an invalid value for a
short period of time.
Setting the level before the direction avoids the invalid output.
…On Fri, Mar 4, 2022, 15:15 Pedro ***@***.***> wrote:
***@***.**** commented on this pull request.
Shouldn't gpio_set_direction be called before gpio_set_level?
—
Reply to this email directly, view it on GitHub
<#8497 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADAIHNSE2H5UF6DBA5YAKTU6ILITANCNFSM5P4ZK5NA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
@@ -638,6 +638,7 @@ esp_err_t ledc_channel_config(const ledc_channel_config_t *ledc_conf) | |||
); | |||
/*set LEDC signal in gpio matrix*/ | |||
gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[gpio_num], PIN_FUNC_GPIO); | |||
gpio_set_level(gpio_num, output_invert); |
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.
This makes sense. You should set the pin H/L value before driving the pin as an output. I'm guessing esp_rom_gpio_connect_out_signal() also sets pin H/L, but by that point you would see a glitch on the pin without this fix. I've done the same thing in other hardware drivers I've written.
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.
I should also mention esp_rom_gpio_connect_out_signal() is in the ESP32 ROM file, so I didn't find a source file.
sha=062f6164ae89d54df3f1a89a67f01e82ae56e0d8 |
@nonoo Unrelated to the PR, but not completely, I found out I know nothing about GPIOs. Can you tell me why driving a GPIO before setting the direction works? And since it works and it's set to output, why set the direction at all? |
The set level call only sets the level internally, it will not be outputted to the pin until the internal pin matrix has the pin mapped to the GPIO. |
If the output of LEDC GPIO is inverted, then the correct level must be set before initializing the GPIO, otherwise it will be driven until the next call to stop LEDC output.