Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit f974253

Browse files
author
Islam Wahdan
authored
Merge pull request #347 from robert-hh/adc_init
mods/pybadc.c: Fix the argument handling of bits=x for adc.init()
2 parents 572788e + d35155e commit f974253

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

esp32/mods/pybadc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,12 @@ STATIC mp_obj_t adc_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *k
152152
mp_arg_val_t args[MP_ARRAY_SIZE(pyb_adc_init_args) - 1];
153153
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_adc_init_args[1], args);
154154
// check the number of bits
155-
if (args[0].u_int != 12) {
155+
if (args[0].u_int < 9 || args[0].u_int > 12) {
156156
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
157157
}
158-
pyb_adc_init(pos_args[0]);
158+
pyb_adc_obj_t *self = pos_args[0];
159+
self->width = args[0].u_int;
160+
pyb_adc_init(self);
159161
return mp_const_none;
160162
}
161163
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adc_init_obj, 1, adc_init);

0 commit comments

Comments
 (0)