diff options
74 files changed, 5491 insertions, 334 deletions
diff --git a/keyboards/keychron/bluetooth/bluetooth.c b/keyboards/keychron/bluetooth/bluetooth.c index 481099af67..e87b435db4 100644 --- a/keyboards/keychron/bluetooth/bluetooth.c +++ b/keyboards/keychron/bluetooth/bluetooth.c @@ -291,6 +291,14 @@ uint8_t bluetooth_keyboard_leds(void) { extern keymap_config_t keymap_config; void bluetooth_send_keyboard(report_keyboard_t *report) { + if (battery_is_critical_low()) { + report_keyboard_t empty_report; + memset(&empty_report, 0, sizeof(empty_report)); + if (memcmp(keyboard_report, &empty_report, sizeof(report_keyboard_t)) != 0) { + return; + } + } + if (bt_state == BLUETOOTH_PARING && !pincodeEntry) return; if (bt_state == BLUETOOTH_CONNECTED || (bt_state == BLUETOOTH_PARING && pincodeEntry)) { @@ -395,7 +403,7 @@ void bluetooth_low_battery_shutdown(void) { indicator_battery_low_backlit_enable(false); #endif clear_keyboard(); - send_keyboard_report(); + wait_ms(50); bluetooth_disconnect(); } diff --git a/keyboards/keychron/common/common.mk b/keyboards/keychron/common/common.mk new file mode 100755 index 0000000000..d7610bce69 --- /dev/null +++ b/keyboards/keychron/common/common.mk @@ -0,0 +1,4 @@ +COMMON_DIR = common +SRC += $(COMMON_DIR)/matrix.c + +VPATH += $(TOP_DIR)/keyboards/keychron/$(COMMON_DIR) diff --git a/keyboards/keychron/common/matrix.c b/keyboards/keychron/common/matrix.c new file mode 100755 index 0000000000..8fe7588118 --- /dev/null +++ b/keyboards/keychron/common/matrix.c @@ -0,0 +1,218 @@ +/* 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" + +#ifndef HC595_STCP +# define HC595_STCP B0 +#endif +#ifndef HC595_SHCP +# define HC595_SHCP A1 +#endif +#ifndef HC595_DS +# define HC595_DS A7 +#endif + +#ifndef HC595_START_INDEX +# define HC595_START_INDEX 0 +#endif +#ifndef HC595_END_INDEX +# define HC595_END_INDEX 15 +#endif +#ifndef HC595_OFFSET_INDEX +# define HC595_OFFSET_INDEX 0 +#endif + +#if defined(HC595_START_INDEX) && defined(HC595_END_INDEX) +# if ((HC595_END_INDEX - HC595_START_INDEX + 1) > 16) +# define SIZE_T uint32_t +# define UNSELECT_ALL_COL 0xFFFFFFFF +# define SELECT_ALL_COL 0x00000000 +# elif ((HC595_END_INDEX - HC595_START_INDEX + 1) > 8) +# define SIZE_T uint16_t +# define UNSELECT_ALL_COL 0xFFFF +# define SELECT_ALL_COL 0x0000 +# else +# define SIZE_T uint8_t +# define UNSELECT_ALL_COL 0xFF +# define SELECT_ALL_COL 0x00 +# endif +#endif + +pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; +pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; + +static inline uint8_t readMatrixPin(pin_t pin) { + if (pin != NO_PIN) { + return readPin(pin); + } else { + return 1; + } +} + +static inline void setPinOutput_writeLow(pin_t pin) { + setPinOutput(pin); + writePinLow(pin); +} + +static inline void setPinOutput_writeHigh(pin_t pin) { + setPinOutput(pin); + writePinHigh(pin); +} + +static inline void HC595_delay(uint16_t n) { + while (n-- > 0) { + asm volatile("nop" ::: "memory"); + } +} + +static void HC595_output(SIZE_T data, bool bit_flag) { + uint8_t n = 1; + + ATOMIC_BLOCK_FORCEON { + for (uint8_t i = 0; i < (HC595_END_INDEX - HC595_START_INDEX + 1); i++) { + if (data & 0x1) { + writePinHigh(HC595_DS); + } else { + writePinLow(HC595_DS); + } + writePinHigh(HC595_SHCP); + HC595_delay(n); + writePinLow(HC595_SHCP); + HC595_delay(n); + if (bit_flag) { + break; + } else { + data = data >> 1; + } + } + writePinHigh(HC595_STCP); + HC595_delay(n); + writePinLow(HC595_STCP); + HC595_delay(n); + } +} + +static void select_col(uint8_t col) { + if (col < HC595_START_INDEX || col > HC595_END_INDEX) { + setPinOutput_writeLow(col_pins[col]); + } else { + if (col == HC595_START_INDEX) { + HC595_output(0x00, true); + if (col < HC595_OFFSET_INDEX) { + HC595_output(0x01, true); + } + } + } +} + +static void unselect_col(uint8_t col) { + if (col < HC595_START_INDEX || col > HC595_END_INDEX) { +#ifdef MATRIX_UNSELECT_DRIVE_HIGH + setPinOutput_writeHigh(col_pins[col]); +#else + setPinInputHigh(col_pins[col]); +#endif + } else { + HC595_output(0x01, true); + } +} + +static void unselect_cols(void) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + if (col < HC595_START_INDEX || col > HC595_END_INDEX) { +#ifdef MATRIX_UNSELECT_DRIVE_HIGH + setPinOutput_writeHigh(col_pins[col]); +#else + setPinInputHigh(col_pins[col]); +#endif + } else { + if (col == HC595_START_INDEX) { + HC595_output(UNSELECT_ALL_COL, false); + } + break; + } + } +} + +void select_all_cols(void) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + if (col < HC595_START_INDEX || col > HC595_END_INDEX) { + setPinOutput_writeLow(col_pins[col]); + } else { + if (col == HC595_START_INDEX) { + HC595_output(SELECT_ALL_COL, false); + } + break; + } + } +} + +static void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col, matrix_row_t row_shifter) { + // Select col + select_col(current_col); // select col + HC595_delay(200); + + // For each row... + for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { + // Check row pin state + if (readMatrixPin(row_pins[row_index]) == 0) { + // Pin LO, set col bit + current_matrix[row_index] |= row_shifter; + } else { + // Pin HI, clear col bit + current_matrix[row_index] &= ~row_shifter; + } + } + + // Unselect col + unselect_col(current_col); + HC595_delay(200); // wait for all Row signals to go HIGH +} + +void matrix_init_custom(void) { + setPinOutput(HC595_DS); + setPinOutput(HC595_STCP); + setPinOutput(HC595_SHCP); + + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + if (row_pins[x] != NO_PIN) { + setPinInputHigh(row_pins[x]); + } + } + + unselect_cols(); +} + +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; +} + +void suspend_wakeup_init_kb(void) { + // code will run on keyboard wakeup + clear_keyboard(); +} diff --git a/keyboards/keychron/k10_pro/ansi/rgb/config.h b/keyboards/keychron/k10_pro/ansi/rgb/config.h index 703644657a..90cfcccf96 100644 --- a/keyboards/keychron/k10_pro/ansi/rgb/config.h +++ b/keyboards/keychron/k10_pro/ansi/rgb/config.h @@ -19,9 +19,10 @@ #ifdef RGB_MATRIX_ENABLE /* RGB Matrix driver configuration */ # define DRIVER_COUNT 2 - # define DRIVER_ADDR_1 0b1110111 # define DRIVER_ADDR_2 0b1110100 + +/* RGB Matrix configuration */ # define RGB_MATRIX_LED_COUNT 108 /* Set to infinit, which is use in USB mode by default */ diff --git a/keyboards/keychron/k10_pro/ansi/rgb/info.json b/keyboards/keychron/k10_pro/ansi/rgb/info.json index ad52f9670c..3923a9ce58 100644 --- a/keyboards/keychron/k10_pro/ansi/rgb/info.json +++ b/keyboards/keychron/k10_pro/ansi/rgb/info.json @@ -30,6 +30,121 @@ "solid_reactive_multinexus": true, "splash": true, "solid_splash": true - } + }, + "layout": [ + {"matrix":[0,0], "flags":1, "x":0, "y":0}, + {"matrix":[0,1], "flags":1, "x":20, "y":0}, + {"matrix":[0,2], "flags":1, "x":31, "y":0}, + {"matrix":[0,3], "flags":1, "x":42, "y":0}, + {"matrix":[0,4], "flags":1, "x":52, "y":0}, + {"matrix":[0,5], "flags":1, "x":67, "y":0}, + {"matrix":[0,6], "flags":1, "x":78, "y":0}, + {"matrix":[0,7], "flags":1, "x":88, "y":0}, + {"matrix":[0,8], "flags":1, "x":98, "y":0}, + {"matrix":[0,9], "flags":1, "x":114, "y":0}, + {"matrix":[0,10], "flags":1, "x":125, "y":0}, + {"matrix":[0,11], "flags":1, "x":135, "y":0}, + {"matrix":[0,12], "flags":1, "x":145, "y":0}, + {"matrix":[0,14], "flags":1, "x":158, "y":0}, + {"matrix":[0,15], "flags":1, "x":169, "y":0}, + {"matrix":[0,16], "flags":1, "x":179, "y":0}, + {"matrix":[0,17], "flags":4, "x":192, "y":0}, + {"matrix":[0,18], "flags":4, "x":203, "y":0}, + {"matrix":[0,19], "flags":4, "x":213, "y":0}, + {"matrix":[0,20], "flags":4, "x":224, "y":0}, + + {"matrix":[1,0], "flags":1, "x":0, "y":15}, + {"matrix":[1,1], "flags":8, "x":10, "y":15}, + {"matrix":[1,2], "flags":8, "x":20, "y":15}, + {"matrix":[1,3], "flags":8, "x":31, "y":15}, + {"matrix":[1,4], "flags":4, "x":41, "y":15}, + {"matrix":[1,5], "flags":4, "x":52, "y":15}, + {"matrix":[1,6], "flags":4, "x":62, "y":15}, + {"matrix":[1,7], "flags":4, "x":72, "y":15}, + {"matrix":[1,8], "flags":4, "x":83, "y":15}, + {"matrix":[1,9], "flags":4, "x":93, "y":15}, + {"matrix":[1,10], "flags":4, "x":104, "y":15}, + {"matrix":[1,11], "flags":4, "x":114, "y":15}, + {"matrix":[1,12], "flags":4, "x":124, "y":15}, + {"matrix":[1,13], "flags":1, "x":140, "y":15}, + {"matrix":[1,14], "flags":1, "x":158, "y":15}, + {"matrix":[1,15], "flags":1, "x":169, "y":15}, + {"matrix":[1,16], "flags":1, "x":180, "y":15}, + {"matrix":[1,17], "flags":8, "x":192, "y":15}, + {"matrix":[1,18], "flags":4, "x":203, "y":15}, + {"matrix":[1,19], "flags":4, "x":213, "y":15}, + {"matrix":[1,20], "flags":4, "x":224, "y":15}, + + {"matrix":[2,0], "flags":1, "x":2, "y":28}, + {"matrix":[2,1], "flags":4, "x":15, "y":28}, + {"matrix":[2,2], "flags":4, "x":26, "y":28}, + {"matrix":[2,3], "flags":4, "x":36, "y":28}, + {"matrix":[2,4], "flags":4, "x":46, "y":28}, + {"matrix":[2,5], "flags":4, "x":57, "y":28}, + {"matrix":[2,6], "flags":4, "x":67, "y":28}, + {"matrix":[2,7], "flags":4, "x":78, "y":28}, + {"matrix":[2,8], "flags":4, "x":88, "y":28}, + {"matrix":[2,9], "flags":4, "x":98, "y":28}, + {"matrix":[2,10], "flags":4, "x":109, "y":28}, + {"matrix":[2,11], "flags":4, "x":119, "y":28}, + {"matrix":[2,12], "flags":4, "x":130, "y":28}, + {"matrix":[2,13], "flags":1, "x":143, "y":28}, + {"matrix":[2,14], "flags":1, "x":158, "y":28}, + {"matrix":[2,15], "flags":1, "x":169, "y":28}, + {"matrix":[2,16], "flags":1, "x":179, "y":28}, + {"matrix":[2,17], "flags":4, "x":192, "y":28}, + {"matrix":[2,18], "flags":4, "x":203, "y":28}, + {"matrix":[2,19], "flags":4, "x":213, "y":28}, + {"matrix":[2,20], "flags":4, "x":224, "y":28}, + + {"matrix":[3,0], "flags":8, "x":3, "y":39}, + {"matrix":[3,1], "flags":4, "x":18, "y":39}, + {"matrix":[3,2], "flags":4, "x":28, "y":39}, + {"matrix":[3,3], "flags":4, "x":39, "y":39}, + {"matrix":[3,4], "flags":4, "x":49, "y":39}, + {"matrix":[3,5], "flags":4, "x":59, "y":39}, + {"matrix":[3,6], "flags":4, "x":70, "y":39}, + {"matrix":[3,7], "flags":4, "x":80, "y":39}, + {"matrix":[3,8], "flags":4, "x":91, "y":39}, + {"matrix":[3,9], "flags":4, "x":101, "y":39}, + {"matrix":[3,10], "flags":4, "x":111, "y":39}, + {"matrix":[3,11], "flags":4, "x":122, "y":39}, + {"matrix":[3,13], "flags":4, "x":139, "y":39}, + {"matrix":[3,17], "flags":4, "x":192, "y":39}, + {"matrix":[3,18], "flags":4, "x":203, "y":39}, + {"matrix":[3,19], "flags":4, "x":213, "y":39}, + + {"matrix":[4,0], "flags":1, "x":6, "y":52}, + {"matrix":[4,2], "flags":4, "x":23, "y":52}, + {"matrix":[4,3], "flags":4, "x":33, "y":52}, + {"matrix":[4,4], "flags":4, "x":44, "y":52}, + {"matrix":[4,5], "flags":4, "x":54, "y":52}, + {"matrix":[4,6], "flags":4, "x":65, "y":52}, + {"matrix":[4,7], "flags":4, "x":75, "y":52}, + {"matrix":[4,8], "flags":4, "x":85, "y":52}, + {"matrix":[4,9], "flags":4, "x":96, "y":52}, + {"matrix":[4,10], "flags":4, "x":106, "y":52}, + {"matrix":[4,11], "flags":4, "x":117, "y":52}, + {"matrix":[4,13], "flags":1, "x":136, "y":52}, + {"matrix":[4,15], "flags":1, "x":169, "y":52}, + {"matrix":[4,17], "flags":4, "x":192, "y":52}, + {"matrix":[4,18], "flags":4, "x":203, "y":52}, + {"matrix":[4,19], "flags":4, "x":213, "y":52}, + {"matrix":[4,20], "flags":4, "x":224, "y":58}, + + {"matrix":[5,0], "flags":1, "x":1, "y":64}, + {"matrix":[5,1], "flags":1, "x":14, "y":64}, + {"matrix":[5,2], "flags":1, "x":27, "y":64}, + {"matrix":[5,6], "flags":4, "x":66, "y":64}, + {"matrix":[5,10], "flags":1, "x":105, "y":64}, + {"matrix":[5,11], "flags":1, "x":118, "y":64}, + {"matrix":[5,12], "flags":1, "x":131, "y":64}, + {"matrix":[5,13], "flags":1, "x":144, "y":64}, + {"matrix":[5,14], "flags":1, "x":158, "y":64}, + {"matrix":[5,15], "flags":1, "x":169, "y":64}, + {"matrix":[5,16], "flags":1, "x":179, "y":64}, + {"matrix":[5,17], "flags":4, "x":197, "y":64}, + {"matrix":[5,19], "flags":4, "x":213, "y":64} + ] } -} +}
\ No newline at end of file diff --git a/keyboards/keychron/k10_pro/ansi/rgb/keymaps/default/keymap.c b/keyboards/keychron/k10_pro/ansi/rgb/keymaps/default/keymap.c index d54f54594b..170a7690a3 100644 --- a/keyboards/keychron/k10_pro/ansi/rgb/keymaps/default/keymap.c +++ b/keyboards/keychron/k10_pro/ansi/rgb/keymaps/default/keymap.c @@ -16,14 +16,14 @@ #include QMK_KEYBOARD_H -// clang-format off -enum layers{ - MAC_BASE, - MAC_FN, - WIN_BASE, - WIN_FN +enum layers { + MAC_BASE, + MAC_FN, |