diff --git a/shared-bindings/keypad/KeyMatrix.c b/shared-bindings/keypad/KeyMatrix.c index 506add0713..83efdd5f16 100644 --- a/shared-bindings/keypad/KeyMatrix.c +++ b/shared-bindings/keypad/KeyMatrix.c @@ -225,50 +225,6 @@ STATIC mp_obj_t keypad_keymatrix_row_column_to_key_number(mp_obj_t self_in, mp_o } MP_DEFINE_CONST_FUN_OBJ_3(keypad_keymatrix_row_column_to_key_number_obj, keypad_keymatrix_row_column_to_key_number); -//| def pressed(self, key_number: int) -> None: -//| """Return ``True`` if the given key is pressed. This is a debounced read -//| of the key state which bypasses the `events` `EventQueue`. -//| """ -//| ... -//| -STATIC mp_obj_t keypad_keymatrix_pressed(mp_obj_t self_in, mp_obj_t key_number_in) { - keypad_keymatrix_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - - mp_uint_t key_number = mp_arg_validate_int_range( - mp_obj_get_int(key_number_in), 0, (mp_int_t)common_hal_keypad_keymatrix_get_key_count(self), MP_QSTR_key_number); - - return mp_obj_new_bool(common_hal_keypad_keymatrix_pressed(self, (mp_uint_t)key_number)); -} -MP_DEFINE_CONST_FUN_OBJ_2(keypad_keymatrix_pressed_obj, keypad_keymatrix_pressed); - -//| def get_states_into(self, states: _typing.WriteableBuffer) -> None: -//| """Write the state of all the keys into ``states``. -//| Write a ``1`` if pressed, and ``0`` if released. -//| The ``length`` of ``states`` must be `key_count`. -//| This is a debounced read of the state of all the keys, and bypasses the `events` `EventQueue`. -//| The read is done atomically. -//| """ -//| ... -//| -STATIC mp_obj_t keypad_keymatrix_get_states_into(mp_obj_t self_in, mp_obj_t pressed) { - keypad_keymatrix_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(pressed, &bufinfo, MP_BUFFER_WRITE); - if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) { - mp_raise_ValueError_varg(translate("%q must store bytes"), MP_QSTR_states); - } - - (void)mp_arg_validate_length_with_name(bufinfo.len, common_hal_keypad_keymatrix_get_key_count(self), - MP_QSTR_states, MP_QSTR_key_count); - - common_hal_keypad_keymatrix_get_states_into(self, (uint8_t *)bufinfo.buf); - return MP_ROM_NONE; -} -MP_DEFINE_CONST_FUN_OBJ_2(keypad_keymatrix_get_states_into_obj, keypad_keymatrix_get_states_into); - //| events: EventQueue //| """The `EventQueue` associated with this `Keys` object. (read-only) //| """ @@ -292,12 +248,10 @@ STATIC const mp_rom_map_elem_t keypad_keymatrix_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&keypad_keymatrix___exit___obj) }, { MP_ROM_QSTR(MP_QSTR_events), MP_ROM_PTR(&keypad_keymatrix_events_obj) }, - { MP_ROM_QSTR(MP_QSTR_get_states_into), MP_ROM_PTR(&keypad_keymatrix_get_states_into_obj) }, + { MP_ROM_QSTR(MP_QSTR_key_count), MP_ROM_PTR(&keypad_keymatrix_key_count_obj) }, + { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&keypad_keymatrix_reset_obj) }, { MP_ROM_QSTR(MP_QSTR_key_number_to_row_column), MP_ROM_PTR(&keypad_keymatrix_key_number_to_row_column_obj) }, { MP_ROM_QSTR(MP_QSTR_row_column_to_key_number), MP_ROM_PTR(&keypad_keymatrix_row_column_to_key_number_obj) }, - { MP_ROM_QSTR(MP_QSTR_key_count), MP_ROM_PTR(&keypad_keymatrix_key_count_obj) }, - { MP_ROM_QSTR(MP_QSTR_pressed), MP_ROM_PTR(&keypad_keymatrix_pressed_obj) }, - { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&keypad_keymatrix_reset_obj) }, }; STATIC MP_DEFINE_CONST_DICT(keypad_keymatrix_locals_dict, keypad_keymatrix_locals_dict_table); diff --git a/shared-bindings/keypad/KeyMatrix.h b/shared-bindings/keypad/KeyMatrix.h index 6643d2f9fd..7ebe1af5b7 100644 --- a/shared-bindings/keypad/KeyMatrix.h +++ b/shared-bindings/keypad/KeyMatrix.h @@ -40,13 +40,11 @@ bool common_hal_keypad_keymatrix_deinited(keypad_keymatrix_obj_t *self); void common_hal_keypad_keymatrix_key_number_to_row_column(keypad_keymatrix_obj_t *self, mp_uint_t key_number, mp_uint_t *row, mp_uint_t *column); mp_uint_t common_hal_keypad_keymatrix_row_column_to_key_number(keypad_keymatrix_obj_t *self, mp_uint_t row, mp_uint_t column); -mp_uint_t common_hal_keypad_keymatrix_get_key_count(keypad_keymatrix_obj_t *self); -mp_uint_t common_hal_keypad_keymatrix_get_column_count(keypad_keymatrix_obj_t *self); -mp_uint_t common_hal_keypad_keymatrix_get_row_count(keypad_keymatrix_obj_t *self); +size_t common_hal_keypad_keymatrix_get_key_count(keypad_keymatrix_obj_t *self); +size_t common_hal_keypad_keymatrix_get_column_count(keypad_keymatrix_obj_t *self); +size_t common_hal_keypad_keymatrix_get_row_count(keypad_keymatrix_obj_t *self); mp_obj_t common_hal_keypad_keymatrix_get_events(keypad_keymatrix_obj_t *self); -bool common_hal_keypad_keymatrix_pressed(keypad_keymatrix_obj_t *self, mp_uint_t key_number); void common_hal_keypad_keymatrix_reset(keypad_keymatrix_obj_t *self); -void common_hal_keypad_keymatrix_get_states_into(keypad_keymatrix_obj_t *self, uint8_t *states); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_KEYPAD_KEYMATRIX_H diff --git a/shared-bindings/keypad/Keys.c b/shared-bindings/keypad/Keys.c index 9c5ca08bf3..e9ed1346e8 100644 --- a/shared-bindings/keypad/Keys.c +++ b/shared-bindings/keypad/Keys.c @@ -167,49 +167,6 @@ const mp_obj_property_t keypad_keys_key_count_obj = { MP_ROM_NONE}, }; -//| def pressed(self, key_number: int) -> None: -//| """Return ``True`` if the given key is pressed. -// This is a debounced read of the key state which bypasses the `events` `EventQueue`. -//| """ -//| ... -//| -STATIC mp_obj_t keypad_keys_pressed(mp_obj_t self_in, mp_obj_t key_number_in) { - keypad_keys_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - - const mp_int_t key_number = mp_obj_get_int(key_number_in); - (void)mp_arg_validate_int_range(key_number, 0, common_hal_keypad_keys_get_key_count(self), MP_QSTR_key_number); - - return mp_obj_new_bool(common_hal_keypad_keys_pressed(self, (mp_uint_t)key_number)); -} -MP_DEFINE_CONST_FUN_OBJ_2(keypad_keys_pressed_obj, keypad_keys_pressed); - -//| def get_states_into(self, states: _typing.WriteableBuffer) -> None: -//| """Write the states of all the keys into ``states``. -//| Write a ``1`` if pressed, and ``0`` if released. -//| The ``length`` of ``states`` must be `key_count`. -//| This is a debounced read of the state of all the keys, and bypasses the `events` `EventQueue`. -//| The read is done atomically. -//| """ -//| ... -//| -STATIC mp_obj_t keypad_keys_get_states_into(mp_obj_t self_in, mp_obj_t pressed) { - keypad_keys_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(pressed, &bufinfo, MP_BUFFER_WRITE); - if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) { - mp_raise_ValueError_varg(translate("%q must store bytes"), MP_QSTR_pressed); - } - (void)mp_arg_validate_length_with_name(bufinfo.len,common_hal_keypad_keys_get_key_count(self), - MP_QSTR_pressed, MP_QSTR_key_count); - - common_hal_keypad_keys_get_states_into(self, (uint8_t *)bufinfo.buf); - return MP_ROM_NONE; -} -MP_DEFINE_CONST_FUN_OBJ_2(keypad_keys_get_states_into_obj, keypad_keys_get_states_into); - //| events: EventQueue //| """The `EventQueue` associated with this `Keys` object. (read-only) //| """ @@ -233,9 +190,7 @@ STATIC const mp_rom_map_elem_t keypad_keys_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&keypad_keys___exit___obj) }, { MP_ROM_QSTR(MP_QSTR_events), MP_ROM_PTR(&keypad_keys_events_obj) }, - { MP_ROM_QSTR(MP_QSTR_get_states_into), MP_ROM_PTR(&keypad_keys_get_states_into_obj) }, - { MP_ROM_QSTR(MP_QSTR_key_count), MP_ROM_PTR(&keypad_keys_key_count_obj) }, - { MP_ROM_QSTR(MP_QSTR_pressed), MP_ROM_PTR(&keypad_keys_pressed_obj) }, + { MP_ROM_QSTR(MP_QSTR_key_count), MP_ROM_PTR(&keypad_keys_key_count_obj) }, { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&keypad_keys_reset_obj) }, }; diff --git a/shared-bindings/keypad/Keys.h b/shared-bindings/keypad/Keys.h index 4d45d9e06a..094220e588 100644 --- a/shared-bindings/keypad/Keys.h +++ b/shared-bindings/keypad/Keys.h @@ -38,9 +38,7 @@ void common_hal_keypad_keys_deinit(keypad_keys_obj_t *self); bool common_hal_keypad_keys_deinited(keypad_keys_obj_t *self); mp_obj_t common_hal_keypad_keys_get_events(keypad_keys_obj_t *self); -mp_uint_t common_hal_keypad_keys_get_key_count(keypad_keys_obj_t *self); -bool common_hal_keypad_keys_pressed(keypad_keys_obj_t *self, mp_uint_t key_number); +size_t common_hal_keypad_keys_get_key_count(keypad_keys_obj_t *self); void common_hal_keypad_keys_reset(keypad_keys_obj_t *self); -void common_hal_keypad_keys_get_states_into(keypad_keys_obj_t *self, uint8_t *states); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_KEYPAD_KEYS_H diff --git a/shared-bindings/keypad/ShiftRegisterKeys.c b/shared-bindings/keypad/ShiftRegisterKeys.c index c76910726f..340960c718 100644 --- a/shared-bindings/keypad/ShiftRegisterKeys.c +++ b/shared-bindings/keypad/ShiftRegisterKeys.c @@ -171,50 +171,6 @@ const mp_obj_property_t keypad_shiftregisterkeys_key_count_obj = { MP_ROM_NONE}, }; -//| def pressed(self, key_number: int) -> None: -//| """Return ``True`` if the given key is pressed. -// This is a debounced read of the key state which bypasses the `events` `EventQueue`. -//| """ -//| ... -//| -STATIC mp_obj_t keypad_shiftregisterkeys_pressed(mp_obj_t self_in, mp_obj_t key_number_in) { - keypad_shiftregisterkeys_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - - mp_uint_t key_number = mp_arg_validate_int_range( - mp_obj_get_int(key_number_in), 0, (mp_int_t)common_hal_keypad_shiftregisterkeys_get_key_count(self), - MP_QSTR_key_number); - - return mp_obj_new_bool(common_hal_keypad_shiftregisterkeys_pressed(self, key_number)); -} -MP_DEFINE_CONST_FUN_OBJ_2(keypad_shiftregisterkeys_pressed_obj, keypad_shiftregisterkeys_pressed); - -//| def get_states_into(self, states: _typing.WriteableBuffer) -> None: -//| """Write the states of all the keys into ``states``. -//| Write a ``1`` if pressed, and ``0`` if released. -//| The ``length`` of ``states`` must be `key_count`. -//| This is a debounced read of the state of all the keys, and bypasses the `events` `EventQueue`. -//| The read is done atomically. -//| """ -//| ... -//| -STATIC mp_obj_t keypad_shiftregisterkeys_get_states_into(mp_obj_t self_in, mp_obj_t pressed) { - keypad_shiftregisterkeys_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(pressed, &bufinfo, MP_BUFFER_WRITE); - if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) { - mp_raise_ValueError_varg(translate("%q must store bytes"), MP_QSTR_pressed); - } - (void)mp_arg_validate_length_with_name(bufinfo.len, common_hal_keypad_shiftregisterkeys_get_key_count(self), - MP_QSTR_states, MP_QSTR_key_count); - - common_hal_keypad_shiftregisterkeys_get_states_into(self, (uint8_t *)bufinfo.buf); - return MP_ROM_NONE; -} -MP_DEFINE_CONST_FUN_OBJ_2(keypad_shiftregisterkeys_get_states_into_obj, keypad_shiftregisterkeys_get_states_into); - //| events: EventQueue //| """The `EventQueue` associated with this `Keys` object. (read-only) //| """ @@ -238,9 +194,7 @@ STATIC const mp_rom_map_elem_t keypad_shiftregisterkeys_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&keypad_shiftregisterkeys___exit___obj) }, { MP_ROM_QSTR(MP_QSTR_events), MP_ROM_PTR(&keypad_shiftregisterkeys_events_obj) }, - { MP_ROM_QSTR(MP_QSTR_get_states_into), MP_ROM_PTR(&keypad_shiftregisterkeys_get_states_into_obj) }, { MP_ROM_QSTR(MP_QSTR_key_count), MP_ROM_PTR(&keypad_shiftregisterkeys_key_count_obj) }, - { MP_ROM_QSTR(MP_QSTR_pressed), MP_ROM_PTR(&keypad_shiftregisterkeys_pressed_obj) }, { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&keypad_shiftregisterkeys_reset_obj) }, }; diff --git a/shared-bindings/keypad/ShiftRegisterKeys.h b/shared-bindings/keypad/ShiftRegisterKeys.h index b81b3b45e6..f1432f1069 100644 --- a/shared-bindings/keypad/ShiftRegisterKeys.h +++ b/shared-bindings/keypad/ShiftRegisterKeys.h @@ -38,9 +38,7 @@ void common_hal_keypad_shiftregisterkeys_deinit(keypad_shiftregisterkeys_obj_t * bool common_hal_keypad_shiftregisterkeys_deinited(keypad_shiftregisterkeys_obj_t *self); mp_obj_t common_hal_keypad_shiftregisterkeys_get_events(keypad_shiftregisterkeys_obj_t *self); -mp_uint_t common_hal_keypad_shiftregisterkeys_get_key_count(keypad_shiftregisterkeys_obj_t *self); -bool common_hal_keypad_shiftregisterkeys_pressed(keypad_shiftregisterkeys_obj_t *self, mp_uint_t key_number); +size_t common_hal_keypad_shiftregisterkeys_get_key_count(keypad_shiftregisterkeys_obj_t *self); void common_hal_keypad_shiftregisterkeys_reset(keypad_shiftregisterkeys_obj_t *self); -void common_hal_keypad_shiftregisterkeys_get_states_into(keypad_shiftregisterkeys_obj_t *self, uint8_t *states); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_KEYPAD_SHIFTREGISTERKEYS_H diff --git a/shared-module/keypad/KeyMatrix.c b/shared-module/keypad/KeyMatrix.c index ac2e715dbd..677a0b7142 100644 --- a/shared-module/keypad/KeyMatrix.c +++ b/shared-module/keypad/KeyMatrix.c @@ -116,18 +116,6 @@ size_t common_hal_keypad_keymatrix_get_column_count(keypad_keymatrix_obj_t *self return self->column_digitalinouts->len; } -bool common_hal_keypad_keymatrix_pressed(keypad_keymatrix_obj_t *self, mp_uint_t key_number) { - return self->currently_pressed[key_number]; -} - -// The length of states has already been validated. -void common_hal_keypad_keymatrix_get_states_into(keypad_keymatrix_obj_t *self, uint8_t *states) { - // Read the state atomically. - supervisor_acquire_lock(&keypad_scanners_linked_list_lock); - memcpy(states, self->currently_pressed, common_hal_keypad_keymatrix_get_key_count(self)); - supervisor_release_lock(&keypad_scanners_linked_list_lock); -} - mp_uint_t common_hal_keypad_keymatrix_row_column_to_key_number(keypad_keymatrix_obj_t *self, mp_uint_t row, mp_uint_t column) { return row_column_to_key_number(self, row, column); } diff --git a/shared-module/keypad/Keys.c b/shared-module/keypad/Keys.c index c621a757d2..1f232a03ed 100644 --- a/shared-module/keypad/Keys.c +++ b/shared-module/keypad/Keys.c @@ -89,17 +89,6 @@ bool common_hal_keypad_keys_deinited(keypad_keys_obj_t *self) { size_t common_hal_keypad_keys_get_key_count(keypad_keys_obj_t *self) { return self->digitalinouts->len; } -bool common_hal_keypad_keys_pressed(keypad_keys_obj_t *self, mp_uint_t key_number) { - return self->currently_pressed[key_number]; -} - -// The length of states has already been validated. -void common_hal_keypad_keys_get_states_into(keypad_keys_obj_t *self, uint8_t *states) { - // Read the state atomically. - supervisor_acquire_lock(&keypad_scanners_linked_list_lock); - memcpy(states, self->currently_pressed, common_hal_keypad_keys_get_key_count(self)); - supervisor_release_lock(&keypad_scanners_linked_list_lock); -} mp_obj_t common_hal_keypad_keys_get_events(keypad_keys_obj_t *self) { return MP_OBJ_FROM_PTR(self->events); diff --git a/shared-module/keypad/ShiftRegisterKeys.c b/shared-module/keypad/ShiftRegisterKeys.c index fd5d8bbdb1..074f226998 100644 --- a/shared-module/keypad/ShiftRegisterKeys.c +++ b/shared-module/keypad/ShiftRegisterKeys.c @@ -101,17 +101,6 @@ bool common_hal_keypad_shiftregisterkeys_deinited(keypad_shiftregisterkeys_obj_t size_t common_hal_keypad_shiftregisterkeys_get_key_count(keypad_shiftregisterkeys_obj_t *self) { return self->key_count; } -bool common_hal_keypad_shiftregisterkeys_pressed(keypad_shiftregisterkeys_obj_t *self, mp_uint_t key_number) { - return self->currently_pressed[key_number]; -} - -// The length of states has already been validated. -void common_hal_keypad_shiftregisterkeys_get_states_into(keypad_shiftregisterkeys_obj_t *self, uint8_t *states) { - // Read the state atomically. - supervisor_acquire_lock(&keypad_scanners_linked_list_lock); - memcpy(states, self->currently_pressed, common_hal_keypad_shiftregisterkeys_get_key_count(self)); - supervisor_release_lock(&keypad_scanners_linked_list_lock); -} mp_obj_t common_hal_keypad_shiftregisterkeys_get_events(keypad_shiftregisterkeys_obj_t *self) { return MP_OBJ_FROM_PTR(self->events);