8000 Make KeyMatrix row output switch faster · domdfcoding/circuitpython@f1d2eee · GitHub
[go: up one dir, main page]

Skip to content

Commit f1d2eee

Browse files
committed
Make KeyMatrix row output switch faster
1 parent ce73015 commit f1d2eee

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

shared-module/keypad/KeyMatrix.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ void keypad_keymatrix_scan(keypad_keymatrix_obj_t *self) {
153153
for (size_t row = 0; row < common_hal_keypad_keymatrix_get_row_count(self); row++) {
154154
// Switch this row to an output and set level appropriately
155155
// Set low if columns_to_anodes is true, else set high.
156+
digitalio_digitalinout_obj_t *row_dio = self->row_digitalinouts->items[row];
156157
common_hal_digitalio_digitalinout_switch_to_output(
157-
self->row_digitalinouts->items[row], !self->columns_to_anodes, DRIVE_MODE_PUSH_PULL);
158+
row_dio, !self->columns_to_anodes, DRIVE_MODE_PUSH_PULL);
158159

159160
for (size_t column = 0; column < common_hal_keypad_keymatrix_get_column_count(self); column++) {
160161
mp_uint_t key_number = row_column_to_key_number(self, row, column);
@@ -175,8 +176,12 @@ void keypad_keymatrix_scan(keypad_keymatrix_obj_t *self) {
175176
}
176177
}
177178

179+
// Done with this row. Set its pin to its resting pull value briefly to shorten the time it takes
180+
// to switch values. Just switching to an input with a (relatively weak) pullup/pulldown
181+
// causes a slight delay in the output changing, which can cause false readings.
182+
common_hal_digitalio_digitalinout_set_value(row_dio, self->columns_to_anodes);
178183
// Switch the row back to an input, pulled appropriately
179184
common_hal_digitalio_digitalinout_switch_to_input(
180-
self->row_digitalinouts->items[row], self->columns_to_anodes ? PULL_UP : PULL_DOWN);
185+
row_dio, self->columns_to_anodes ? PULL_UP : PULL_DOWN);
181186
}
182187
}

0 commit comments

Comments
 (0)
0