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

adc.init() takes only bits=12 and ignores it. #324

Closed
@robert-hh

Description

@robert-hh

The implementation of adc.init() accepts for bits only the value 12, and, to make it worse, ignores the supplied value. That does not matter, since the default value is 12. To make adc.init() to meet the documentation, the functions in file modes/pybadc.c can e.g. be changed as follows:

STATIC mp_obj_t adc_init(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
    // parse args
    mp_arg_val_t args[MP_ARRAY_SIZE(pyb_adc_init_args) - 1];
    mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_adc_init_args[1], args);
    // check the number of bits
    if (args[0].u_int < 9 || args[0].u_int > 12) {
        nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
    }
    pyb_adc_obj_t *self = pos_args[0];
    self->width = args[0].u_int;
    pyb_adc_init(self);
    return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adc_init_obj, 1, adc_init);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions