diff --git a/quantum/haptic.c b/quantum/haptic.c index 81bad469b37f..2f422600841a 100644 --- a/quantum/haptic.c +++ b/quantum/haptic.c @@ -29,10 +29,6 @@ # include "solenoid.h" #endif -#if defined(SPLIT_KEYBOARD) && defined(SPLIT_HAPTIC_ENABLE) -extern uint8_t split_haptic_play; -#endif - haptic_config_t haptic_config; static void update_haptic_enable_gpios(void) { @@ -335,15 +331,9 @@ void haptic_play(void) { uint8_t play_eff = 0; play_eff = haptic_config.mode; drv2605l_pulse(play_eff); -# if defined(SPLIT_KEYBOARD) && defined(SPLIT_HAPTIC_ENABLE) - split_haptic_play = haptic_config.mode; -# endif #endif #ifdef HAPTIC_SOLENOID solenoid_fire_handler(); -# if defined(SPLIT_KEYBOARD) && defined(SPLIT_HAPTIC_ENABLE) - split_haptic_play = 1; -# endif #endif } diff --git a/quantum/keyboard.c b/quantum/keyboard.c index ec8923db80a9..55ffb66ce1d0 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -504,6 +504,11 @@ void switch_events(uint8_t row, uint8_t col, bool pressed) { #if defined(RGB_MATRIX_ENABLE) rgb_matrix_handle_key_event(row, col, pressed); #endif +#if defined(HAPTIC_ENABLE) && defined(SPLIT_HAPTIC_ENABLE) + void haptic_handle_key_event(uint8_t row, uint8_t col, bool pressed); + haptic_handle_key_event(row, col, pressed); +#endif // HAPTIC_ENABLE && SPLIT_HAPTIC_ENABLE + wakeup_matrix_handle_key_event(row, col, pressed); } diff --git a/quantum/process_keycode/process_haptic.c b/quantum/process_keycode/process_haptic.c index 54cd7b817ef3..5406317af5c6 100644 --- a/quantum/process_keycode/process_haptic.c +++ b/quantum/process_keycode/process_haptic.c @@ -145,3 +145,29 @@ bool process_haptic(uint16_t keycode, keyrecord_t *record) { return true; } + + + +void haptic_handle_key_event(uint8_t row, uint8_t col, bool pressed) { + if (is_keyboard_master()) { + return; + } + keyevent_t event = MAKE_KEYEVENT(row, col, pressed); + keyrecord_t record = {.event = event}; + uint16_t keycode = get_event_keycode(event, false); + + if (haptic_get_enable() && ((!HAPTIC_OFF_IN_LOW_POWER) || (usb_device_state_get_configure_state() == USB_DEVICE_STATE_CONFIGURED))) { + if (record.event.pressed) { + // keypress + if (haptic_get_feedback() < 2 && get_haptic_enabled_key(keycode, &record)) { + haptic_play(); + } + } else { + // keyrelease + if (haptic_get_feedback() > 0 && get_haptic_enabled_key(keycode, &record)) { + haptic_play(); + } + } + } + +} diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index f66b2ad89fb5..e97ad6a9b4c0 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c @@ -817,7 +817,6 @@ static void watchdog_handlers_slave(matrix_row_t master_matrix[], matrix_row_t s #if defined(HAPTIC_ENABLE) && defined(SPLIT_HAPTIC_ENABLE) -uint8_t split_haptic_play = 0xFF; extern haptic_config_t haptic_config; static bool haptic_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { @@ -825,22 +824,12 @@ static bool haptic_handlers_master(matrix_row_t master_matrix[], matrix_row_t sl split_slave_haptic_sync_t haptic_sync; memcpy(&haptic_sync.haptic_config, &haptic_config, sizeof(haptic_config_t)); - haptic_sync.haptic_play = split_haptic_play; - bool okay = send_if_data_mismatch(PUT_HAPTIC, &last_update, &haptic_sync, &split_shmem->haptic_sync, sizeof(haptic_sync)); - - split_haptic_play = 0xFF; - - return okay; + return send_if_data_mismatch(PUT_HAPTIC, &last_update, &haptic_sync, &split_shmem->haptic_sync, sizeof(haptic_sync)); } static void haptic_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { memcpy(&haptic_config, &split_shmem->haptic_sync.haptic_config, sizeof(haptic_config_t)); - - if (split_shmem->haptic_sync.haptic_play != 0xFF) { - haptic_set_mode(split_shmem->haptic_sync.haptic_play); - haptic_play(); - } } // clang-format off