Update Keychron C1 Pro and C2 Pro

This commit is contained in:
lalalademaxiya1 2023-03-18 10:46:17 +08:00
parent 85ed1f368b
commit 0bfd113682
45 changed files with 641 additions and 176 deletions

View File

@ -16,10 +16,6 @@
#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, A6, A7, B0, B1, A8, A9, A10, H3 }
/* If PH3 used with a stronger pull resistor then the following definition needs be included */
// #define MATRIX_UNSELECT_DRIVE_HIGH
@ -35,7 +31,8 @@
/* Scan phase of led driver set as MSKPHASE_9CHANNEL(defined as 0x03 in CKLED2001.h) */
#define PHASE_CHANNEL MSKPHASE_9CHANNEL
#define CKLED2001_CURRENT_TUNE { 0x9D, 0x9D, 0x44, 0x9D, 0x9D, 0x44, 0x9D, 0x9D, 0x44, 0x9D, 0x9D, 0x44 }
#define CKLED2001_CURRENT_TUNE \
{ 0x9D, 0x9D, 0x44, 0x9D, 0x9D, 0x44, 0x9D, 0x9D, 0x44, 0x9D, 0x9D, 0x44 }
/* turn off effects when suspended */
#define RGB_DISABLE_WHEN_USB_SUSPENDED
@ -74,9 +71,13 @@
#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
@ -90,6 +91,3 @@
// #define ENABLE_RGB_MATRIX_MULTISPLASH
#define ENABLE_RGB_MATRIX_SOLID_SPLASH
// #define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH
#define RGB_MATRIX_FRAMEBUFFER_EFFECTS
#define RGB_MATRIX_KEYPRESSES

View File

@ -8,6 +8,13 @@
"pid": "0x0510",
"device_version": "1.0.1"
},
"matrix_pins": {
"cols": ["C14", "C15", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "B0", "B1", "A8", "A9", "A10", "H3"],
"rows": ["B5", "B4", "B3", "A15", "A14", "A13"]
},
"diode_direction": "ROW2COL",
"processor": "STM32L432",
"bootloader": "stm32-dfu",
"layouts": {
"LAYOUT_ansi_87": {
"layout": [

View File

@ -15,7 +15,7 @@
*/
#include QMK_KEYBOARD_H
#include "keychron_common.h"
#include "keychron_common_ft.h"
// clang-format off
@ -26,6 +26,40 @@ enum layers{
WIN_FN
};
enum custom_keycodes {
KC_LOPTN = QK_KB_2, // TECH DEBT: Starts at QK_KB_2 to maintain ordering with VIA definitions. See #19884. Revert to QK_KB_0 when VIA catches up with QMK.
KC_ROPTN,
KC_LCMMD,
KC_RCMMD,
KC_SIRI,
KC_TASK_VIEW,
KC_FILE_EXPLORER,
KC_SCREEN_SHOT,
KC_CORTANA
};
#define KC_TASK KC_TASK_VIEW
#define KC_FLXP KC_FILE_EXPLORER
#define KC_SNAP KC_SCREEN_SHOT
#define KC_CRTA KC_CORTANA
typedef struct PACKED {
uint8_t len;
uint8_t keycode[3];
} key_combination_t;
bool is_siri_active = false;
uint32_t siri_timer = 0;
// clang-format off
key_combination_t key_comb_list[4] = {
{2, {KC_LWIN, KC_TAB}},
{2, {KC_LWIN, KC_E}},
{3, {KC_LSFT, KC_LCMD, KC_4}},
{2, {KC_LWIN, KC_C}}
};
static uint8_t mac_keycode[4] = {KC_LOPT, KC_ROPT, KC_LCMD, KC_RCMD};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[MAC_BASE] = LAYOUT_ansi_87(
KC_ESC, KC_BRID, KC_BRIU, KC_MCTL, KC_LPAD, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_SNAP, KC_SIRI, RGB_MOD,
@ -67,7 +101,13 @@ extern void rgb_matrix_update_pwm_buffers(void);
#endif // RGB_MATRIX_ENABLE
void housekeeping_task_user(void) {
housekeeping_task_keychron();
if (is_siri_active) {
if (sync_timer_elapsed32(siri_timer) >= 500) {
unregister_code(KC_LCMD);
unregister_code(KC_SPACE);
is_siri_active = false;
}
}
#if defined(RGB_MATRIX_ENABLE) && defined(CAPS_MAC_WIN_LOCK_LED_INDEX)
if (!rgb_matrix_is_enabled()) {
@ -88,24 +128,52 @@ void housekeeping_task_user(void) {
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if(!process_record_keychron(keycode, record)) {
if(!process_record_keychron_ft(keycode, record)) {
return false;
}
return true;
}
bool dip_switch_update_user(uint8_t index, bool active) {
if (!dip_switch_update_keychron(index, active)) {
return false;
bool process_record_keychron(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_LOPTN:
case KC_ROPTN:
case KC_LCMMD:
case KC_RCMMD:
if (record->event.pressed) {
register_code(mac_keycode[keycode - KC_LOPTN]);
} else {
unregister_code(mac_keycode[keycode - KC_LOPTN]);
}
return false; // Skip all further processing of this key
case KC_SIRI:
if (record->event.pressed) {
if (!is_siri_active) {
is_siri_active = true;
register_code(KC_LCMD);
register_code(KC_SPACE);
}
siri_timer = sync_timer_read32();
} else {
// Do something else when release
}
return false; // Skip all further processing of this key
case KC_TASK:
case KC_FLXP:
case KC_SNAP:
case KC_CRTA:
if (record->event.pressed) {
for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) {
register_code(key_comb_list[keycode - KC_TASK].keycode[i]);
}
} else {
for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) {
unregister_code(key_comb_list[keycode - KC_TASK].keycode[i]);
}
}
return false; // Skip all further processing of this key
default:
return true; // Process all other keycodes normally
}
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_ft_common.c

View File

@ -151,7 +151,7 @@ led_config_t g_led_config = {
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1,
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 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, 8,
1, 1, 1, 4, 1, 1, 4, 1, 1, 1, 1, 8,
}
};

View File

@ -16,10 +16,6 @@
#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, A6, A7, B0, B1, A8, A9, A10, H3 }
/* If PH3 used with a stronger pull resistor then the following definition needs be included */
// #define MATRIX_UNSELECT_DRIVE_HIGH

View File

@ -8,6 +8,13 @@
"pid": "0x0513",
"device_version": "1.0.1"
},
"matrix_pins": {
"cols": ["C14", "C15", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "B0", "B1", "A8", "A9", "A10", "H3"],
"rows": ["B5", "B4", "B3", "A15", "A14", "A13"]
},
"diode_direction": "ROW2COL",
"processor": "STM32L432",
"bootloader": "stm32-dfu",
"layouts": {
"LAYOUT_ansi_87": {
"layout": [

View File

@ -14,7 +14,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "quantum_keycodes.h"
#include QMK_KEYBOARD_H
#include "keychron_common.h"
@ -27,6 +26,40 @@ enum layers{
WIN_FN
};
enum custom_keycodes {
KC_LOPTN = QK_KB_2, // TECH DEBT: Starts at QK_KB_2 to maintain ordering with VIA definitions. See #19884. Revert to QK_KB_0 when VIA catches up with QMK.
KC_ROPTN,
KC_LCMMD,
KC_RCMMD,
KC_SIRI,
KC_TASK_VIEW,
KC_FILE_EXPLORER,
KC_SCREEN_SHOT,
KC_CORTANA
};
#define KC_TASK KC_TASK_VIEW
#define KC_FLXP KC_FILE_EXPLORER
#define KC_SNAP KC_SCREEN_SHOT
#define KC_CRTA KC_CORTANA
typedef struct PACKED {
uint8_t len;
uint8_t keycode[3];
} key_combination_t;
bool is_siri_active = false;
uint32_t siri_timer = 0;
// clang-format off
key_combination_t key_comb_list[4] = {
{2, {KC_LWIN, KC_TAB}},
{2, {KC_LWIN, KC_E}},
{3, {KC_LSFT, KC_LCMD, KC_4}},
{2, {KC_LWIN, KC_C}}
};
static uint8_t mac_keycode[4] = {KC_LOPT, KC_ROPT, KC_LCMD, KC_RCMD};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[MAC_BASE] = LAYOUT_ansi_87(
KC_ESC, KC_BRID, KC_BRIU, KC_MCTL, KC_LPAD, BL_DEC, BL_INC, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_SNAP, KC_SIRI, BL_STEP,
@ -68,7 +101,13 @@ extern void led_matrix_update_pwm_buffers(void);
#endif // LED_MATRIX_ENABLE
void housekeeping_task_user(void) {
housekeeping_task_keychron();
if (is_siri_active) {
if (sync_timer_elapsed32(siri_timer) >= 500) {
unregister_code(KC_LCMD);
unregister_code(KC_SPACE);
is_siri_active = false;
}
}
#if defined(LED_MATRIX_ENABLE) && defined(CAPS_LOCK_LED_INDEX) && defined(MAC_LOCK_LED_INDEX) && defined(WIN_LOCK_LED_INDEX)
if (!led_matrix_is_enabled()) {
@ -95,24 +134,52 @@ void housekeeping_task_user(void) {
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if(!process_record_keychron(keycode, record)) {
if (!process_record_keychron_ft(keycode, record)) {
return false;
}
return true;
}
bool dip_switch_update_user(uint8_t index, bool active) {
if (!dip_switch_update_keychron(index, active)) {
return false;
bool process_record_keychron(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_LOPTN:
case KC_ROPTN:
case KC_LCMMD:
case KC_RCMMD:
if (record->event.pressed) {
register_code(mac_keycode[keycode - KC_LOPTN]);
} else {
unregister_code(mac_keycode[keycode - KC_LOPTN]);
}
return false; // Skip all further processing of this key
case KC_SIRI:
if (record->event.pressed) {
if (!is_siri_active) {
is_siri_active = true;
register_code(KC_LCMD);
register_code(KC_SPACE);
}
siri_timer = sync_timer_read32();
} else {
// Do something else when release
}
return false; // Skip all further processing of this key
case KC_TASK:
case KC_FLXP:
case KC_SNAP:
case KC_CRTA:
if (record->event.pressed) {
for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) {
register_code(key_comb_list[keycode - KC_TASK].keycode[i]);
}
} else {
for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) {
unregister_code(key_comb_list[keycode - KC_TASK].keycode[i]);
}
}
return false; // Skip all further processing of this key
default:
return true; // Process all other keycodes normally
}
return true;
}
#ifdef LED_MATRIX_ENABLE
bool led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
if (!led_matrix_indicators_advanced_keychron(led_min, led_max)) {
return false;
}
return true;
}
#endif // LED_MATRIX_ENABLE`

View File

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

View File

@ -151,7 +151,7 @@ led_config_t g_led_config = {
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1,
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 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, 8, 8, 8,
1, 1, 1, 4, 1, 1, 4, 1, 1, 1, 1, 8, 8, 8,
}
};

View File

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

View File

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

View File

@ -16,14 +16,14 @@
#pragma once
/* COL2ROW or ROW2COL */
#define DIODE_DIRECTION ROW2COL
/* Set 0 if debouncing isn't needed */
#define DEBOUNCE 5
/* DIP switch */
#define DIP_SWITCH_MATRIX_GRID { { 5, 4 } }
#define DIP_SWITCH_MATRIX_GRID \
{ \
{ 5, 4 } \
}
#define SCAN_COUNT_MAX 100
/* Disable DIP switch in matrix data */
@ -39,8 +39,3 @@
#define I2C1_TIMINGR_SDADEL 0U
#define I2C1_TIMINGR_SCLH 15U
#define I2C1_TIMINGR_SCLL 51U
/* Enable receive custom command from host */
#define RAW_HID_CMD 0xAB
#define HOLD_ON_OTHER_KEY_PRESS

View File

@ -1,5 +1,7 @@
# Keychron C1 Pro
![Keychron C1 Pro](https://i.imgur.com/Svdm4lp.jpg[/img])
A customizable 100% keyboard.
* Keyboard Maintainer: [Keychron](https://github.com/keychron)
@ -8,15 +10,11 @@ A customizable 100% keyboard.
Make example for this keyboard (after setting up your build environment):
```bash
make keychron/c1/c1_ansi_rgb_stm32l432:default
```
make keychron/c1/c1_ansi_rgb_stm32l432:default
Flashing example for this keyboard:
```bash
make keychron/c1/c1_ansi_rgb_stm32l432:flash
```
make keychron/c1/c1_ansi_rgb_stm32l432:flash
**Reset Key**: Hold down the key located at *K00*, commonly programmed as *Esc* while plugging in the keyboard.

View File

@ -16,24 +16,12 @@
#pragma once
/* Key matrix pins */
#define MATRIX_ROW_PINS { B5, B4, B3, A15, A14, A13 }
#define MATRIX_COL_PINS { A10, A9, A8, B1, B0, A7, A6, A5, A4, A3, A2, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, C14 }
/* Pin connected to DS of 74HC595 */
#define DATA_PIN_74HC595 C15
/* Pin connected to SH_CP of 74HC595 */
#define CLOCK_PIN_74HC595 A1
/* Pin connected to ST_CP of 74HC595 */
#define LATCH_PIN_74HC595 A0
/* Pin used index start of 74HC595 */
#define PIN_START_74HC595 11
/* RGB Matrix Driver Configuration */
#define DRIVER_COUNT 2
#define DRIVER_ADDR_1 0b1110111
#define DRIVER_ADDR_2 0b1110100
#define CKLED2001_CURRENT_TUNE { 0xAA, 0xAA, 0x56, 0xAA, 0xAA, 0x56, 0xAA, 0xAA, 0x56, 0xAA, 0xAA, 0x56 }
#define CKLED2001_CURRENT_TUNE \
{ 0xAA, 0xAA, 0x56, 0xAA, 0xAA, 0x56, 0xAA, 0xAA, 0x56, 0xAA, 0xAA, 0x56 }
/* RGB Matrix Configuration */
#define DRIVER_1_LED_TOTAL 60
@ -81,9 +69,13 @@
#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
@ -97,6 +89,3 @@
// #define ENABLE_RGB_MATRIX_MULTISPLASH
#define ENABLE_RGB_MATRIX_SOLID_SPLASH
// #define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH
#define RGB_MATRIX_FRAMEBUFFER_EFFECTS
#define RGB_MATRIX_KEYPRESSES

View File

@ -8,6 +8,13 @@
"pid": "0x0520",
"device_version": "1.0.2"
},
"matrix_pins": {
"cols": ["A10", "A9", "A8", "B1", "B0", "A7", "A6", "A5", "A4", "A3", "A2", null, null, null, null, null, null, null, null, "C14"],
"rows": ["B5", "B4", "B3", "A15", "A14", "A13"]
},
"diode_direction": "ROW2COL",
"processor": "STM32L432",
"bootloader": "stm32-dfu",
"layouts": {
"LAYOUT_ansi_104": {
"layout": [

View File

@ -36,6 +36,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_P4, KC_P5, KC_P6,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_P1, KC_P2, KC_P3, KC_PENT,
KC_LCTL, KC_LOPT, KC_LCMD, KC_SPC, KC_RCMD, KC_ROPT, MO(MAC_FN), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT),
[MAC_FN] = LAYOUT_ansi_104(
_______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, RGB_TOG,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
@ -43,6 +44,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______),
[WIN_BASE] = LAYOUT_ansi_104(
KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_NO, RGB_MOD,
KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_INS, KC_HOME, KC_PGUP, KC_NUM, KC_PSLS, KC_PAST, KC_PMNS,
@ -50,6 +52,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_P4, KC_P5, KC_P6,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_P1, KC_P2, KC_P3, KC_PENT,
KC_LCTL, KC_LWIN, KC_LALT, KC_SPC, KC_RALT, KC_RWIN, MO(WIN_FN), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT),
[WIN_FN] = LAYOUT_ansi_104(
_______, KC_BRID, KC_BRIU, KC_TASK, KC_FLXP, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______, RGB_TOG,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,

View File

@ -15,7 +15,7 @@
*/
#include QMK_KEYBOARD_H
#include "keychron_common.h"
#include "keychron_ft_common.h"
// clang-format off
@ -26,6 +26,40 @@ enum layers{
WIN_FN
};
enum custom_keycodes {
KC_LOPTN = QK_KB_2, // TECH DEBT: Starts at QK_KB_2 to maintain ordering with VIA definitions. See #19884. Revert to QK_KB_0 when VIA catches up with QMK.
KC_ROPTN,
KC_LCMMD,
KC_RCMMD,
KC_SIRI,
KC_TASK_VIEW,
KC_FILE_EXPLORER,
KC_SCREEN_SHOT,
KC_CORTANA
};
#define KC_TASK KC_TASK_VIEW
#define KC_FLXP KC_FILE_EXPLORER
#define KC_SNAP KC_SCREEN_SHOT
#define KC_CRTA KC_CORTANA
typedef struct PACKED {
uint8_t len;
uint8_t keycode[3];
} key_combination_t;
bool is_siri_active = false;
uint32_t siri_timer = 0;
// clang-format off
key_combination_t key_comb_list[4] = {
{2, {KC_LWIN, KC_TAB}},
{2, {KC_LWIN, KC_E}},
{3, {KC_LSFT, KC_LCMD, KC_4}},
{2, {KC_LWIN, KC_C}}
};
static uint8_t mac_keycode[4] = {KC_LOPT, KC_ROPT, KC_LCMD, KC_RCMD};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[MAC_BASE] = LAYOUT_ansi_104(
KC_ESC, KC_BRID, KC_BRIU, KC_MCTL, KC_LPAD, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_SNAP, KC_SIRI, RGB_MOD,
@ -34,6 +68,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_P4, KC_P5, KC_P6,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_P1, KC_P2, KC_P3, KC_PENT,
KC_LCTL, KC_LOPTN, KC_LCMMD, KC_SPC, KC_RCMMD, KC_ROPTN, MO(MAC_FN), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT),
[MAC_FN] = LAYOUT_ansi_104(
_______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, RGB_TOG,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
@ -41,6 +76,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______),
[WIN_BASE] = LAYOUT_ansi_104(
KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_CRTA, RGB_MOD,
KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_INS, KC_HOME, KC_PGUP, KC_NUM, KC_PSLS, KC_PAST, KC_PMNS,
@ -48,6 +84,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_P4, KC_P5, KC_P6,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_P1, KC_P2, KC_P3, KC_PENT,
KC_LCTL, KC_LWIN, KC_LALT, KC_SPC, KC_RALT, KC_RWIN, MO(WIN_FN), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT),
[WIN_FN] = LAYOUT_ansi_104(
_______, KC_BRID, KC_BRIU, KC_TASK, KC_FLXP, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______, RGB_TOG,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
@ -64,7 +101,13 @@ extern void rgb_matrix_update_pwm_buffers(void);
#endif // RGB_MATRIX_ENABLE
void housekeeping_task_user(void) {
housekeeping_task_keychron();
if (is_siri_active) {
if (sync_timer_elapsed32(siri_timer) >= 500) {
unregister_code(KC_LCMD);
unregister_code(KC_SPACE);
is_siri_active = false;
}
}
#if defined(RGB_MATRIX_ENABLE) && defined(MAC_OS_LED_INDEX) && defined(WIN_OS_LED_INDEX)
if (!rgb_matrix_is_enabled()) {
@ -82,30 +125,58 @@ void housekeeping_task_user(void) {
rgb_matrix_set_color(WIN_OS_LED_INDEX, 0, 0, 0);
}
# endif // WIN_OS_LED_INDEX
rgb_matrix_update_pwm_buffers();
rgb_matrix_update_pwm_buffers();
}
#endif // RGB_MATRIX_ENABLE
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (!process_record_keychron(keycode, record)) {
if (!process_record_keychron_ft(keycode, record)) {
return false;
}
return true;
}
bool dip_switch_update_user(uint8_t index, bool active) {
if (!dip_switch_update_keychron(index, active)) {
return false;
bool process_record_keychron(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_LOPTN:
case KC_ROPTN:
case KC_LCMMD:
case KC_RCMMD:
if (record->event.pressed) {
register_code(mac_keycode[keycode - KC_LOPTN]);
} else {
unregister_code(mac_keycode[keycode - KC_LOPTN]);
}
return false; // Skip all further processing of this key
case KC_SIRI:
if (record->event.pressed) {
if (!is_siri_active) {
is_siri_active = true;
register_code(KC_LCMD);
register_code(KC_SPACE);
}
siri_timer = sync_timer_read32();
} else {
// Do something else when release
}
return false; // Skip all further processing of this key
case KC_TASK:
case KC_FLXP:
case KC_SNAP:
case KC_CRTA:
if (record->event.pressed) {
for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) {
register_code(key_comb_list[keycode - KC_TASK].keycode[i]);
}
} else {
for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) {
unregister_code(key_comb_list[keycode - KC_TASK].keycode[i]);
}
}
return false; // Skip all further processing of this key
default:
return true; // Process all other keycodes normally
}
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_ft_common.c

View File

@ -34,6 +34,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_P4, KC_P5, KC_P6,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_P1, KC_P2, KC_P3, KC_PENT,
KC_LCTL, KC_LOPT, KC_LCMD, KC_SPC, KC_RCMD, KC_ROPT, MO(MAC_FN), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT),
[MAC_FN] = LAYOUT_ansi_104(
_______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, RGB_TOG,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
@ -41,6 +42,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______),
[WIN_BASE] = LAYOUT_ansi_104(
KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_NO, RGB_MOD,
KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_INS, KC_HOME, KC_PGUP, KC_NUM, KC_PSLS, KC_PAST, KC_PMNS,
@ -48,6 +50,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_P4, KC_P5, KC_P6,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_P1, KC_P2, KC_P3, KC_PENT,
KC_LCTL, KC_LWIN, KC_LALT, KC_SPC, KC_RALT, KC_RWIN, MO(WIN_FN), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT),
[WIN_FN] = LAYOUT_ansi_104(
_______, KC_BRID, KC_BRIU, KC_TASK, KC_FLXP, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______, RGB_TOG,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,

View File

@ -21,7 +21,7 @@
// clang-format off
const ckled2001_led PROGMEM g_ckled2001_leds[RGB_MATRIX_LED_COUNT] = {
/* Refer to IS31 manual for these locations
/* Refer to CKLED2001 manual for these locations
* driver
* | R location
* | | G location
@ -171,7 +171,7 @@ led_config_t g_led_config = {
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 4, 4, 4, 4,
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 4, 4, 4,
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 4, 4,
1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 4,
1, 1, 1, 4, 1, 1, 4, 1, 1, 1, 1, 4, 4,
}
};

View File

@ -1,9 +1,3 @@
# MCU name
MCU = STM32L432
# Bootloader selection
BOOTLOADER = stm32-dfu
# Build Options
# change yes to no to disable.
#

View File

@ -16,19 +16,6 @@
#pragma once
/* Key matrix pins */
#define MATRIX_ROW_PINS { B5, B4, B3, A15, A14, A13 }
#define MATRIX_COL_PINS { A10, A9, A8, B1, B0, A7, A6, A5, A4, A3, A2, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, NO_PIN, C14 }
/* Pin connected to DS of 74HC595 */
#define DATA_PIN_74HC595 C15
/* Pin connected to SH_CP of 74HC595 */
#define CLOCK_PIN_74HC595 A1
/* Pin connected to ST_CP of 74HC595 */
#define LATCH_PIN_74HC595 A0
/* Pin used index start of 74HC595 */
#define PIN_START_74HC595 11
/* RGB Matrix Driver Configuration */
#define DRIVER_COUNT 1
#define DRIVER_ADDR_1 0b1110100

View File

@ -8,6 +8,13 @@
"pid": "0x0523",
"device_version": "1.0.1"
},
"matrix_pins": {
"cols": ["A10", "A9", "A8", "B1", "B0", "A7", "A6", "A5", "A4", "A3", "A2", null, null, null, null, null, null, null, null, "C14"],
"rows": ["B5", "B4", "B3", "A15", "A14", "A13"]
},
"diode_direction": "ROW2COL",
"processor": "STM32L432",
"bootloader": "stm32-dfu",
"layouts": {
"LAYOUT_ansi_104": {
"layout": [

View File

@ -15,7 +15,7 @@
*/
#include QMK_KEYBOARD_H
#include "keychron_common.h"
#include "keychron_common_ft.h"
// clang-format off
@ -26,6 +26,38 @@ enum layers{
WIN_FN
};
enum custom_keycodes {
KC_LOPTN = QK_KB_2, // TECH DEBT: Starts at QK_KB_2 to maintain ordering with VIA definitions. See #19884. Revert to QK_KB_0 when VIA catches up with QMK.
KC_ROPTN,
KC_LCMMD,
KC_RCMMD,
KC_SIRI,
KC_TASK_VIEW,
KC_FILE_EXPLORER,
KC_SCREEN_SHOT,
KC_CORTANA
};
#define KC_TASK KC_TASK_VIEW
#define KC_FLXP KC_FILE_EXPLORER
#define KC_SNAP KC_SCREEN_SHOT
#define KC_CRTA KC_CORTANA
typedef struct PACKED {
uint8_t len;
uint8_t keycode[3];
} key_combination_t;
bool is_siri_active = false;
uint32_t siri_timer = 0;
// clang-format off
key_combination_t key_comb_list[4] = {
{2, {KC_LWIN, KC_TAB}},
{2, {KC_LWIN, KC_E}},
{3, {KC_LSFT, KC_LCMD, KC_4}},
{2, {KC_LWIN, KC_C}}
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[MAC_BASE] = LAYOUT_ansi_104(
KC_ESC, KC_BRID, KC_BRIU, KC_MCTL, KC_LPAD, BL_DEC, BL_INC, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_SNAP, KC_SIRI, BL_STEP,
@ -34,6 +66,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_P4, KC_P5, KC_P6,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_P1, KC_P2, KC_P3, KC_PENT,
KC_LCTL, KC_LOPTN, KC_LCMMD, KC_SPC, KC_RCMMD, KC_ROPTN, MO(MAC_FN), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT),
[MAC_FN] = LAYOUT_ansi_104(
_______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, BL_TOGG,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
@ -41,6 +74,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_______, _______, BL_DEC, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______),
[WIN_BASE] = LAYOUT_ansi_104(
KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_CRTA, BL_STEP,
KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_INS, KC_HOME, KC_PGUP, KC_NUM, KC_PSLS, KC_PAST, KC_PMNS,
@ -48,6 +82,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_P4, KC_P5, KC_P6,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_P1, KC_P2, KC_P3, KC_PENT,
KC_LCTL, KC_LWIN, KC_LALT, KC_SPC, KC_RALT, KC_RWIN, MO(WIN_FN), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT),
[WIN_FN] = LAYOUT_ansi_104(
_______, KC_BRID, KC_BRIU, KC_TASK, KC_FLXP, BL_DEC, BL_INC, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______, BL_TOGG,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
@ -64,7 +99,13 @@ extern void led_matrix_update_pwm_buffers(void);
#endif
void housekeeping_task_user(void) {
housekeeping_task_keychron();
if (is_siri_active) {
if (sync_timer_elapsed32(siri_timer) >= 500) {
unregister_code(KC_LCMD);
unregister_code(KC_SPACE);
is_siri_active = false;
}
}
#if defined(LED_MATRIX_ENABLE) && defined(MAC_OS_LED_INDEX) && defined(WIN_OS_LED_INDEX)
if (!led_matrix_is_enabled()) {
@ -84,24 +125,51 @@ void housekeeping_task_user(void) {
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (!process_record_keychron(keycode, record)) {
if (!process_record_keychron_ft(keycode, record)) {
return false;
}
return true;
}
bool dip_switch_update_user(uint8_t index, bool active) {
if (!dip_switch_update_keychron(index, active)) {
return false;
bool process_record_keychron(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_LOPTN:
case KC_ROPTN:
case KC_LCMMD:
case KC_RCMMD:
if (record->event.pressed) {
register_code(mac_keycode[keycode - KC_LOPTN]);
} else {
unregister_code(mac_keycode[keycode - KC_LOPTN]);
}
return false; // Skip all further processing of this key
case KC_SIRI:
if (record->event.pressed) {
if (!is_siri_active) {
is_siri_active = true;
register_code(KC_LCMD);
register_code(KC_SPACE);
}
siri_timer = sync_timer_read32();
} else {
// Do something else when release
}
return false; // Skip all further processing of this key
case KC_TASK:
case KC_FLXP:
case KC_SNAP:
case KC_CRTA:
if (record->event.pressed) {
for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) {
register_code(key_comb_list[keycode - KC_TASK].keycode[i]);
}
} else {
for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) {
unregister_code(key_comb_list[keycode - KC_TASK].keycode[i]);
}
}
return false; // Skip all further processing of this key
default:
return true; // Process all other keycodes normally
}
return true;
}
#ifdef LED_MATRIX_ENABLE
bool led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
if(!led_matrix_indicators_advanced_keychron(led_min, led_max)) {
return false;
}
return true;
}
#endif

View File

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

View File

@ -1,9 +1,3 @@
# MCU name
MCU = STM32L432
# Bootloader selection
BOOTLOADER = stm32-dfu
# Build Options
# change yes to no to disable.
#
@ -28,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

@ -169,7 +169,7 @@ led_config_t g_led_config = {
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 4, 4, 4, 4,
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 4, 4, 4,
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 4, 4,
1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 4, 4,
1, 1, 1, 4, 1, 1, 4, 1, 1, 1, 1, 4, 4,
}
};

View File

@ -1,4 +0,0 @@
VIA_ENABLE = yes
SRC += keychron_common.c
SRC += keychron_factory_test_common.c

View File

@ -1,4 +0,0 @@
VIA_ENABLE = yes
SRC += keychron_common.c
SRC += keychron_factory_test_common.c

View File

@ -16,13 +16,6 @@
#pragma once
/* Key matrix size */
#define MATRIX_ROWS 6
#define MATRIX_COLS 20
/* COL2ROW or ROW2COL */
#define DIODE_DIRECTION ROW2COL
/* Set 0 if debouncing isn't needed */
#define DEBOUNCE 5
@ -43,8 +36,3 @@
#define I2C1_TIMINGR_SDADEL 0U
#define I2C1_TIMINGR_SCLH 15U
#define I2C1_TIMINGR_SCLL 51U
/* Enable receive custom command from host */
#define RAW_HID_CMD 0xAB
#define HOLD_ON_OTHER_KEY_PRESS

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 A0
#define HC595_SHCP A1
#define HC595_DS C15
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 == 10) {
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 == 10)
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 == 10)
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

@ -1,5 +1,7 @@
# Keychron C2 Pro
![Keychron C2 Pro](https://i.imgur.com/BQE1tFO.jpg[/img])
A customizable 100% keyboard.
* Keyboard Maintainer: [Keychron](https://github.com/keychron)
@ -8,15 +10,13 @@ A customizable 100% keyboard.
Make example for this keyboard (after setting up your build environment):
```bash
make keychron/c2/c2_ansi_rgb_stm32l432:default
```
make keychron/c2/ansi/rgb:default
make keychron/c2/ansi/white:default
Flashing example for this keyboard:
```bash
make keychron/c2/c2_ansi_rgb_stm32l432:flash
```
make keychron/c2/ansi/rgb:default:flash
make keychron/c2/ansi/white:default:flash
**Reset Key**: Hold down the key located at *K00*, commonly programmed as *Esc* while plugging in the keyboard.