From 92a55bc5074450c50df4bcda337f0255c83f200e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 5 Apr 2019 17:14:26 +0200 Subject: [PATCH] [ion] Keyboard: cheat to get user key-pressing on B3 layout as B2 in the keyboard matrix --- ion/include/ion/keyboard.h | 2 +- ion/src/device/n0100/drivers/config/keyboard.h | 4 ++++ ion/src/device/n0101/drivers/config/keyboard.h | 7 +++++++ ion/src/device/shared/drivers/keyboard.cpp | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ion/include/ion/keyboard.h b/ion/include/ion/keyboard.h index 384954d14..0bfa662bd 100644 --- a/ion/include/ion/keyboard.h +++ b/ion/include/ion/keyboard.h @@ -11,7 +11,7 @@ namespace Keyboard { enum class Key : uint8_t { A1=0, A2=1, A3=2, A4=3, A5=4, A6=5, - B1=6, B2=7, /* B3=8, B4=9, B5=10, B6=11, */ + B1=6, B2=7, B3=8, /*B4=9, B5=10, B6=11, */ C1=12, C2=13, C3=14, C4=15, C5=16, C6=17, D1=18, D2=19, D3=20, D4=21, D5=22, D6=23, E1=24, E2=25, E3=26, E4=27, E5=28, E6=29, diff --git a/ion/src/device/n0100/drivers/config/keyboard.h b/ion/src/device/n0100/drivers/config/keyboard.h index 8a4028d14..4c55b8729 100644 --- a/ion/src/device/n0100/drivers/config/keyboard.h +++ b/ion/src/device/n0100/drivers/config/keyboard.h @@ -37,6 +37,10 @@ constexpr GPIO ColumnGPIO = GPIOC; constexpr uint8_t numberOfColumns = 6; constexpr uint8_t ColumnPins[numberOfColumns] = {0, 1, 2, 3, 4, 5}; +inline uint64_t cheat(uint64_t state) { + return state; +} + } } } diff --git a/ion/src/device/n0101/drivers/config/keyboard.h b/ion/src/device/n0101/drivers/config/keyboard.h index 41b57c43f..cf8a23bef 100644 --- a/ion/src/device/n0101/drivers/config/keyboard.h +++ b/ion/src/device/n0101/drivers/config/keyboard.h @@ -2,6 +2,7 @@ #define ION_DEVICE_N0101_CONFIG_KEYBOARD_H #include +#include /* Pin | Role | Mode * -----+-------------------+-------------------- @@ -37,6 +38,12 @@ constexpr GPIO ColumnGPIO = GPIOC; constexpr uint8_t numberOfColumns = 6; constexpr uint8_t ColumnPins[numberOfColumns] = {0, 1, 2, 3, 4, 5}; +/* The key B2 is actually on B3 in hardware on model N0101. To avoid some extra + * work, we switch B2 and B3 bit in the bit array 'state'. */ +inline uint64_t cheat(uint64_t state) { + return state & Ion::Keyboard::State(Ion::Keyboard::Key::B3) ? state | Ion::Keyboard::State(Ion::Keyboard::Key::B2) : state; +} + } } } diff --git a/ion/src/device/shared/drivers/keyboard.cpp b/ion/src/device/shared/drivers/keyboard.cpp index 6e27a8cc8..aa5e3d480 100644 --- a/ion/src/device/shared/drivers/keyboard.cpp +++ b/ion/src/device/shared/drivers/keyboard.cpp @@ -62,6 +62,9 @@ State scan() { state = (state << 6) | (~columns & 0x3F); } + // On model N0101, the B2 key is located on B3. We cheat here to avoid extra re-work. + state = Config::cheat(state); + /* Last but not least, keys number 8, 9, 10, 11, 35, 41, 47 and 53 are not * defined. Therefore we want to make sure those bits are forced to zero in * whatever value we return. */