diff options
| author | Dan Halbert <halbert@halwitz.org> | 2017-10-02 20:49:40 -0400 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2017-10-03 12:07:17 -0700 |
| commit | c478c10923b9085b2abe135470e968029aaf2fdb (patch) | |
| tree | 6d76c8aa9cc4553d68fe3ff766f2f36b59378ec5 /shared-bindings/pulseio/PWMOut.c | |
| parent | c2bb9e2eb50e0dee6d7405fd738f1b4b0f94d10b (diff) | |
Do not allow a *io object to be used after deinit().
Fixes #278, #277, #276, #275.
Diffstat (limited to 'shared-bindings/pulseio/PWMOut.c')
| -rw-r--r-- | shared-bindings/pulseio/PWMOut.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/shared-bindings/pulseio/PWMOut.c b/shared-bindings/pulseio/PWMOut.c index 80036ae72..8f6c76680 100644 --- a/shared-bindings/pulseio/PWMOut.c +++ b/shared-bindings/pulseio/PWMOut.c @@ -29,8 +29,10 @@ #include "lib/utils/context_manager_helpers.h" #include "py/objproperty.h" #include "py/runtime.h" + #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/pulseio/PWMOut.h" +#include "shared-bindings/util.h" //| .. currentmodule:: pulseio //| @@ -147,13 +149,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pulseio_pwmout___exit___obj, 4, 4, pu //| (0). 0xffff will always be high, 0 will always be low and 0x7fff will //| be half high and then half low. STATIC mp_obj_t pulseio_pwmout_obj_get_duty_cycle(mp_obj_t self_in) { - pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_NEW_SMALL_INT(common_hal_pulseio_pwmout_get_duty_cycle(self)); + pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); + raise_error_if_deinited(common_hal_pulseio_pwmout_deinited(self)); + return MP_OBJ_NEW_SMALL_INT(common_hal_pulseio_pwmout_get_duty_cycle(self)); } MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pwmout_get_duty_cycle_obj, pulseio_pwmout_obj_get_duty_cycle); STATIC mp_obj_t pulseio_pwmout_obj_set_duty_cycle(mp_obj_t self_in, mp_obj_t duty_cycle) { pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); + raise_error_if_deinited(common_hal_pulseio_pwmout_deinited(self)); mp_int_t duty = mp_obj_get_int(duty_cycle); if (duty < 0 || duty > 0xffff) { mp_raise_ValueError("PWM duty_cycle must be between 0 and 65535 inclusive (16 bit resolution)"); @@ -176,13 +180,15 @@ const mp_obj_property_t pulseio_pwmout_duty_cycle_obj = { //| second). Only writeable when constructed with ``variable_frequency=True``. //| STATIC mp_obj_t pulseio_pwmout_obj_get_frequency(mp_obj_t self_in) { - pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_NEW_SMALL_INT(common_hal_pulseio_pwmout_get_frequency(self)); + pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); + raise_error_if_deinited(common_hal_pulseio_pwmout_deinited(self)); + return MP_OBJ_NEW_SMALL_INT(common_hal_pulseio_pwmout_get_frequency(self)); } MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pwmout_get_frequency_obj, pulseio_pwmout_obj_get_frequency); STATIC mp_obj_t pulseio_pwmout_obj_set_frequency(mp_obj_t self_in, mp_obj_t frequency) { pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); + raise_error_if_deinited(common_hal_pulseio_pwmout_deinited(self)); if (!common_hal_pulseio_pwmout_get_variable_frequency(self)) { mp_raise_AttributeError( "PWM frequency not writeable when variable_frequency is False on " |
