Update x4

This commit is contained in:
lalalademaxiya1 2023-10-16 17:04:06 +08:00
parent 74f31a21e8
commit 47ea587ef0
16 changed files with 108 additions and 10 deletions

View File

@ -1,9 +1,4 @@
VIA_ENABLE = yes
ENCODER_MAP_ENABLE = yes
<<<<<<< HEAD
include keyboards/keychron/common/common.mk
=======
VPATH += keyboards/keychron/common
SRC += keychron_common.c
>>>>>>> temp

View File

@ -1 +0,0 @@
VIA_ENABLE = yes

View File

@ -24,6 +24,9 @@
/* RGB Matrix Configuration */
# define LED_MATRIX_LED_COUNT 81
/* Winlock indicator */
# define LED_WIN_LOCK_INDEX 72
/* Scan phase of led driver set as MSKPHASE_6CHANNEL(defined as 0x03 in CKLED2001.h) */
# define PHASE_CHANNEL MSKPHASE_6CHANNEL
# define CKLED2001_CURRENT_TUNE \

View File

@ -59,3 +59,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______),
};
#if defined(ENCODER_MAP_ENABLE)
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
[WIN_BASE] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU)},
[WIN_FN] = { ENCODER_CCW_CW(BL_DOWN, BL_UP)},
[WIN_L2] = { ENCODER_CCW_CW(_______, _______)},
[WIN_L3] = { ENCODER_CCW_CW(_______, _______)}
};
#endif // ENCODER_MAP_ENABLE

View File

@ -0,0 +1 @@
ENCODER_MAP_ENABLE = yes

View File

@ -59,6 +59,15 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______),
};
#if defined(ENCODER_MAP_ENABLE)
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
[WIN_BASE] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU)},
[WIN_FN] = { ENCODER_CCW_CW(BL_DOWN, BL_UP)},
[WIN_L2] = { ENCODER_CCW_CW(_______, _______)},
[WIN_L3] = { ENCODER_CCW_CW(_______, _______)}
};
#endif // ENCODER_MAP_ENABLE
// clang-format on
void housekeeping_task_user(void) {

View File

@ -1,3 +1,4 @@
VIA_ENABLE = yes
ENCODER_MAP_ENABLE = yes
include keyboards/keychron/common/common.mk

View File

@ -59,3 +59,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______),
};
#if defined(ENCODER_MAP_ENABLE)
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
[WIN_BASE] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU)},
[WIN_FN] = { ENCODER_CCW_CW(BL_DOWN, BL_UP)},
[WIN_L2] = { ENCODER_CCW_CW(_______, _______)},
[WIN_L3] = { ENCODER_CCW_CW(_______, _______)}
};
#endif // ENCODER_MAP_ENABLE

View File

@ -0,0 +1,2 @@
VIA_ENABLE = yes
ENCODER_MAP_ENABLE = yes

View File

@ -10,11 +10,11 @@ A customizable 75% keyboard.
Make example for this keyboard (after setting up your build environment):
make keychron/x4/ansi/red:default
make keychron/x4/ansi_encoder/red:default
Flashing example for this keyboard:
make keychron/x4/ansi/red:default:flash
make keychron/x4/ansi_encoder/red:default:flash
## bootloader

View File

@ -16,6 +16,8 @@
#include "quantum.h"
static uint8_t win_lock_state = 0;
void eeconfig_init_kb(void) {
#if (EECONFIG_KB_DATA_SIZE) == 0
// Reset Keyboard EEPROM value to blank, rather than to a set value
@ -25,5 +27,63 @@ void eeconfig_init_kb(void) {
keymap_config.nkro = 1;
eeconfig_update_keymap(keymap_config.raw);
win_lock_state = 0;
eeconfig_update_user_datablock(&win_lock_state);
eeconfig_init_user();
}
void keyboard_post_init_kb(void) {
eeconfig_read_user_datablock(&win_lock_state);
keyboard_post_init_user();
}
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
if (!process_record_user(keycode, record)) {
return false;
}
switch (keycode) {
#ifdef LED_MATRIX_ENABLE
case BL_TOGG:
if (record->event.pressed) {
switch (led_matrix_get_flags()) {
case LED_FLAG_ALL: {
led_matrix_set_flags(LED_FLAG_NONE);
led_matrix_set_value_all(0);
} break;
default: {
led_matrix_set_flags(LED_FLAG_ALL);
} break;
}
}
if (!led_matrix_is_enabled()) {
led_matrix_set_flags(LED_FLAG_ALL);
led_matrix_enable();
}
return false;
#endif
case GU_TOGG:
if (record->event.pressed) {
win_lock_state = !win_lock_state;
eeconfig_update_user_datablock(&win_lock_state);
}
return true;
default:
return true;
}
}
bool led_matrix_indicators_kb(void) {
if (!led_matrix_indicators_user()) {
return false;
}
if (win_lock_state) {
led_matrix_set_value(LED_WIN_LOCK_INDEX, 0xFF);
} else {
if (!led_matrix_get_flags()) {
led_matrix_set_value(LED_WIN_LOCK_INDEX, 0);
}
}
return true;
}

View File

@ -61,6 +61,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_interrupt_update[NUM_ENCODERS] = {false};
// encoder counts
static uint8_t thisCount;
@ -248,15 +249,23 @@ 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) {
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_interrupt_update[i] = false;
}
}
return changed;
}
void encoder_interrupt_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_interrupt_update[index] = true;
}
#ifdef SPLIT_KEYBOARD
void last_encoder_activity_trigger(void);

View File

@ -27,10 +27,11 @@ bool encoder_read(void);
bool encoder_update_kb(uint8_t index, bool clockwise);
bool encoder_update_user(uint8_t index, bool clockwise);
void encoder_interrupt_read(uint8_t index);
#ifdef SPLIT_KEYBOARD
void encoder_state_raw(uint8_t* slave_state);
void encoder_state_raw(uint8_t* slave_state);
void encoder_update_raw(uint8_t* slave_state);
# if defined(ENCODERS_PAD_A_RIGHT)