Skip to content

Commit

Permalink
stm32/adc: Make ADCAll.read_channel reject invalid channels.
Browse files Browse the repository at this point in the history
pyb.ADC(channel) checks whether specified channel is valid or have ADC
capability but pyb.ADCAll().read_channel() does not.

This change adds checking whether specified channel is valid and throw
ValueError if channel is invalid.  This is same as pyb.ADC().
  • Loading branch information
yn386 authored and dpgeorge committed Sep 6, 2022
1 parent 4e4c28b commit 8770cd2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ports/stm32/adc.c
Expand Up @@ -856,6 +856,9 @@ STATIC mp_obj_t adc_all_make_new(const mp_obj_type_t *type, size_t n_args, size_
STATIC mp_obj_t adc_all_read_channel(mp_obj_t self_in, mp_obj_t channel) {
pyb_adc_all_obj_t *self = MP_OBJ_TO_PTR(self_in);
uint32_t chan = adc_get_internal_channel(mp_obj_get_int(channel));
if (!is_adcx_channel(chan)) {
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("not a valid ADC Channel: %d"), chan);
}
uint32_t data = adc_config_and_read_channel(&self->handle, chan);
return mp_obj_new_int(data);
}
Expand Down

0 comments on commit 8770cd2

Please sign in to comment.