From d3f74a31c0a5ac71de6bc68db64ab1a59d6b183a Mon Sep 17 00:00:00 2001 From: lalalademaxiya1 <66767061+lalalademaxiya1@users.noreply.github.com> Date: Thu, 28 Apr 2022 17:21:19 +0800 Subject: [PATCH 1/3] Update q2 Fixed encoder and update q2 --- keyboards/keychron/q2/config.h | 8 +-- keyboards/keychron/q2/halconf.h | 3 + keyboards/keychron/q2/rev_0111/config.h | 5 +- .../keychron/q2/rev_0111/keymaps/via/config.h | 20 +++++++ keyboards/keychron/q2/rev_0111/rev_0111.c | 56 +++++++++++++------ keyboards/keychron/q2/rev_0111/rev_0111.h | 20 +++---- keyboards/keychron/q2/rev_0111/rules.mk | 3 +- quantum/encoder.c | 6 ++ quantum/encoder.h | 1 + 9 files changed, 86 insertions(+), 36 deletions(-) create mode 100644 keyboards/keychron/q2/rev_0111/keymaps/via/config.h diff --git a/keyboards/keychron/q2/config.h b/keyboards/keychron/q2/config.h index d019bcee1563..bdf350ff0b79 100644 --- a/keyboards/keychron/q2/config.h +++ b/keyboards/keychron/q2/config.h @@ -57,14 +57,14 @@ /* turn off effects when suspended */ #define RGB_DISABLE_WHEN_USB_SUSPENDED -/* Use 5 dynamic keymap layers */ -#define DYNAMIC_KEYMAP_LAYER_COUNT 5 - /* We have 2KB EEPROM size on STM32L432 */ #define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 2047 +/* Total size of the EEPROM storage in bytes */ +#define TRANSIENT_EEPROM_SIZE 4096 + /* EEPROM Driver Configuration */ -#define EXTERNAL_EEPROM_I2C_BASE_ADDRESS 0b10100010 +// #define EXTERNAL_EEPROM_I2C_BASE_ADDRESS 0b10100010 // RGB Matrix Animation modes. Explicitly enabled // For full list of effects, see: diff --git a/keyboards/keychron/q2/halconf.h b/keyboards/keychron/q2/halconf.h index 41bddcb2799b..b6b05c07e347 100644 --- a/keyboards/keychron/q2/halconf.h +++ b/keyboards/keychron/q2/halconf.h @@ -17,5 +17,8 @@ #pragma once #define HAL_USE_I2C TRUE +#ifdef ENCODER_ENABLE +#define PAL_USE_CALLBACKS TRUE +#endif #include_next diff --git a/keyboards/keychron/q2/rev_0111/config.h b/keyboards/keychron/q2/rev_0111/config.h index 76cd5d0e782f..e44cc78818a3 100644 --- a/keyboards/keychron/q2/rev_0111/config.h +++ b/keyboards/keychron/q2/rev_0111/config.h @@ -25,9 +25,8 @@ #define DRIVER_2_LED_TOTAL 33 #define DRIVER_LED_TOTAL (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL) -/* Encoder used pins */ +/* Encoder Configuration */ #define ENCODERS_PAD_A { A10 } #define ENCODERS_PAD_B { B5 } - -/* Specifies the number of pulses the encoder registers between each detent */ #define ENCODER_RESOLUTION 4 +#define ENCODER_DEFAULT_POS 0x3 diff --git a/keyboards/keychron/q2/rev_0111/keymaps/via/config.h b/keyboards/keychron/q2/rev_0111/keymaps/via/config.h new file mode 100644 index 000000000000..84d17b3721aa --- /dev/null +++ b/keyboards/keychron/q2/rev_0111/keymaps/via/config.h @@ -0,0 +1,20 @@ +/* Copyright 2022 @ Keychron (https://www.keychron.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +/* Set dynamic keymap layer counts to 5 */ +#define DYNAMIC_KEYMAP_LAYER_COUNT 5 diff --git a/keyboards/keychron/q2/rev_0111/rev_0111.c b/keyboards/keychron/q2/rev_0111/rev_0111.c index cbadafc458ee..325203d7018b 100644 --- a/keyboards/keychron/q2/rev_0111/rev_0111.c +++ b/keyboards/keychron/q2/rev_0111/rev_0111.c @@ -97,27 +97,32 @@ const ckled2001_led PROGMEM g_ckled2001_leds[DRIVER_LED_TOTAL] = { {1, F_16, D_16, E_16}, }; +#define __ NO_LED + led_config_t g_led_config = { - { - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, - { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 }, - { 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 65, 42, 43 }, - { 44, NO_LED, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, NO_LED, 55, 56 }, - { 57, 58, 59, NO_LED, NO_LED, NO_LED, 60, NO_LED, NO_LED, NO_LED, 61, 62, 63, 64, 66 }, + { + // Key Matrix to LED Index + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, + { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 }, + { 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 65, 42, 43 }, + { 44, __, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, __, 55, 56 }, + { 57, 58, 59, __, __, __, 60, __, __, __, 61, 62, 63, 64, 66 } }, { - {0, 0}, {15, 0}, {30, 0}, {45, 0}, {60, 0}, {75, 0}, {90, 0}, {105, 0}, {120, 0}, {135, 0}, {150, 0}, {165, 0}, {180, 0}, {195, 0}, {224, 0}, - {0,16}, {15,16}, {30,16}, {45,16}, {60,16}, {75,16}, {90,16}, {105,16}, {120,16}, {135,16}, {150,16}, {165,16}, {180,16}, {195,16}, {224,16}, - {0,32}, {15,32}, {30,32}, {45,32}, {60,32}, {75,32}, {90,32}, {105,32}, {120,32}, {135,32}, {150,32}, {165,32}, {195,32}, {224,32}, - {0,48}, {30,48}, {45,48}, {60,48}, {75,48}, {90,48}, {105,48}, {120,48}, {135,48}, {150,48}, {165,48}, {180,48}, {210,48}, - {0,64}, {15,64}, {30,64}, {90,64}, {150,64}, {165,64}, {180,64}, {195,64}, {210,64}, {224,64}, + // LED Index to Physical Position + {0,0}, {15,0}, {29,0}, {44,0}, {59,0}, {73,0}, {88,0}, {103,0}, {118,0}, {132,0}, {147,0}, {162,0}, {176,0}, {198,0}, {224,0}, // {244,-4} + {4,15}, {22,15}, {37,15}, {51,15}, {66,15}, {81,15}, {95,15}, {110,15}, {125,15}, {140,15}, {154,15}, {169,15}, {184,15}, {202,15}, {224,15}, + {6,30}, {26,30}, {40,30}, {55,30}, {70,30}, {84,30}, {99,30}, {114,30}, {129,30}, {143,30}, {158,30}, {173,30}, {196,30}, {224,30}, + {9,45}, {33,45}, {48,45}, {62,45}, {77,45}, {92,45}, {106,45}, {121,45}, {136,45}, {151,45}, {165,45}, {185,45}, {209,49}, + {2,60}, {20,60}, {39,60}, {94,60}, {147,60}, {162,60}, {176,60}, {195,64}, {209,64}, {224,64} }, { - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + // RGB LED Index to Flag + 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, + 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 } }; #endif @@ -127,11 +132,26 @@ bool encoder_update_kb(uint8_t index, bool clockwise) { if (!encoder_update_user(index, clockwise)) { return false; } if (index == 0) { if (clockwise) { - tap_code_delay(KC_VOLU, 10); + tap_code_delay(KC_VOLU, TAP_CODE_DELAY); } else { - tap_code_delay(KC_VOLD, 10); + tap_code_delay(KC_VOLD, TAP_CODE_DELAY); } } return true; } + +void encoder0_pad_cb(void *param) { + (void)param; + + encoder_insert_state(0); +} + +void keyboard_post_init_kb(void) { + pin_t encoders_pad_a[] = ENCODERS_PAD_A; + pin_t encoders_pad_b[] = ENCODERS_PAD_B; + palEnableLineEvent(encoders_pad_a[0], PAL_EVENT_MODE_BOTH_EDGES); + palEnableLineEvent(encoders_pad_b[0], PAL_EVENT_MODE_BOTH_EDGES); + palSetLineCallback(encoders_pad_a[0], encoder0_pad_cb, NULL); + palSetLineCallback(encoders_pad_b[0], encoder0_pad_cb, NULL); +} #endif diff --git a/keyboards/keychron/q2/rev_0111/rev_0111.h b/keyboards/keychron/q2/rev_0111/rev_0111.h index 5033db61fc4e..9ae527a98a4e 100644 --- a/keyboards/keychron/q2/rev_0111/rev_0111.h +++ b/keyboards/keychron/q2/rev_0111/rev_0111.h @@ -27,11 +27,11 @@ K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3D, K3E, \ K40, K41, K42, K46, K4A, K4B, K4C, K4D, K2C, K4E \ ) { \ - { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, }, \ - { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, }, \ - { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, K2E, }, \ - { K30, XXX, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, XXX, K3D, K3E, }, \ - { K40, K41, K42, XXX, XXX, XXX, K46, K47, K48, XXX, K4A, K4B, K4C, K4D, K4E, } \ + { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, }, \ + { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, }, \ + { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, K2E, }, \ + { K30, XXX, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, XXX, K3D, K3E, }, \ + { K40, K41, K42, XXX, XXX, XXX, K46, K47, K48, XXX, K4A, K4B, K4C, K4D, K4E, } \ } #define LAYOUT_ansi_67( \ K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E,\ @@ -40,9 +40,9 @@ K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3D, K3E, \ K40, K41, K42, K46, K4A, K4B, K4C, K4D, K2C, K4E \ ) { \ - { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, }, \ - { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, }, \ - { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, K2E, }, \ - { K30, XXX, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, XXX, K3D, K3E, }, \ - { K40, K41, K42, XXX, XXX, XXX, K46, XXX, XXX, XXX, K4A, K4B, K4C, K4D, K4E, } \ + { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, }, \ + { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, }, \ + { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, K2E, }, \ + { K30, XXX, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, XXX, K3D, K3E, }, \ + { K40, K41, K42, XXX, XXX, XXX, K46, XXX, XXX, XXX, K4A, K4B, K4C, K4D, K4E, } \ } diff --git a/keyboards/keychron/q2/rev_0111/rules.mk b/keyboards/keychron/q2/rev_0111/rules.mk index a295f48e1055..56a22430c661 100644 --- a/keyboards/keychron/q2/rev_0111/rules.mk +++ b/keyboards/keychron/q2/rev_0111/rules.mk @@ -20,7 +20,8 @@ ENCODER_ENABLE = yes # Enable Encoder DIP_SWITCH_ENABLE = yes RGB_MATRIX_ENABLE = yes RGB_MATRIX_DRIVER = CKLED2001 -EEPROM_DRIVER = i2c +# EEPROM_DRIVER = i2c +EEPROM_DRIVER = transient # Enter lower-power sleep mode when on the ChibiOS idle thread OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE diff --git a/quantum/encoder.c b/quantum/encoder.c index 438c7d8564e1..d1b7544dad19 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -177,3 +177,9 @@ void encoder_update_raw(uint8_t* slave_state) { if (changed) last_encoder_activity_trigger(); } #endif + +void encoder_insert_state(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]; +} \ No newline at end of file diff --git a/quantum/encoder.h b/quantum/encoder.h index 25dc77721da9..a81b7c84f8f2 100644 --- a/quantum/encoder.h +++ b/quantum/encoder.h @@ -24,6 +24,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); #ifdef SPLIT_KEYBOARD void encoder_state_raw(uint8_t* slave_state); From 8d41c7c3a536e21144e9c92016e406c9558f5555 Mon Sep 17 00:00:00 2001 From: lalalademaxiya1 <2831039915@qq.com> Date: Mon, 21 Nov 2022 11:21:13 +0800 Subject: [PATCH 2/3] Update q2 to keep trace with upstream/develop --- keyboards/keychron/q2/config.h | 6 +- keyboards/keychron/q2/halconf.h | 3 - keyboards/keychron/q2/rev_0111/config.h | 5 +- .../keychron/q2/rev_0111/keymaps/via/config.h | 20 ------- keyboards/keychron/q2/rev_0111/rev_0111.c | 56 ++++++------------- keyboards/keychron/q2/rev_0111/rev_0111.h | 20 +++---- 6 files changed, 34 insertions(+), 76 deletions(-) delete mode 100644 keyboards/keychron/q2/rev_0111/keymaps/via/config.h diff --git a/keyboards/keychron/q2/config.h b/keyboards/keychron/q2/config.h index 124de30e4d8b..5961b6292962 100644 --- a/keyboards/keychron/q2/config.h +++ b/keyboards/keychron/q2/config.h @@ -52,12 +52,12 @@ /* turn off effects when suspended */ #define RGB_DISABLE_WHEN_USB_SUSPENDED +/* Use 5 dynamic keymap layers */ +#define DYNAMIC_KEYMAP_LAYER_COUNT 5 + /* We have 2KB EEPROM size on STM32L432 */ #define DYNAMIC_KEYMAP_EEPROM_MAX_ADDR 2047 -/* Total size of the EEPROM storage in bytes */ -#define TRANSIENT_EEPROM_SIZE 4096 - /* EEPROM Driver Configuration */ #define WEAR_LEVELING_LOGICAL_SIZE 2048 #define WEAR_LEVELING_BACKING_SIZE (WEAR_LEVELING_LOGICAL_SIZE * 2) diff --git a/keyboards/keychron/q2/halconf.h b/keyboards/keychron/q2/halconf.h index b6b05c07e347..41bddcb2799b 100644 --- a/keyboards/keychron/q2/halconf.h +++ b/keyboards/keychron/q2/halconf.h @@ -17,8 +17,5 @@ #pragma once #define HAL_USE_I2C TRUE -#ifdef ENCODER_ENABLE -#define PAL_USE_CALLBACKS TRUE -#endif #include_next diff --git a/keyboards/keychron/q2/rev_0111/config.h b/keyboards/keychron/q2/rev_0111/config.h index ce4dbfd5f227..8ef6c542f0f0 100644 --- a/keyboards/keychron/q2/rev_0111/config.h +++ b/keyboards/keychron/q2/rev_0111/config.h @@ -21,8 +21,9 @@ #define DRIVER_2_LED_TOTAL 33 #define RGB_MATRIX_LED_COUNT (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL) -/* Encoder Configuration */ +/* Encoder used pins */ #define ENCODERS_PAD_A { A10 } #define ENCODERS_PAD_B { B5 } + +/* Specifies the number of pulses the encoder registers between each detent */ #define ENCODER_RESOLUTION 4 -#define ENCODER_DEFAULT_POS 0x3 diff --git a/keyboards/keychron/q2/rev_0111/keymaps/via/config.h b/keyboards/keychron/q2/rev_0111/keymaps/via/config.h deleted file mode 100644 index 84d17b3721aa..000000000000 --- a/keyboards/keychron/q2/rev_0111/keymaps/via/config.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright 2022 @ Keychron (https://www.keychron.com) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -/* Set dynamic keymap layer counts to 5 */ -#define DYNAMIC_KEYMAP_LAYER_COUNT 5 diff --git a/keyboards/keychron/q2/rev_0111/rev_0111.c b/keyboards/keychron/q2/rev_0111/rev_0111.c index d92b5be38226..1bada84daac2 100644 --- a/keyboards/keychron/q2/rev_0111/rev_0111.c +++ b/keyboards/keychron/q2/rev_0111/rev_0111.c @@ -97,32 +97,27 @@ const ckled2001_led PROGMEM g_ckled2001_leds[RGB_MATRIX_LED_COUNT] = { {1, F_16, D_16, E_16}, }; -#define __ NO_LED - led_config_t g_led_config = { - { - // Key Matrix to LED Index - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, - { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 }, - { 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 65, 42, 43 }, - { 44, __, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, __, 55, 56 }, - { 57, 58, 59, __, __, __, 60, __, __, __, 61, 62, 63, 64, 66 } + { + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, + { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 }, + { 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 65, 42, 43 }, + { 44, NO_LED, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, NO_LED, 55, 56 }, + { 57, 58, 59, NO_LED, NO_LED, NO_LED, 60, NO_LED, NO_LED, NO_LED, 61, 62, 63, 64, 66 }, }, { - // LED Index to Physical Position - {0,0}, {15,0}, {29,0}, {44,0}, {59,0}, {73,0}, {88,0}, {103,0}, {118,0}, {132,0}, {147,0}, {162,0}, {176,0}, {198,0}, {224,0}, // {244,-4} - {4,15}, {22,15}, {37,15}, {51,15}, {66,15}, {81,15}, {95,15}, {110,15}, {125,15}, {140,15}, {154,15}, {169,15}, {184,15}, {202,15}, {224,15}, - {6,30}, {26,30}, {40,30}, {55,30}, {70,30}, {84,30}, {99,30}, {114,30}, {129,30}, {143,30}, {158,30}, {173,30}, {196,30}, {224,30}, - {9,45}, {33,45}, {48,45}, {62,45}, {77,45}, {92,45}, {106,45}, {121,45}, {136,45}, {151,45}, {165,45}, {185,45}, {209,49}, - {2,60}, {20,60}, {39,60}, {94,60}, {147,60}, {162,60}, {176,60}, {195,64}, {209,64}, {224,64} + {0, 0}, {15, 0}, {30, 0}, {45, 0}, {60, 0}, {75, 0}, {90, 0}, {105, 0}, {120, 0}, {135, 0}, {150, 0}, {165, 0}, {180, 0}, {195, 0}, {224, 0}, + {0,16}, {15,16}, {30,16}, {45,16}, {60,16}, {75,16}, {90,16}, {105,16}, {120,16}, {135,16}, {150,16}, {165,16}, {180,16}, {195,16}, {224,16}, + {0,32}, {15,32}, {30,32}, {45,32}, {60,32}, {75,32}, {90,32}, {105,32}, {120,32}, {135,32}, {150,32}, {165,32}, {195,32}, {224,32}, + {0,48}, {30,48}, {45,48}, {60,48}, {75,48}, {90,48}, {105,48}, {120,48}, {135,48}, {150,48}, {165,48}, {180,48}, {210,48}, + {0,64}, {15,64}, {30,64}, {90,64}, {150,64}, {165,64}, {180,64}, {195,64}, {210,64}, {224,64}, }, { - // RGB LED Index to Flag - 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, - 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 + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, } }; #endif @@ -132,26 +127,11 @@ bool encoder_update_kb(uint8_t index, bool clockwise) { if (!encoder_update_user(index, clockwise)) { return false; } if (index == 0) { if (clockwise) { - tap_code_delay(KC_VOLU, TAP_CODE_DELAY); + tap_code_delay(KC_VOLU, 10); } else { - tap_code_delay(KC_VOLD, TAP_CODE_DELAY); + tap_code_delay(KC_VOLD, 10); } } return true; } - -void encoder0_pad_cb(void *param) { - (void)param; - - encoder_insert_state(0); -} - -void keyboard_post_init_kb(void) { - pin_t encoders_pad_a[] = ENCODERS_PAD_A; - pin_t encoders_pad_b[] = ENCODERS_PAD_B; - palEnableLineEvent(encoders_pad_a[0], PAL_EVENT_MODE_BOTH_EDGES); - palEnableLineEvent(encoders_pad_b[0], PAL_EVENT_MODE_BOTH_EDGES); - palSetLineCallback(encoders_pad_a[0], encoder0_pad_cb, NULL); - palSetLineCallback(encoders_pad_b[0], encoder0_pad_cb, NULL); -} #endif diff --git a/keyboards/keychron/q2/rev_0111/rev_0111.h b/keyboards/keychron/q2/rev_0111/rev_0111.h index 9ae527a98a4e..5033db61fc4e 100644 --- a/keyboards/keychron/q2/rev_0111/rev_0111.h +++ b/keyboards/keychron/q2/rev_0111/rev_0111.h @@ -27,11 +27,11 @@ K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3D, K3E, \ K40, K41, K42, K46, K4A, K4B, K4C, K4D, K2C, K4E \ ) { \ - { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, }, \ - { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, }, \ - { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, K2E, }, \ - { K30, XXX, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, XXX, K3D, K3E, }, \ - { K40, K41, K42, XXX, XXX, XXX, K46, K47, K48, XXX, K4A, K4B, K4C, K4D, K4E, } \ + { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, }, \ + { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, }, \ + { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, K2E, }, \ + { K30, XXX, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, XXX, K3D, K3E, }, \ + { K40, K41, K42, XXX, XXX, XXX, K46, K47, K48, XXX, K4A, K4B, K4C, K4D, K4E, } \ } #define LAYOUT_ansi_67( \ K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E,\ @@ -40,9 +40,9 @@ K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3D, K3E, \ K40, K41, K42, K46, K4A, K4B, K4C, K4D, K2C, K4E \ ) { \ - { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, }, \ - { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, }, \ - { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, K2E, }, \ - { K30, XXX, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, XXX, K3D, K3E, }, \ - { K40, K41, K42, XXX, XXX, XXX, K46, XXX, XXX, XXX, K4A, K4B, K4C, K4D, K4E, } \ + { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, }, \ + { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, }, \ + { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, K2E, }, \ + { K30, XXX, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, XXX, K3D, K3E, }, \ + { K40, K41, K42, XXX, XXX, XXX, K46, XXX, XXX, XXX, K4A, K4B, K4C, K4D, K4E, } \ } From 2a5161e05c3594037c1d1d4af2f579108fe47284 Mon Sep 17 00:00:00 2001 From: lalalademaxiya1 <2831039915@qq.com> Date: Mon, 21 Nov 2022 13:10:27 +0800 Subject: [PATCH 3/3] Add new feature --- quantum/encoder.c | 15 ++++++++++----- quantum/encoder.h | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/quantum/encoder.c b/quantum/encoder.c index c81c73975267..453ccee2bd3e 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -40,6 +40,7 @@ extern volatile bool isLeftHand; static pin_t encoders_pad_a[NUM_ENCODERS_MAX_PER_SIDE] = ENCODERS_PAD_A; static pin_t encoders_pad_b[NUM_ENCODERS_MAX_PER_SIDE] = ENCODERS_PAD_B; +static bool encoder_external_update[NUM_ENCODERS] = {false}; #ifdef ENCODER_RESOLUTIONS static uint8_t encoder_resolutions[NUM_ENCODERS] = ENCODER_RESOLUTIONS; @@ -225,6 +226,7 @@ bool encoder_read(void) { encoder_state[i] <<= 2; encoder_state[i] |= new_status; changed |= encoder_update(i, encoder_state[i]); + encoder_external_update[i] = false; } } return changed; @@ -269,8 +271,11 @@ void encoder_update_raw(uint8_t *slave_state) { } #endif -void encoder_insert_state(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]; -} \ No newline at end of file +void encoder_insert_state(void) { + for (uint8_t i = 0; i < thisCount; i++) { + encoder_state[i] <<= 2; + encoder_state[i] |= (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); + encoder_pulses[i] += encoder_LUT[encoder_state[i] & 0xF]; + encoder_external_update[i] = true; + } +} diff --git a/quantum/encoder.h b/quantum/encoder.h index 54c97c8dc6fc..bc02889ee8f8 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_insert_state(void); #ifdef SPLIT_KEYBOARD