-
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: check if pulse > period and other cleanups #44583
Conversation
Calling pwm_pin_set_cycles with a pulse > period doesn't make sense. By definition, pulse ranges from 0 up to the period value. Signed-off-by: Gerard Marull-Paretas <[email protected]>
The API call checks for this condition before calling the pin_set driver OP call, so drivers don't have to do this check now. Signed-off-by: Gerard Marull-Paretas <[email protected]>
The API spec states that calling pin_set() with period set to 0 is equivalent to set the PWM channel to an inactive level. Some drivers treat this input as invalid (-EINVAL), however, it's an unsupported feature. Maybe it's due to copy&paste effect? This changes error message to be clear and changes return value to -ENOTSUP for this case. Signed-off-by: Gerard Marull-Paretas <[email protected]>
If dev was null, caller would have faulted before since dev->api needs to be accessed before reaching this point. Also, a well-defined device will never have a NULL dev->config. Signed-off-by: Gerard Marull-Paretas <[email protected]>
All these sort of helpers were removed from tree a while ago, this one was missed as it uses a custom name. Signed-off-by: Gerard Marull-Paretas <[email protected]>
@@ -193,6 +194,10 @@ static inline int z_impl_pwm_pin_set_cycles(const struct device *dev, | |||
const struct pwm_driver_api *api = | |||
(const struct pwm_driver_api *)dev->api; | |||
|
|||
if (pulse > period) { | |||
return -EINVAL; |
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 not do pulse = period;
instead?
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.
It's an option to clamp pulse to period value, but still, I think that a pulse > period is wrong, so it may indicate an application issue.
Calling pwm_pin_set_cycles with a pulse > period doesn't make sense. By
definition, pulse ranges from 0 up to the period value.
Also:
equivalent to set the PWM channel to an inactive level. Some drivers
treat this input as invalid (-EINVAL), however, it's an unsupported
feature. Maybe it's due to copy&paste effect? This changes error message
to be clear, and changes return value to -ENOTSUP for this case.