Browse Source

drivers: pwm: return -ENOTSUP if inactive level is not supported

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 <gerard.marull@nordicsemi.no>
pull/44629/head
Gerard Marull-Paretas 3 years ago committed by Carles Cufí
parent
commit
ccc12be0a5
  1. 5
      drivers/pwm/pwm_imx.c
  2. 5
      drivers/pwm/pwm_mcux.c
  3. 5
      drivers/pwm/pwm_mcux_ftm.c
  4. 5
      drivers/pwm/pwm_mcux_sctimer.c
  5. 5
      drivers/pwm/pwm_mcux_tpm.c
  6. 5
      drivers/pwm/pwm_rv32m1_tpm.c
  7. 2
      drivers/pwm/pwm_sam.c

5
drivers/pwm/pwm_imx.c

@ -61,9 +61,8 @@ static int imx_pwm_pin_set(const struct device *dev, uint32_t pwm, @@ -61,9 +61,8 @@ static int imx_pwm_pin_set(const struct device *dev, uint32_t pwm,
if (period_cycles == 0U) {
LOG_ERR("Invalid combination: period_cycles=%d, "
"pulse_cycles=%d", period_cycles, pulse_cycles);
return -EINVAL;
LOG_ERR("Channel can not be set to inactive level");
return -ENOTSUP;
}
if (flags) {

5
drivers/pwm/pwm_mcux.c

@ -53,9 +53,8 @@ static int mcux_pwm_pin_set(const struct device *dev, uint32_t pwm, @@ -53,9 +53,8 @@ static int mcux_pwm_pin_set(const struct device *dev, uint32_t pwm,
}
if (period_cycles == 0) {
LOG_ERR("Invalid combination: period_cycles=%u, "
"pulse_cycles=%u", period_cycles, pulse_cycles);
return -EINVAL;
LOG_ERR("Channel can not be set to inactive level");
return -ENOTSUP;
}
if (period_cycles > UINT16_MAX) {

5
drivers/pwm/pwm_mcux_ftm.c

@ -71,9 +71,8 @@ static int mcux_ftm_pin_set(const struct device *dev, uint32_t pwm, @@ -71,9 +71,8 @@ static int mcux_ftm_pin_set(const struct device *dev, uint32_t pwm,
#endif /* CONFIG_PWM_CAPTURE */
if (period_cycles == 0U) {
LOG_ERR("Invalid combination: period_cycles=%d, "
"pulse_cycles=%d", period_cycles, pulse_cycles);
return -EINVAL;
LOG_ERR("Channel can not be set to inactive level");
return -ENOTSUP;
}
if (pwm >= config->channel_count) {

5
drivers/pwm/pwm_mcux_sctimer.c

@ -49,9 +49,8 @@ static int mcux_sctimer_pwm_pin_set(const struct device *dev, uint32_t pwm, @@ -49,9 +49,8 @@ static int mcux_sctimer_pwm_pin_set(const struct device *dev, uint32_t pwm,
}
if (period_cycles == 0) {
LOG_ERR("Invalid combination: period_cycles=%u, "
"pulse_cycles=%u", period_cycles, pulse_cycles);
return -EINVAL;
LOG_ERR("Channel can not be set to inactive level");
return -ENOTSUP;
}
if ((flags & PWM_POLARITY_INVERTED) == 0) {

5
drivers/pwm/pwm_mcux_tpm.c

@ -50,9 +50,8 @@ static int mcux_tpm_pin_set(const struct device *dev, uint32_t pwm, @@ -50,9 +50,8 @@ static int mcux_tpm_pin_set(const struct device *dev, uint32_t pwm,
uint8_t duty_cycle;
if (period_cycles == 0U) {
LOG_ERR("Invalid combination: period_cycles=%d, "
"pulse_cycles=%d", period_cycles, pulse_cycles);
return -EINVAL;
LOG_ERR("Channel can not be set to inactive level");
return -ENOTSUP;
}
if (pwm >= config->channel_count) {

5
drivers/pwm/pwm_rv32m1_tpm.c

@ -47,9 +47,8 @@ static int rv32m1_tpm_pin_set(const struct device *dev, uint32_t pwm, @@ -47,9 +47,8 @@ static int rv32m1_tpm_pin_set(const struct device *dev, uint32_t pwm,
uint8_t duty_cycle;
if (period_cycles == 0U) {
LOG_ERR("Invalid combination: period_cycles=%d, "
"pulse_cycles=%d", period_cycles, pulse_cycles);
return -EINVAL;
LOG_ERR("Channel can not be set to inactive level");
return -ENOTSUP;
}
if (pwm >= config->channel_count) {

2
drivers/pwm/pwm_sam.c

@ -55,7 +55,7 @@ static int sam_pwm_pin_set(const struct device *dev, uint32_t ch, @@ -55,7 +55,7 @@ static int sam_pwm_pin_set(const struct device *dev, uint32_t ch,
}
if (period_cycles == 0U) {
return -EINVAL;
return -ENOTSUP;
}
if (period_cycles > 0xffff) {

Loading…
Cancel
Save