From 72988cd5cf871291c8898f709112d8d16e89f3d0 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Sun, 15 Nov 2020 20:38:28 +0100 Subject: [PATCH] Fix for both issue #5 and a bug in keyboard driver leading to undetected keypresses in some cases --- platform/drivers/keyboard/keyboard_MDxx380.c | 9 +++++++++ platform/targets/MD-380/hwconfig.h | 5 +++++ platform/targets/MD-390/hwconfig.h | 5 +++++ platform/targets/MD-UV380/hwconfig.h | 6 ++++++ 4 files changed, 25 insertions(+) diff --git a/platform/drivers/keyboard/keyboard_MDxx380.c b/platform/drivers/keyboard/keyboard_MDxx380.c index 9918fe6c..ad05c5d8 100644 --- a/platform/drivers/keyboard/keyboard_MDxx380.c +++ b/platform/drivers/keyboard/keyboard_MDxx380.c @@ -66,10 +66,17 @@ uint32_t kbd_getKeys() /* * Scan keyboard by coloumns. * For key configuration, see: https://www.qsl.net/dl4yhf/RT3/md380_hw.html#keyboard + * + * Keys coloumns (LCD_D...) have 1k series resistor and a 10pF capacitor + * connected to ground, making a low-pass filter with a settling time of + * ~50ns. CPU runs at 168MHz and 50ns are approximately eigth instructions, + * this means that we have to put a small delay before reading the GPIOs to + * allow voltage to settle. */ uint32_t keys = 0; gpio_setPin(KB_ROW1); + delayUs(1); if(gpio_readPin(LCD_D7)) keys |= KEY_STAR; if(gpio_readPin(LCD_D2)) keys |= KEY_3; if(gpio_readPin(LCD_D1)) keys |= KEY_2; @@ -82,6 +89,7 @@ uint32_t kbd_getKeys() gpio_clearPin(KB_ROW1); gpio_setPin(KB_ROW2); + delayUs(1); if(gpio_readPin(LCD_D7)) keys |= KEY_ESC; if(gpio_readPin(LCD_D2)) keys |= KEY_DOWN; if(gpio_readPin(LCD_D1)) keys |= KEY_UP; @@ -94,6 +102,7 @@ uint32_t kbd_getKeys() gpio_clearPin(KB_ROW2); gpio_setPin(KB_ROW3); + delayUs(1); if(gpio_readPin(LCD_D6)) keys |= KEY_F1; if(gpio_readPin(LCD_D7)) keys |= KEY_MONI; diff --git a/platform/targets/MD-380/hwconfig.h b/platform/targets/MD-380/hwconfig.h index c0052c6b..5e1e8a2a 100644 --- a/platform/targets/MD-380/hwconfig.h +++ b/platform/targets/MD-380/hwconfig.h @@ -69,10 +69,15 @@ /* * Keyboard. Here we define only rows, since coloumn lines are the same as * LCD_Dx. See also: https://www.qsl.net/dl4yhf/RT3/md380_hw.html#keyboard + * + * "Monitor" and "Function" buttons, on the other hand, are connected to + * keyboard row 3 and on LCD_D7 and LCD_D6. See also the schematic. */ #define KB_ROW1 GPIOA,6 /* K1 */ #define KB_ROW2 GPIOD,2 /* K2 */ #define KB_ROW3 GPIOD,3 /* K3 */ +#define MONI_SW LCD_D7 +#define FUNC_SW LCD_D6 /* Tone generator */ #define CTCSS_OUT GPIOC,7 /* System "beep" */ diff --git a/platform/targets/MD-390/hwconfig.h b/platform/targets/MD-390/hwconfig.h index c3b9d19f..bb34e81e 100644 --- a/platform/targets/MD-390/hwconfig.h +++ b/platform/targets/MD-390/hwconfig.h @@ -66,10 +66,15 @@ /* * Keyboard. Here we define only rows, since coloumn lines are the same as * LCD_Dx. See also: https://www.qsl.net/dl4yhf/RT3/md380_hw.html#keyboard + * + * "Monitor" and "Function" buttons, on the other hand, are connected to + * keyboard row 3 and on LCD_D7 and LCD_D6. See also the schematic. */ #define KB_ROW1 GPIOA,6 /* K1 */ #define KB_ROW2 GPIOD,2 /* K2 */ #define KB_ROW3 GPIOD,3 /* K3 */ +#define MONI_SW LCD_D7 +#define FUNC_SW LCD_D6 /* Tone generator */ #define CTCSS_OUT GPIOC,7 /* System "beep" */ diff --git a/platform/targets/MD-UV380/hwconfig.h b/platform/targets/MD-UV380/hwconfig.h index 684464c2..466894e6 100644 --- a/platform/targets/MD-UV380/hwconfig.h +++ b/platform/targets/MD-UV380/hwconfig.h @@ -61,10 +61,16 @@ /* * Keyboard. Here we define only rows, since coloumn lines are the same as * LCD_Dx. See also: https://www.qsl.net/dl4yhf/RT3/md380_hw.html#keyboard + * + * "Monitor" and "Function" buttons, on the other hand, are connected to + * keyboard row 3 and on LCD_D6 and LCD_D7. They are SWAPPED with respect to + * connections made on MD-380. */ #define KB_ROW1 GPIOA,6 /* K1 */ #define KB_ROW2 GPIOD,2 /* K2 */ #define KB_ROW3 GPIOD,3 /* K3 */ +#define MONI_SW LCD_D6 +#define FUNC_SW LCD_D7 /* * To enable pwm for display backlight dimming uncomment this directive.