From 8c5b31a68cd4782b24eff0dbbcead29ed7e96c1c Mon Sep 17 00:00:00 2001 From: lalalademaxiya1 <66767061+lalalademaxiya1@users.noreply.github.com> Date: Wed, 6 Apr 2022 15:34:46 +0800 Subject: [PATCH] Update q9 --- .../keychron/q9/q9_ansi_stm32l432/config.h | 2 +- .../keymaps/default/keymap.c | 6 - .../q9/q9_ansi_stm32l432/keymaps/via/keymap.c | 6 - .../q9/q9_ansi_stm32l432/q9_ansi_stm32l432.c | 2 +- .../q9/q9_ansi_stm32l432_ec11/config.h | 2 +- .../keymaps/default/keymap.c | 6 - .../keymaps/via/keymap.c | 17 +-- .../q9_ansi_stm32l432_ec11.c | 2 +- keyboards/keychron/q9/test.c | 107 +++++++++--------- keyboards/keychron/q9/test.h | 2 - 10 files changed, 65 insertions(+), 87 deletions(-) diff --git a/keyboards/keychron/q9/q9_ansi_stm32l432/config.h b/keyboards/keychron/q9/q9_ansi_stm32l432/config.h index 104deb763b..3d4af6c2b9 100644 --- a/keyboards/keychron/q9/q9_ansi_stm32l432/config.h +++ b/keyboards/keychron/q9/q9_ansi_stm32l432/config.h @@ -18,7 +18,7 @@ /* USB Device descriptor parameter */ #define PRODUCT_ID 0x0190 -#define DEVICE_VER 0x0101 +#define DEVICE_VER 0x0102 /* RGB Matrix Configuration */ #define DRIVER_1_LED_TOTAL 52 diff --git a/keyboards/keychron/q9/q9_ansi_stm32l432/keymaps/default/keymap.c b/keyboards/keychron/q9/q9_ansi_stm32l432/keymaps/default/keymap.c index 48f911f06e..fcdf6a4361 100644 --- a/keyboards/keychron/q9/q9_ansi_stm32l432/keymaps/default/keymap.c +++ b/keyboards/keychron/q9/q9_ansi_stm32l432/keymaps/default/keymap.c @@ -85,11 +85,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS) }; -void matrix_scan_user(void) { - /* Set timers for factory reset and backlight test */ - timer_task_start(); -} - bool dip_switch_update_user(uint8_t index, bool active) { /* Send default layer state to host */ system_switch_state_report(index, active); @@ -97,7 +92,6 @@ bool dip_switch_update_user(uint8_t index, bool active) { } bool process_record_user(uint16_t keycode, keyrecord_t *record) { - process_other_record(keycode, record); switch (keycode) { case KC_MCTL: if (record->event.pressed) { diff --git a/keyboards/keychron/q9/q9_ansi_stm32l432/keymaps/via/keymap.c b/keyboards/keychron/q9/q9_ansi_stm32l432/keymaps/via/keymap.c index ceb5e86d6f..87b944e327 100644 --- a/keyboards/keychron/q9/q9_ansi_stm32l432/keymaps/via/keymap.c +++ b/keyboards/keychron/q9/q9_ansi_stm32l432/keymaps/via/keymap.c @@ -85,11 +85,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS) }; -void matrix_scan_user(void) { - /* Set timers for factory reset and backlight test */ - timer_task_start(); -} - bool dip_switch_update_user(uint8_t index, bool active) { /* Send default layer state to host */ system_switch_state_report(index, active); @@ -97,7 +92,6 @@ bool dip_switch_update_user(uint8_t index, bool active) { } bool process_record_user(uint16_t keycode, keyrecord_t *record) { - process_other_record(keycode, record); switch (keycode) { case KC_MCTL: if (record->event.pressed) { diff --git a/keyboards/keychron/q9/q9_ansi_stm32l432/q9_ansi_stm32l432.c b/keyboards/keychron/q9/q9_ansi_stm32l432/q9_ansi_stm32l432.c index 5d37494644..3eb8d215b7 100644 --- a/keyboards/keychron/q9/q9_ansi_stm32l432/q9_ansi_stm32l432.c +++ b/keyboards/keychron/q9/q9_ansi_stm32l432/q9_ansi_stm32l432.c @@ -102,7 +102,7 @@ led_config_t g_led_config = { { // RGB LED Index to Flag 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, - 9, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, + 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, } diff --git a/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/config.h b/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/config.h index c470872d3e..c5ef91d3f9 100644 --- a/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/config.h +++ b/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/config.h @@ -18,7 +18,7 @@ /* USB Device descriptor parameter */ #define PRODUCT_ID 0x0191 -#define DEVICE_VER 0x0101 +#define DEVICE_VER 0x0102 /* RGB Matrix Configuration */ #define DRIVER_1_LED_TOTAL 52 diff --git a/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/keymaps/default/keymap.c b/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/keymaps/default/keymap.c index b87434620c..c888491b57 100644 --- a/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/keymaps/default/keymap.c +++ b/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/keymaps/default/keymap.c @@ -85,11 +85,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS) }; -void matrix_scan_user(void) { - /* Set timers for factory reset and backlight test */ - timer_task_start(); -} - bool dip_switch_update_user(uint8_t index, bool active) { /* Send default layer state to host */ system_switch_state_report(index, active); @@ -97,7 +92,6 @@ bool dip_switch_update_user(uint8_t index, bool active) { } bool process_record_user(uint16_t keycode, keyrecord_t *record) { - process_other_record(keycode, record); switch (keycode) { case KC_MCTL: if (record->event.pressed) { diff --git a/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/keymaps/via/keymap.c b/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/keymaps/via/keymap.c index 353e0943ee..cf8b8a26e3 100644 --- a/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/keymaps/via/keymap.c +++ b/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/keymaps/via/keymap.c @@ -52,7 +52,7 @@ key_combination_t key_comb_list[2] = { }; static uint8_t mac_keycode[4] = { KC_LOPT, KC_ROPT, KC_LCMD, KC_RCMD }; - +// clang-format off const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [MAC_BASE] = LAYOUT_all( KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_VOLD, KC_MUTE, KC_VOLU, @@ -84,7 +84,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS) }; - +//clang-format on #if defined(VIA_ENABLE) && defined(ENCODER_ENABLE) #define ENCODERS 1 @@ -108,6 +108,10 @@ void encoder_action_register(uint8_t index, bool clockwise) { action_exec(encoder_event); } +void matrix_scan_user(void) { + encoder_action_unregister(); +} + bool encoder_update_user(uint8_t index, bool clockwise) { encoder_action_register(index, clockwise); return false; @@ -115,14 +119,6 @@ bool encoder_update_user(uint8_t index, bool clockwise) { #endif -void matrix_scan_user(void) { -#if defined(VIA_ENABLE) && defined(ENCODER_ENABLE) - encoder_action_unregister(); -#endif - /* Set timers for factory reset and backlight test */ - timer_task_start(); -} - bool dip_switch_update_user(uint8_t index, bool active) { /* Send default layer state to host */ system_switch_state_report(index, active); @@ -130,7 +126,6 @@ bool dip_switch_update_user(uint8_t index, bool active) { } bool process_record_user(uint16_t keycode, keyrecord_t *record) { - process_other_record(keycode, record); switch (keycode) { case KC_MCTL: if (record->event.pressed) { diff --git a/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/q9_ansi_stm32l432_ec11.c b/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/q9_ansi_stm32l432_ec11.c index 0834bb74dc..de9c073b20 100644 --- a/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/q9_ansi_stm32l432_ec11.c +++ b/keyboards/keychron/q9/q9_ansi_stm32l432_ec11/q9_ansi_stm32l432_ec11.c @@ -102,7 +102,7 @@ led_config_t g_led_config = { { // RGB LED Index to Flag 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, - 9, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, + 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, } diff --git a/keyboards/keychron/q9/test.c b/keyboards/keychron/q9/test.c index 32954bcd3b..083557aa26 100644 --- a/keyboards/keychron/q9/test.c +++ b/keyboards/keychron/q9/test.c @@ -19,9 +19,8 @@ #define MAC_FN 2 #define WIN_FN 3 -static void timer_3000ms_task(void); -static void timer_250ms_task(void); -static void factory_test_send(uint8_t *payload, uint8_t length); +static void timer_3s_task(void); +static void timer_300ms_task(void); #define KEY_PRESS_FN (0x1<<0) #define KEY_PRESS_J (0x1<<1) @@ -51,12 +50,12 @@ enum { }; uint16_t key_press_status = 0; -uint32_t timer_3000ms_buffer = 0; -uint32_t timer_250ms_buffer = 0; +uint32_t timer_3s_buffer = 0; +uint32_t timer_300ms_buffer = 0; uint8_t factory_reset_count = 0; bool report_os_sw_state = false; -void process_other_record(uint16_t keycode, keyrecord_t *record) { +bool process_record_kb(uint16_t keycode, keyrecord_t *record) { switch (keycode) { case MO(MAC_FN): case MO(WIN_FN): @@ -64,31 +63,31 @@ void process_other_record(uint16_t keycode, keyrecord_t *record) { key_press_status |= KEY_PRESS_FN; } else { key_press_status &= ~KEY_PRESS_FN; - timer_3000ms_buffer = 0; + timer_3s_buffer = 0; } - break; + return true; case KC_J: if (record->event.pressed) { key_press_status |= KEY_PRESS_J; if (key_press_status == KEY_PRESS_FACTORY_RESET) { - timer_3000ms_buffer = sync_timer_read32() | 1; + timer_3s_buffer = sync_timer_read32() | 1; } } else { key_press_status &= ~KEY_PRESS_J; - timer_3000ms_buffer = 0; + timer_3s_buffer = 0; } - break; + return true; case RGB_RMOD: if (record->event.pressed) { key_press_status |= KEY_PRESS_Z; if (key_press_status == KEY_PRESS_FACTORY_RESET) { - timer_3000ms_buffer = sync_timer_read32() | 1; + timer_3s_buffer = sync_timer_read32() | 1; } } else { key_press_status &= ~KEY_PRESS_Z; - timer_3000ms_buffer = 0; + timer_3s_buffer = 0; } - break; + return true; case KC_RGHT: if (record->event.pressed) { key_press_status |= KEY_PRESS_RIGHT; @@ -97,46 +96,52 @@ void process_other_record(uint16_t keycode, keyrecord_t *record) { led_test_mode = LED_TEST_MODE_WHITE; } } else if (key_press_status == KEY_PRESS_LED_TEST) { - timer_3000ms_buffer = sync_timer_read32() | 1; + timer_3s_buffer = sync_timer_read32() | 1; } } else { key_press_status &= ~KEY_PRESS_RIGHT; - timer_3000ms_buffer = 0; + timer_3s_buffer = 0; } - break; + return true; case KC_HOME: if (record->event.pressed) { key_press_status |= KEY_PRESS_HOME; if (led_test_mode) { led_test_mode = LED_TEST_MODE_OFF; } else if (key_press_status == KEY_PRESS_LED_TEST) { - timer_3000ms_buffer = sync_timer_read32() | 1; + timer_3s_buffer = sync_timer_read32() | 1; } } else { key_press_status &= ~KEY_PRESS_HOME; - timer_3000ms_buffer = 0; + timer_3s_buffer = 0; } - break; + return true; + default: + return process_record_user(keycode, record); } } -void timer_task_start(void) { - if (timer_3000ms_buffer) { - timer_3000ms_task(); - } else if (timer_250ms_buffer) { - timer_250ms_task(); +void matrix_scan_kb(void) { + if (timer_3s_buffer) { + timer_3s_task(); } + if (timer_300ms_buffer) { + timer_300ms_task(); + } + + matrix_scan_user(); } -static void timer_3000ms_task(void) { - if (sync_timer_elapsed32(timer_3000ms_buffer) > 3000) { - timer_3000ms_buffer = 0; +static void timer_3s_task(void) { + if (sync_timer_elapsed32(timer_3s_buffer) > 3000) { + timer_3s_buffer = 0; if (key_press_status == KEY_PRESS_FACTORY_RESET) { - timer_250ms_buffer = sync_timer_read32() | 1; + timer_300ms_buffer = sync_timer_read32() | 1; factory_reset_count++; layer_state_t default_layer_tmp = default_layer_state; eeconfig_init(); default_layer_set(default_layer_tmp); + led_test_mode = LED_TEST_MODE_OFF; #ifdef LED_MATRIX_ENABLE if (!led_matrix_is_enabled()) led_matrix_enable(); led_matrix_init(); @@ -159,13 +164,13 @@ static void timer_3000ms_task(void) { } } -static void timer_250ms_task(void) { - if (timer_250ms_buffer && sync_timer_elapsed32(timer_250ms_buffer) > 250) { +static void timer_300ms_task(void) { + if (timer_300ms_buffer && sync_timer_elapsed32(timer_300ms_buffer) > 300) { if (factory_reset_count++ > 6) { - timer_250ms_buffer = 0; + timer_300ms_buffer = 0; factory_reset_count = 0; } else { - timer_250ms_buffer = sync_timer_read32() | 1; + timer_300ms_buffer = sync_timer_read32() | 1; } } } @@ -232,13 +237,13 @@ void raw_hid_receive_kb(uint8_t *data, uint8_t length) { switch (data[1]) { case FACTORY_TEST_CMD_BACKLIGHT: led_test_mode = data[2]; - timer_3000ms_buffer = 0; + timer_3s_buffer = 0; break; case FACTORY_TEST_CMD_OS_SWITCH: report_os_sw_state = data[2]; - if (report_os_sw_state) { - // dip_switch_read(true); - } + // if (report_os_sw_state) { + // dip_switch_read(true); + // } break; case FACTORY_TEST_CMD_JUMP_TO_BL: if (memcmp(&data[2], "JumpToBootloader", strlen("JumpToBootloader")) == 0) @@ -248,25 +253,23 @@ void raw_hid_receive_kb(uint8_t *data, uint8_t length) { } } -static void factory_test_send(uint8_t *payload, uint8_t length) { +void system_switch_state_report(uint8_t index, bool active) { uint16_t checksum = 0; uint8_t data[RAW_EPSIZE] = {0}; - uint8_t i = 0; - data[i++] = 0xAB; - memcpy(&data[i], payload, length); - i += length; - for (uint8_t i=1; i> 8) & 0xFF; - raw_hid_send(data, RAW_EPSIZE); -} + uint8_t payload[3] = { 0 }; -void system_switch_state_report(uint8_t index, bool active) { if (report_os_sw_state) { - uint8_t payload[3] = {FACTORY_TEST_CMD_OS_SWITCH, OS_SWITCH, active}; - factory_test_send(payload, 3); + payload[0] = FACTORY_TEST_CMD_OS_SWITCH; + payload[1] = OS_SWITCH; + payload[2] = active; + data[0] = 0xAB; + memcpy(&data[1], payload, 3); + for (uint8_t i=1; i> 8) & 0xFF; + raw_hid_send(data, RAW_EPSIZE); } } diff --git a/keyboards/keychron/q9/test.h b/keyboards/keychron/q9/test.h index 0c4bf877c3..f0bcbf39da 100644 --- a/keyboards/keychron/q9/test.h +++ b/keyboards/keychron/q9/test.h @@ -20,8 +20,6 @@ #include "quantum.h" #include "raw_hid.h" -void process_other_record(uint16_t keycode, keyrecord_t *record); -void timer_task_start(void); void system_switch_state_report(uint8_t index, bool active); #endif /* _TEST_H_ */