From 3589bbabc4b58eda09c6b53b60a2e82c52b9b28d Mon Sep 17 00:00:00 2001 From: Pete <41942933+PJ789@users.noreply.github.com> Date: Fri, 10 Dec 2021 15:29:23 +0100 Subject: [PATCH 1/8] Adds support for Danish language MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit KeyboardLayout_da_DK.cpp is Danish keyboard layout Keyboard.h references da_DK.cpp Keyboard_da_DK.h defines scan codes for Danish characters such as ÆØ. --- src/Keyboard.h | 1 + src/KeyboardLayout_da_DK.cpp | 138 +++++++++++++++++++++++++++++++++++ src/Keyboard_da_DK.h | 44 +++++++++++ 3 files changed, 183 insertions(+) create mode 100644 src/KeyboardLayout_da_DK.cpp create mode 100644 src/Keyboard_da_DK.h diff --git a/src/Keyboard.h b/src/Keyboard.h index bede653..9dbb3a9 100644 --- a/src/Keyboard.h +++ b/src/Keyboard.h @@ -117,6 +117,7 @@ extern const uint8_t KeyboardLayout_es_ES[]; extern const uint8_t KeyboardLayout_fr_FR[]; extern const uint8_t KeyboardLayout_it_IT[]; extern const uint8_t KeyboardLayout_sv_SE[]; +extern const uint8_t KeyboardLayout_da_DK[]; // Low level key report: up to 6 keys and shift, ctrl etc at once typedef struct diff --git a/src/KeyboardLayout_da_DK.cpp b/src/KeyboardLayout_da_DK.cpp new file mode 100644 index 0000000..c08ae54 --- /dev/null +++ b/src/KeyboardLayout_da_DK.cpp @@ -0,0 +1,138 @@ +/* + * Danish keyboard layout. + */ + +#include "KeyboardLayout.h" + +extern const uint8_t KeyboardLayout_da_DK[128] PROGMEM = +{ + 0x00, // NUL + 0x00, // SOH + 0x00, // STX + 0x00, // ETX + 0x00, // EOT + 0x00, // ENQ + 0x00, // ACK + 0x00, // BEL + 0x2a, // BS Backspace + 0x2b, // TAB Tab + 0x28, // LF Enter + 0x00, // VT + 0x00, // FF + 0x00, // CR + 0x00, // SO + 0x00, // SI + 0x00, // DEL + 0x00, // DC1 + 0x00, // DC2 + 0x00, // DC3 + 0x00, // DC4 + 0x00, // NAK + 0x00, // SYN + 0x00, // ETB + 0x00, // CAN + 0x00, // EM + 0x00, // SUB + 0x00, // ESC + 0x00, // FS + 0x00, // GS + 0x00, // RS + 0x00, // US + + 0x2c, // ' ' + 0x1e|SHIFT, // ! + 0x1f|SHIFT, // " + 0x20|SHIFT, // # + 0x21|ALT_GR, // $ + 0x22|SHIFT, // % + 0x23|SHIFT, // & + 0x31, // ' + 0x25|SHIFT, // ( + 0x26|SHIFT, // ) + 0x31|SHIFT, // * + 0x2d, // + + 0x36, // , + 0x38, // - + 0x37, // . + 0x24|SHIFT, // / + 0x27, // 0 + 0x1e, // 1 + 0x1f, // 2 + 0x20, // 3 + 0x21, // 4 + 0x22, // 5 + 0x23, // 6 + 0x24, // 7 + 0x25, // 8 + 0x26, // 9 + 0x37|SHIFT, // : + 0x36|SHIFT, // ; + 0x32, // < + 0x27|SHIFT, // = + 0x32|SHIFT, // > + 0x2d|SHIFT, // ? + 0x1f|ALT_GR, // @ + 0x04|SHIFT, // A + 0x05|SHIFT, // B + 0x06|SHIFT, // C + 0x07|SHIFT, // D + 0x08|SHIFT, // E + 0x09|SHIFT, // F + 0x0a|SHIFT, // G + 0x0b|SHIFT, // H + 0x0c|SHIFT, // I + 0x0d|SHIFT, // J + 0x0e|SHIFT, // K + 0x0f|SHIFT, // L + 0x10|SHIFT, // M + 0x11|SHIFT, // N + 0x12|SHIFT, // O + 0x13|SHIFT, // P + 0x14|SHIFT, // Q + 0x15|SHIFT, // R + 0x16|SHIFT, // S + 0x17|SHIFT, // T + 0x18|SHIFT, // U + 0x19|SHIFT, // V + 0x1a|SHIFT, // W + 0x1b|SHIFT, // X + 0x1c|SHIFT, // Y + 0x1d|SHIFT, // Z + 0x25|ALT_GR, // [ + 0x2d|ALT_GR, // bslash + 0x26|ALT_GR, // ] + 0x00, // ^ not supported (requires dead key + space) + 0x38|SHIFT, // _ + 0x00, // ` not supported (requires dead key + space) + 0x04, // a + 0x05, // b + 0x06, // c + 0x07, // d + 0x08, // e + 0x09, // f + 0x0a, // g + 0x0b, // h + 0x0c, // i + 0x0d, // j + 0x0e, // k + 0x0f, // l + 0x10, // m + 0x11, // n + 0x12, // o + 0x13, // p + 0x14, // q + 0x15, // r + 0x16, // s + 0x17, // t + 0x18, // u + 0x19, // v + 0x1a, // w + 0x1b, // x + 0x1c, // y + 0x1d, // z + 0x24|ALT_GR, // { + 0x2e|ALT_GR, // | + 0x27|ALT_GR, // } + 0x00, // ~ not supported (requires dead key + space) + 0x00 // DEL +}; diff --git a/src/Keyboard_da_DK.h b/src/Keyboard_da_DK.h new file mode 100644 index 0000000..d1eba61 --- /dev/null +++ b/src/Keyboard_da_DK.h @@ -0,0 +1,44 @@ +/* + Keyboard_da_DK.h + + Copyright (c) 2021, Peter John + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef KEYBOARD_DA_DK_h +#define KEYBOARD_DA_DK_h + +#include "HID.h" + +#if !defined(_USING_HID) + +#warning "Using legacy HID core (non pluggable)" + +#else + +//================================================================================ +//================================================================================ +// Keyboard + +// DA_DK keys +#define KEY_A_RING (136+0x2f) +#define KEY_SLASHED_O (136+0x34) +#define KEY_ASH (136+0x33) +#define KEY_UMLAUT (136+0x30) +#define KEY_ACUTE_ACC (136+0x2e) + +#endif +#endif From 124a0cbf4ef271b96c4dd673ebf28299862fb0b5 Mon Sep 17 00:00:00 2001 From: Pete <41942933+PJ789@users.noreply.github.com> Date: Sun, 26 Dec 2021 10:05:52 +0100 Subject: [PATCH 2/8] Changes scan code for blash Changed scan code for bslash as suggested by @edgar-bonnet --- src/KeyboardLayout_da_DK.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/KeyboardLayout_da_DK.cpp b/src/KeyboardLayout_da_DK.cpp index c08ae54..b7f9895 100644 --- a/src/KeyboardLayout_da_DK.cpp +++ b/src/KeyboardLayout_da_DK.cpp @@ -99,7 +99,7 @@ extern const uint8_t KeyboardLayout_da_DK[128] PROGMEM = 0x1c|SHIFT, // Y 0x1d|SHIFT, // Z 0x25|ALT_GR, // [ - 0x2d|ALT_GR, // bslash + 0x32|ALT_GR, // bslash 0x26|ALT_GR, // ] 0x00, // ^ not supported (requires dead key + space) 0x38|SHIFT, // _ From e4341097c6ba518048ae119adba453b5857ed4aa Mon Sep 17 00:00:00 2001 From: Pete <41942933+PJ789@users.noreply.github.com> Date: Sun, 26 Dec 2021 17:06:49 +0100 Subject: [PATCH 3/8] Adds support for keyboard LED status --- src/Keyboard.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Keyboard.cpp b/src/Keyboard.cpp index d9fcbad..231c578 100644 --- a/src/Keyboard.cpp +++ b/src/Keyboard.cpp @@ -49,6 +49,16 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = { 0x75, 0x08, // REPORT_SIZE (8) 0x81, 0x03, // INPUT (Cnst,Var,Abs) + 0x95, 0x05, // REPORT_COUNT (5) + 0x75, 0x01, // REPORT_SIZE (1) + 0x05, 0x08, // USAGE_PAGE (LEDs) + 0x19, 0x01, // USAGE_MINIMUM (1) + 0x29, 0x05, // USAGE_MAXIMUM (5) + 0x91, 0x02, // OUTPUT (Data,Var,Abs) // LED report + 0x95, 0x01, // REPORT_COUNT (1) + 0x75, 0x03, // REPORT_SIZE (3) + 0x91, 0x01, // OUTPUT (Constant) // padding + 0x95, 0x06, // REPORT_COUNT (6) 0x75, 0x08, // REPORT_SIZE (8) 0x15, 0x00, // LOGICAL_MINIMUM (0) @@ -209,6 +219,26 @@ size_t Keyboard_::write(const uint8_t *buffer, size_t size) { return n; } +bool Keyboard_::getLedStatus(uint8_t led) +{ + uint8_t _keyboardLedsStatus = HID().getKeyboardLedsStatus(); + if (led == LED_CAPS_LOCK) { + if (_keyboardLedsStatus == 2 || _keyboardLedsStatus == 3 || _keyboardLedsStatus == 6 || _keyboardLedsStatus == 7) { + return true; + } + } else if (led == LED_NUM_LOCK) { + if (_keyboardLedsStatus == 1 || _keyboardLedsStatus == 3 || _keyboardLedsStatus == 5 || _keyboardLedsStatus == 7) { + return true; + } + } else if (led == LED_SCROLL_LOCK) { + if (_keyboardLedsStatus == 4 || _keyboardLedsStatus == 5 || _keyboardLedsStatus == 6 || _keyboardLedsStatus == 7) { + return true; + } + } + return false; +} + + Keyboard_ Keyboard; #endif From 8e2feda9eed7a272c32e11c68975452e2c462a84 Mon Sep 17 00:00:00 2001 From: Pete <41942933+PJ789@users.noreply.github.com> Date: Sun, 26 Dec 2021 17:08:13 +0100 Subject: [PATCH 4/8] Adds support for keyboard LED status --- src/Keyboard.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Keyboard.h b/src/Keyboard.h index 9dbb3a9..e9fec15 100644 --- a/src/Keyboard.h +++ b/src/Keyboard.h @@ -110,6 +110,13 @@ #define KEY_F23 0xFA #define KEY_F24 0xFB +#define KEY_NUM_LOCK 0xDB +#define KEY_SCROLL_LOCK 0xCF + +#define LED_CAPS_LOCK 0x02 +#define LED_NUM_LOCK 0x01 +#define LED_SCROLL_LOCK 0x04 + // Supported keyboard layouts extern const uint8_t KeyboardLayout_de_DE[]; extern const uint8_t KeyboardLayout_en_US[]; @@ -142,6 +149,7 @@ class Keyboard_ : public Print size_t press(uint8_t k); size_t release(uint8_t k); void releaseAll(void); + bool getLedStatus(uint8_t led); }; extern Keyboard_ Keyboard; From ebbc47f355eab51db25c25a233f3efa1555659e8 Mon Sep 17 00:00:00 2001 From: Pete <41942933+PJ789@users.noreply.github.com> Date: Mon, 27 Dec 2021 07:22:32 +0100 Subject: [PATCH 5/8] Code efficiency improvement --- src/Keyboard.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Keyboard.cpp b/src/Keyboard.cpp index 231c578..69d7b81 100644 --- a/src/Keyboard.cpp +++ b/src/Keyboard.cpp @@ -223,15 +223,15 @@ bool Keyboard_::getLedStatus(uint8_t led) { uint8_t _keyboardLedsStatus = HID().getKeyboardLedsStatus(); if (led == LED_CAPS_LOCK) { - if (_keyboardLedsStatus == 2 || _keyboardLedsStatus == 3 || _keyboardLedsStatus == 6 || _keyboardLedsStatus == 7) { + if (_keyboardLedsStatus & 2) { return true; } } else if (led == LED_NUM_LOCK) { - if (_keyboardLedsStatus == 1 || _keyboardLedsStatus == 3 || _keyboardLedsStatus == 5 || _keyboardLedsStatus == 7) { + if (_keyboardLedsStatus & 1) { return true; } } else if (led == LED_SCROLL_LOCK) { - if (_keyboardLedsStatus == 4 || _keyboardLedsStatus == 5 || _keyboardLedsStatus == 6 || _keyboardLedsStatus == 7) { + if (_keyboardLedsStatus & 4) { return true; } } From 073b5c80486fe4cb7fc6a8afce61dbc1d7a938e3 Mon Sep 17 00:00:00 2001 From: Pete <41942933+PJ789@users.noreply.github.com> Date: Mon, 27 Dec 2021 07:35:52 +0100 Subject: [PATCH 6/8] Code style & legibility improvement/rearrangement --- src/Keyboard.cpp | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/Keyboard.cpp b/src/Keyboard.cpp index 69d7b81..ea91cf3 100644 --- a/src/Keyboard.cpp +++ b/src/Keyboard.cpp @@ -222,20 +222,29 @@ size_t Keyboard_::write(const uint8_t *buffer, size_t size) { bool Keyboard_::getLedStatus(uint8_t led) { uint8_t _keyboardLedsStatus = HID().getKeyboardLedsStatus(); - if (led == LED_CAPS_LOCK) { - if (_keyboardLedsStatus & 2) { - return true; - } - } else if (led == LED_NUM_LOCK) { - if (_keyboardLedsStatus & 1) { - return true; - } - } else if (led == LED_SCROLL_LOCK) { - if (_keyboardLedsStatus & 4) { - return true; - } + switch(led) + { + case LED_NUM_LOCK: + if (_keyboardLedsStatus & LED_NUM_LOCK) { + return true; + } + break; + case LED_CAPS_LOCK: + if (_keyboardLedsStatus & LED_CAPS_LOCK) { + return true; + } + break; + case LED_SCROLL_LOCK: + if (_keyboardLedsStatus & LED_SCROLL_LOCK) { + return true; + } + break; + default: + return false; + break; } - return false; + return false; + } From f893a60d8194b89c14156410dd61a357c7aaa159 Mon Sep 17 00:00:00 2001 From: Pete <41942933+PJ789@users.noreply.github.com> Date: Sat, 1 Jan 2022 10:29:41 +0100 Subject: [PATCH 7/8] Enhance the efficiency of led logic handling Co-authored-by: Edgar Bonet --- src/Keyboard.cpp | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/src/Keyboard.cpp b/src/Keyboard.cpp index ea91cf3..c425daa 100644 --- a/src/Keyboard.cpp +++ b/src/Keyboard.cpp @@ -221,30 +221,7 @@ size_t Keyboard_::write(const uint8_t *buffer, size_t size) { bool Keyboard_::getLedStatus(uint8_t led) { - uint8_t _keyboardLedsStatus = HID().getKeyboardLedsStatus(); - switch(led) - { - case LED_NUM_LOCK: - if (_keyboardLedsStatus & LED_NUM_LOCK) { - return true; - } - break; - case LED_CAPS_LOCK: - if (_keyboardLedsStatus & LED_CAPS_LOCK) { - return true; - } - break; - case LED_SCROLL_LOCK: - if (_keyboardLedsStatus & LED_SCROLL_LOCK) { - return true; - } - break; - default: - return false; - break; - } - return false; - + return ((HID().getKeyboardLedsStatus() & led)!=0); } From befd8b51458d015c79e935d3c152e4a1b4f2b875 Mon Sep 17 00:00:00 2001 From: Pete <41942933+PJ789@users.noreply.github.com> Date: Sat, 1 Jan 2022 10:31:37 +0100 Subject: [PATCH 8/8] Update Keyboard.h --- src/Keyboard.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Keyboard.h b/src/Keyboard.h index e9fec15..87b95ad 100644 --- a/src/Keyboard.h +++ b/src/Keyboard.h @@ -110,9 +110,6 @@ #define KEY_F23 0xFA #define KEY_F24 0xFB -#define KEY_NUM_LOCK 0xDB -#define KEY_SCROLL_LOCK 0xCF - #define LED_CAPS_LOCK 0x02 #define LED_NUM_LOCK 0x01 #define LED_SCROLL_LOCK 0x04