summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2021-03-11 08:52:47 -0500
committerDan Halbert <halbert@halwitz.org>2021-03-11 08:52:47 -0500
commit08c5dbb0033c2f3838d7d52f98d3844a56253f81 (patch)
tree81c6967882451709878cd9380d48feb7cb7246c6 /shared-bindings
parent702978398573a652fb5df5540669424d3fa54c78 (diff)
use return values in STM PWMOut constructor, not exceptions
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/pwmio/PWMOut.c34
-rw-r--r--shared-bindings/pwmio/PWMOut.h6
2 files changed, 31 insertions, 9 deletions
diff --git a/shared-bindings/pwmio/PWMOut.c b/shared-bindings/pwmio/PWMOut.c
index da0755592..43944977e 100644
--- a/shared-bindings/pwmio/PWMOut.c
+++ b/shared-bindings/pwmio/PWMOut.c
@@ -102,14 +102,32 @@ 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_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 de2ebd1cf..69e7249e7 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,