Skip to content

Commit 4f538b6

Browse files
committed
remove pressed() and get_states_into()
1 parent 7774b18 commit 4f538b6

File tree

9 files changed

+8
-185
lines changed

9 files changed

+8
-185
lines changed

shared-bindings/keypad/KeyMatrix.c

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -225,50 +225,6 @@ STATIC mp_obj_t keypad_keymatrix_row_column_to_key_number(mp_obj_t self_in, mp_o
225225
}
226226
MP_DEFINE_CONST_FUN_OBJ_3(keypad_keymatrix_row_column_to_key_number_obj, keypad_keymatrix_row_column_to_key_number);
227227

228-
//| def pressed(self, key_number: int) -> None:
229-
//| """Return ``True`` if the given key is pressed. This is a debounced read
230-
//| of the key state which bypasses the `events` `EventQueue`.
231-
//| """
232-
//| ...
233-
//|
234-
STATIC mp_obj_t keypad_keymatrix_pressed(mp_obj_t self_in, mp_obj_t key_number_in) {
235-
keypad_keymatrix_obj_t *self = MP_OBJ_TO_PTR(self_in);
236-
check_for_deinit(self);
237-
238-
mp_uint_t key_number = mp_arg_validate_int_range(
239-
mp_obj_get_int(key_number_in), 0, (mp_int_t)common_hal_keypad_keymatrix_get_key_count(self), MP_QSTR_key_number);
240-
241-
return mp_obj_new_bool(common_hal_keypad_keymatrix_pressed(self, (mp_uint_t)key_number));
242-
}
243-
MP_DEFINE_CONST_FUN_OBJ_2(keypad_keymatrix_pressed_obj, keypad_keymatrix_pressed);
244-
245-
//| def get_states_into(self, states: _typing.WriteableBuffer) -> None:
246-
//| """Write the state of all the keys into ``states``.
247-
//| Write a ``1`` if pressed, and ``0`` if released.
248-
//| The ``length`` of ``states`` must be `key_count`.
249-
//| This is a debounced read of the state of all the keys, and bypasses the `events` `EventQueue`.
250-
//| The read is done atomically.
251-
//| """
252-
//| ...
253-
//|
254-
STATIC mp_obj_t keypad_keymatrix_get_states_into(mp_obj_t self_in, mp_obj_t pressed) {
255-
keypad_keymatrix_obj_t *self = MP_OBJ_TO_PTR(self_in);
256-
check_for_deinit(self);
257-
258-
mp_buffer_info_t bufinfo;
259-
mp_get_buffer_raise(pressed, &bufinfo, MP_BUFFER_WRITE);
260-
if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) {
261-
mp_raise_ValueError_varg(translate("%q must store bytes"), MP_QSTR_states);
262-
}
263-
264-
(void)mp_arg_validate_length_with_name(bufinfo.len, common_hal_keypad_keymatrix_get_key_count(self),
265-
MP_QSTR_states, MP_QSTR_key_count);
266-
267-
common_hal_keypad_keymatrix_get_states_into(self, (uint8_t *)bufinfo.buf);
268-
return MP_ROM_NONE;
269-
}
270-
MP_DEFINE_CONST_FUN_OBJ_2(keypad_keymatrix_get_states_into_obj, keypad_keymatrix_get_states_into);
271-
272228
//| events: EventQueue
273229
//| """The `EventQueue` associated with this `Keys` object. (read-only)
274230
//| """
@@ -292,12 +248,10 @@ STATIC const mp_rom_map_elem_t keypad_keymatrix_locals_dict_table[] = {
292248
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&keypad_keymatrix___exit___obj) },
293249

294250
{ MP_ROM_QSTR(MP_QSTR_events), MP_ROM_PTR(&keypad_keymatrix_events_obj) },
295-
{ MP_ROM_QSTR(MP_QSTR_get_states_into), MP_ROM_PTR(&keypad_keymatrix_get_states_into_obj) },
296-
{ MP_ROM_QSTR(MP_QSTR_key_number_to_row_column), MP_ROM_PTR(&keypad_keymatrix_key_number_to_row_column_obj) },
297-
{ MP_ROM_QSTR(MP_QSTR_row_column_to_key_number), MP_ROM_PTR(&keypad_keymatrix_row_column_to_key_number_obj) },
298251
{ MP_ROM_QSTR(MP_QSTR_key_count), MP_ROM_PTR(&keypad_keymatrix_key_count_obj) },
299-
{ MP_ROM_QSTR(MP_QSTR_pressed), MP_ROM_PTR(&keypad_keymatrix_pressed_obj) },
300252
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&keypad_keymatrix_reset_obj) },
253+
{ MP_ROM_QSTR(MP_QSTR_key_number_to_row_column), MP_ROM_PTR(&keypad_keymatrix_key_number_to_row_column_obj) },
254+
{ MP_ROM_QSTR(MP_QSTR_row_column_to_key_number), MP_ROM_PTR(&keypad_keymatrix_row_column_to_key_number_obj) },
301255
};
302256

303257
STATIC MP_DEFINE_CONST_DICT(keypad_keymatrix_locals_dict, keypad_keymatrix_locals_dict_table);

shared-bindings/keypad/KeyMatrix.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@ bool common_hal_keypad_keymatrix_deinited(keypad_keymatrix_obj_t *self);
4040
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);
4141
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);
4242

43-
mp_uint_t common_hal_keypad_keymatrix_get_key_count(keypad_keymatrix_obj_t *self);
44-
mp_uint_t common_hal_keypad_keymatrix_get_column_count(keypad_keymatrix_obj_t *self);
45-
mp_uint_t common_hal_keypad_keymatrix_get_row_count(keypad_keymatrix_obj_t *self);
43+
size_t common_hal_keypad_keymatrix_get_key_count(keypad_keymatrix_obj_t *self);
44+
size_t common_hal_keypad_keymatrix_get_column_count(keypad_keymatrix_obj_t *self);
45+
size_t common_hal_keypad_keymatrix_get_row_count(keypad_keymatrix_obj_t *self);
4646

4747
mp_obj_t common_hal_keypad_keymatrix_get_events(keypad_keymatrix_obj_t *self);
48-
bool common_hal_keypad_keymatrix_pressed(keypad_keymatrix_obj_t *self, mp_uint_t key_number);
4948
void common_hal_keypad_keymatrix_reset(keypad_keymatrix_obj_t *self);
50-
void common_hal_keypad_keymatrix_get_states_into(keypad_keymatrix_obj_t *self, uint8_t *states);
5149

5250
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_KEYPAD_KEYMATRIX_H

shared-bindings/keypad/Keys.c

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -167,49 +167,6 @@ const mp_obj_property_t keypad_keys_key_count_obj = {
167167
MP_ROM_NONE},
168168
};
169169

170-
//| def pressed(self, key_number: int) -> None:
171-
//| """Return ``True`` if the given key is pressed.
172-
// This is a debounced read of the key state which bypasses the `events` `EventQueue`.
173-
//| """
174-
//| ...
175-
//|
176-
STATIC mp_obj_t keypad_keys_pressed(mp_obj_t self_in, mp_obj_t key_number_in) {
177-
keypad_keys_obj_t *self = MP_OBJ_TO_PTR(self_in);
178-
check_for_deinit(self);
179-
180-
const mp_int_t key_number = mp_obj_get_int(key_number_in);
181-
(void)mp_arg_validate_int_range(key_number, 0, common_hal_keypad_keys_get_key_count(self), MP_QSTR_key_number);
182-
183-
return mp_obj_new_bool(common_hal_keypad_keys_pressed(self, (mp_uint_t)key_number));
184-
}
185-
MP_DEFINE_CONST_FUN_OBJ_2(keypad_keys_pressed_obj, keypad_keys_pressed);
186-
187-
//| def get_states_into(self, states: _typing.WriteableBuffer) -> None:
188-
//| """Write the states of all the keys into ``states``.
189-
//| Write a ``1`` if pressed, and ``0`` if released.
190-
//| The ``length`` of ``states`` must be `key_count`.
191-
//| This is a debounced read of the state of all the keys, and bypasses the `events` `EventQueue`.
192-
//| The read is done atomically.
193-
//| """
194-
//| ...
195-
//|
196-
STATIC mp_obj_t keypad_keys_get_states_into(mp_obj_t self_in, mp_obj_t pressed) {
197-
keypad_keys_obj_t *self = MP_OBJ_TO_PTR(self_in);
198-
check_for_deinit(self);
199-
200-
mp_buffer_info_t bufinfo;
201-
mp_get_buffer_raise(pressed, &bufinfo, MP_BUFFER_WRITE);
202-
if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) {
203-
mp_raise_ValueError_varg(translate("%q must store bytes"), MP_QSTR_pressed);
204-
}
205-
(void)mp_arg_validate_length_with_name(bufinfo.len,common_hal_keypad_keys_get_key_count(self),
206-
MP_QSTR_pressed, MP_QSTR_key_count);
207-
208-
common_hal_keypad_keys_get_states_into(self, (uint8_t *)bufinfo.buf);
209-
return MP_ROM_NONE;
210-
}
211-
MP_DEFINE_CONST_FUN_OBJ_2(keypad_keys_get_states_into_obj, keypad_keys_get_states_into);
212-
213170
//| events: EventQueue
214171
//| """The `EventQueue` associated with this `Keys` object. (read-only)
215172
//| """
@@ -233,9 +190,7 @@ STATIC const mp_rom_map_elem_t keypad_keys_locals_dict_table[] = {
233190
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&keypad_keys___exit___obj) },
234191

235192
{ MP_ROM_QSTR(MP_QSTR_events), MP_ROM_PTR(&keypad_keys_events_obj) },
236-
{ MP_ROM_QSTR(MP_QSTR_get_states_into), MP_ROM_PTR(&keypad_keys_get_states_into_obj) },
237-
{ MP_ROM_QSTR(MP_QSTR_key_count), MP_ROM_PTR(&keypad_keys_key_count_obj) },
238-
{ MP_ROM_QSTR(MP_QSTR_pressed), MP_ROM_PTR(&keypad_keys_pressed_obj) },
193+
{ MP_ROM_QSTR(MP_QSTR_key_count), MP_ROM_PTR(&keypad_keys_key_count_obj) },
239194
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&keypad_keys_reset_obj) },
240195
};
241196

shared-bindings/keypad/Keys.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ void common_hal_keypad_keys_deinit(keypad_keys_obj_t *self);
3838
bool common_hal_keypad_keys_deinited(keypad_keys_obj_t *self);
3939

4040
mp_obj_t common_hal_keypad_keys_get_events(keypad_keys_obj_t *self);
41-
mp_uint_t common_hal_keypad_keys_get_key_count(keypad_keys_obj_t *self);
42-
bool common_hal_keypad_keys_pressed(keypad_keys_obj_t *self, mp_uint_t key_number);
41+
size_t common_hal_keypad_keys_get_key_count(keypad_keys_obj_t *self);
4342
void common_hal_keypad_keys_reset(keypad_keys_obj_t *self);
44-
void common_hal_keypad_keys_get_states_into(keypad_keys_obj_t *self, uint8_t *states);
4543

4644
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_KEYPAD_KEYS_H

shared-bindings/keypad/ShiftRegisterKeys.c

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -171,50 +171,6 @@ const mp_obj_property_t keypad_shiftregisterkeys_key_count_obj = {
171171
MP_ROM_NONE},
172172
};
173173

174-
//| def pressed(self, key_number: int) -> None:
175-
//| """Return ``True`` if the given key is pressed.
176-
// This is a debounced read of the key state which bypasses the `events` `EventQueue`.
177-
//| """
178-
//| ...
179-
//|
180-
STATIC mp_obj_t keypad_shiftregisterkeys_pressed(mp_obj_t self_in, mp_obj_t key_number_in) {
181-
keypad_shiftregisterkeys_obj_t *self = MP_OBJ_TO_PTR(self_in);
182-
check_for_deinit(self);
183-
184-
mp_uint_t key_number = mp_arg_validate_int_range(
185-
mp_obj_get_int(key_number_in), 0, (mp_int_t)common_hal_keypad_shiftregisterkeys_get_key_count(self),
186-
MP_QSTR_key_number);
187-
188-
return mp_obj_new_bool(common_hal_keypad_shiftregisterkeys_pressed(self, key_number));
189-
}
190-
MP_DEFINE_CONST_FUN_OBJ_2(keypad_shiftregisterkeys_pressed_obj, keypad_shiftregisterkeys_pressed);
191-
192-
//| def get_states_into(self, states: _typing.WriteableBuffer) -> None:
193-
//| """Write the states of all the keys into ``states``.
194-
//| Write a ``1`` if pressed, and ``0`` if released.
195-
//| The ``length`` of ``states`` must be `key_count`.
196-
//| This is a debounced read of the state of all the keys, and bypasses the `events` `EventQueue`.
197-
//| The read is done atomically.
198-
//| """
199-
//| ...
200-
//|
201-
STATIC mp_obj_t keypad_shiftregisterkeys_get_states_into(mp_obj_t self_in, mp_obj_t pressed) {
202-
keypad_shiftregisterkeys_obj_t *self = MP_OBJ_TO_PTR(self_in);
203-
check_for_deinit(self);
204-
205-
mp_buffer_info_t bufinfo;
206-
mp_get_buffer_raise(pressed, &bufinfo, MP_BUFFER_WRITE);
207-
if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) {
208-
mp_raise_ValueError_varg(translate("%q must store bytes"), MP_QSTR_pressed);
209-
}
210-
(void)mp_arg_validate_length_with_name(bufinfo.len, common_hal_keypad_shiftregisterkeys_get_key_count(self),
211-
MP_QSTR_states, MP_QSTR_key_count);
212-
213-
common_hal_keypad_shiftregisterkeys_get_states_into(self, (uint8_t *)bufinfo.buf);
214-
return MP_ROM_NONE;
215-
}
216-
MP_DEFINE_CONST_FUN_OBJ_2(keypad_shiftregisterkeys_get_states_into_obj, keypad_shiftregisterkeys_get_states_into);
217-
218174
//| events: EventQueue
219175
//| """The `EventQueue` associated with this `Keys` object. (read-only)
220176
//| """
@@ -238,9 +194,7 @@ STATIC const mp_rom_map_elem_t keypad_shiftregisterkeys_locals_dict_table[] = {
238194
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&keypad_shiftregisterkeys___exit___obj) },
239195

240196
{ MP_ROM_QSTR(MP_QSTR_events), MP_ROM_PTR(&keypad_shiftregisterkeys_events_obj) },
241-
{ MP_ROM_QSTR(MP_QSTR_get_states_into), MP_ROM_PTR(&keypad_shiftregisterkeys_get_states_into_obj) },
242197
{ MP_ROM_QSTR(MP_QSTR_key_count), MP_ROM_PTR(&keypad_shiftregisterkeys_key_count_obj) },
243-
{ MP_ROM_QSTR(MP_QSTR_pressed), MP_ROM_PTR(&keypad_shiftregisterkeys_pressed_obj) },
244198
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&keypad_shiftregisterkeys_reset_obj) },
245199
};
246200

shared-bindings/keypad/ShiftRegisterKeys.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ void common_hal_keypad_shiftregisterkeys_deinit(keypad_shiftregisterkeys_obj_t *
3838
bool common_hal_keypad_shiftregisterkeys_deinited(keypad_shiftregisterkeys_obj_t *self);
3939

4040
mp_obj_t common_hal_keypad_shiftregisterkeys_get_events(keypad_shiftregisterkeys_obj_t *self);
41-
mp_uint_t common_hal_keypad_shiftregisterkeys_get_key_count(keypad_shiftregisterkeys_obj_t *self);
42-
bool common_hal_keypad_shiftregisterkeys_pressed(keypad_shiftregisterkeys_obj_t *self, mp_uint_t key_number);
41+
size_t common_hal_keypad_shiftregisterkeys_get_key_count(keypad_shiftregisterkeys_obj_t *self);
4342
void common_hal_keypad_shiftregisterkeys_reset(keypad_shiftregisterkeys_obj_t *self);
44-
void common_hal_keypad_shiftregisterkeys_get_states_into(keypad_shiftregisterkeys_obj_t *self, uint8_t *states);
4543

4644
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_KEYPAD_SHIFTREGISTERKEYS_H

shared-module/keypad/KeyMatrix.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,6 @@ size_t common_hal_keypad_keymatrix_get_column_count(keypad_keymatrix_obj_t *self
116116
return self->column_digitalinouts->len;
117117
}
118118

119-
bool common_hal_keypad_keymatrix_pressed(keypad_keymatrix_obj_t *self, mp_uint_t key_number) {
120-
return self->currently_pressed[key_number];
121-
}
122-
123-
// The length of states has already been validated.
124-
void common_hal_keypad_keymatrix_get_states_into(keypad_keymatrix_obj_t *self, uint8_t *states) {
125-
// Read the state atomically.
126-
supervisor_acquire_lock(&keypad_scanners_linked_list_lock);
127-
memcpy(states, self->currently_pressed, common_hal_keypad_keymatrix_get_key_count(self));
128-
supervisor_release_lock(&keypad_scanners_linked_list_lock);
129-
}
130-
131119
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) {
132120
return row_column_to_key_number(self, row, column);
133121
}

shared-module/keypad/Keys.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,6 @@ bool common_hal_keypad_keys_deinited(keypad_keys_obj_t *self) {
8989
size_t common_hal_keypad_keys_get_key_count(keypad_keys_obj_t *self) {
9090
return self->digitalinouts->len;
9191
}
92-
bool common_hal_keypad_keys_pressed(keypad_keys_obj_t *self, mp_uint_t key_number) {
93-
return self->currently_pressed[key_number];
94-
}
95-
96-
// The length of states has already been validated.
97-
void common_hal_keypad_keys_get_states_into(keypad_keys_obj_t *self, uint8_t *states) {
98-
// Read the state atomically.
99-
supervisor_acquire_lock(&keypad_scanners_linked_list_lock);
100-
memcpy(states, self->currently_pressed, common_hal_keypad_keys_get_key_count(self));
101-
supervisor_release_lock(&keypad_scanners_linked_list_lock);
102-
}
10392

10493
mp_obj_t common_hal_keypad_keys_get_events(keypad_keys_obj_t *self) {
10594
return MP_OBJ_FROM_PTR(self->events);

shared-module/keypad/ShiftRegisterKeys.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,6 @@ bool common_hal_keypad_shiftregisterkeys_deinited(keypad_shiftregisterkeys_obj_t
101101
size_t common_hal_keypad_shiftregisterkeys_get_key_count(keypad_shiftregisterkeys_obj_t *self) {
102102
return self->key_count;
103103
}
104-
bool common_hal_keypad_shiftregisterkeys_pressed(keypad_shiftregisterkeys_obj_t *self, mp_uint_t key_number) {
105-
return self->currently_pressed[key_number];
106-
}
107-
108-
// The length of states has already been validated.
109-
void common_hal_keypad_shiftregisterkeys_get_states_into(keypad_shiftregisterkeys_obj_t *self, uint8_t *states) {
110-
// Read the state atomically.
111-
supervisor_acquire_lock(&keypad_scanners_linked_list_lock);
112-
memcpy(states, self->currently_pressed, common_hal_keypad_shiftregisterkeys_get_key_count(self));
113-
supervisor_release_lock(&keypad_scanners_linked_list_lock);
114-
}
115104

116105
mp_obj_t common_hal_keypad_shiftregisterkeys_get_events(keypad_shiftregisterkeys_obj_t *self) {
117106
return MP_OBJ_FROM_PTR(self->events);

0 commit comments

Comments
 (0)