From 77e6996b5ccaee5365787d136c9be9c83f5e0a3a Mon Sep 17 00:00:00 2001 From: lalalademaxiya1 <66767061+lalalademaxiya1@users.noreply.github.com> Date: Mon, 27 Mar 2023 14:51:38 +0800 Subject: [PATCH] Update v2 --- keyboards/keychron/v2/config.h | 19 +---- keyboards/keychron/v2/v2.c | 77 ------------------- .../v2/v2_ansi_stm32l432_ec11/config.h | 3 - .../v2/v2_ansi_stm32l432_ec11/info.json | 12 ++- .../keymaps/keychron/keymap.c | 14 +--- .../keymaps/keychron/rules.mk | 3 +- .../v2/v2_ansi_stm32l432_ec11/rules.mk | 2 - .../v2_ansi_stm32l432_ec11.c | 28 +++++-- quantum/encoder.c | 10 +-- quantum/encoder.h | 2 +- 10 files changed, 47 insertions(+), 123 deletions(-) diff --git a/keyboards/keychron/v2/config.h b/keyboards/keychron/v2/config.h index 56d381a578..cd7361118e 100644 --- a/keyboards/keychron/v2/config.h +++ b/keyboards/keychron/v2/config.h @@ -16,13 +16,6 @@ #pragma once -/* COL2ROW or ROW2COL */ -#define DIODE_DIRECTION ROW2COL - -/* key matrix pins */ -#define MATRIX_ROW_PINS { B4, B3, A15, A14, A13 } -#define MATRIX_COL_PINS { C14, C15, A0, A1, A2, A3, A4, A5, A6, A7, B0, B1, A8, A9, H3 } - /* If uses PH3 with a stronger pull resistor then the following definition should be included */ // #define MATRIX_UNSELECT_DRIVE_HIGH @@ -87,6 +80,10 @@ #define ENABLE_RGB_MATRIX_PIXEL_RAIN // #define ENABLE_RGB_MATRIX_PIXEL_FLOW // #define ENABLE_RGB_MATRIX_PIXEL_FRACTAL + +#define RGB_MATRIX_FRAMEBUFFER_EFFECTS +#define RGB_MATRIX_KEYPRESSES + // enabled only if RGB_MATRIX_FRAMEBUFFER_EFFECTS is defined #define ENABLE_RGB_MATRIX_TYPING_HEATMAP #define ENABLE_RGB_MATRIX_DIGITAL_RAIN @@ -103,11 +100,3 @@ // #define ENABLE_RGB_MATRIX_MULTISPLASH #define ENABLE_RGB_MATRIX_SOLID_SPLASH // #define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH - -#define RGB_MATRIX_KEYPRESSES -#define RGB_MATRIX_FRAMEBUFFER_EFFECTS - -/* Enable receive custom command from host */ -#define RAW_HID_CMD 0xAB - -#define HOLD_ON_OTHER_KEY_PRESS diff --git a/keyboards/keychron/v2/v2.c b/keyboards/keychron/v2/v2.c index 019dc5f890..26e992723e 100644 --- a/keyboards/keychron/v2/v2.c +++ b/keyboards/keychron/v2/v2.c @@ -35,80 +35,3 @@ bool dip_switch_update_kb(uint8_t index, bool active) { } #endif // DIP_SWITCH_ENABLE - -#if defined(RGB_MATRIX_ENABLE) && defined(CAPS_LOCK_LED_INDEX) - -# define CAPS_LOCK_MAX_BRIGHTNESS 0xFF -# ifdef RGB_MATRIX_MAXIMUM_BRIGHTNESS -# undef CAPS_LOCK_MAX_BRIGHTNESS -# define CAPS_LOCK_MAX_BRIGHTNESS RGB_MATRIX_MAXIMUM_BRIGHTNESS -# endif - -# define CAPS_LOCK_VAL_STEP 8 -# ifdef RGB_MATRIX_VAL_STEP -# undef CAPS_LOCK_VAL_STEP -# define CAPS_LOCK_VAL_STEP RGB_MATRIX_VAL_STEP -# endif - -extern void rgb_matrix_update_pwm_buffers(void); - -static uint8_t light_brightness_get(void) { - uint8_t value = rgb_matrix_get_val(); - if (value < CAPS_LOCK_VAL_STEP) { - value = CAPS_LOCK_VAL_STEP; - } else if (value < (CAPS_LOCK_MAX_BRIGHTNESS - CAPS_LOCK_VAL_STEP)) { - value += CAPS_LOCK_VAL_STEP; // one step more than current brightness - } else { - value = CAPS_LOCK_MAX_BRIGHTNESS; - } - - return value; -} - -bool rgb_matrix_indicators_kb(void) { - if (!rgb_matrix_indicators_user()) { - return false; - } - if (host_keyboard_led_state().caps_lock) { - uint8_t v = light_brightness_get(); - rgb_matrix_set_color(CAPS_LOCK_LED_INDEX, v, v, v); // white, with the adjusted brightness - } - return true; -} - -void rgb_matrix_indicators_none_kb(void) { - rgb_matrix_indicators_kb(); - rgb_matrix_update_pwm_buffers(); -} - -bool led_update_kb(led_t led_state) { - bool res = led_update_user(led_state); - - if (rgb_matrix_is_enabled() -# if defined(ENABLE_RGB_MATRIX_RAINDROPS) - && (rgb_matrix_get_mode() != RGB_MATRIX_RAINDROPS) -# endif -# if defined(ENABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS) - && (rgb_matrix_get_mode() != RGB_MATRIX_JELLYBEAN_RAINDROPS) -# endif -# if defined(ENABLE_RGB_MATRIX_PIXEL_RAIN) - && (rgb_matrix_get_mode() != RGB_MATRIX_PIXEL_RAIN) -# endif - ) { - return res; - } - - if (res) { - if (led_state.caps_lock) { - uint8_t v = light_brightness_get(); - rgb_matrix_set_color(CAPS_LOCK_LED_INDEX, v, v, v); - } else { - rgb_matrix_set_color(CAPS_LOCK_LED_INDEX, 0, 0, 0); - } - rgb_matrix_update_pwm_buffers(); - } - - return res; -} - -#endif // CAPS_LOCK_LED_INDEX diff --git a/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/config.h b/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/config.h index 9fa6121c6c..9f850f1b79 100644 --- a/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/config.h +++ b/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/config.h @@ -24,9 +24,6 @@ #define CKLED2001_CURRENT_TUNE { 0xCA, 0xCA, 0x60, 0xCA, 0xCA, 0x60, 0xCA, 0xCA, 0x60, 0xCA, 0xCA, 0x60 } /* Encoder Configuration */ -#define ENCODERS_PAD_A { A10 } -#define ENCODERS_PAD_B { B5 } -#define ENCODER_RESOLUTION 4 #define ENCODER_DEFAULT_POS 0x3 /* Enable caps-lock LED */ diff --git a/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/info.json b/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/info.json index 6b8ba63872..e73e236108 100644 --- a/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/info.json +++ b/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/info.json @@ -6,7 +6,17 @@ "usb": { "vid": "0x3434", "pid": "0x0321", - "device_version": "1.0.3" + "device_version": "1.0.4" + }, + "matrix_pins": { + "cols": ["C14", "C15", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "B0", "B1", "A8", "A9", "H3"], + "rows": ["B4", "B3", "A15", "A14", "A13"] + }, + "diode_direction": "ROW2COL", + "encoder": { + "rotary": [ + {"pin_a": "A10", "pin_b": "B5"} + ] }, "processor": "STM32L432", "bootloader": "stm32-dfu", diff --git a/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/keymaps/keychron/keymap.c b/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/keymaps/keychron/keymap.c index 88fa58b6fa..5f3bf6b679 100644 --- a/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/keymaps/keychron/keymap.c +++ b/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/keymaps/keychron/keymap.c @@ -16,6 +16,7 @@ #include QMK_KEYBOARD_H #include "keychron_common.h" +#include "keychron_ft_common.h" // clang-format off @@ -84,21 +85,10 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { if (!process_record_keychron(keycode, record)) { return false; } - return true; -} -bool dip_switch_update_user(uint8_t index, bool active) { - if (!dip_switch_update_keychron(index, active)) { + if (!process_record_keychron_ft(keycode, record)) { return false; } - return true; -} -#ifdef RGB_MATRIX_ENABLE -bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { - if(!rgb_matrix_indicators_advanced_keychron(led_min, led_max)) { - return false; - } return true; } -#endif // RGB_MATRIX_ENABLE diff --git a/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/keymaps/keychron/rules.mk b/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/keymaps/keychron/rules.mk index f33d417444..88c27a468a 100644 --- a/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/keymaps/keychron/rules.mk +++ b/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/keymaps/keychron/rules.mk @@ -2,5 +2,4 @@ VIA_ENABLE = yes ENCODER_MAP_ENABLE = yes VPATH += keyboards/keychron/common -SRC += keychron_common.c -SRC += keychron_factory_test_common.c +SRC += keychron_common.c keychron_ft_common.c diff --git a/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/rules.mk b/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/rules.mk index f2cbf4a660..a5dbd2a938 100644 --- a/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/rules.mk +++ b/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/rules.mk @@ -7,8 +7,6 @@ EXTRAKEY_ENABLE = yes # Audio control and System control CONSOLE_ENABLE = no # Console for debug COMMAND_ENABLE = no # Commands for debug and configuration NKRO_ENABLE = yes # Enable USB N-key Rollover -BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality -RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow AUDIO_ENABLE = no # Audio output ENCODER_ENABLE = yes # Enable Encoder ENCODER_MAP_ENABLE = no diff --git a/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/v2_ansi_stm32l432_ec11.c b/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/v2_ansi_stm32l432_ec11.c index 23273cdbab..8472f99600 100644 --- a/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/v2_ansi_stm32l432_ec11.c +++ b/keyboards/keychron/v2/v2_ansi_stm32l432_ec11/v2_ansi_stm32l432_ec11.c @@ -125,7 +125,7 @@ led_config_t g_led_config = { 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 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 + 1, 1, 1, 4, 1, 4, 1, 1, 1, 1 } }; @@ -136,18 +136,36 @@ led_config_t g_led_config = { void encoder0_pad_cb(void *param) { (void)param; - encoder_insert_state(); + encoder_inerrupt_read(0); } -void keyboard_post_init_kb(void) { +void encoder1_pad_cb(void *param) { + (void)param; + + encoder_inerrupt_read(1); +} + +void encoder_interrupt_init(void) { pin_t encoders_pad_a[NUM_ENCODERS] = ENCODERS_PAD_A; pin_t encoders_pad_b[NUM_ENCODERS] = ENCODERS_PAD_B; for (uint8_t i = 0; i < NUM_ENCODERS; i++) { palEnableLineEvent(encoders_pad_a[i], PAL_EVENT_MODE_BOTH_EDGES); palEnableLineEvent(encoders_pad_b[i], PAL_EVENT_MODE_BOTH_EDGES); - palSetLineCallback(encoders_pad_a[i], encoder0_pad_cb, NULL); - palSetLineCallback(encoders_pad_b[i], encoder0_pad_cb, NULL); } + if (NUM_ENCODERS > 0) { + palSetLineCallback(encoders_pad_a[0], encoder0_pad_cb, NULL); + palSetLineCallback(encoders_pad_b[0], encoder0_pad_cb, NULL); + } + if (NUM_ENCODERS > 1) { + palSetLineCallback(encoders_pad_a[1], encoder1_pad_cb, NULL); + palSetLineCallback(encoders_pad_b[1], encoder1_pad_cb, NULL); + } +} + +void keyboard_post_init_kb(void) { +#if defined(ENCODER_ENABLE) && defined(PAL_USE_CALLBACKS) + encoder_interrupt_init(); +#endif // allow user keymaps to do custom post_init keyboard_post_init_user(); diff --git a/quantum/encoder.c b/quantum/encoder.c index a6a4542f15..8cd7a45c7a 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -56,7 +56,7 @@ static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, static uint8_t encoder_state[NUM_ENCODERS] = {0}; static int8_t encoder_pulses[NUM_ENCODERS] = {0}; -static bool encoder_external_update[NUM_ENCODERS] = {false}; +static bool encoder_interrupt_update[NUM_ENCODERS] = {false}; // encoder counts static uint8_t thisCount; @@ -222,11 +222,11 @@ bool encoder_read(void) { bool changed = false; for (uint8_t i = 0; i < thisCount; i++) { uint8_t new_status = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); - if ((encoder_state[i] & 0x3) != new_status || encoder_external_update[i]) { + if ((encoder_state[i] & 0x3) != new_status || encoder_interrupt_update[i]) { encoder_state[i] <<= 2; encoder_state[i] |= new_status; changed |= encoder_update(i, encoder_state[i]); - encoder_external_update[i] = false; + encoder_interrupt_update[i] = false; } } return changed; @@ -271,9 +271,9 @@ void encoder_update_raw(uint8_t *slave_state) { } #endif -void encoder_insert_state(uint8_t index) { +void encoder_inerrupt_read(uint8_t index) { encoder_state[index] <<= 2; encoder_state[index] |= (readPin(encoders_pad_a[index]) << 0) | (readPin(encoders_pad_b[index]) << 1); encoder_pulses[index] += encoder_LUT[encoder_state[index] & 0xF]; - encoder_external_update[index] = true; + encoder_interrupt_update[index] = true; } diff --git a/quantum/encoder.h b/quantum/encoder.h index 54c97c8dc6..fb0fd18aa8 100644 --- a/quantum/encoder.h +++ b/quantum/encoder.h @@ -25,7 +25,7 @@ bool encoder_read(void); bool encoder_update_kb(uint8_t index, bool clockwise); bool encoder_update_user(uint8_t index, bool clockwise); -void encoder_insert_state(uint8_t index); +void encoder_inerrupt_read(uint8_t index); #ifdef SPLIT_KEYBOARD