|
31 | 31 | //| print("touched!")""" |
32 | 32 | //| |
33 | 33 |
|
34 | | -//| def __init__(self, pin: microcontroller.Pin) -> None: |
| 34 | +//| def __init__(self, pin: microcontroller.Pin, pull: Optional[digitalio.Pull] = None) -> None: |
35 | 35 | //| """Use the TouchIn on the given pin. |
36 | 36 | //| |
37 | 37 | //| :param ~microcontroller.Pin pin: the pin to read from""" |
| 38 | +//| :param Optional[digitalio.Pull] pull: specify external pull resistor type. If None, assume pull-down or chip-specific implementation |
38 | 39 | //| ... |
39 | 40 | //| |
40 | 41 | static mp_obj_t touchio_touchin_make_new(const mp_obj_type_t *type, |
41 | | - size_t n_args, size_t n_kw, const mp_obj_t *args) { |
42 | | - // check number of arguments |
43 | | - mp_arg_check_num(n_args, n_kw, 1, 1, false); |
| 42 | + size_t n_args, size_t n_kw, const mp_obj_t *all_args) { |
44 | 43 |
|
45 | | - // 1st argument is the pin |
46 | | - const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0], MP_QSTR_pin); |
| 44 | + enum { ARG_pin, ARG_pull }; |
| 45 | + static const mp_arg_t allowed_args[] = { |
| 46 | + { MP_QSTR_pin, MP_ARG_OBJ | MP_ARG_REQUIRED }, |
| 47 | + { MP_QSTR_pull, MP_ARG_OBJ, {.u_obj = mp_const_none} }, |
| 48 | + }; |
| 49 | + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; |
| 50 | + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); |
| 51 | + |
| 52 | + const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj, MP_QSTR_pin); |
| 53 | + const digitalio_pull_t pull = validate_pull(args[ARG_pull].u_obj, MP_QSTR_pull); |
47 | 54 |
|
48 | 55 | touchio_touchin_obj_t *self = mp_obj_malloc(touchio_touchin_obj_t, &touchio_touchin_type); |
49 | | - common_hal_touchio_touchin_construct(self, pin); |
| 56 | + common_hal_touchio_touchin_construct(self, pin, pull); |
50 | 57 |
|
51 | 58 | return (mp_obj_t)self; |
52 | 59 | } |
|
0 commit comments