Skip to content

Commit

Permalink
remove the workaround in users/mtei/matrix_output_delay.c
Browse files Browse the repository at this point in the history
Since qmk's standard wait_us() is now accurate due to the changes in qmk#17607, the workaround is no longer necessary.
  • Loading branch information
mtei committed Nov 10, 2022
1 parent 62e140d commit fcff042
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
22 changes: 1 addition & 21 deletions users/mtei/matrix_output_delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,6 @@
# define MATRIX_IO_DELAY 30
#endif

// The implementation of wait_cpuclock(n) in platforms/chibios/_wait.h has an upper bound on the value of the argument.
// The following implementation of wait_cpuclock_local() bypasses that limitation.

static void wait_cpuclock_local(unsigned int n) {
unsigned int l = n / 128;
n &= (128-1);
for (; l > 0; l--) {
wait_cpuclock(128);
}
wait_cpuclock(n);
}

static void wait_us_local(unsigned int n) {
wait_cpuclock_local(n * (CPU_CLOCK / 1000000L));
}

void matrix_output_select_delay(void) {
wait_cpuclock_local(GPIO_INPUT_PIN_DELAY);
}

void matrix_output_unselect_delay(uint8_t line, bool key_pressed) {
#ifdef MATRIX_UNSELECT_DELAY_ONDEMAND
if (!key_pressed) {
Expand All @@ -39,6 +19,6 @@ void matrix_output_unselect_delay(uint8_t line, bool key_pressed) {
* calls 'chThdSleepMicroseconds(1)' when 'wait_us(0)'.
* However, 'wait_us(0)' should do nothing. */
if (MATRIX_IO_DELAY > 0) {
wait_us_local(MATRIX_IO_DELAY);
wait_us(MATRIX_IO_DELAY);
}
}
24 changes: 14 additions & 10 deletions users/mtei/matrix_output_unselect_delay_ondemand.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
// Copyright (c) 2021 Takeshi Ishii (mtei@github)
// Copyright (c) 2022 Takeshi Ishii (mtei@github)
// SPDX-License-Identifier: GPL-2.0-or-later

#include QMK_KEYBOARD_H

#ifndef MATRIX_IO_DELAY
# define MATRIX_IO_DELAY 30
#endif

void matrix_output_unselect_delay(uint8_t line, bool key_pressed) {
/* If none of the keys are pressed,
* there is no need to wait for time for the next line. */
if (key_pressed) {
# ifdef MATRIX_IO_DELAY
# if MATRIX_IO_DELAY > 0
if (!key_pressed) {
/* If none of the keys are pressed,
* there is no need to wait for time for the next line. */
return;
}
/* In platforms/chibios/_wait.h, the implementation for PROTOCOL_CHIBIOS
* calls 'chThdSleepMicroseconds(1)' when 'wait_us(0)'.
* However, 'wait_us(0)' should do nothing. */
if (MATRIX_IO_DELAY > 0) {
wait_us(MATRIX_IO_DELAY);
# endif
# else
wait_us(30);
# endif
}
}

0 comments on commit fcff042

Please sign in to comment.