From 920b502077030614ff7c4b9e1c2df6c987ffcfbf Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sat, 7 Jan 2023 22:48:59 +0800 Subject: [PATCH] lotus: Reduce sleep before ADC read 5us seems enough sleep. Still works Also need to measure delay not between each ADC scan but between each matrix scan! That's what matters to the user. Signed-off-by: Daniel Schaefer --- keyboards/lotus/matrix.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/keyboards/lotus/matrix.c b/keyboards/lotus/matrix.c index d39a2ca298..19ef434cdb 100644 --- a/keyboards/lotus/matrix.c +++ b/keyboards/lotus/matrix.c @@ -316,15 +316,8 @@ void drive_col(int col, bool high) { * Read a value from the ADC and print some debugging details */ static void read_adc(void) { - uint32_t current_ts = timer_read32(); - if (prev_matrix_ts) { - uint32_t delta = current_ts - prev_matrix_ts; - uprintf("%lu ms (%ld Hz)\n", delta, 1000 / delta); - } - prev_matrix_ts = current_ts; - // Need to sleep a bit, otherwise we seem to get stuck - chThdSleepMilliseconds(5); + wait_us(5); #if !CHIBIOS_ADC uint16_t val = analogReadPin(ADC_CH2_PIN); adc_voltage = val * CONV_FACTOR; @@ -380,6 +373,13 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) { print("scan\n"); + uint32_t current_ts = timer_read32(); + if (prev_matrix_ts) { + uint32_t delta = current_ts - prev_matrix_ts; + uprintf("%lu ms (%ld Hz)\n", delta, 1000 / delta); + } + prev_matrix_ts = current_ts; + handle_idle(); for (int col = 0; col < MATRIX_COLS; col++) {