diff --git a/ports/cxd56/common-hal/analogio/AnalogIn.c b/ports/cxd56/common-hal/analogio/AnalogIn.c index ebe291582a..e2ca5e4a42 100644 --- a/ports/cxd56/common-hal/analogio/AnalogIn.c +++ b/ports/cxd56/common-hal/analogio/AnalogIn.c @@ -68,9 +68,11 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const mp_raise_ValueError(translate("Pin does not have ADC capabilities")); } - analogin_dev[self->number].fd = open(analogin_dev[pin->number].devpath, O_RDONLY); if (analogin_dev[self->number].fd < 0) { - mp_raise_ValueError(translate("Pin does not have ADC capabilities")); + analogin_dev[self->number].fd = open(analogin_dev[self->number].devpath, O_RDONLY); + if (analogin_dev[self->number].fd < 0) { + mp_raise_ValueError(translate("Pin does not have ADC capabilities")); + } } // SCU FIFO overwrite @@ -99,7 +101,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) { } bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) { - return self->pin == mp_const_none; + return analogin_dev[self->number].fd < 0; } uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { diff --git a/ports/cxd56/common-hal/analogio/AnalogIn.h b/ports/cxd56/common-hal/analogio/AnalogIn.h index 4e8b41e52b..9cf73003f5 100644 --- a/ports/cxd56/common-hal/analogio/AnalogIn.h +++ b/ports/cxd56/common-hal/analogio/AnalogIn.h @@ -34,7 +34,7 @@ typedef struct { mp_obj_base_t base; const mcu_pin_obj_t *pin; - uint8_t number; + int8_t number; } analogio_analogin_obj_t; void analogin_reset(void);