Skip to content
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

Allow access to the PWM channel assigned to the Pin. Opportunity to change PWM configurations #6992

Merged
merged 5 commits into from
Jul 20, 2022

Conversation

VasilyRakche
Copy link
Contributor

Description of Change

In current code, after calling analogWrite(), pin is automatically assigned a channel. It is also configured. But:

  • There is no way to change the channel configurations since one does not have access to the channel assigned to the pin - arduino-esp32/cores/esp32/esp32-hal-ledc.c:212
  • Of course one can just use bare ledc functions, but there is no way to make it compatible with analogWrite(). If user calls the analogWrite() until it reaches the channel limit, original ledc configuration will be overwritten

Example. Better compatibility between ledc and native Arduino

#define PIN 20

// simple usage
analogWrite(PIN, 0);

// advanced user configuration update
channel = analogGetChannel(PIN);
int new_freq = 20000;
int new_bit_num = 9;
ledcSetup(channel, new_freq, new_bit_num);  

Copy link
Member

@P-R-O-C-H-Y P-R-O-C-H-Y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @VasilyRakche for the PR, seems reasonable to have this option availible :)
Just fix the 1 comment I have, else its good and we can merge 👍

cores/esp32/esp32-hal-ledc.c Outdated Show resolved Hide resolved
Copy link
Contributor

@PilnyTomas PilnyTomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@P-R-O-C-H-Y P-R-O-C-H-Y merged commit cc8f4e5 into espressif:master Jul 20, 2022
@VasilyRakche VasilyRakche deleted the feature-analog-channel branch July 22, 2022 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants