From 05359dc320341dc470f05310641c217f979a58a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Thu, 20 Oct 2016 20:54:14 +0200 Subject: [PATCH] Add back the code of the old KeyMatrix functions via ifdefs. --- shared/key_matrix.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/shared/key_matrix.c b/shared/key_matrix.c index 75c0b67..20d6dfd 100644 --- a/shared/key_matrix.c +++ b/shared/key_matrix.c @@ -1,6 +1,45 @@ #include "fsl_gpio.h" #include "key_matrix.h" +#ifdef OLD_MATRIX + +// This ifdef clause will be completely erased as soon as Santiago's prototype will be out of use. +// Since the creation of his v6.0 prototype the diodes of the key matrix have been reversed in order +// to optimize the key scanning algorithm. + +void KeyMatrix_Init(key_matrix_t *keyMatrix) +{ + for (uint8_t col_i=0; col_icolNum; col_i++) { + key_matrix_pin_t col = keyMatrix->cols[col_i]; + CLOCK_EnableClock(col.clock); + PORT_SetPinConfig(col.port, col.pin, + &(port_pin_config_t){.pullSelect=kPORT_PullDisable, .mux=kPORT_MuxAsGpio}); + GPIO_PinInit(col.gpio, col.pin, &(gpio_pin_config_t){kGPIO_DigitalOutput, 0}); + } + + for (uint8_t row_i=0; row_irowNum; row_i++) { + key_matrix_pin_t row = keyMatrix->rows[row_i]; + CLOCK_EnableClock(row.clock); + PORT_SetPinConfig(row.port, row.pin, + &(port_pin_config_t){.pullSelect=kPORT_PullDown, .mux=kPORT_MuxAsGpio}); + GPIO_PinInit(row.gpio, row.pin, &(gpio_pin_config_t){kGPIO_DigitalInput}); + } +} + +void KeyMatrix_Scan(key_matrix_t *keyMatrix) +{ + for (uint8_t col=0; colcolNum; col++) { + GPIO_WritePinOutput(keyMatrix->cols[col].gpio, keyMatrix->cols[col].pin, 1); + for (uint8_t row=0; rowrowNum; row++) { + keyMatrix->keyStates[row*keyMatrix->colNum + col] = GPIO_ReadPinInput(keyMatrix->rows[row].gpio, keyMatrix->rows[row].pin); + } + GPIO_WritePinOutput(keyMatrix->cols[col].gpio, keyMatrix->cols[col].pin, 0); + for (volatile uint32_t i=0; i<100; i++); // Wait for the new port state to settle. This avoid bogus key state detection. + } +} + +#else + void KeyMatrix_Init(key_matrix_t *keyMatrix) { for (key_matrix_pin_t *row = keyMatrix->rows; row < keyMatrix->rows + keyMatrix->rowNum; row++) { @@ -37,3 +76,5 @@ void KeyMatrix_Scan(key_matrix_t *keyMatrix) for (volatile uint32_t i=0; i<100; i++); // Wait for the new port state to settle. This avoid bogus key state detection. } } + +#endif