-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
drivers: pwm_led: esp32: add inverted pwm polarity #80673
drivers: pwm_led: esp32: add inverted pwm polarity #80673
Conversation
f37ba7c
to
fa5a4f5
Compare
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.
LGTM so far, just consider the point from @wmrsouza and I will also approve it.
@epc-ake Can you please add an issue with details and link that issue to this PR. After RC2 only bug fixes with an associated Github ssue will be merged into the upcoming 4.0 release. |
71a6c00
fa5a4f5
to
71a6c00
Compare
Thanks for pointing this out. I didn't notice it actually. @raffarost please tell me how you'd like to proceed with this and I'll adopt. |
@epc-ake I think the way you implemented is also alright, but I'd personally leave the possibility to set the value in the DT, including the max res (for applications which won't use duty = 100%). Probably not that relevant but I think leaving open the possibility of using the config is better. @sylvioalves what do you think? |
I suggest that I remove my changes regarding 100% pwm issue so we can use your PR for that. Looks cleaner to me. |
hi @epc-ake, |
3a14f4e
to
231a780
Compare
Hi all I intentionally made this changes in a separate commit but if you prefer, I can also squeeze them into one. |
231a780
to
155b219
Compare
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.
LGTM
you'll need to rebase it with latest main
drivers/pwm/pwm_led_esp32.c
Outdated
.speed_mode = DT_REG_ADDR(node_id) < SOC_LEDC_CHANNEL_NUM ? LEDC_LOW_SPEED_MODE \ | ||
: !LEDC_LOW_SPEED_MODE, \ | ||
.clock_src = CLOCK_SOURCE, \ | ||
.inverted = DT_PROP(node_id, init_high), \ |
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 couldn't be sure this flag would fit in the field flags
already foreseen in the DT (pwm_dt_spec / pwm_flags_t)
It would align better with the runtime check made in function set_cycles
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.
Do you know how to get the value of the flags field here?
I‘d actually prefer that over adding an extra dt-property but I didn’t find a way to do it.
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.
in include/zephyr/drivers/pwm.h
stay all the macros to unpack dts values:
* const struct pwm_dt_spec spec =
* PWM_DT_SPEC_GET_BY_NAME(DT_NODELABEL(n), alpha);
*
* // Initializes 'spec' to:
* // {
* // .dev = DEVICE_DT_GET(DT_NODELABEL(pwm1)),
* // .channel = 1,
* // .period = 1000,
* // .flags = PWM_POLARITY_NORMAL,
* // }
does it make sense to declare a pwms field for this driver (and include the flag)?
I don't know enough about the API to give a solid opinion now, but others might know better.
pwms = <&pwm2 3 2000 PWM_POLARITY_INVERTED>;
@epc-ake do you intend to keep working on this PR? |
Hi @raffarost. |
no rush, if you'll submit it at some point it's fine |
This PR enables the PWM to be inverted by making use of the `PWM_POLARITY_INVERTED` flag. It also fixes an overflow bug when setting duty-cycle to 100 percent. Signed-off-by: Armin Kessler <ake@espros.com>
Set pwm init state to value defined in flags field. Furthermore 100 percent is now actually 100 percent and not 99. Signed-off-by: Armin Kessler <ake@espros.com>
155b219
to
d788349
Compare
@raffarost |
@epc-ake I did some testing and think a fix regarding frequency update is needed (please check #82820, last commit). I tested on all devices and it seems to work fine. If you agree and can also kindly test them, feel free to incorporate the changes in your PR. @breiden can you check if this PR with these changes solve the problem you reported in #82177? |
.speed_mode = DT_REG_ADDR(node_id) < SOC_LEDC_CHANNEL_NUM ? LEDC_LOW_SPEED_MODE \ | ||
: !LEDC_LOW_SPEED_MODE, \ | ||
.clock_src = CLOCK_SOURCE, \ | ||
.inverted = DT_PWMS_FLAGS(node_id), \ |
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.
regarding this field, I checked other PWM
drivers and these macros and pwms
field seems to be only used by application, not directly by the driver. Considering this apparent 'standard' for the drivers, I'm not sure we can use it here. Possibly your earlier solution was more appropriate.
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.
Sounds the earlier solution is indeed more appropriate.
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 don't see the issue with using 'DT_PWMS_FLAGS' here.
To me this seems to be better since we avoid having redundant information in the device tree.
@raffarost Since you already made a PR on top of this one (#82820), would you take over this? |
hi @epc-ake @braiden |
This PR enables the PWM to be inverted by making use of the
PWM_POLARITY_INVERTED
flag.It also fixes an overflow bug when setting duty-cycle to 100 percent.