[Keymap] Drashna split transport improvement (#13905)

* Fix up split stuff

* Fix Split perf issues

* Allow LTO to be disabled

* Fixup WPM and encoders

* Fixup qmk keys per scan

* Add bootloader info

* Change encoder pins

* Fixup corne oled code

* Expand transport sync

* Improve user transport

* Cleanup mouse processing at keymap level

* Improve layer checking for mouse layering
This commit is contained in:
Drashna Jaelre 2021-08-07 21:40:48 -07:00 committed by GitHub
parent 100333818f
commit b9dcd5ac38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 205 additions and 72 deletions

View File

@ -75,7 +75,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define ENCODERS_PAD_A \ #define ENCODERS_PAD_A \
{ D5 } { D5 }
#define ENCODERS_PAD_B \ #define ENCODERS_PAD_B \
{ D6 } { D4 }
#define ENCODER_RESOLUTION 4 #define ENCODER_RESOLUTION 4
/* Set 0 if debouncing isn't needed */ /* Set 0 if debouncing isn't needed */

View File

@ -140,9 +140,9 @@ const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = {
#else #else
bool encoder_update_user(uint8_t index, bool clockwise) { bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) { if (index == 0) {
tap_code_delay(clockwise ? KC_VOLU : KC_VOLD, 5); tap_code_delay(clockwise ? KC_VOLD : KC_VOLU, 5);
} else if (index == 1) { } else if (index == 1) {
tap_code_delay(clockwise ? KC_WH_U : KC_WH_D, 5); tap_code_delay(clockwise ? KC_WH_D : KC_WH_U, 5);
} }
return false; return false;
} }
@ -155,26 +155,29 @@ static uint16_t mouse_debounce_timer = 0;
static uint8_t mouse_keycode_tracker = 0; static uint8_t mouse_keycode_tracker = 0;
bool tap_toggling = false; bool tap_toggling = false;
# ifdef TAPPING_TERM_PER_KEY
# define TAP_CHECK get_tapping_term(KC_BTN1, NULL)
# else
# ifndef TAPPING_TERM
# define TAPPING_TERM 200
# endif
# define TAP_CHECK TAPPING_TERM
# endif
void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) { void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
if ((x || y) && timer_elapsed(mouse_timer) > 125) { if (x != 0 && y != 0) {
mouse_timer = timer_read(); mouse_timer = timer_read();
if (!layer_state_is(_MOUSE) && !(layer_state_is(_GAMEPAD) || layer_state_is(_DIABLO)) && timer_elapsed(mouse_debounce_timer) > 125) { # ifdef OLED_DRIVER_ENABLE
oled_timer = timer_read32();
# endif
if (timer_elapsed(mouse_debounce_timer) > TAP_CHECK) {
mouse_report->x = x;
mouse_report->y = y;
if (!layer_state_is(_MOUSE)) {
layer_on(_MOUSE); layer_on(_MOUSE);
} }
} }
# ifdef TAPPING_TERM_PER_KEY
if (timer_elapsed(mouse_debounce_timer) > get_tapping_term(KC_BTN1, NULL)
# else
if (timer_elapsed(mouse_debounce_timer) > TAPPING_TERM
# endif
|| (layer_state_is(_GAMEPAD) || layer_state_is(_DIABLO))) {
mouse_report->x = x;
mouse_report->y = y;
} }
# ifdef OLED_DRIVER_ENABLE
if (x || y) oled_timer = timer_read32();
# endif
} }
void matrix_scan_keymap(void) { void matrix_scan_keymap(void) {
@ -191,7 +194,6 @@ void matrix_scan_keymap(void) {
bool process_record_keymap(uint16_t keycode, keyrecord_t* record) { bool process_record_keymap(uint16_t keycode, keyrecord_t* record) {
switch (keycode) { switch (keycode) {
case TT(_MOUSE): case TT(_MOUSE):
{
if (record->event.pressed) { if (record->event.pressed) {
mouse_keycode_tracker++; mouse_keycode_tracker++;
} else { } else {
@ -210,7 +212,11 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t* record) {
} }
mouse_timer = timer_read(); mouse_timer = timer_read();
break; break;
case TG(_MOUSE):
if (record->event.pressed) {
tap_toggling ^= 1;
} }
break;
case MO(_MOUSE): case MO(_MOUSE):
case DPI_CONFIG: case DPI_CONFIG:
case KC_MS_UP ... KC_MS_WH_RIGHT: case KC_MS_UP ... KC_MS_WH_RIGHT:
@ -219,6 +225,11 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t* record) {
break; break;
default: default:
if (IS_NOEVENT(record->event)) break; if (IS_NOEVENT(record->event)) break;
if ((keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX) && (((keycode >> 0x8) & 0xF) == _MOUSE)) {
record->event.pressed ? mouse_keycode_tracker++ : mouse_keycode_tracker--;
mouse_timer = timer_read();
break;
}
if (layer_state_is(_MOUSE) && !mouse_keycode_tracker) { if (layer_state_is(_MOUSE) && !mouse_keycode_tracker) {
layer_off(_MOUSE); layer_off(_MOUSE);
} }

View File

@ -10,3 +10,5 @@ WPM_ENABLE = yes
ENCODER_ENABLE = yes ENCODER_ENABLE = yes
ENCODER_MAP_ENABLE = yes ENCODER_MAP_ENABLE = yes
# DEBOUNCE_TYPE = sym_eager_pk # DEBOUNCE_TYPE = sym_eager_pk
LTO_SUPPORTED = no

View File

@ -61,7 +61,7 @@ void keyboard_post_init_kb(void) {
void kb_state_update(void) { void kb_state_update(void) {
# ifdef POINTING_DEVICE_ENABLE # ifdef POINTING_DEVICE_ENABLE
if (is_keyboard_master() && !is_keyboard_left()) { if (is_keyboard_master()) {
static uint16_t cpi = 0; static uint16_t cpi = 0;
if (cpi != kb_state.device_cpi) { if (cpi != kb_state.device_cpi) {
cpi = kb_state.device_cpi; cpi = kb_state.device_cpi;

View File

@ -207,12 +207,11 @@ void master_mouse_send(int8_t x, int8_t y) {
#endif #endif
} }
void trackball_set_cpi(uint16_t cpi) { void trackball_set_cpi(uint16_t cpi) {
if (!is_keyboard_left()) {
pmw_set_cpi(cpi);
} else {
#ifdef SPLIT_TRANSACTION_IDS_KB #ifdef SPLIT_TRANSACTION_IDS_KB
kb_state.device_cpi = cpi; kb_state.device_cpi = cpi;
#endif #endif
if (!is_keyboard_left()) {
pmw_set_cpi(cpi);
} }
} }
#endif #endif

View File

@ -33,3 +33,11 @@
#endif #endif
#define KEYLOGGER_LENGTH 10 #define KEYLOGGER_LENGTH 10
#define QMK_ESC_INPUT D4
#define QMK_ESC_OUTPUT B2
#define BOOTMAGIC_LITE_ROW 0
#define BOOTMAGIC_LITE_COLUMN 7
#define BOOTMAGIC_LITE_ROW_RIGHT 4
#define BOOTMAGIC_LITE_COLUMN_RIGHT 7

View File

@ -37,7 +37,7 @@ enum crkbd_keycodes { RGBRST = NEW_SAFE_RANGE };
KC_ESC, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, KC_MINS, \ KC_ESC, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, KC_MINS, \
ALT_T(KC_TAB), K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, RALT_T(K1B), \ ALT_T(KC_TAB), K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, RALT_T(K1B), \
OS_LSFT, CTL_T(K21), K22, K23, K24, K25, K26, K27, K28, K29, RCTL_T(K2A), OS_RSFT, \ OS_LSFT, CTL_T(K21), K22, K23, K24, K25, K26, K27, K28, K29, RCTL_T(K2A), OS_RSFT, \
RGB_MOD, KC_SPC, BK_LWER, DL_RAIS, KC_ENT, OS_RGUI \ OS_LGUI, KC_SPC, BK_LWER, DL_RAIS, KC_ENT, OS_RGUI \
) )
#define LAYOUT_base_wrapper(...) LAYOUT_split_3x6_3_base(__VA_ARGS__) #define LAYOUT_base_wrapper(...) LAYOUT_split_3x6_3_base(__VA_ARGS__)

View File

@ -31,4 +31,5 @@ ifeq ($(strip $(CTPC)), yes)
WS2812_DRIVER = pwm # won't work without a patch to the ctpc mk file WS2812_DRIVER = pwm # won't work without a patch to the ctpc mk file
SERIAL_DRIVER = usart SERIAL_DRIVER = usart
SWAP_HANDS_ENABLE = yes SWAP_HANDS_ENABLE = yes
WPM_ENABLE = yes
endif endif

View File

@ -23,13 +23,15 @@
#define USB_POLLING_INTERVAL_MS 1 #define USB_POLLING_INTERVAL_MS 1
#if defined(SPLIT_KEYBOARD) #if defined(SPLIT_KEYBOARD)
# define SPLIT_MODS_ENABLE // # define SPLIT_TRANSPORT_MIRROR
# define SPLIT_LAYER_STATE_ENABLE # define SPLIT_LAYER_STATE_ENABLE
# define SPLIT_LED_STATE_ENABLE # define SPLIT_LED_STATE_ENABLE
# define SPLIT_MODS_ENABLE
// # define SPLIT_TRANSPORT_MIRROR # ifdef WPM_ENABLE
# define SERIAL_USE_MULTI_TRANSACTION # define SPLIT_WPM_ENABLE
# define SPLIT_TRANSACTION_IDS_USER RPC_ID_USER_STATE_SYNC # endif
# define SELECT_SOFT_SERIAL_SPEED 1
# define SPLIT_TRANSACTION_IDS_USER RPC_ID_USER_STATE_SYNC, RPC_ID_USER_KEYMAP_SYNC, RPC_ID_USER_CONFIG_SYNC
#endif #endif
#ifdef AUDIO_ENABLE #ifdef AUDIO_ENABLE
@ -165,8 +167,8 @@
#ifdef QMK_KEYS_PER_SCAN #ifdef QMK_KEYS_PER_SCAN
# undef QMK_KEYS_PER_SCAN # undef QMK_KEYS_PER_SCAN
# define QMK_KEYS_PER_SCAN 2 #endif
#endif // !QMK_KEYS_PER_SCAN #define QMK_KEYS_PER_SCAN 4
// this makes it possible to do rolling combos (zx) with keys that // this makes it possible to do rolling combos (zx) with keys that
// convert to other keys on hold (z becomes ctrl when you hold it, // convert to other keys on hold (z becomes ctrl when you hold it,

View File

@ -141,10 +141,8 @@ void render_keylock_status(uint8_t led_usb_state) {
oled_write_P(PSTR(OLED_RENDER_LOCK_CAPS), led_usb_state & (1 << USB_LED_CAPS_LOCK)); oled_write_P(PSTR(OLED_RENDER_LOCK_CAPS), led_usb_state & (1 << USB_LED_CAPS_LOCK));
oled_write_P(PSTR(" "), false); oled_write_P(PSTR(" "), false);
oled_write_P(PSTR(OLED_RENDER_LOCK_SCLK), led_usb_state & (1 << USB_LED_SCROLL_LOCK)); oled_write_P(PSTR(OLED_RENDER_LOCK_SCLK), led_usb_state & (1 << USB_LED_SCROLL_LOCK));
#ifndef OLED_DISPLAY_128X64
oled_advance_page(true);
#endif
} }
void render_matrix_scan_rate(void) { void render_matrix_scan_rate(void) {
#ifdef DEBUG_MATRIX_SCAN_RATE #ifdef DEBUG_MATRIX_SCAN_RATE
char matrix_rate[5]; char matrix_rate[5];
@ -315,12 +313,11 @@ void render_wpm(void) {
} }
#if defined(KEYBOARD_handwired_tractyl_manuform_5x6_right) #if defined(KEYBOARD_handwired_tractyl_manuform_5x6_right)
extern keyboard_config_t keyboard_config;
extern uint16_t dpi_array[];
extern kb_runtime_config_t kb_state;
void render_pointing_dpi_status(void) { void render_pointing_dpi_status(void) {
char dpi_status[6]; char dpi_status[6];
uint16_t n = dpi_array[keyboard_config.dpi_config]; uint16_t n = kb_state.device_cpi;
dpi_status[5] = '\0'; dpi_status[5] = '\0';
dpi_status[4] = '0' + n % 10; dpi_status[4] = '0' + n % 10;
dpi_status[3] = (n /= 10) % 10 ? '0' + (n) % 10 : (n / 10) % 10 ? '0' : ' '; dpi_status[3] = (n /= 10) % 10 ? '0' + (n) % 10 : (n / 10) % 10 ? '0' : ' ';
@ -340,7 +337,9 @@ void render_status_secondary(void) {
render_default_layer_state(); render_default_layer_state();
render_layer_state(); render_layer_state();
render_mod_status(get_mods() | get_oneshot_mods()); render_mod_status(get_mods() | get_oneshot_mods());
#if !defined(OLED_DISPLAY_128X64) && defined(WPM_ENABLE)
render_wpm();
#endif
// render_keylock_status(host_keyboard_leds()); // render_keylock_status(host_keyboard_leds());
} }
@ -349,7 +348,7 @@ void render_status_main(void) {
oled_driver_render_logo(); oled_driver_render_logo();
# ifdef DEBUG_MATRIX_SCAN_RATE # ifdef DEBUG_MATRIX_SCAN_RATE
render_matrix_scan_rate(); render_matrix_scan_rate();
# else # elif defined(WPM_ENABLE)
render_wpm(); render_wpm();
# endif # endif
# if defined(KEYBOARD_handwired_tractyl_manuform_5x6_right) # if defined(KEYBOARD_handwired_tractyl_manuform_5x6_right)

View File

@ -2,7 +2,9 @@ SRC += drashna.c \
process_records.c process_records.c
ifneq ($(PLATFORM),CHIBIOS) ifneq ($(PLATFORM),CHIBIOS)
ifneq ($(strip $(LTO_SUPPORTED)), no)
LTO_ENABLE = yes LTO_ENABLE = yes
endif
endif endif
SPACE_CADET_ENABLE = no SPACE_CADET_ENABLE = no
GRAVE_ESC_ENABLE = no GRAVE_ESC_ENABLE = no

View File

@ -3,31 +3,77 @@
# include "transactions.h" # include "transactions.h"
# include <string.h> # include <string.h>
# ifdef UNICODE_ENABLE
extern unicode_config_t unicode_config;
# endif
# ifdef AUDIO_ENABLE
# include "audio.h"
# endif
# if defined(POINTING_DEVICE_ENABLE) && defined(KEYBOARD_handwired_tractyl_manuform)
extern bool tap_toggling;
# endif
# ifdef SWAP_HANDS_ENABLE
extern bool swap_hands;
# endif
extern userspace_config_t userspace_config;
typedef struct { typedef struct {
bool oled_on; bool oled_on;
uint16_t keymap_config; bool audio_enable;
bool audio_clicky_enable;
bool tap_toggling;
bool unicode_mode;
bool swap_hands;
uint8_t reserved :2;
} user_runtime_config_t; } user_runtime_config_t;
uint16_t transport_keymap_config = 0;
uint32_t transport_userspace_config = 0;
user_runtime_config_t user_state; user_runtime_config_t user_state;
void user_sync(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) { void user_state_sync(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) {
if (initiator2target_buffer_size == sizeof(user_state)) { if (initiator2target_buffer_size == sizeof(user_state)) {
memcpy(&user_state, initiator2target_buffer, initiator2target_buffer_size); memcpy(&user_state, initiator2target_buffer, initiator2target_buffer_size);
} }
} }
void user_keymap_sync(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) {
if (initiator2target_buffer_size == sizeof(transport_keymap_config)) {
memcpy(&transport_keymap_config, initiator2target_buffer, initiator2target_buffer_size);
}
}
void user_config_sync(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) {
if (initiator2target_buffer_size == sizeof(transport_userspace_config)) {
memcpy(&transport_userspace_config, initiator2target_buffer, initiator2target_buffer_size);
}
}
void keyboard_post_init_transport_sync(void) { void keyboard_post_init_transport_sync(void) {
// Register keyboard state sync split transaction // Register keyboard state sync split transaction
transaction_register_rpc(RPC_ID_USER_STATE_SYNC, user_sync); transaction_register_rpc(RPC_ID_USER_STATE_SYNC, user_state_sync);
transaction_register_rpc(RPC_ID_USER_KEYMAP_SYNC, user_keymap_sync);
transaction_register_rpc(RPC_ID_USER_CONFIG_SYNC, user_config_sync);
} }
void user_state_update(void) { void user_transport_update(void) {
if (is_keyboard_master()) { if (is_keyboard_master()) {
# ifdef OLED_DRIVER_ENABLE # ifdef OLED_DRIVER_ENABLE
user_state.oled_on = is_oled_on(); user_state.oled_on = is_oled_on();
# endif # endif
user_state.keymap_config = keymap_config.raw; transport_keymap_config = keymap_config.raw;
transport_userspace_config = userspace_config.raw;
# ifdef AUDIO_ENABLE
user_state.audio_enable = is_audio_on();
user_state.audio_clicky_enable = is_clicky_on();
# endif
# if defined(POINTING_DEVICE_ENABLE) && defined(KEYBOARD_handwired_tractyl_manuform)
user_state.tap_toggling = tap_toggling;
# endif
# ifdef SWAP_HANDS_ENABLE
user_state.swap_hands = swap_hands;
# endif
} else { } else {
# ifdef OLED_DRIVER_ENABLE # ifdef OLED_DRIVER_ENABLE
if (user_state.oled_on) { if (user_state.oled_on) {
@ -36,17 +82,43 @@ void user_state_update(void) {
oled_off(); oled_off();
} }
# endif # endif
if (keymap_config.raw != user_state.keymap_config) { keymap_config.raw = transport_keymap_config;
keymap_config.raw = user_state.keymap_config; userspace_config.raw = transport_userspace_config;
# ifdef UNICODE_ENABLE
unicode_config.input_mode = user_state.unicode_mode;
# endif
# ifdef AUDIO_ENABLE
if (user_state.audio_enable != is_audio_on()) {
if (user_state.audio_enable) {
audio_on();
} else {
audio_off();
} }
} }
if (user_state.audio_clicky_enable != is_clicky_on()) {
if (user_state.audio_clicky_enable) {
clicky_on();
} else {
clicky_off();
}
}
# endif
# if defined(POINTING_DEVICE_ENABLE) && defined(KEYBOARD_handwired_tractyl_manuform)
tap_toggling = user_state.tap_toggling;
# endif
# ifdef SWAP_HANDS_ENABLE
swap_hands = user_state.swap_hands;
# endif
}
} }
void user_state_sync(void) { void user_transport_sync(void) {
if (is_keyboard_master()) { if (is_keyboard_master()) {
// Keep track of the last state, so that we can tell if we need to propagate to slave // Keep track of the last state, so that we can tell if we need to propagate to slave
static user_runtime_config_t last_user_state; static user_runtime_config_t last_user_state;
static uint32_t last_sync; static uint16_t last_keymap = 0;
static uint32_t last_config = 0;
static uint32_t last_sync[3];
bool needs_sync = false; bool needs_sync = false;
// Check if the state values are different // Check if the state values are different
@ -54,16 +126,53 @@ void user_state_sync(void) {
needs_sync = true; needs_sync = true;
memcpy(&last_user_state, &user_state, sizeof(user_state)); memcpy(&last_user_state, &user_state, sizeof(user_state));
} }
// Send to slave every 500ms regardless of state change // Send to slave every 500ms regardless of state change
if (timer_elapsed32(last_sync) > 250) { if (timer_elapsed32(last_sync[0]) > 250) {
needs_sync = true; needs_sync = true;
} }
// Perform the sync if requested // Perform the sync if requested
if (needs_sync) { if (needs_sync) {
if (transaction_rpc_send(RPC_ID_USER_STATE_SYNC, sizeof(user_state), &user_state)) { if (transaction_rpc_send(RPC_ID_USER_STATE_SYNC, sizeof(user_state), &user_state)) {
last_sync = timer_read32(); last_sync[0] = timer_read32();
}
needs_sync = false;
}
// Check if the state values are different
if (memcmp(&transport_keymap_config, &last_keymap, sizeof(transport_keymap_config))) {
needs_sync = true;
memcpy(&last_keymap, &transport_keymap_config, sizeof(transport_keymap_config));
}
// Send to slave every 500ms regardless of state change
if (timer_elapsed32(last_sync[1]) > 250) {
needs_sync = true;
}
// Perform the sync if requested
if (needs_sync) {
if (transaction_rpc_send(RPC_ID_USER_KEYMAP_SYNC, sizeof(transport_keymap_config), &transport_keymap_config)) {
last_sync[1] = timer_read32();
}
needs_sync = false;
}
// Check if the state values are different
if (memcmp(&user_state, &last_config, sizeof(transport_userspace_config))) {
needs_sync = true;
memcpy(&last_config, &user_state, sizeof(transport_userspace_config));
}
// Send to slave every 500ms regardless of state change
if (timer_elapsed32(last_sync[2]) > 250) {
needs_sync = true;
}
// Perform the sync if requested
if (needs_sync) {
if (transaction_rpc_send(RPC_ID_USER_CONFIG_SYNC, sizeof(transport_userspace_config), &transport_userspace_config)) {
last_sync[2] = timer_read32();
} }
} }
} }
@ -71,9 +180,9 @@ void user_state_sync(void) {
void housekeeping_task_user(void) { void housekeeping_task_user(void) {
// Update kb_state so we can send to slave // Update kb_state so we can send to slave
user_state_update(); user_transport_update();
// Data sync from master to slave // Data sync from master to slave
user_state_sync(); user_transport_sync();
} }
#endif #endif