Update q11

This commit is contained in:
lalalademaxiya1 2023-03-01 14:22:12 +08:00
parent ae5da70c52
commit cc22ddb962
67 changed files with 366 additions and 216 deletions

View File

@ -37,6 +37,14 @@ uint8_t factory_reset_count = 0;
bool report_os_sw_state = false;
extern matrix_row_t matrix[MATRIX_ROWS];
#ifdef SPLIT_KEYBOARD
# ifdef RGB_MATRIX_ENABLE
uint8_t led_state = 0;
uint8_t light_test_state = 0;
HSV hsv;
# endif
#endif
__attribute__((weak)) bool process_record_keychron_ft(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case MO(1):
@ -123,6 +131,11 @@ static void factory_reset(void) {
rgb_matrix_enable();
}
rgb_matrix_init();
# ifdef SPLIT_KEYBOARD
led_state = rgb_matrix_get_mode();
hsv = rgb_matrix_get_hsv();
rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_COLOR);
# endif
#endif
}
@ -132,6 +145,9 @@ static void timer_3s_task(void) {
if (key_press_status == KEY_PRESS_FACTORY_RESET) {
factory_reset();
} else if (key_press_status == KEY_PRESS_LED_TEST) {
#ifdef SPLIT_KEYBOARD
rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_COLOR);
#endif
led_test_mode = LED_TEST_MODE_WHITE;
#ifdef LED_MATRIX_ENABLE
if (!led_matrix_is_enabled()) {
@ -153,6 +169,10 @@ static void timer_300ms_task(void) {
if (factory_reset_count++ > 6) {
timer_300ms_buffer = 0;
factory_reset_count = 0;
#ifdef SPLIT_KEYBOARD
rgb_matrix_mode_noeeprom(led_state);
rgb_matrix_sethsv_noeeprom(hsv.h, hsv.s, hsv.v);
#endif
} else {
timer_300ms_buffer = sync_timer_read32() == 0 ? 1 : sync_timer_read32();
}
@ -173,29 +193,53 @@ bool led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
#ifdef RGB_MATRIX_ENABLE
bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
if (factory_reset_count) {
for (uint8_t i = led_min; i <= led_max; i++) {
rgb_matrix_set_color(i, factory_reset_count % 2 ? 0 : RGB_RED);
if (rgb_matrix_get_mode() == RGB_MATRIX_SOLID_COLOR) {
if (factory_reset_count % 2) {
rgb_matrix_sethsv_noeeprom(HSV_RED);
} else {
rgb_matrix_sethsv_noeeprom(HSV_OFF);
}
} else {
for (uint8_t i = led_min; i <= led_max; i++) {
rgb_matrix_set_color(i, factory_reset_count % 2 ? 0 : RGB_RED);
}
}
} else if (led_test_mode) {
switch (led_test_mode) {
case LED_TEST_MODE_WHITE:
for (uint8_t i = led_min; i <= led_max; i++) {
rgb_matrix_set_color(i, RGB_WHITE);
if (rgb_matrix_get_mode() == RGB_MATRIX_SOLID_COLOR) {
rgb_matrix_sethsv_noeeprom(HSV_WHITE);
} else {
for (uint8_t i = led_min; i <= led_max; i++) {
rgb_matrix_set_color(i, RGB_WHITE);
}
}
break;
case LED_TEST_MODE_RED:
for (uint8_t i = led_min; i <= led_max; i++) {
rgb_matrix_set_color(i, RGB_RED);
if (rgb_matrix_get_mode() == RGB_MATRIX_SOLID_COLOR) {
rgb_matrix_sethsv_noeeprom(HSV_RED);
} else {
for (uint8_t i = led_min; i <= led_max; i++) {
rgb_matrix_set_color(i, RGB_RED);
}
}
break;
case LED_TEST_MODE_GREEN:
for (uint8_t i = led_min; i <= led_max; i++) {
rgb_matrix_set_color(i, RGB_GREEN);
if (rgb_matrix_get_mode() == RGB_MATRIX_SOLID_COLOR) {
rgb_matrix_sethsv_noeeprom(HSV_GREEN);
} else {
for (uint8_t i = led_min; i <= led_max; i++) {
rgb_matrix_set_color(i, RGB_GREEN);
}
}
break;
case LED_TEST_MODE_BLUE:
for (uint8_t i = led_min; i <= led_max; i++) {
rgb_matrix_set_color(i, RGB_BLUE);
if (rgb_matrix_get_mode() == RGB_MATRIX_SOLID_COLOR) {
rgb_matrix_sethsv_noeeprom(HSV_BLUE);
} else {
for (uint8_t i = led_min; i <= led_max; i++) {
rgb_matrix_set_color(i, RGB_BLUE);
}
}
break;
default:
@ -258,7 +302,23 @@ bool via_command_kb(uint8_t *data, uint8_t length) {
switch (data[1]) {
#if defined(RGB_MATRIX_ENABLE)
case FACTORY_TEST_CMD_BACKLIGHT:
led_test_mode = data[2];
led_test_mode = data[2];
# if defined(SPLIT_KEYBOARD)
if (led_test_mode) {
light_test_state += 1;
if (light_test_state == 1) {
led_state = rgb_matrix_get_mode();
hsv = rgb_matrix_get_hsv();
}
rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_COLOR);
} else {
if (light_test_state) {
light_test_state = 0;
rgb_matrix_mode_noeeprom(led_state);
rgb_matrix_sethsv_noeeprom(hsv.h, hsv.s, hsv.v);
}
}
# endif
timer_3s_buffer = 0;
break;
#endif
@ -287,9 +347,3 @@ bool via_command_kb(uint8_t *data, uint8_t length) {
}
return false;
}
#if defined(MCU) && (MCU == STM32L432)
void restart_usb_driver(USBDriver *usbp) {
(void)usbp;
}
#endif

View File

@ -36,6 +36,13 @@ enum {
extern uint16_t key_press_status;
extern uint32_t timer_3s_buffer;
#ifdef SPLIT_KEYBOARD
# ifdef RGB_MATRIX_ENABLE
extern uint8_t led_state;
extern uint8_t light_test_state;
extern HSV hsv;
# endif
#endif
void housekeeping_task_keychron_ft(void);
bool process_record_keychron_ft(uint16_t keycode, keyrecord_t *record);

View File

@ -17,81 +17,77 @@
#include "keychron_ft_common.h"
#include "split_util.h"
bool process_record_ft(uint16_t keycode, keyrecord_t *record) {
static bool skip_next_step = false;
bool process_record_keychron_ft(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case MO(1):
case MO(2):
case MO(3):
case MO(4):
if (record->event.pressed) {
key_press_status |= KEY_PRESS_FN;
key_press_status |= KEY_PRESS_STEP_0;
} else {
key_press_status &= ~KEY_PRESS_FN;
key_press_status &= ~KEY_PRESS_STEP_0;
timer_3s_buffer = 0;
}
return true;
case KC_STEP_1:
#if defined(KEYBOARD_keychron_q11_q11_ansi_stm32l432_ec11)
case KC_ESC:
if (is_transport_connected() || !is_keyboard_left()) {
return true;
} else {
skip_next_step = true;
}
case KC_STEP_5:
case KC_EQL:
if ((is_transport_connected() || is_keyboard_left()) && !skip_next_step) {
return true;
} else {
skip_next_step = true;
}
case KC_STEP_9:
case KC_J:
if (!is_transport_connected() && !skip_next_step) {
return true;
}
skip_next_step = false;
#endif // KEYBOARD_keychron_q11_q11_ansi_stm32l432_ec11
if (record->event.pressed) {
key_press_status |= KEY_PRESS_STEP_1;
if (key_press_status == KEY_PRESS_FACTORY_RESET) {
timer_3s_buffer = sync_timer_read32();
timer_3s_buffer = sync_timer_read32() == 0 ? 1 : sync_timer_read32();
}
} else {
key_press_status &= ~KEY_PRESS_STEP_1;
timer_3s_buffer = 0;
}
return true;
case KC_STEP_2:
#if defined(KEYBOARD_keychron_q11_q11_ansi_stm32l432_ec11)
case KC_6:
if (is_transport_connected() || !is_keyboard_left()) {
return true;
} else {
skip_next_step = true;
}
case KC_STEP_6:
case KC_M:
if ((is_transport_connected() || is_keyboard_left()) && !skip_next_step) {
return true;
} else {
skip_next_step = true;
}
case KC_STEP_A:
case KC_Z:
if (!is_transport_connected() && !skip_next_step) {
return true;
}
skip_next_step = false;
#endif // KEYBOARD_keychron_q11_q11_ansi_stm32l432_ec11
if (record->event.pressed) {
key_press_status |= KEY_PRESS_STEP_2;
if (key_press_status == KEY_PRESS_FACTORY_RESET) {
timer_3s_buffer = sync_timer_read32();
timer_3s_buffer = sync_timer_read32() == 0 ? 1 : sync_timer_read32();
}
} else {
key_press_status &= ~KEY_PRESS_STEP_2;
timer_3s_buffer = 0;
}
return true;
case KC_STEP_3:
#if defined(KEYBOARD_keychron_q11_q11_ansi_stm32l432_ec11)
case KC_STEP_7:
#endif // KEYBOARD_keychron_q11_q11_ansi_stm32l432_ec11
case KC_LSFT:
case KC_RIGHT:
if (record->event.pressed) {
key_press_status |= KEY_PRESS_STEP_3;
if (led_test_mode) {
@ -99,31 +95,25 @@ bool process_record_ft(uint16_t keycode, keyrecord_t *record) {
led_test_mode = LED_TEST_MODE_WHITE;
}
} else if (key_press_status == KEY_PRESS_LED_TEST) {
timer_3s_buffer = sync_timer_read32();
timer_3s_buffer = sync_timer_read32() == 0 ? 1 : sync_timer_read32();
}
} else {
key_press_status &= ~KEY_PRESS_STEP_3;
timer_3s_buffer = 0;
}
return true;
case KC_STEP_4:
#if defined(KEYBOARD_keychron_q11_q11_ansi_stm32l432_ec11)
case KC_STEP_8:
#endif // KEYBOARD_keychron_q11_q11_ansi_stm32l432_ec11
case KC_5:
case KC_HOME:
if (record->event.pressed) {
key_press_status |= KEY_PRESS_STEP_4;
if (led_test_mode) {
led_test_mode = LED_TEST_MODE_OFF;
#if defined(KEYBOARD_keychron_q11_q11_ansi_stm32l432_ec11) && defined(RGB_MATRIX_ENABLE)
rgb_matrix_mode_noeeprom(led_state);
rgb_matrix_sethsv_noeeprom(hsv.h, hsv.s, hsv.v);
#endif
} else if (key_press_status == KEY_PRESS_LED_TEST) {
#if defined(KEYBOARD_keychron_q11_q11_ansi_stm32l432_ec11) && defined(RGB_MATRIX_ENABLE)
led_state = rgb_matrix_get_mode();
hsv = rgb_matrix_get_hsv();
#endif
timer_3s_buffer = sync_timer_read32();
led_state = rgb_matrix_get_mode();
hsv = rgb_matrix_get_hsv();
timer_3s_buffer = sync_timer_read32() == 0 ? 1 : sync_timer_read32();
}
} else {
key_press_status &= ~KEY_PRESS_STEP_4;

View File

@ -46,3 +46,7 @@ bool dip_switch_update_kb(uint8_t index, bool active) {
return true;
}
#endif
void restart_usb_driver(USBDriver *usbp) {
(void)usbp;
}

View File

@ -8,11 +8,11 @@ A customizable 75% split keyboard.
Make example for this keyboard (after setting up your build environment):
make keychron/q11/q11_ansi_stm32l432:default
make keychron/q11/ansi_encoder:default
Flashing example for this keyboard:
make keychron/q11/q11_ansi_stm32l432:default:flash
make keychron/q11/ansi_encoder:default:flash
**Reset Key**: Hold down the key located at *K01*, which programmed as *Esc* while plugging in the keyboard.

View File

@ -17,15 +17,10 @@
#pragma once
/* key matrix pins */
#define MATRIX_ROW_PINS { B5, B4, B3, A15, A14, A13 }
#define MATRIX_COL_PINS { C14, C15, A0, A1, A2, A3, A4, A5, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN }
/* Pin connected to DS of 74HC595 */
#define DATA_PIN_74HC595 A7
/* Pin connected to SH_CP of 74HC595 */
#define CLOCK_PIN_74HC595 B1
/* Pin connected to ST_CP of 74HC595 */
#define LATCH_PIN_74HC595 B0
#define MATRIX_ROW_PINS \
{ B5, B4, B3, A15, A14, A13 }
#define MATRIX_COL_PINS \
{ C14, C15, A0, A1, A2, A3, A4, A5, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN }
/* COL2ROW or ROW2COL */
#define DIODE_DIRECTION ROW2COL
@ -34,7 +29,10 @@
#define MATRIX_MASKED
/* DIP switch */
#define DIP_SWITCH_MATRIX_GRID { {5,4} }
#define DIP_SWITCH_MATRIX_GRID \
{ \
{ 5, 4 } \
}
#define SCAN_COUNT_MAX 100
/* RGB Matrix Driver Configuration */
@ -47,7 +45,7 @@
#define I2C1_TIMINGR_SCLDEL 3U
#define I2C1_TIMINGR_SDADEL 0U
#define I2C1_TIMINGR_SCLH 15U
#define I2C1_TIMINGR_SCLL 51U
#define I2C1_TIMINGR_SCLL 30U
/* Scan phase of led driver set as MSKPHASE_9CHANNEL(defined as 0x03 in CKLED2001.h) */
#define PHASE_CHANNEL MSKPHASE_9CHANNEL
@ -91,9 +89,15 @@
#define ENABLE_RGB_MATRIX_PIXEL_RAIN
// #define ENABLE_RGB_MATRIX_PIXEL_FLOW
// #define ENABLE_RGB_MATRIX_PIXEL_FRACTAL
#define RGB_MATRIX_FRAMEBUFFER_EFFECTS
// enabled only if RGB_MATRIX_FRAMEBUFFER_EFFECTS is defined
#define ENABLE_RGB_MATRIX_TYPING_HEATMAP
#define ENABLE_RGB_MATRIX_DIGITAL_RAIN
#define RGB_MATRIX_KEYPRESSES
// enabled only of RGB_MATRIX_KEYPRESSES or RGB_MATRIX_KEYRELEASES is defined
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
// #define ENABLE_RGB_MATRIX_SOLID_REACTIVE
@ -108,10 +112,3 @@
#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

View File

@ -17,6 +17,6 @@
#pragma once
#define HAL_USE_I2C TRUE
#define PAL_USE_CALLBACKS TRUE
#define PAL_USE_CALLBACKS FALSE
#include_next <halconf.h>

View File

@ -26,7 +26,8 @@
#define DRIVER_2_LED_TOTAL 40
#define RGB_MATRIX_LED_COUNT (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)
#define CKLED2001_CURRENT_TUNE { 0xA0, 0xA0, 0x4D, 0xA0, 0xA0, 0x4D, 0xA0, 0xA0, 0x4D, 0xA0, 0xA0, 0x4D }
#define CKLED2001_CURRENT_TUNE \
{ 0xA0, 0xA0, 0x4D, 0xA0, 0xA0, 0x4D, 0xA0, 0xA0, 0x4D, 0xA0, 0xA0, 0x4D }
/* Enable caps-lock LED */
#define CAPS_LOCK_LED_INDEX 45

View File

@ -6,7 +6,7 @@
"usb": {
"vid": "0x3434",
"pid": "0x0314",
"device_version": "1.0.2"
"device_version": "1.0.3"
},
"processor": "STM32L432",
"bootloader": "stm32-dfu",
@ -73,7 +73,7 @@
{"matrix":[3, 9], "x":9.75, "y":3.25},
{"matrix":[3,10], "x":10.75, "y":3.25},
{"matrix":[3,11], "x":11.75, "y":3.25},
{"matrix":[3,12], "x":12.75, "y":3.25},
{"matrix":[3,13], "x":12.75, "y":3.25},
{"matrix":[2,13], "x":13.75, "y":2.25, "w":1.25, "h":2},
{"matrix":[3,15], "x":15.25, "y":3.25},

View File

@ -152,4 +152,4 @@ led_config_t g_led_config = {
}
};
#endif // RGB_MATRIX_ENABLE
#endif

View File

@ -16,6 +16,7 @@
#include QMK_KEYBOARD_H
#include "keychron_common.h"
#include "keychron_ft_common.h"
// clang-format off
@ -64,27 +65,17 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
void housekeeping_task_user(void) {
housekeeping_task_keychron();
housekeeping_task_keychron_ft();
}
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

View File

@ -0,0 +1,4 @@
VIA_ENABLE = yes
VPATH += keyboards/keychron/common
SRC += keychron_common.c keychron_ft_common.c

View File

@ -22,5 +22,4 @@ OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE
# custom matrix setup
CUSTOM_MATRIX = lite
VPATH ?= keyboards/keychron/common
SRC += matrix.c

View File

@ -21,12 +21,14 @@
#define DRIVER_2_LED_TOTAL 40
#define RGB_MATRIX_LED_COUNT (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)
#define CKLED2001_CURRENT_TUNE { 0xA0, 0xA0, 0x4D, 0xA0, 0xA0, 0x4D, 0xA0, 0xA0, 0x4D, 0xA0, 0xA0, 0x4D }
#define CKLED2001_CURRENT_TUNE \
{ 0xA0, 0xA0, 0x4D, 0xA0, 0xA0, 0x4D, 0xA0, 0xA0, 0x4D, 0xA0, 0xA0, 0x4D }
/* Encoder Configuration */
#define ENCODERS_PAD_A { A10 }
#define ENCODERS_PAD_B { A8 }
#define ENCODER_RESOLUTION 4
#define ENCODERS_PAD_A \
{ A10 }
#define ENCODERS_PAD_B \
{ A8 }
#define ENCODER_DEFAULT_POS 0x3
/* Enable caps-lock LED */

View File

@ -6,7 +6,7 @@
"usb": {
"vid": "0x3434",
"pid": "0x0315",
"device_version": "1.0.2"
"device_version": "1.0.3"
},
"processor": "STM32L432",
"bootloader": "stm32-dfu",
@ -73,7 +73,7 @@
{"matrix":[3, 9], "x":9.75, "y":3.25},
{"matrix":[3,10], "x":10.75, "y":3.25},
{"matrix":[3,11], "x":11.75, "y":3.25},
{"matrix":[3,12], "x":12.75, "y":3.25},
{"matrix":[3,13], "x":12.75, "y":3.25},
{"matrix":[2,13], "x":13.75, "y":2.25, "w":1.25, "h":2},
{"matrix":[3,15], "x":15.25, "y":3.25},

View File

@ -152,29 +152,4 @@ led_config_t g_led_config = {
}
};
#endif // RGB_MATRIX_ENABLE
#ifdef ENCODER_ENABLE
void encoder0_pad_cb(void *param) {
(void)param;
encoder_insert_state();
}
void keyboard_post_init_kb(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);
}
// allow user keymaps to do custom post_init
keyboard_post_init_user();
}
#endif

View File

@ -16,6 +16,7 @@
#include QMK_KEYBOARD_H
#include "keychron_common.h"
#include "keychron_ft_common.h"
// clang-format off
@ -75,27 +76,17 @@ const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = {
void housekeeping_task_user(void) {
housekeeping_task_keychron();
housekeeping_task_keychron_ft();
}
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

View File

@ -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

View File

@ -23,5 +23,4 @@ OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE
# custom matrix setup
CUSTOM_MATRIX = lite
VPATH ?= keyboards/keychron/common
SRC += matrix.c

View File

@ -0,0 +1,221 @@
/* Copyright 2023 @ 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/>.
*/
#include "quantum.h"
#define HC595_STCP B0
#define HC595_SHCP B1
#define HC595_DS A7
pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
#define ROWS_PER_HAND (MATRIX_ROWS)
static inline void setPinOutput_writeLow(pin_t pin) {
ATOMIC_BLOCK_FORCEON {
setPinOutput(pin);
writePinLow(pin);
}
}
static inline void setPinOutput_writeHigh(pin_t pin) {
ATOMIC_BLOCK_FORCEON {
setPinOutput(pin);
writePinHigh(pin);
}
}
static inline void setPinInputHigh_atomic(pin_t pin) {
ATOMIC_BLOCK_FORCEON {
setPinInputHigh(pin);
}
}
static inline uint8_t readMatrixPin(pin_t pin) {
if (pin != NO_PIN) {
return readPin(pin);
} else {
return 1;
}
}
static inline void HC595_delay(uint16_t n) {
while (n-- > 0) {
asm volatile("nop" ::: "memory");
};
}
static void HC595_output(uint8_t data) {
ATOMIC_BLOCK_FORCEON {
for (uint8_t i = 0; i < 8; i++) {
if (data & 0x1) {
writePinHigh(HC595_DS);
} else {
writePinLow(HC595_DS);
}
data = data >> 1;
writePinHigh(HC595_SHCP);
HC595_delay(3);
writePinLow(HC595_SHCP);
}
writePinHigh(HC595_STCP);
HC595_delay(3);
writePinLow(HC595_STCP);
}
}
static void HC595_output_byte(uint8_t data) {
ATOMIC_BLOCK_FORCEON {
if (data & 0x1) {
writePinHigh(HC595_DS);
} else {
writePinLow(HC595_DS);
}
writePinHigh(HC595_SHCP);
HC595_delay(3);
writePinLow(HC595_SHCP);
writePinHigh(HC595_STCP);
HC595_delay(3);
writePinLow(HC595_STCP);
}
}
static bool select_col(uint8_t col) {
pin_t pin = col_pins[col];
if (pin != NO_PIN) {
setPinOutput_writeLow(pin);
return true;
} else {
if (col == 8) {
HC595_output_byte(0x00);
}
return true;
}
return false;
}
void select_all_cols(void) {
for (uint8_t x = 0; x < MATRIX_COLS; x++) {
pin_t pin = col_pins[x];
if (pin != NO_PIN) {
setPinOutput_writeLow(pin);
} else {
if (x == 8)
HC595_output(0x00);
}
}
}
static void unselect_col(uint8_t col) {
pin_t pin = col_pins[col];
if (pin != NO_PIN) {
#ifdef MATRIX_UNSELECT_DRIVE_HIGH
setPinOutput_writeHigh(pin);
#else
setPinInputHigh_atomic(pin);
#endif
} else {
HC595_output_byte(0x01);
}
}
static void unselect_cols(void) {
// unselect column pins
for (uint8_t x = 0; x < MATRIX_COLS; x++) {
pin_t pin = col_pins[x];
if (pin != NO_PIN) {
#ifdef MATRIX_UNSELECT_DRIVE_HIGH
setPinOutput_writeHigh(pin);
#else
setPinInputHigh_atomic(pin);
#endif
}
if (x == 8)
HC595_output(0xFF);
}
}
static void matrix_init_pins(void) {
setPinOutput(HC595_DS);
setPinOutput(HC595_SHCP);
setPinOutput(HC595_STCP);
#ifdef MATRIX_UNSELECT_DRIVE_HIGH
for (uint8_t x = 0; x < MATRIX_COLS; x++) {
if (col_pins[x] != NO_PIN) {
setPinOutput(col_pins[x]);
}
}
#endif
unselect_cols();
for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
if (row_pins[x] != NO_PIN) {
setPinInputHigh_atomic(row_pins[x]);
}
}
}
static void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col, matrix_row_t row_shifter) {
bool key_pressed = false;
// Select col
if (!select_col(current_col)) { // select col
return; // skip NO_PIN col
}
matrix_output_select_delay();
// For each row...
for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) {
// Check row pin state
if (readMatrixPin(row_pins[row_index]) == 0) {
// Pin LO, set col bit
current_matrix[row_index] |= row_shifter;
key_pressed = true;
} else {
// Pin HI, clear col bit
current_matrix[row_index] &= ~row_shifter;
}
}
// Unselect col
unselect_col(current_col);
matrix_output_unselect_delay(current_col, key_pressed); // wait for all Row signals to go HIGH
}
void matrix_init_custom(void) {
// initialize key pins
matrix_init_pins();
}
bool matrix_scan_custom(matrix_row_t current_matrix[]) {
matrix_row_t curr_matrix[MATRIX_ROWS] = {0};
// Set col, read rows
matrix_row_t row_shifter = MATRIX_ROW_SHIFTER;
for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++, row_shifter <<= 1) {
matrix_read_rows_on_col(curr_matrix, current_col, row_shifter);
}
bool changed = memcmp(current_matrix, curr_matrix, sizeof(curr_matrix)) != 0;
if (changed) memcpy(current_matrix, curr_matrix, sizeof(curr_matrix));
return changed;
}

View File

@ -26,7 +26,6 @@ const matrix_row_t matrix_mask[] = {
};
#ifdef DIP_SWITCH_ENABLE
bool dip_switch_update_kb(uint8_t index, bool active) {
if (!dip_switch_update_user(index, active)) {
return false;
@ -36,82 +35,4 @@ bool dip_switch_update_kb(uint8_t index, bool active) {
}
return true;
}
#endif
#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

View File

@ -1,5 +0,0 @@
VIA_ENABLE = yes
VPATH += keyboards/keychron/common
SRC += keychron_common.c
SRC += keychron_factory_test_common.c