From afb6a05dbe4a61bb5e64f5e104e1efd1e71e749d Mon Sep 17 00:00:00 2001 From: minisbett <39670899+minisbett@users.noreply.github.com> Date: Thu, 6 Jun 2024 11:35:20 +0200 Subject: [PATCH 1/4] Fix incorrect DIGITAL_PIN macro comment --- include/definitions.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/definitions.hpp b/include/definitions.hpp index 304e12d..6c23269 100644 --- a/include/definitions.hpp +++ b/include/definitions.hpp @@ -82,8 +82,9 @@ // NOTE: By the RP2040, the amount of analog pins (and therefore keys) is limited o 4. #define HE_PIN(index) A0 + HE_KEYS - index - 1 -// Macro for getting the pin of the specified index of the digital key. The pin order is not swapped here, meaning -// the first digital key is on pin 0, the second on 1, and so on. +// Macro for getting the pin of the specified index of the digital key. The pin order is swapped here, meaning +// the first digital key is on DIGITAL_KEYS - 1, the second on DIGITAL_KEYS - 2, and so on. +// For 3 digital keys, this would mean that the keys 1, 2 and 3 are bound to the pins 2, 1 and 0 respectively. // NOTE: This way, the amount of keys is limited to 26 since the 27th key overlaps with the first analog port, 26. #define DIGITAL_PIN(index) 0 + DIGITAL_KEYS - index - 1 From 24daaf0337684fbcf5e3720c382b422836b2d368 Mon Sep 17 00:00:00 2001 From: minisbett <39670899+minisbett@users.noreply.github.com> Date: Thu, 6 Jun 2024 11:36:12 +0200 Subject: [PATCH 2/4] set pin mode for digital keys to INPUT_PULLUP --- src/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index e7908e5..c075c52 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,6 +20,10 @@ void setup() // Set the amount of bits for the ADC to the defined one for a better resolution on the analog readings. analogReadResolution(ANALOG_RESOLUTION); + // Set the pinmode for all pins with digital buttons connected to PULLUP, as that's the standard for working with digital buttons. + for(int i = 0; i < DIGITAL_KEYS; i++) + pinMode(DIGITAL_PIN(i), INPUT_PULLUP); + // Allows to boot into UF2 bootloader mode by pressing the reset button twice. rp2040.enableDoubleResetBootloader(); } From 946b3a13d2778d60cab0d0ee29185117b03439f7 Mon Sep 17 00:00:00 2001 From: minisbett <39670899+minisbett@users.noreply.github.com> Date: Thu, 6 Jun 2024 11:38:06 +0200 Subject: [PATCH 3/4] change digital keys to consider LOW as pressed instead of HIGH --- include/handlers/keys/digital_key.hpp | 4 ++-- src/handlers/key_handler.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/handlers/keys/digital_key.hpp b/include/handlers/keys/digital_key.hpp index f0de265..ffec67d 100644 --- a/include/handlers/keys/digital_key.hpp +++ b/include/handlers/keys/digital_key.hpp @@ -21,6 +21,6 @@ struct DigitalKey : Key // The last time a key press on the digital key was sent, in milliseconds since firmware bootup. unsigned long lastDebounce = 0; - // Bool whether the pin status on the key is currently HIGH. - bool isHigh; + // Bool whether the key is currently considered pressed, ignoring any debouncing and only considering the current digital signal. + bool pressed; }; diff --git a/src/handlers/key_handler.cpp b/src/handlers/key_handler.cpp index 9f072fb..57059e6 100644 --- a/src/handlers/key_handler.cpp +++ b/src/handlers/key_handler.cpp @@ -148,8 +148,8 @@ void KeyHandler::scanHEKey(HEKey &key) void KeyHandler::scanDigitalKey(DigitalKey &key) { - // Read the digital key and save the pin status in the key. - key.isHigh = digitalRead(DIGITAL_PIN(key.index)) == PinStatus::HIGH; + // Read the digital key and consider it pressed if the pin status is LOW (because of PULLUP). + key.pressed = digitalRead(DIGITAL_PIN(key.index)) == PinStatus::LOW; } void KeyHandler::checkHEKey(HEKey &key) @@ -207,15 +207,15 @@ void KeyHandler::checkHEKey(HEKey &key) void KeyHandler::checkDigitalKey(DigitalKey &key) { - // Check whether the pin status on the key is HIGH and the key is fully debounced. - if (key.isHigh && millis() - key.lastDebounce >= DIGITAL_DEBOUNCE_DELAY) + // Check whether the key is pressed and debounced. + if (key.pressed && millis() - key.lastDebounce >= DIGITAL_DEBOUNCE_DELAY) { // Set the key to pressed and update the last debounce time. setPressedState(key, true); key.lastDebounce = millis(); } // If the key is not pressed, just set it to unpressed. - else if (!key.isHigh) + else if (!key.pressed) setPressedState(key, false); } From 17075b044e3b2a71193b3a6ee31a73875eccb068 Mon Sep 17 00:00:00 2001 From: minisbett <39670899+minisbett@users.noreply.github.com> Date: Thu, 6 Jun 2024 11:52:10 +0200 Subject: [PATCH 4/4] bump firmware version --- include/definitions.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/definitions.hpp b/include/definitions.hpp index 6c23269..6455229 100644 --- a/include/definitions.hpp +++ b/include/definitions.hpp @@ -1,7 +1,7 @@ #pragma once // The version of this firmware in the YYYY.MDD.PATCH format. (e.g. 2022.1219.2 for the 2nd release on the 19th december 2022) -#define FIRMWARE_VERSION "2024.309.1" +#define FIRMWARE_VERSION "2024.606.1" // ┌───────────────────────────────────────────────────────────────────────────────────────────────────┐ // │ │