Skip to content

Commit

Permalink
[Keymap] Drashna split transport improvement (qmk#13905)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
drashna authored and nhongooi committed Dec 5, 2021
1 parent 853e038 commit 9ad2b9d
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 71 deletions.
2 changes: 1 addition & 1 deletion keyboards/handwired/tractyl_manuform/5x6_right/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define ENCODERS_PAD_A \
{ D5 }
#define ENCODERS_PAD_B \
{ D6 }
{ D4 }
#define ENCODER_RESOLUTION 4

/* Set 0 if debouncing isn't needed */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = {
#else
bool encoder_update_user(uint8_t index, bool clockwise) {
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) {
tap_code_delay(clockwise ? KC_WH_U : KC_WH_D, 5);
tap_code_delay(clockwise ? KC_WH_D : KC_WH_U, 5);
}
return false;
}
Expand All @@ -155,26 +155,29 @@ static uint16_t mouse_debounce_timer = 0;
static uint8_t mouse_keycode_tracker = 0;
bool tap_toggling = false;

void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
if ((x || y) && timer_elapsed(mouse_timer) > 125) {
mouse_timer = timer_read();
if (!layer_state_is(_MOUSE) && !(layer_state_is(_GAMEPAD) || layer_state_is(_DIABLO)) && timer_elapsed(mouse_debounce_timer) > 125) {
layer_on(_MOUSE);
}
}

# ifdef TAPPING_TERM_PER_KEY
if (timer_elapsed(mouse_debounce_timer) > get_tapping_term(KC_BTN1, NULL)
# define TAP_CHECK get_tapping_term(KC_BTN1, NULL)
# else
if (timer_elapsed(mouse_debounce_timer) > TAPPING_TERM
# ifndef TAPPING_TERM
# define TAPPING_TERM 200
# endif
# define TAP_CHECK TAPPING_TERM
# endif
|| (layer_state_is(_GAMEPAD) || layer_state_is(_DIABLO))) {
mouse_report->x = x;
mouse_report->y = y;
}

void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
if (x != 0 && y != 0) {
mouse_timer = timer_read();
# ifdef OLED_DRIVER_ENABLE
if (x || y) oled_timer = timer_read32();
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);
}
}
}
}

void matrix_scan_keymap(void) {
Expand All @@ -191,26 +194,29 @@ void matrix_scan_keymap(void) {
bool process_record_keymap(uint16_t keycode, keyrecord_t* record) {
switch (keycode) {
case TT(_MOUSE):
{
if (record->event.pressed) {
mouse_keycode_tracker++;
} else {
if (record->event.pressed) {
mouse_keycode_tracker++;
} else {
# if TAPPING_TOGGLE != 0
if (record->tap.count == TAPPING_TOGGLE) {
tap_toggling ^= 1;
if (record->tap.count == TAPPING_TOGGLE) {
tap_toggling ^= 1;
# if TAPPING_TOGGLE == 1
if (!tap_toggling) mouse_keycode_tracker -= record->tap.count + 1;
if (!tap_toggling) mouse_keycode_tracker -= record->tap.count + 1;
# else
if (!tap_toggling) mouse_keycode_tracker -= record->tap.count;
if (!tap_toggling) mouse_keycode_tracker -= record->tap.count;
# endif
} else {
mouse_keycode_tracker--;
}
# endif
} else {
mouse_keycode_tracker--;
}
mouse_timer = timer_read();
break;
# endif
}
mouse_timer = timer_read();
break;
case TG(_MOUSE):
if (record->event.pressed) {
tap_toggling ^= 1;
}
break;
case MO(_MOUSE):
case DPI_CONFIG:
case KC_MS_UP ... KC_MS_WH_RIGHT:
Expand All @@ -219,6 +225,11 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t* record) {
break;
default:
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) {
layer_off(_MOUSE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ WPM_ENABLE = yes
ENCODER_ENABLE = yes
ENCODER_MAP_ENABLE = yes
# DEBOUNCE_TYPE = sym_eager_pk

LTO_SUPPORTED = no
2 changes: 1 addition & 1 deletion keyboards/handwired/tractyl_manuform/tm_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void keyboard_post_init_kb(void) {

void kb_state_update(void) {
# ifdef POINTING_DEVICE_ENABLE
if (is_keyboard_master() && !is_keyboard_left()) {
if (is_keyboard_master()) {
static uint16_t cpi = 0;
if (cpi != kb_state.device_cpi) {
cpi = kb_state.device_cpi;
Expand Down
5 changes: 2 additions & 3 deletions keyboards/handwired/tractyl_manuform/tractyl_manuform.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,11 @@ void master_mouse_send(int8_t x, int8_t y) {
#endif
}
void trackball_set_cpi(uint16_t cpi) {
if (!is_keyboard_left()) {
pmw_set_cpi(cpi);
} else {
#ifdef SPLIT_TRANSACTION_IDS_KB
kb_state.device_cpi = cpi;
#endif
if (!is_keyboard_left()) {
pmw_set_cpi(cpi);
}
}
#endif
16 changes: 12 additions & 4 deletions keyboards/splitkb/kyria/keymaps/drashna/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@
#ifdef RGBLIGHT_ENABLE
# define RGBLIGHT_SLEEP
# define RGBLIGHT_LIMIT_VAL 200
# define RGBLIGHT_HUE_STEP 8
# define RGBLIGHT_SAT_STEP 8
# define RGBLIGHT_VAL_STEP 8
# define RGBLIGHT_HUE_STEP 8
# define RGBLIGHT_SAT_STEP 8
# define RGBLIGHT_VAL_STEP 8
# define RGBLIGHT_SPLIT
// # define RGBLIGHT_LAYERS
#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
2 changes: 1 addition & 1 deletion layouts/community/split_3x6_3/drashna/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
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, \
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__)

Expand Down
1 change: 1 addition & 0 deletions layouts/community/split_3x6_3/drashna/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ ifeq ($(strip $(CTPC)), yes)
WS2812_DRIVER = pwm # won't work without a patch to the ctpc mk file
SERIAL_DRIVER = usart
SWAP_HANDS_ENABLE = yes
WPM_ENABLE = yes
endif
16 changes: 9 additions & 7 deletions users/drashna/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
#define USB_POLLING_INTERVAL_MS 1

#if defined(SPLIT_KEYBOARD)
# define SPLIT_MODS_ENABLE
// # define SPLIT_TRANSPORT_MIRROR
# define SPLIT_LAYER_STATE_ENABLE
# define SPLIT_LED_STATE_ENABLE

// # define SPLIT_TRANSPORT_MIRROR
# define SERIAL_USE_MULTI_TRANSACTION
# define SPLIT_TRANSACTION_IDS_USER RPC_ID_USER_STATE_SYNC
# define SPLIT_MODS_ENABLE
# ifdef WPM_ENABLE
# define SPLIT_WPM_ENABLE
# 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

#ifdef AUDIO_ENABLE
Expand Down Expand Up @@ -165,8 +167,8 @@

#ifdef QMK_KEYS_PER_SCAN
# undef QMK_KEYS_PER_SCAN
# define QMK_KEYS_PER_SCAN 2
#endif // !QMK_KEYS_PER_SCAN
#endif
#define QMK_KEYS_PER_SCAN 4

// 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,
Expand Down
15 changes: 7 additions & 8 deletions users/drashna/oled_stuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(" "), false);
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) {
#ifdef DEBUG_MATRIX_SCAN_RATE
char matrix_rate[5];
Expand Down Expand Up @@ -315,12 +313,11 @@ void render_wpm(void) {
}

#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) {
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[4] = '0' + n % 10;
dpi_status[3] = (n /= 10) % 10 ? '0' + (n) % 10 : (n / 10) % 10 ? '0' : ' ';
Expand All @@ -340,7 +337,9 @@ void render_status_secondary(void) {
render_default_layer_state();
render_layer_state();
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());
}

Expand All @@ -349,7 +348,7 @@ void render_status_main(void) {
oled_driver_render_logo();
# ifdef DEBUG_MATRIX_SCAN_RATE
render_matrix_scan_rate();
# else
# elif defined(WPM_ENABLE)
render_wpm();
# endif
# if defined(KEYBOARD_handwired_tractyl_manuform_5x6_right)
Expand Down
4 changes: 3 additions & 1 deletion users/drashna/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ SRC += drashna.c \
process_records.c

ifneq ($(PLATFORM),CHIBIOS)
LTO_ENABLE = yes
ifneq ($(strip $(LTO_SUPPORTED)), no)
LTO_ENABLE = yes
endif
endif
SPACE_CADET_ENABLE = no
GRAVE_ESC_ENABLE = no
Expand Down
Loading

0 comments on commit 9ad2b9d

Please sign in to comment.