diff --git a/ports/cxd56/common-hal/pulseio/PWMOut.c b/ports/cxd56/common-hal/pulseio/PWMOut.c index 38692146c2..a0b4e79c60 100644 --- a/ports/cxd56/common-hal/pulseio/PWMOut.c +++ b/ports/cxd56/common-hal/pulseio/PWMOut.c @@ -62,9 +62,11 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t *self, return PWMOUT_INVALID_PIN; } - pwmout_dev[self->number].fd = open(pwmout_dev[self->number].devpath, O_RDONLY); if (pwmout_dev[self->number].fd < 0) { - return PWMOUT_INVALID_PIN; + pwmout_dev[self->number].fd = open(pwmout_dev[self->number].devpath, O_RDONLY); + if (pwmout_dev[self->number].fd < 0) { + return PWMOUT_INVALID_PIN; + } } self->info.frequency = frequency; @@ -97,7 +99,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t *self) { } bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t *self) { - return self->pin == mp_const_none; + return pwmout_dev[self->number].fd < 0; } void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t *self, uint16_t duty) { diff --git a/ports/cxd56/common-hal/pulseio/PWMOut.h b/ports/cxd56/common-hal/pulseio/PWMOut.h index c16084fe62..57fc4181f0 100644 --- a/ports/cxd56/common-hal/pulseio/PWMOut.h +++ b/ports/cxd56/common-hal/pulseio/PWMOut.h @@ -38,7 +38,7 @@ typedef struct { const mcu_pin_obj_t *pin; struct pwm_info_s info; bool variable_frequency; - uint8_t number; + int8_t number; } pulseio_pwmout_obj_t; void pwmout_reset(void);