Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new function for encode module #16954

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions keyboards/keychron/q2/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions keyboards/keychron/q2/halconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
#pragma once

#define HAL_USE_I2C TRUE
#ifdef ENCODER_ENABLE
#define PAL_USE_CALLBACKS TRUE
#endif

#include_next <halconf.h>
5 changes: 2 additions & 3 deletions keyboards/keychron/q2/rev_0111/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions keyboards/keychron/q2/rev_0111/keymaps/via/config.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#pragma once

/* Set dynamic keymap layer counts to 5 */
#define DYNAMIC_KEYMAP_LAYER_COUNT 5
56 changes: 38 additions & 18 deletions keyboards/keychron/q2/rev_0111/rev_0111.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
20 changes: 10 additions & 10 deletions keyboards/keychron/q2/rev_0111/rev_0111.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,\
Expand All @@ -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, } \
}
3 changes: 2 additions & 1 deletion keyboards/keychron/q2/rev_0111/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

This would remove any eeprom support from the board and make via support useless.

EEPROM_DRIVER = transient

# Enter lower-power sleep mode when on the ChibiOS idle thread
OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE
6 changes: 6 additions & 0 deletions quantum/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,9 @@ void encoder_update_raw(uint8_t* slave_state) {
if (changed) last_encoder_activity_trigger();
}
#endif

drashna marked this conversation as resolved.
Show resolved Hide resolved
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];
}
1 change: 1 addition & 0 deletions quantum/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down