From 6f638fccf86fda34d19ce2014819deb682923b46 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Mon, 26 Dec 2022 00:56:05 +0800 Subject: [PATCH] lotus: Basic ADC threshold Signed-off-by: Daniel Schaefer --- keyboards/lotus/matrix.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/keyboards/lotus/matrix.c b/keyboards/lotus/matrix.c index 334ac55714..2fe33409d7 100644 --- a/keyboards/lotus/matrix.c +++ b/keyboards/lotus/matrix.c @@ -8,6 +8,8 @@ #include "print.h" #include "quantum.h" +#define ADC_THRESHOLD 3 + /** * Tell RP2040 ADC controller to initialize a specific GPIO for ADC input */ @@ -78,10 +80,20 @@ static uint16_t adc_read(void) { return 0; } static bool interpret_adc_row(matrix_row_t cur_matrix[], uint16_t adc_value, int col, int row) { bool changed = false; - // TODO: Decode adc_value and set each row in this column - uint8_t key_state = 0; + // TODO: Convert adc value to voltage + uint16_t voltage = adc_value; - printf("Col %d - Row %d - ADC value:%04X\n", col, row, adc_value); + // By default the voltage is high (3.3V) + // When a key is pressed it causes the voltage to go down. + // But because every key is connected in a matrix, pressing multiple keys + // changes the voltage at every key again. So we can't check for a specific + // voltage but need to have a threshold. + uint8_t key_state = 0; + if (voltage < ADC_THRESHOLD) { + key_state = 1; + } + + printf("Col %d - Row %d - ADC value:%04X, Voltage: %d\n", col, row, adc_value, voltage); cur_matrix[row] |= key_state ? 0 : (1 << col); return changed;