From 986540b4b54971327e717f5c6562a1ae3ad1d014 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Tue, 24 Sep 2019 15:24:12 +0100 Subject: [PATCH] ARM split - Add bootmagic/magic keycodes for setting handedness (#6545) * Add docs on bootmagic/magic keycodes for setting handedness * Clang format fixes * Maintain backwards compatibility * Maintain backwards compatibility --- quantum/quantum.c | 8 +++++++- quantum/quantum_keycodes.h | 2 ++ quantum/split_common/split_util.c | 3 +-- tmk_core/common/bootmagic.c | 8 ++++++++ tmk_core/common/bootmagic.h | 6 ++++++ tmk_core/common/eeconfig.c | 19 +++++++++++++++++-- tmk_core/common/eeconfig.h | 3 +++ 7 files changed, 44 insertions(+), 5 deletions(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index 90df0293b7df..51f095de9983 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -544,7 +544,7 @@ bool process_record_quantum(keyrecord_t *record) { # endif #endif case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_ALT_GUI: - case MAGIC_SWAP_LCTL_LGUI ... MAGIC_TOGGLE_CTL_GUI: + case MAGIC_SWAP_LCTL_LGUI ... MAGIC_EE_HANDS_RIGHT: if (record->event.pressed) { // MAGIC actions (BOOTMAGIC without the boot) if (!eeconfig_is_enabled()) { @@ -662,6 +662,12 @@ bool process_record_quantum(keyrecord_t *record) { case MAGIC_TOGGLE_NKRO: keymap_config.nkro = !keymap_config.nkro; break; + case MAGIC_EE_HANDS_LEFT: + eeconfig_update_handedness(true); + break; + case MAGIC_EE_HANDS_RIGHT: + eeconfig_update_handedness(false); + break; default: break; } diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index f5dca02e6bf2..a06efd58fe14 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -499,6 +499,8 @@ enum quantum_keycodes { MAGIC_SWAP_CTL_GUI, MAGIC_UNSWAP_CTL_GUI, MAGIC_TOGGLE_CTL_GUI, + MAGIC_EE_HANDS_LEFT, + MAGIC_EE_HANDS_RIGHT, // always leave at the end SAFE_RANGE diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c index 5114b188ec6c..d16a989770ad 100644 --- a/quantum/split_common/split_util.c +++ b/quantum/split_common/split_util.c @@ -7,7 +7,6 @@ #include "quantum.h" #ifdef EE_HANDS -# include "tmk_core/common/eeprom.h" # include "eeconfig.h" #endif @@ -23,7 +22,7 @@ __attribute__((weak)) bool is_keyboard_left(void) { setPinInput(SPLIT_HAND_PIN); return readPin(SPLIT_HAND_PIN); #elif defined(EE_HANDS) - return eeprom_read_byte(EECONFIG_HANDEDNESS); + return eeconfig_read_handedness(); #elif defined(MASTER_RIGHT) return !is_keyboard_master(); #endif diff --git a/tmk_core/common/bootmagic.c b/tmk_core/common/bootmagic.c index 09b1664c9048..bb2aa0db8cdd 100644 --- a/tmk_core/common/bootmagic.c +++ b/tmk_core/common/bootmagic.c @@ -122,6 +122,14 @@ void bootmagic(void) { default_layer = eeconfig_read_default_layer(); default_layer_set((layer_state_t)default_layer); } + + /* EE_HANDS handedness */ + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_LEFT)) { + eeconfig_update_handedness(true); + } + if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_RIGHT)) { + eeconfig_update_handedness(false); + } } /** \brief Scan Keycode diff --git a/tmk_core/common/bootmagic.h b/tmk_core/common/bootmagic.h index fb764725798f..c64dc1785844 100644 --- a/tmk_core/common/bootmagic.h +++ b/tmk_core/common/bootmagic.h @@ -36,6 +36,12 @@ #ifndef BOOTMAGIC_KEY_DEBUG_MOUSE # define BOOTMAGIC_KEY_DEBUG_MOUSE KC_M #endif +#ifndef BOOTMAGIC_KEY_EE_HANDS_LEFT +# define BOOTMAGIC_KEY_EE_HANDS_LEFT KC_L +#endif +#ifndef BOOTMAGIC_KEY_EE_HANDS_RIGHT +# define BOOTMAGIC_KEY_EE_HANDS_RIGHT KC_R +#endif /* * keymap config diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c index f33d831f77d1..4369e44ac29c 100644 --- a/tmk_core/common/eeconfig.c +++ b/tmk_core/common/eeconfig.c @@ -163,8 +163,8 @@ uint32_t eeconfig_read_kb(void) { return eeprom_read_dword(EECONFIG_KEYBOARD); } * * FIXME: needs doc */ - void eeconfig_update_kb(uint32_t val) { eeprom_update_dword(EECONFIG_KEYBOARD, val); } + /** \brief eeconfig read user * * FIXME: needs doc @@ -176,9 +176,24 @@ uint32_t eeconfig_read_user(void) { return eeprom_read_dword(EECONFIG_USER); } */ void eeconfig_update_user(uint32_t val) { eeprom_update_dword(EECONFIG_USER, val); } +/** \brief eeconfig read haptic + * + * FIXME: needs doc + */ uint32_t eeconfig_read_haptic(void) { return eeprom_read_dword(EECONFIG_HAPTIC); } -/** \brief eeconfig update user +/** \brief eeconfig update haptic * * FIXME: needs doc */ void eeconfig_update_haptic(uint32_t val) { eeprom_update_dword(EECONFIG_HAPTIC, val); } + +/** \brief eeconfig read split handedness + * + * FIXME: needs doc + */ +bool eeconfig_read_handedness(void) { return !!eeprom_read_byte(EECONFIG_HANDEDNESS); } +/** \brief eeconfig update split handedness + * + * FIXME: needs doc + */ +void eeconfig_update_handedness(bool val) { eeprom_update_byte(EECONFIG_HANDEDNESS, !!val); } diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h index 6db1b0c2205f..a7a78b352e08 100644 --- a/tmk_core/common/eeconfig.h +++ b/tmk_core/common/eeconfig.h @@ -107,4 +107,7 @@ uint32_t eeconfig_read_haptic(void); void eeconfig_update_haptic(uint32_t val); #endif +bool eeconfig_read_handedness(void); +void eeconfig_update_handedness(bool val); + #endif