Skip to content

Commit

Permalink
Merge pull request #168 from wladimir-computin/master
Browse files Browse the repository at this point in the history
Added generic keyboard layout support
  • Loading branch information
NicoHood authored Apr 16, 2019
2 parents 5c9c6ff + c47bfa9 commit cc946b9
Show file tree
Hide file tree
Showing 7 changed files with 1,178 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/HID-APIs/KeyboardAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ THE SOFTWARE.

#include <Arduino.h>
#include "HID-Settings.h"
#include "ImprovedKeylayouts.h"
#include "../KeyboardLayouts/ImprovedKeylayouts.h"


class KeyboardAPI : public Print
Expand Down
37 changes: 31 additions & 6 deletions src/HID-APIs/KeyboardAPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,39 @@ size_t KeyboardAPI::set(uint8_t k, bool s){
}

// Read key from ascii lookup table
k = pgm_read_byte(_asciimap + k);
auto ret = set(KeyboardKeycode(k & ~SHIFT), s);
uint16_t key = pgm_read_word(_asciimap + k);
auto ret = set(KeyboardKeycode((uint8_t)(key & 0xFF)), s);

// Only add shift if keycode was successfully added before.
// Always try to release shift (if used).
if((k & SHIFT) && (ret || !s)){
ret |= set(KEY_LEFT_SHIFT, s);
// Only add modifier if keycode was successfully added before.
// Always try to release modifier (if used).
if(ret || !s){
if (key & MOD_LEFT_CTRL) {
ret |= set(KEY_LEFT_CTRL, s);
}
if (key & MOD_LEFT_SHIFT) {
ret |= set(KEY_LEFT_SHIFT, s);
}
if (key & MOD_LEFT_ALT) {
ret |= set(KEY_LEFT_ALT, s);
}
if (key & MOD_LEFT_GUI) {
ret |= set(KEY_LEFT_GUI, s);
}
if (key & MOD_RIGHT_CTRL) {
ret |= set(KEY_RIGHT_CTRL, s);
}
if (key & MOD_RIGHT_SHIFT) {
ret |= set(KEY_RIGHT_SHIFT, s);
}
if (key & MOD_RIGHT_ALT) {
ret |= set(KEY_RIGHT_ALT, s);
}
if (key & MOD_RIGHT_GUI) {
ret |= set(KEY_RIGHT_GUI, s);
}
}


return ret;
}

1 change: 0 additions & 1 deletion src/HID-Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,3 @@ THE SOFTWARE.
#include "MultiReport/SurfaceDial.h"

// Include Teensy HID afterwards to overwrite key definitions if used
// TODO include Teensy API if non english keyboard layout was used
6 changes: 3 additions & 3 deletions src/HID-Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ THE SOFTWARE.
// Settings
//================================================================================

//#define LAYOUT_US_ENGLISH
#define LAYOUT_US_ENGLISH
//#define LAYOUT_CANADIAN_FRENCH
//#define LAYOUT_CANADIAN_MULTILINGUAL
//#define LAYOUT_DANISH
//#define LAYOUT_FINNISH
//#define LAYOUT_FRENCH
//#define LAYOUT_FRENCH_BELGIAN
//#define LAYOUT_FRENCH_SWISS
//#define LAYOUT_GERMAN
//define LAYOUT_GERMAN
//#define LAYOUT_GERMAN_MAC
//#define LAYOUT_GERMAN_SWISS
//#define LAYOUT_ICELANDIC
Expand Down Expand Up @@ -171,4 +171,4 @@ int USB_SendControl(uint8_t x, const void* y, uint8_t z);

#error "Unsupported architecture"

#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,59 @@ THE SOFTWARE.
// Include guard
#pragma once

#if !defined(LAYOUT_US_ENGLISH)
#error This API does not support non US english layouts.
// Keyboard Modifiers
enum KeyboardMods : uint16_t {
MOD_LEFT_CTRL = (1 << 8),
MOD_LEFT_SHIFT = (1 << 9),
MOD_LEFT_ALT = (1 << 10),
MOD_LEFT_GUI = (1 << 11),
MOD_RIGHT_CTRL = (1 << 12),
MOD_RIGHT_SHIFT = (1 << 13),
MOD_RIGHT_ALT = (1 << 14),
MOD_RIGHT_GUI = (uint16_t)(1 << 15),
};

// Keyboard Leds
enum KeyboardLeds : uint8_t {
LED_NUM_LOCK = (1 << 0),
LED_CAPS_LOCK = (1 << 1),
LED_SCROLL_LOCK = (1 << 2),
LED_COMPOSE = (1 << 3),
LED_KANA = (1 << 4),
LED_POWER = (1 << 5),
LED_SHIFT = (1 << 6),
LED_DO_NOT_DISTURB = (1 << 7),
};

#if defined(LAYOUT_US_ENGLISH)
#include "ImprovedKeylayoutsUS.h"
#elif defined(LAYOUT_CANADIAN_FRENCH)
#elif defined(LAYOUT_CANADIAN_MULTILINGUAL)
#elif defined(LAYOUT_DANISH)
#elif defined(LAYOUT_FINNISH)
#elif defined(LAYOUT_FRENCH)
#elif defined(LAYOUT_FRENCH_BELGIAN)
#elif defined(LAYOUT_FRENCH_SWISS)
#elif defined(LAYOUT_GERMAN)
#include "ImprovedKeylayoutsDE.h"
#elif defined(LAYOUT_GERMAN_MAC)
#elif defined(LAYOUT_GERMAN_SWISS)
#elif defined(LAYOUT_ICELANDIC)
#elif defined(LAYOUT_IRISH)
#elif defined(LAYOUT_ITALIAN)
#elif defined(LAYOUT_NORWEGIAN)
#elif defined(LAYOUT_PORTUGUESE)
#elif defined(LAYOUT_PORTUGUESE_BRAZILIAN)
#elif defined(LAYOUT_SPANISH)
#elif defined(LAYOUT_SPANISH_LATIN_AMERICA)
#elif defined(LAYOUT_SWEDISH)
#elif defined(LAYOUT_TURKISH)
#elif defined(LAYOUT_UNITED_KINGDOM)
#elif defined(LAYOUT_US_INTERNATIONAL)
#endif

// Hut1_12v2.pdf
/*
enum KeyboardKeycode : uint8_t {
KEY_RESERVED = 0,
KEY_ERROR_ROLLOVER = 1,
Expand Down Expand Up @@ -490,21 +538,10 @@ enum KeyboardKeycode : uint8_t {
HID_KEYBOARD_RIGHT_ALT = 0xE6,
HID_KEYBOARD_RIGHT_GUI = 0xE7,
};
*/

// Keyboard Leds
enum KeyboardLeds : uint8_t {
LED_NUM_LOCK = (1 << 0),
LED_CAPS_LOCK = (1 << 1),
LED_SCROLL_LOCK = (1 << 2),
LED_COMPOSE = (1 << 3),
LED_KANA = (1 << 4),
LED_POWER = (1 << 5),
LED_SHIFT = (1 << 6),
LED_DO_NOT_DISTURB = (1 << 7),
};

#define SHIFT 0x80
static const uint8_t _asciimap[] PROGMEM =
/*
static const uint16_t _asciimap[] PROGMEM =
{
KEY_RESERVED, // NUL
KEY_RESERVED, // SOH
Expand Down Expand Up @@ -636,4 +673,4 @@ static const uint8_t _asciimap[] PROGMEM =
KEY_TILDE|SHIFT, // ~
KEY_RESERVED // DEL
};

*/
Loading

0 comments on commit cc946b9

Please sign in to comment.