From 1dc607711ad72d33c6e4d49a6dfef9320d526f6a Mon Sep 17 00:00:00 2001 From: Dane Skalski Date: Thu, 30 Mar 2023 18:28:38 -0700 Subject: [PATCH] Strip sync functionality re @tzarc The sync and QoL enhancements may be better served by core changes --- keyboards/junco/junco.c | 198 --------------- keyboards/junco/junco.h | 51 ---- keyboards/junco/junco_sync.c | 286 ---------------------- keyboards/junco/junco_sync.h | 41 ---- keyboards/junco/keymaps/default/config.h | 10 - keyboards/junco/keymaps/default/readme.md | 2 +- keyboards/junco/keymaps/deluxe/config.h | 16 -- keyboards/junco/keymaps/deluxe/keymap.c | 58 +---- keyboards/junco/keymaps/deluxe/readme.md | 10 +- keyboards/junco/keymaps/deluxe/rules.mk | 2 - keyboards/junco/keymaps/deluxe/via_sync.c | 88 ------- keyboards/junco/keymaps/deluxe/via_sync.h | 37 --- keyboards/junco/keymaps/via/config.h | 12 +- keyboards/junco/post_config.h | 17 -- keyboards/junco/readme.md | 120 --------- keyboards/junco/rev1/rev1.c | 53 +--- keyboards/junco/rules.mk | 2 - 17 files changed, 8 insertions(+), 995 deletions(-) delete mode 100644 keyboards/junco/junco.c delete mode 100644 keyboards/junco/junco.h delete mode 100644 keyboards/junco/junco_sync.c delete mode 100644 keyboards/junco/junco_sync.h delete mode 100644 keyboards/junco/keymaps/deluxe/via_sync.c delete mode 100644 keyboards/junco/keymaps/deluxe/via_sync.h delete mode 100644 keyboards/junco/post_config.h diff --git a/keyboards/junco/junco.c b/keyboards/junco/junco.c deleted file mode 100644 index 91c3ec8695ad..000000000000 --- a/keyboards/junco/junco.c +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright 2022 Dane Skalski (@Daneski13) -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "junco.h" - -// Keyboard level data -kb_config_t kb_config; - -#ifdef JUNCO_SYNC_ENABLE - -/* Whether to sync flags */ -// Whether a reset needs to happen (applies to both sides) -kb_needs_reset_t kb_needs_reset = {.reset = false, .eeprom = false}; -// Whether the sides need to sync -bool kb_needs_sync = false; -// Whether the sides need to sync the RGB -bool kb_needs_rgb_sync = false; - -/* - Enable/Disable Junco Sync status - (will be synced between sides) -*/ -void junco_sync_enable(void) { - if (kb_config.junco_sync_enabled) return; - kb_config.junco_sync_enabled = true; - dprintf("Junco Sync: Enabled\n"); - kb_needs_sync = true; -} -void junco_sync_disable(void) { - if (!kb_config.junco_sync_enabled) return; - kb_config.junco_sync_enabled = false; - dprintf("Junco Sync: Disabled\n"); - kb_needs_sync = true; -} -bool is_junco_sync_enabled(void) { - return kb_config.junco_sync_enabled; -} - -#endif - -// With EE_HANDS, if the user didn't explicitly set the handedness at compile time, -// the handedness is cleared with a normal eeconfig_init. This function gets around -// that. -#ifdef EE_HANDS -void eeconfig_init_persist_handedness(void) { - // Clear EEPROM but persist handedness - bool handedness = eeconfig_read_handedness(); - eeconfig_init(); - eeconfig_update_handedness(handedness); -} -#endif - -// Keyboard level EEPROM init -void eeconfig_init_kb(void) { - /* Reset kb eeprom */ - kb_config.raw = 0; - kb_config.junco_sync_enabled = true; // Enabled by default - eeconfig_update_kb(kb_config.raw); - - // Call the user EEPROM init - eeconfig_init_user(); -} - -// Keyboard level post init -void keyboard_post_init_kb(void) { - // Read the kb config from EEPROM - kb_config.raw = eeconfig_read_kb(); - -#ifdef JUNCO_SYNC_ENABLE - printf("Junco Sync available, status: %s\n", kb_config.junco_sync_enabled ? "enabled" : "disabled"); - - // Register the RPC calls for syncing. Init regardless - // of junco_sync_enabled because if re-enabled, we - // want to be able to sync that state to the slave - // and bring it up-to-date with the master. - junco_sync_init(); -#endif - - // Call the user post init - keyboard_post_init_user(); -} - -// Keyboard level intercept of key processing -bool process_record_kb(uint16_t keycode, keyrecord_t *record) { - // Call the user key processing first - bool user_process = process_record_user(keycode, record); - // If the user processing returns false, return false - if (!user_process) return false; - -#ifdef JUNCO_SYNC_ENABLE - // If Junco sync is disabled, skip - if (!kb_config.junco_sync_enabled) return true; - - /* - Intercept EEPROM related keycodes and reboot, setting - flags that will cause syncing - */ - switch (keycode) { - // Intercept eeprom clear/reboot - case QK_CLEAR_EEPROM: - if (record->event.pressed) { - kb_needs_reset.reset = true; - kb_needs_reset.eeprom = true; - } - return false; - case QK_REBOOT: - if (record->event.pressed) { - kb_needs_reset.reset = true; - kb_needs_reset.eeprom = false; - } - return false; - - // Intercept all Magic keycodes for extension - case CL_SWAP ... EC_TOGG: - // Set kb_needs_sync on key release because the - // keypress down will be processed normally. - // It will update the master's EEPROM for us - // so we can be absolutely sure the master - // is up to date - if (!record->event.pressed) { - kb_needs_sync = true; - } - break; - // Intercept all RGB keycodes for extension - case RGB_TOG ... RGB_MODE_TWINKLE: - // Process RGB sync on key release because - // we want both events to be processed normally. - // Depending on the user's settings, RGB changes - // may only actually happen on key release. - if (!record->event.pressed) { - kb_needs_rgb_sync = true; - } - break; - // Intercept default layer changes - case QK_DEF_LAYER ... QK_DEF_LAYER_MAX: - // Processes sync on key release because the - // keypress should be processed normally - if (!record->event.pressed) { - kb_needs_sync = true; - } - break; - // Default case - default: - break; - } -#endif - - return true; -} - -/* - - Keyboard level housekeeping - - Actually where the syncs get called. Housekeeping is called periodically, - so if a sync fails it will be retried in a timely manner, also acts as - a loop that allows junco_sync_reset to work. - */ -void housekeeping_task_kb(void) { -#ifdef JUNCO_SYNC_ENABLE - // If Junco sync is disabled, skip (assuming we don't need to sync it being disabled) - if (!kb_config.junco_sync_enabled && !kb_needs_sync) return; - - // Will only actually reset when the kb_needs_reset.reset is true - // Top level because needs to be called on both the slave and master - junco_sync_reset(&kb_needs_reset.reset, &kb_needs_reset.eeprom, NULL); - - /* The rest is only for master side */ - if (!is_keyboard_master()) return; - - // Ensure something actually needs to be synced. - if (!kb_needs_sync && !kb_needs_rgb_sync) return; - - // Throttles syncing to the specified speed. - // (Default is sync no faster than once per second) - static uint32_t last_sync = 0; - if (timer_elapsed32(last_sync) < JUNCO_SYNC_THROTTLE) return; - - // Update timer - last_sync = timer_read32(); - - // Check if sync is needed - if (kb_needs_sync) { - // If attempt failed, flag still needs to be true - kb_needs_sync = !junco_sync(); - return; - } - - if (kb_needs_rgb_sync) { -# ifdef RGB_MATRIX_ENABLE - // If attempt failed, flag still needs to be true - kb_needs_rgb_sync = !junco_sync_rgb(); -# else - kb_needs_rgb_sync = false; -# endif - return; - } - -#endif -} diff --git a/keyboards/junco/junco.h b/keyboards/junco/junco.h deleted file mode 100644 index e1e41daa3fdb..000000000000 --- a/keyboards/junco/junco.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2022 Dane Skalski (@Daneski13) -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include "quantum.h" - -typedef union { - uint32_t raw; - struct { - bool junco_sync_enabled; - }; -} kb_config_t; -// Keyboard level data -extern kb_config_t kb_config; - -#ifdef EE_HANDS -// Clear EEPROM but persist handedness -void eeconfig_init_persist_handedness(void); -#endif - -#ifdef JUNCO_SYNC_ENABLE -# include "junco_sync.h" - -/* Whether to sync flags */ -typedef struct { - bool reset; - bool eeprom; - bool previous_failed; -} kb_needs_reset_t; -// Whether a reboot and/or eeprom clear needs to happen (applies to both sides) -extern kb_needs_reset_t kb_needs_reset; -// Whether the sides need to sync -extern bool kb_needs_sync; -// Whether the sides need to sync the RGB -extern bool kb_needs_rgb_sync; - -/* Ability to disable/enable Junco Sync and get status*/ - -// Disables Junco Sync without the need for recompiling the firmware. -// Will sync across both halves. -void junco_sync_disable(void); - -// Enables Junco Sync after it has been disabled by junco_sync_disable. -// Will sync across both halves. -void junco_sync_enable(void); - -// Whether or not Junco Sync is currently enabled. -bool is_junco_sync_enabled(void); - -#endif diff --git a/keyboards/junco/junco_sync.c b/keyboards/junco/junco_sync.c deleted file mode 100644 index 3f746d588ee9..000000000000 --- a/keyboards/junco/junco_sync.c +++ /dev/null @@ -1,286 +0,0 @@ -// Copyright 2022 Dane Skalski (@Daneski13) -// SPDX-License-Identifier: GPL-2.0-or-later - -/* Only relevant if junco sync is enabled */ -#ifdef JUNCO_SYNC_ENABLE -# include "junco_sync.h" -# include "print.h" -# include "transactions.h" -# include "split_util.h" -# include "junco.h" - -/* Sync common keyboard data */ - -// Pointer to the user's user_config.raw. If the user wants to sync their own user config, -// set this to the address of user_config.raw in the keyboard_post_init after reading the -// user_config from eeprom `user_config_raw_ptr = &user_config.raw`. -uint32_t* user_config_raw_ptr = NULL; - -// Data type for sending data to slave -typedef struct { - uint32_t kb_conf; // Current keyboard config - uint32_t default_lay; // Current default layer, SPLIT_LAYER_STATE_ENABLE is not persistent and may not sync in time - uint32_t user_conf; // If the user has a config... - uint16_t keymap_conf; // Current keymap config -} kb_sync_data_t; -// Saves common data on master and sends it to slave -bool junco_sync(void) { - // Count how many times retried - static uint8_t retries = 0; - // Allow max retries - if (retries >= JUNCO_SYNC_RETRIES) { - dprintf("Failure to sync: too many retries\n"); - retries = 0; - return true; - } - - // Ensure a split is actually connected - if (!is_transport_connected()) { - dprintf("Failure to sync: No split detected\n"); - retries++; - return false; - } - - uint8_t layer = get_highest_layer(default_layer_state); - - /* - Save data to eeprom on master - All the update functions will read before writing, so we - don't need to ensure something changed before attempting to - write. - */ - // Save the kb data on master - eeconfig_update_kb(kb_config.raw); - - // Save the default layer - set_single_persistent_default_layer(layer); - - // Save user config on master - uint32_t user_configuration = 0; - if (user_config_raw_ptr) user_configuration = *user_config_raw_ptr; - if (user_configuration != 0) eeconfig_update_user(user_configuration); - - // Save the Magic settings on master - eeconfig_update_keymap(keymap_config.raw); - - // Data to be sent - kb_sync_data_t m2s = { - kb_config.raw, // Send the keyboard config - layer, // Send the default layer - user_configuration, // Send user config - keymap_config.raw // Send the keymap config (Magic) - }; - - // Execute RPC - if (transaction_rpc_send(KB_SYNC, sizeof(m2s), &m2s)) { - dprintf("Split synced!\n"); - retries = 0; - return true; - } else { - dprintf("Failure to sync: RPC failed\n"); - retries++; - return false; - } -} -// Slave handler for KB_SYNC -void kb_sync_slave_handler(uint8_t in_buflen, const void* in_data, uint8_t out_buflen, void* out_data) { - const kb_sync_data_t* m2s = (kb_sync_data_t*)in_data; - - /* Save data to eeprom on slave side */ - // Save the keyboard data on slave - eeconfig_update_kb(m2s->kb_conf); - // Save the default layer - set_single_persistent_default_layer(m2s->default_lay); - // Save the keymap config - if (m2s->keymap_conf != keymap_config.raw) eeconfig_update_keymap(m2s->keymap_conf); - // Save the user config - if (m2s->user_conf != 0) eeconfig_update_user(m2s->user_conf); -} - -/* Reboot/Reset both halves, optionally clear eeprom */ -typedef struct { - bool reset; - bool clear_eeproms; -} kb_sync_reset_flags_t; -// Flags for reset and clear. Will be the same on both the slave and master -kb_sync_reset_flags_t kb_sync_reset_flags = {false, false}; - -// Helper function that will clear EEPROM and reboot -void _junco_reset_helper(void) { - // Clear EEPROM if needed - if (kb_sync_reset_flags.clear_eeproms) { - dprintf("Clearing EEPROM...\n"); -# ifdef EE_HANDS - eeconfig_init_persist_handedness(); -# else - ee_config_disable(); -# endif - } - - // Flags back to false - kb_sync_reset_flags.reset = false; - kb_sync_reset_flags.clear_eeproms = false; - - // Soft reset - dprintf("Rebooting...\n"); - soft_reset_keyboard(); -} -// Reboots the keyboard, optionally clearing EEPROMs -void junco_sync_reset(bool* needs_reset, bool* clear_eeprom, bool* failed) { - // Count how many times retried - static uint8_t retries = 0; - // Allow max retries until just reseting the master - if (retries >= JUNCO_SYNC_RETRIES) { - // Give the user a chance to detect the failure before just resetting the master - if ((failed) && (retries == JUNCO_SYNC_RETRIES)) { - *failed = true; - retries++; - return; - } - - dprintf("Failure to reset both halves: too many retries. Resetting master...\n"); - retries = 0; - // Reset the external booleans - if (needs_reset) *needs_reset = false; - if (clear_eeprom) *clear_eeprom = false; - if (failed) *failed = false; - _junco_reset_helper(); - } - - // Check pointer - if (!needs_reset) { - dprintf("Failure to reset: needs_reset is NULL\n"); - retries = JUNCO_SYNC_RETRIES; - return; - } - - // Ensure reset actually needs to happen (only the master will know this) - if (!*needs_reset && is_keyboard_master()) return; - - /* - The slave will always reach this point, the master will only reach - this point when a reset needs to happen. We can be assured that - the flag struct will match on both halves. If reset is false on - the slave it can return from the function, but the master knows - a reset needs to happen so it sets its flags and tells the slave - to do the same. We do it this way because rebooting directly - within the slave handler will cause the slave to reset before - the master knows what's happening, causing issues. Thus, this - function is always called twice when a reset need to happen, - first time sets the flags on both halves and the second time - actually resets both halves. - */ - - // When the flag is set (will be same on slave & master) - if (kb_sync_reset_flags.reset) { - // Set the external booleans to false, reset is about to happen - if (needs_reset) *needs_reset = false; - if (clear_eeprom) *clear_eeprom = false; - if (failed) *failed = false; - - // Let master finish first - if (!is_keyboard_master()) wait_ms(100); - - retries = 0; - // On both sides, reboot and clear eeproms as needed - _junco_reset_helper(); - } else { - // Only execute the following on master - if (!is_keyboard_master()) return; - - // Ensure split is actually connected - if (!is_transport_connected()) { - dprintf("Failure to reset: no split detected\n"); - retries++; - return; - } - - /* Send reset request to slave */ - kb_sync_reset_flags_t m2s = {true, clear_eeprom ? (*clear_eeprom ? true : false) : false}; - // Execute RPC (sets flags on slave) - if (transaction_rpc_send(KB_SYNC_RESET, sizeof(m2s), &m2s)) { - // Set flags on master - kb_sync_reset_flags = m2s; - } else { - dprintf("Failed to reset, retrying...\n"); - retries++; - } - } -} -// Slave handler for KB_SYNC_RESET -void kb_sync_reset_slave_handler(uint8_t in_buflen, const void* in_data, uint8_t out_buflen, void* out_data) { - const kb_sync_reset_flags_t* m2s = (kb_sync_reset_flags_t*)in_data; - // Set flags on slave - kb_sync_reset_flags = *m2s; -} - -# ifdef RGB_MATRIX_ENABLE -/* Sync RGB settings between halves */ -// Data to receive from slave -typedef struct { - rgb_config_t config; -} kb_sync_rgb_data_t; -bool junco_sync_rgb(void) { - // Count how many times retried - static uint8_t retries = 0; - // Allow max retries - if (retries >= JUNCO_SYNC_RETRIES) { - dprintf("Failure to sync RGB: too many retries\n"); - retries = 0; - return true; - } - - // Ensure split is actually connected - if (!is_transport_connected()) { - dprintf("Failure to sync RGB: no split detected\n"); - retries++; - return false; - } - - // Receive the slave's config - kb_sync_rgb_data_t s2m = {0}; - // Execute RPC - if (transaction_rpc_recv(KB_SYNC_RGB, sizeof(s2m), &s2m)) { - /* Check if the configs match */ - if (memcmp(&s2m.config, &rgb_matrix_config, sizeof(rgb_matrix_config)) != 0) { - retries++; - dprintf("Failure to sync RGB: config mismatch, retrying...\n"); - return false; - } - - // Success, both match - dprintf("Successfully synced RGB\n"); - retries = 0; - return true; - } else { - dprintf("Failure to sync RGB: RPC failed, retrying...\n"); - retries++; - return false; - } -} -// Slave handler for KB_SYNC_RGB -void kb_sync_rgb_slave_handler(uint8_t in_buflen, const void* in_data, uint8_t out_buflen, void* out_data) { - kb_sync_rgb_data_t* s2m = (kb_sync_rgb_data_t*)out_data; - // Update the slave's matrix config in EEPROM. - // The slave and master configs sync on in the core, - // however only the master side is saved to EEPROM. - // Thus we can call update on the slave and both will be - // be synced. The update implementation already ensures - // a write only happens when a change is actually needed. - eeconfig_update_rgb_matrix(); - // Send back to master - s2m->config = rgb_matrix_config; -} - -# endif - -/* Register RPC calls for syncing */ -void junco_sync_init(void) { - transaction_register_rpc(KB_SYNC, kb_sync_slave_handler); - transaction_register_rpc(KB_SYNC_RESET, kb_sync_reset_slave_handler); -# ifdef RGB_MATRIX_ENABLE - transaction_register_rpc(KB_SYNC_RGB, kb_sync_rgb_slave_handler); -# endif -} - -#endif diff --git a/keyboards/junco/junco_sync.h b/keyboards/junco/junco_sync.h deleted file mode 100644 index 2484e34703e6..000000000000 --- a/keyboards/junco/junco_sync.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2022 Dane Skalski (@Daneski13) -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#ifdef JUNCO_SYNC_ENABLE - -// Must be called once before any other sync functions. -// Already always be called within Junco's keyboard_post_init_kb -void junco_sync_init(void); - -// Pointer to the user's user_config.raw. If the user wants to sync their own user config, -// set this to the address of user_config.raw in the keyboard_post_init after reading the -// user_config from eeprom `user_config_raw_ptr = &user_config.raw`. -extern uint32_t* user_config_raw_ptr; - -// Syncs common settings between the halves (default layer, Magic settings, user config), -// call only on master. True on success, false on failure. Allows syncing of a user's -// custom config (pass in the user_config.raw, pass 0 if not). -bool junco_sync(void); - -// Reset/reboot both halves, optionally clearing EEPROM. -// Must be called from both halves (top housekeeping). -// -// needs_reset: is required, will set to false on success. -// -// clear_eeprom: is optional, will be set to false when cleared, -// if NULL or false won't clear EEPROM. -// -// failed: is optional, will be set to true if reseting both halves failed, -// just the master will be reset on the next call -void junco_sync_reset(bool* needs_reset, bool* clear_eeprom, bool* failed); - -# ifdef RGB_MATRIX_ENABLE -// Sync RGB matrix settings between the halves, call only on master. -// Also, ensure reaction on both keypress and key release events. -// Returns true on success, false on failure. -bool junco_sync_rgb(void); -# endif - -#endif diff --git a/keyboards/junco/keymaps/default/config.h b/keyboards/junco/keymaps/default/config.h index f7a85f7a939b..43c47b9122a1 100644 --- a/keyboards/junco/keymaps/default/config.h +++ b/keyboards/junco/keymaps/default/config.h @@ -3,16 +3,6 @@ #pragma once -/* - Junco Sync - - Uncomment to enable a special feature that will sync - data between the halves of the split keyboard. - So no matter which side you plug in, your - default layer, RGB settings, and any changes made - via the Magic keycodes will be the same and saved - after powering off or using a different computer. -*/ -// #define JUNCO_SYNC_ENABLE - /* - Encoder settings - */ #ifdef ENCODER_ENABLE # define ENCODER_RESOLUTION 4 diff --git a/keyboards/junco/keymaps/default/readme.md b/keyboards/junco/keymaps/default/readme.md index 75e6c10f46a0..e37bf97ac7f5 100644 --- a/keyboards/junco/keymaps/default/readme.md +++ b/keyboards/junco/keymaps/default/readme.md @@ -54,4 +54,4 @@ QWERTY is default when flashing your keyboard, but you can change it to Colemak- If you've never heard of it, Colemak is a keyboard layout that was designed to be a more ergonomic, modern, efficient, and comfortable replacement to QWERTY. Colemak was designed to place the most common letters in english on the home row along with many of the most common bigrams together (two letters typed in a row). Colemak-DH is a variant of Colemak that moves D and H to beneath the index fingers rather than the home row since most people find it easier and faster to reach the keys that way rather than the middle of the home row. -![Junco's Colemak-DH Layout](https://i.imgur.com/u5iXszJh.png) +![Junco's Colemak-DH Layout](https://i.imgur.com/8biZfn2h.png) diff --git a/keyboards/junco/keymaps/deluxe/config.h b/keyboards/junco/keymaps/deluxe/config.h index fd47313868d4..bec55fbd4c30 100644 --- a/keyboards/junco/keymaps/deluxe/config.h +++ b/keyboards/junco/keymaps/deluxe/config.h @@ -3,16 +3,6 @@ #pragma once -/* - Junco Sync - - Enables a special feature that will sync - data between the halves of the split keyboard. - So no matter which side you plug in, your - default layer, RGB settings, and any changes made - via the Magic keycodes will be the same and saved - after powering off or using a different computer. -*/ -#define JUNCO_SYNC_ENABLE - /* Indicator LEDs */ // LED index for caps lock key on the extension layer #define CAPS_LOCK_LED_INDEX 25 @@ -25,12 +15,6 @@ // Change this if you want more layers #define DYNAMIC_KEYMAP_LAYER_COUNT 6 -/* Syncing VIA */ -// Time between each packet being sent (100ms), increase if issues -#define VIA_SYNC_THROTTLE 100 -// User level sync ID -#define SPLIT_TRANSACTION_IDS_USER USER_VIA_SYNC - /* - Encoder settings - */ #ifdef ENCODER_ENABLE # define ENCODER_RESOLUTION 4 diff --git a/keyboards/junco/keymaps/deluxe/keymap.c b/keyboards/junco/keymaps/deluxe/keymap.c index 116e28aa13c0..e4dcb97faed2 100644 --- a/keyboards/junco/keymaps/deluxe/keymap.c +++ b/keyboards/junco/keymaps/deluxe/keymap.c @@ -2,7 +2,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include QMK_KEYBOARD_H -#include "via_sync.h" // Layers enum enum junco_layers { _QWERTY, _COLEMAK_DH, _SYMB, _EXT, _ADJUST }; @@ -14,10 +13,6 @@ enum custom_keycodes { KC_OS = MAGIC_TOGGLE_ALT_GUI, // Keycode for swapping the base layer between QWERTY and Colemak-DH KC_TOGGLE_BASE = SAFE_RANGE, - // Keycode for toggling Junco Sync On/Off - KC_JSYNC, - // Keycode for manually syncing VIA data - KC_VIASYNC, // Keycode for redo action (Ctrl + Y on windows, Ctrl + Shift + Z on macOS) KC_REDO, // Keycodes for next/previous word @@ -27,9 +22,6 @@ enum custom_keycodes { KC_ADJST }; -// Whether VIA needs sync -bool needs_via_sync = false; - /* LED indicators */ bool is_caps_lock_enabled(void) { // Caps lock return (host_keyboard_led_state().caps_lock); @@ -165,7 +157,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ├────┼────┼────┼────┼────┼────┤ ├────┼────┼────┼────┼────┼────┤ │SpdU│HueU│SatU│ValU│Rnxt│Stck│ │ │EClr│Rbt │DBUG│BOOT│ │ ├────┼────┼────┼────┼────┼────┤ ├────┼────┼────┼────┼────┼────┤ - │SpdD│HueD│SatD│ValD│Rprv│RTgl│ │ │LOUT│ OS │VSNC│TJSC│ │ + │SpdD│HueD│SatD│ValD│Rprv│RTgl│ │ │LOUT│ OS │ │ │ │ ├────┼────┼────┼────┼────┼────┼────┐ ┌────┼────┼────┼────┼────┼────┼────┤ │ │ │ │ │ │ │RTgl│ │ │ │ │ │ │ │ │ └────┴────┴────┴────┴────┴────┴────┘ └────┴────┴────┴────┴────┴────┴────┘ @@ -176,7 +168,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [_ADJUST] = LAYOUT_split4x6_r1( KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, RGB_SPI, RGB_HUI, RGB_SAI, RGB_VAI, RGB_MOD, KC_ADJST, KC_NO, EE_CLR, QK_RBT, DB_TOGG, QK_BOOT, KC_NO, - RGB_SPD, RGB_HUD, RGB_SAD, RGB_VAD, RGB_RMOD, RGB_TOG, KC_NO, KC_TOGGLE_BASE, KC_OS, KC_VIASYNC, KC_JSYNC, KC_NO, + RGB_SPD, RGB_HUD, RGB_SAD, RGB_VAD, RGB_RMOD, RGB_TOG, KC_NO, KC_TOGGLE_BASE, KC_OS, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, RGB_TOG, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ ) @@ -218,12 +210,6 @@ const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = { #endif -// User level post init -void keyboard_post_init_user(void) { - // Register VIA Sync - via_sync_init(); -} - // Called whenever a layer is changed layer_state_t layer_state_set_user(layer_state_t state) { // Make sure the adjust layer isn't sticky @@ -245,24 +231,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { } else { default_layer_set(1UL << _QWERTY); } - // Junco Sync will automatically save and sync the default layer when we use DF(layer) - // in a keymap, but because we are manually setting the default layer we need - // to tell the keyboard a sync is needed. - kb_needs_sync = true; - } - return false; - - // Toggle Junco Sync On/Off - case KC_JSYNC: - if (record->event.pressed) { - is_junco_sync_enabled() ? junco_sync_disable() : junco_sync_enable(); - } - return false; - - // Manually sync VIA data - case KC_VIASYNC: - if (record->event.pressed) { - needs_via_sync = true; } return false; @@ -359,25 +327,3 @@ bool rgb_matrix_indicators_user(void) { return false; } - -/* - - User level housekeeping - - Actually where the VIA sync get called. Housekeeping is called periodically, - so sync reties will happen automatically and it can be used as a loop - that doesn't block processing key events. -*/ -void housekeeping_task_user(void) { - // See if a VIA sync needs to happen - if (!needs_via_sync) return; - - /* Only for master side */ - if (!is_keyboard_master()) return; - - // Throttle packet sending - static uint32_t last_sync = 0; - if (timer_elapsed32(last_sync) < VIA_SYNC_THROTTLE) return; - last_sync = timer_read32(); - - // Want to stay true when retrying and sending packets - needs_via_sync = !via_sync(); -} diff --git a/keyboards/junco/keymaps/deluxe/readme.md b/keyboards/junco/keymaps/deluxe/readme.md index a097dc4d0a6d..d52d315f7d41 100644 --- a/keyboards/junco/keymaps/deluxe/readme.md +++ b/keyboards/junco/keymaps/deluxe/readme.md @@ -1,10 +1,6 @@ # Deluxe Junco Keymap -This is my personal keymap for Junco at time of writing. It has [VIA](https://www.caniusevia.com/) and [Junco Sync](../../README.md#junco-sync) enabled and departs from the [default layout](../default/README.md) with the encoder mappings and some extra keycodes. - -Also, this keymap implements the ability to sync VIA settings between the keyboard halves (key to trigger on the [adjust layer](#adjust-layer)). It did not make sense to add this feature at the keyboard level within Junco Sync as VIA is not fundamental like the default layer, RGB lighting, and Magic settings. VIA should be relegated to user keymaps. - -This keymap also adds indicators when caps lock and num lock are enabled. When enabled, that key will become a static white (green on the white backlight mode) but only when the layer that respective key is on is active. +This is my personal keymap for Junco at time of writing. It departs from the [default layout](../default/README.md) with the encoder mappings and some extra keycodes. This keymap also adds indicators when caps lock and num lock are enabled. When enabled, that key will become a static white (green on the white backlight mode) but only when the layer that respective key is on is active. I wanted that classic rainbow barf RGB effect for the underglow even if the per-key lighting is something else, so I added 2 custom RGB matrix animations: white per-key lighting with rainbow underglow and pixel rain with rainbow underglow. @@ -42,6 +38,6 @@ Encoders on the right side become undo/redo and scrolling horizontally by word. Pressing "Stick Adj Layer" will "stick" the adjust layer so you can use the rotary encoders for RGB settings rather than holding down both backspace and delete. To go back to the default layer, press that stick key again or press and release either Del or Backspace. When the adjust layer is currently "sticky" the sticky key will become the indicator color mentioned earlier. -"Toggle Base" will toggle between QWERTY and Colemak-DH, toggle OS will toggle between macOS and Windows key-mappings (swapping WIN/Command with Alt/Option by the thumb keys and properly mapping redo/word scrolling), "VIA Sync" will sync the VIA settings between the keyboard halves (there isn't a way to do this automatically), and "Toggle Junco Sync" will disable/enable Junco Sync. +"Toggle Base" will toggle between QWERTY and Colemak-DH and toggle OS will toggle between macOS and Windows key-mappings (swapping WIN/Command with Alt/Option by the thumb keys and properly mapping redo/word scrolling). -![Adjust layer](https://i.imgur.com/fRsdlt3h.png) +![Adjust layer](https://i.imgur.com/71ftNoNh.png) diff --git a/keyboards/junco/keymaps/deluxe/rules.mk b/keyboards/junco/keymaps/deluxe/rules.mk index 832eb9a17c69..b788c6155b42 100644 --- a/keyboards/junco/keymaps/deluxe/rules.mk +++ b/keyboards/junco/keymaps/deluxe/rules.mk @@ -18,5 +18,3 @@ VIA_ENABLE = yes # Custom RGB Matrix Effect RGB_MATRIX_CUSTOM_USER = yes - -SRC += via_sync.c diff --git a/keyboards/junco/keymaps/deluxe/via_sync.c b/keyboards/junco/keymaps/deluxe/via_sync.c deleted file mode 100644 index a1c37cd85059..000000000000 --- a/keyboards/junco/keymaps/deluxe/via_sync.c +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2022 Dane Skalski (@Daneski13) -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "via_sync.h" -#include "transactions.h" -#include "print.h" - -typedef struct { - // The address that was read from - uint32_t addr; - // The 20 bytes of data that was read - uint8_t data[20]; - // How many of those 20 bytes should be updated - uint8_t num_bytes; -} via_sync_packet_t; - -// How many packets we'll be sending in total (+ 1 to always round up) -const uint16_t total_packets = VIA_BLOCK_SIZE / 20 + 1; - -bool via_sync(void) { - /* - The RPC buffer is 32 bytes and changing it caused failures in testing - so we'll send 20 byte packets on each call. The housekeeping task will - act as our loop for sending the next packet / retrying a failed one. - */ - - // What packet we're on - static uint16_t packet_number = 0; - - // Count how many times retried - static uint8_t retries = 0; - // Allow max retries - if (retries >= JUNCO_SYNC_RETRIES) { - dprintf("Failure to sync VIA: too many retries\n"); - packet_number = 0; - retries = 0; - return true; - } - - // First call - if (packet_number == 0) { - dprintf("Attempting to sync VIA's %u bytes of data...\n", VIA_BLOCK_SIZE); - dprintf("This will take about %u seconds\n", total_packets * VIA_SYNC_THROTTLE / 1000); - packet_number = 1; - } - - /* Copy the nth 20 bytes to the packet from EEPROM */ - // The address to read from, start of the VIA block offset to where the last packet left off - uint32_t addr = START_ADDR + ((packet_number - 1) * 20); - // How many bytes to read/update, will be 20 unless we're about to read past the end - // of the VIA block. At which point we'll read the remaining bytes in the block, 1 + the - // difference between the end address and the offset address. - uint8_t num_bytes = ((addr + 20) > END_ADDR) ? (END_ADDR - addr + 1) : 20; - - via_sync_packet_t m2s = {addr, {0}, num_bytes}; - eeprom_read_block(m2s.data, (uint32_t*)addr, num_bytes); - - // Execute the RPC - if (transaction_rpc_send(USER_VIA_SYNC, sizeof(m2s), &m2s)) { - // If we've sent the last packet, return true - if (packet_number == total_packets) { - dprintf("VIA Synced!\n"); - packet_number = 0; - retries = 0; - return true; - } - // Otherwise, increment the packet number and return false - packet_number++; - return false; - } else { - dprintf("Failure to sync VIA, RPC failed, retrying...\n"); - retries++; - return false; - } -} -// Slave handler for USER_VIA_SYNC -void via_sync_slave_handler(uint8_t in_buflen, const void* in_data, uint8_t out_buflen, void* out_data) { - const via_sync_packet_t* m2s = (const via_sync_packet_t*)in_data; - // The address to write to - const uint32_t addr = m2s->addr; - // Update the EEPROM with the data - eeprom_update_block(m2s->data, (uint32_t*)addr, m2s->num_bytes); -} - -void via_sync_init(void) { - // Register the VIA RPC - transaction_register_rpc(USER_VIA_SYNC, via_sync_slave_handler); -} diff --git a/keyboards/junco/keymaps/deluxe/via_sync.h b/keyboards/junco/keymaps/deluxe/via_sync.h deleted file mode 100644 index e3b00028038a..000000000000 --- a/keyboards/junco/keymaps/deluxe/via_sync.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2022 Dane Skalski (@Daneski13) -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once -#include "eeprom.h" - -/* Manually Sync VIA Data */ -// Size of keymaps in EEPROM -#define KEYMAPS_SIZE (DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2) -// Size of encoders in EEPROM -#define ENCODER_SIZE (DYNAMIC_KEYMAP_LAYER_COUNT * NUM_ENCODERS * 2 * 2) -// Starting address of VIA's non-core data -#define START_ADDR VIA_EEPROM_LAYOUT_OPTIONS_ADDR -// DYNAMIC_KEYMAP_EEPROM_MAX_ADDR is the maximum address that VIA will use for its data, -// including macros. This end address minus the start address + 1 is how large the VIA -// data block will be. I'm roughly copying how this address is calculated by default by -// taking the starting address, adding the custom config size, adding the keymaps size (including -// encoders), and the rest for macros. VIA says up to 1 Kilobyte is usable for macros (despite -// it delegating the entire rest of EEPROM to them). Personally I don't use them so I'm setting -// it to 1/3 of that Kilobyte just in case I choose to in the future. Lower numbers will -// speed up the syncing process. If you have no need for macros, you can set it to 0. Syncing VIA -// takes about 5 seconds at the default speed of 10 packets per second with my settings. -#define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR (START_ADDR + VIA_EEPROM_CUSTOM_CONFIG_SIZE + KEYMAPS_SIZE + ENCODER_SIZE + 333) -// Ending address of all VIA data (macros included) -#define END_ADDR DYNAMIC_KEYMAP_EEPROM_MAX_ADDR -// How big the VIA data block is -#define VIA_BLOCK_SIZE (END_ADDR - START_ADDR + 1) - -// Call within keyboard_post_init_user to initialize the VIA sync RPC -void via_sync_init(void); - -// Syncs VIA's data from the master to the slave. -// True when finished, false when still needs to -// send packets and/or retry. -// Call within housekeeping_task_user on the master -// only. VIA sync sends the data in packets of 20 bytes. -bool via_sync(void); diff --git a/keyboards/junco/keymaps/via/config.h b/keyboards/junco/keymaps/via/config.h index 85e22a687dbc..c4ce821594d5 100644 --- a/keyboards/junco/keymaps/via/config.h +++ b/keyboards/junco/keymaps/via/config.h @@ -3,16 +3,6 @@ #pragma once -/* - Junco Sync - - Uncomment to enable a special feature that will sync - data between the halves of the split keyboard. - So no matter which side you plug in, your - default layer, RGB settings, and any changes made - via the Magic keycodes will be the same and saved - after powering off or using a different computer. -*/ -// #define JUNCO_SYNC_ENABLE - // Number of Layers that can be used by VIA. // Change this if you want more layers #define DYNAMIC_KEYMAP_LAYER_COUNT 6 @@ -28,7 +18,7 @@ /* - RGB - - Defines all effects so VIA can properly select them + Defines all effects so VIA can properly select them via index */ #ifdef RGB_MATRIX_ENABLE diff --git a/keyboards/junco/post_config.h b/keyboards/junco/post_config.h deleted file mode 100644 index 4f19a6243a8b..000000000000 --- a/keyboards/junco/post_config.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2022 Dane Skalski (@Daneski13) -// SPDX-License-Identifier: GPL-2.0-or-later - -#ifdef JUNCO_SYNC_ENABLE -// Keyboard-level data sync ids -# define SPLIT_TRANSACTION_IDS_KB KB_SYNC, KB_SYNC_RESET, KB_SYNC_RGB - -// By default will throttle syncs to a maximum of 1 per second -# ifndef JUNCO_SYNC_THROTTLE -# define JUNCO_SYNC_THROTTLE 1000 -# endif -// By default, syncs will be tried 10 times before giving up -# ifndef JUNCO_SYNC_RETRIES -# define JUNCO_SYNC_RETRIES 10 -# endif - -#endif diff --git a/keyboards/junco/readme.md b/keyboards/junco/readme.md index 0faa949b8e6f..b5817ff7e760 100644 --- a/keyboards/junco/readme.md +++ b/keyboards/junco/readme.md @@ -30,8 +30,6 @@ qmk flash -kb junco --keymap default -bl uf2-split-right See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). -Does one side of your keyboard think it's the other side? Holding down the `1` key on the left side of your keyboard while plugging it in will tell the left side it's the left side. Holding down the `9` key on the right side of your keyboard while plugging it in will tell the right side it's the right side. - ## Bootloader Enter the bootloader in 3 ways: @@ -41,121 +39,3 @@ Enter the bootloader in 3 ways: - **Keycode in layout**: In the default layout, the `Bootloader` keycode is above home row pinky on the right side's adjust layer. Once you enter the bootloader, the keyboard will show up as a USB device on your computer, you could drag and drop a firmware file to flash it, but I recommend using the flash commands for the respective side. - -## Junco Sync - -Junco has a special feature called Junco Sync that will automatically save and sync certain data between the halves of the split. This means that no matter which side you plug in, whenever you change your default layer in a keymap with `DF(layer)`, change your RGB settings with `RGB_***` keycodes, or use one of the `MAGIC_***` keycodes, the data will be saved to EEPROM and synced to the other half of the keyboard. If you choose to plug the other half into a computer, your settings will be the same. - -Also, if you ever clear the EEPROM with `EE_CLR` or reboot with `QK_RBT` on one half, the other half will automatically do the same. - -To enable Junco Sync in your firmware, uncomment `#define JUNCO_SYNC_ENABLE` in your `config.h` so it looks like this: - -```c -/* - Junco Sync - - Enables a special feature that will sync - data between the halves of the split keyboard. - So no matter which side you plug in, your - default layer, RGB settings, and any changes made - via the Magic keycodes will be the same. -*/ -#define JUNCO_SYNC_ENABLE - -// ... Rest of config.h ... -``` - -Junco Sync will do its thing by default, but you can disable it at any time without having to re-compile your firmware. `junco_sync_disable()` will disable syncing and `junco_sync_enable()` will re-enable syncing (these settings will sync and persist between sides). Clearing EEPROM will re-enable Junco Sync since it's enabled by default. `is_junco_sync_enabled()` will tell you whether or not Junco Sync is enabled. - -### Junco Sync - Advanced - -- [Settings](#settings) -- [Syncing User Data](#syncing-user-data) -- [Manually Trigger a Sync](#manually-trigger-a-sync) -- [Extras](#extras) - -#### Settings - -There is a couple of settings for Junco Sync that you can define in your `config.h`. They are: - -- The time between syncs. This is to prevent syncs from happening back to back and/or retries happening too quickly, reducing keyboard responsiveness. The default by not defining anything is 1 second, but you can change it by defining `JUNCO_SYNC_THROTTLE` in your `config.h`. -- The number of retries a sync will attempt before giving up. The default is 10, but you can change it by defining `JUNCO_SYNC_RETRIES` in your `config.h`. - -```c - #define JUNCO_SYNC_THROTTLE 1000 // Throttle to 1 second (already default) - #define JUNCO_SYNC_RETRIES 10 // Allow up to 10 retries (already default) -``` - -Both of these settings have very sane defaults so there is not really a benefit to defining them. Syncs shouldn't decrease responsiveness at all during normal keyboard use since. They are only triggered after pressing keys that have an effect on EEPROM, which shouldn't happen during normal typing or gaming. - -If for some reason you're having issues with syncs not working, you can try increasing the number of retries, but you should probably check if your TRRS cable or TRRS jack soldering job is the problem. - -#### Syncing User Data - -You can sync your own "user level" data between the halves, see [QMK's documentation](https://docs.qmk.fm/#/feature_eeprom) on the subject. To enable syncing of user data between the halves, set `user_config_raw_ptr` to your config's `raw` value in the `keyboard_post_init_user` after reading the config from EEPROM. For example: - -```c -void keyboard_post_init_user(void) { - // Read your config from EEPROM - user_config.raw = eeconfig_read_user(); - // Set the pointer to your config's raw value - user_config_raw_ptr = &user_config.raw; - - /* ... do stuff ... */ -} -``` - -To sync your user data between the halves you can do: - -```c -// Update your config -user_config.my_setting = 123; -// Trigger sync -kb_needs_sync = true; -``` - -The sync will save your config to both side's EEPROM so you so don't have to call `eeconfig_update_user(user_config.raw)` yourself. - -For more info, see the next section about manually triggering a sync. - -#### Manually Trigger a Sync - -You can trigger sync updates manually by setting a flag in your `keymap.c`. You would want to do this if you are updating the default layer, magic settings, RGB, or rebooting / clearing EEPROM within `process_record_user`. - -With Junco Sync... - -- Magic settigs (`keymap_config`) will only be synced if a `MAGIC_***` keycode is pressed and not overridden by the user. -- Default layer will only become persistent and sync if a `DF(layer)` keycode is pressed. -- RGB will only be synced if a `RGB_***` keycode is pressed and not overridden by the user. -- Synced reboot and clear eeprom only happens when `QK_RBT` or `EE_CLR` is pressed and not overridden by the user. -- Custom user data between the halves won't be synced automatically, it won't know whenuser data needs to be synced. - -Triggering a sync is as simple as setting the respective flag to true. For example: - -*Don't worry if your IDE complains about any values being undefined, they will be defined if you have `#defne JUNCO_SYNC_ENABLE` in your config.h and your firmware should still compile.* - -```c -/* Trigger a sync */ -// Syncs keymap_config ("Magic" settings), -// keyboard level config, default layer, and -// user level config (if you have set user_config_raw_ptr) -kb_needs_sync = true; - -// Trigger a RGB sync -kb_needs_rgb_sync = true; - -// Trigger a reboot and optionally an EEPROM clear -// .reset needs to be true even when you want to -// just clear EEPROM -kb_needs_reset = { - .reset = true, // True will trigger a reboot - .eeprom = true // True will clear EEPROM before rebooting -}; -``` - -Once you have set a flag, the keyboard will carry out the action on it's own and set the flag back to false when it's complete. No need to worry about clearing the flags yourself. - -If for some reason your sync isn't working, try setting the flag on the key's release instead of press. - -#### Extras - -- You can directly call Junco Sync functions by including the `junco_sync.h` header file in your `keymap.c`. - - Even after calling `junco_sync_disable()`, you can still manually sync data between the halves by calling Junco Sync functions directly within your `housekeeping_task_user`. `junco.c` can give you some ideas on how to do this. diff --git a/keyboards/junco/rev1/rev1.c b/keyboards/junco/rev1/rev1.c index 7facd4af8dc6..d1346b82e215 100644 --- a/keyboards/junco/rev1/rev1.c +++ b/keyboards/junco/rev1/rev1.c @@ -1,58 +1,7 @@ // Copyright 2022 Dane Skalski (@Daneski13) // SPDX-License-Identifier: GPL-2.0-or-later -#include "junco.h" - -// New default bootmagic lite, adds ability to manually set the handedness -// and won't clear it. Mostly copied from the Core bootmagic_lite. -__attribute__((weak)) void bootmagic_lite(void) { - // Multiple scans because debouncing can't be turned off. - matrix_scan(); -#if defined(DEBOUNCE) && DEBOUNCE > 0 - wait_ms(DEBOUNCE * 2); -#else - wait_ms(30); -#endif - matrix_scan(); - - uint8_t row = BOOTMAGIC_LITE_ROW; - uint8_t col = BOOTMAGIC_LITE_COLUMN; - -#if defined(BOOTMAGIC_LITE_ROW_RIGHT) && defined(BOOTMAGIC_LITE_COLUMN_RIGHT) - if (!is_keyboard_left()) { - row = BOOTMAGIC_LITE_ROW_RIGHT; - col = BOOTMAGIC_LITE_COLUMN_RIGHT; - } -#endif - - if (is_keyboard_master()) { - // If key next to bootmagic is pressed - if (matrix_get_row(row) & (1 << (col + 1))) { - // Set left side - eeconfig_update_handedness(true); - soft_reset_keyboard(); - } - - // If key 2 over from bootmagic is pressed - if (matrix_get_row(row) & (1 << (col + 2))) { - // Set right side - eeconfig_update_handedness(false); - soft_reset_keyboard(); - } - } - - // Normal bootmagic - if (matrix_get_row(row) & (1 << col)) { - // Clear EEPROM -#ifdef EE_HANDS - eeconfig_init_persist_handedness(); -#else - eeconfig_disable(); -#endif - // Jump to bootloader. - bootloader_jump(); - } -} +#include "quantum.h" // Hand swap #ifdef SWAP_HANDS_ENABLE diff --git a/keyboards/junco/rules.mk b/keyboards/junco/rules.mk index 9ab3bb2eb629..a04c7822f91e 100644 --- a/keyboards/junco/rules.mk +++ b/keyboards/junco/rules.mk @@ -7,5 +7,3 @@ BOOTMAGIC_ENABLE = yes # Default Folder DEFAULT_FOLDER = junco/rev1 - -SRC += junco_sync.c