Skip to content

Commit e185c28

Browse files
committed
Fix transpose logic
1 parent 029a29a commit e185c28

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

shared-module/keypad_demux/DemuxKeyMatrix.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ static size_t demuxkeymatrix_get_key_count(void *self_in) {
114114

115115
static void demuxkeymatrix_scan_now(void *self_in, mp_obj_t timestamp) {
116116
keypad_demux_demuxkeymatrix_obj_t *self = self_in;
117-
118-
for (size_t row = 0; row < common_hal_keypad_demux_demuxkeymatrix_get_row_count(self); row++) {
117+
// We always scan through the multiplexed lines using the array sizes directly
118+
// and apply transposition only when translating to key number.
119+
for (int row = 0; row < (1 << self->row_addr_digitalinouts->len); row++) {
119120
// Set the row address on the demultiplexer.
120121
// When columns_to_anodes is True (default) we've got an inverting demux
121122
// so the selected line is pulled low, and we look for rows that get pulled low.
122123
// When columns_to_anodes is False we do the reverse.
123-
// We can safely ignore transposition since it's handled by row_column_to_key_number
124124
size_t mask = 0b00000001;
125125
for (size_t row_addr_pin = 0; row_addr_pin < self->row_addr_digitalinouts->len; row_addr_pin++) {
126126
digitalio_digitalinout_obj_t *dio = self->row_addr_digitalinouts->items[row_addr_pin];
@@ -136,8 +136,10 @@ static void demuxkeymatrix_scan_now(void *self_in, mp_obj_t timestamp) {
136136
// The QMK implementation for this keyboard uses a 5us delay which works here too
137137
mp_hal_delay_us(5);
138138

139-
for (size_t column = 0; column < common_hal_keypad_demux_demuxkeymatrix_get_column_count(self); column++) {
140-
mp_uint_t key_number = row_column_to_key_number(self, row, column);
139+
for (size_t column = 0; column < self->column_digitalinouts->len; column++) {
140+
mp_uint_t key_number = self->transpose
141+
? row_column_to_key_number(self, column, row)
142+
: row_column_to_key_number(self, row, column);
141143

142144
// Get the current state, by reading whether the column got pulled to the row value or not,
143145
// which is the opposite of columns_to_anodes.

0 commit comments

Comments
 (0)