diff options
| author | Hosted Weblate <hosted@weblate.org> | 2021-03-19 17:35:04 +0100 |
|---|---|---|
| committer | Hosted Weblate <hosted@weblate.org> | 2021-03-19 17:35:04 +0100 |
| commit | caafae3b3da3f05a530fcb337fe53a80968ff72b (patch) | |
| tree | 036484d5904e2dd2b7393044b17d0461c0451588 /shared-bindings | |
| parent | 38e791381e60f09bcb8005bdb1b8a4c82b037668 (diff) | |
| parent | 0615876d9f738cf7e040c5014cf953823498573e (diff) | |
Merge remote-tracking branch 'origin/main' into main
Diffstat (limited to 'shared-bindings')
| -rw-r--r-- | shared-bindings/pwmio/PWMOut.c | 36 | ||||
| -rw-r--r-- | shared-bindings/pwmio/PWMOut.h | 6 |
2 files changed, 33 insertions, 9 deletions
diff --git a/shared-bindings/pwmio/PWMOut.c b/shared-bindings/pwmio/PWMOut.c index 0f3111485..01b5bf77a 100644 --- a/shared-bindings/pwmio/PWMOut.c +++ b/shared-bindings/pwmio/PWMOut.c @@ -102,14 +102,34 @@ STATIC mp_obj_t pwmio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args, pwmio_pwmout_obj_t *self = m_new_obj(pwmio_pwmout_obj_t); self->base.type = &pwmio_pwmout_type; pwmout_result_t result = common_hal_pwmio_pwmout_construct(self, pin, duty_cycle, frequency, variable_frequency); - if (result == PWMOUT_INVALID_PIN) { - mp_raise_ValueError(translate("Invalid pin")); - } else if (result == PWMOUT_INVALID_FREQUENCY) { - mp_raise_ValueError(translate("Invalid PWM frequency")); - } else if (result == PWMOUT_ALL_TIMERS_ON_PIN_IN_USE) { - mp_raise_ValueError(translate("All timers for this pin are in use")); - } else if (result == PWMOUT_ALL_TIMERS_IN_USE) { - mp_raise_RuntimeError(translate("All timers in use")); + switch (result) { + case PWMOUT_OK: + break; + case PWMOUT_INVALID_PIN: + mp_raise_ValueError(translate("Invalid pin")); + break; + case PWMOUT_INVALID_FREQUENCY: + mp_raise_ValueError(translate("Invalid PWM frequency")); + break; + case PWMOUT_INVALID_FREQUENCY_ON_PIN: + mp_raise_ValueError(translate("Frequency must match existing PWMOut using this timer")); + break; + case PWMOUT_VARIABLE_FREQUENCY_NOT_AVAILABLE: + mp_raise_ValueError(translate("Cannot vary frequency on a timer that is already in use")); + break; + case PWMOUT_ALL_TIMERS_ON_PIN_IN_USE: + mp_raise_ValueError(translate("All timers for this pin are in use")); + break; + case PWMOUT_ALL_TIMERS_IN_USE: + mp_raise_RuntimeError(translate("All timers in use")); + break; + case PWMOUT_ALL_CHANNELS_IN_USE: + mp_raise_RuntimeError(translate("All channels in use")); + break; + default: + case PWMOUT_INITIALIZATION_ERROR: + mp_raise_RuntimeError(translate("Could not start PWM")); + break; } return MP_OBJ_FROM_PTR(self); diff --git a/shared-bindings/pwmio/PWMOut.h b/shared-bindings/pwmio/PWMOut.h index 4155ba12d..f4d205b21 100644 --- a/shared-bindings/pwmio/PWMOut.h +++ b/shared-bindings/pwmio/PWMOut.h @@ -36,8 +36,12 @@ typedef enum pwmout_result_t { PWMOUT_OK, PWMOUT_INVALID_PIN, PWMOUT_INVALID_FREQUENCY, + PWMOUT_INVALID_FREQUENCY_ON_PIN, + PWMOUT_VARIABLE_FREQUENCY_NOT_AVAILABLE, PWMOUT_ALL_TIMERS_ON_PIN_IN_USE, - PWMOUT_ALL_TIMERS_IN_USE + PWMOUT_ALL_TIMERS_IN_USE, + PWMOUT_ALL_CHANNELS_IN_USE, + PWMOUT_INITIALIZATION_ERROR, } pwmout_result_t; extern pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self, |
