Do not open the same ADC device again

This commit is contained in:
Kamil Tomaszewski 2019-10-18 12:38:39 +02:00
parent bd6c7c5546
commit 1decd111d5
2 changed files with 6 additions and 4 deletions

View File

@ -68,10 +68,12 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const
mp_raise_ValueError(translate("Pin does not have ADC capabilities")); 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) {
analogin_dev[self->number].fd = open(analogin_dev[self->number].devpath, O_RDONLY);
if (analogin_dev[self->number].fd < 0) { if (analogin_dev[self->number].fd < 0) {
mp_raise_ValueError(translate("Pin does not have ADC capabilities")); mp_raise_ValueError(translate("Pin does not have ADC capabilities"));
} }
}
// SCU FIFO overwrite // SCU FIFO overwrite
ioctl(analogin_dev[self->number].fd, SCUIOC_SETFIFOMODE, 1); ioctl(analogin_dev[self->number].fd, SCUIOC_SETFIFOMODE, 1);
@ -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) { 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) { uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {

View File

@ -34,7 +34,7 @@
typedef struct { typedef struct {
mp_obj_base_t base; mp_obj_base_t base;
const mcu_pin_obj_t *pin; const mcu_pin_obj_t *pin;
uint8_t number; int8_t number;
} analogio_analogin_obj_t; } analogio_analogin_obj_t;
void analogin_reset(void); void analogin_reset(void);