From 27aeec56b904df16a97678bf048365bbbcacef9b Mon Sep 17 00:00:00 2001 From: harvey Date: Fri, 18 Oct 2024 16:50:11 +0200 Subject: [PATCH] Add per keyboard configuration to keep QMK main clean --- users/halcyon_modules/config.h | 32 +++- users/halcyon_modules/halcyon.c | 40 ++++- users/halcyon_modules/hlc_encoder/config.h | 3 +- .../halcyon_modules/hlc_encoder/hlc_encoder.c | 142 ++++++++++++++++-- .../halcyon_modules/hlc_encoder/hlc_encoder.h | 9 -- .../hlc_encoder/hlc_encoder_matrix.c | 141 ----------------- users/halcyon_modules/hlc_encoder/rules.mk | 2 +- 7 files changed, 199 insertions(+), 170 deletions(-) delete mode 100644 users/halcyon_modules/hlc_encoder/hlc_encoder.h delete mode 100644 users/halcyon_modules/hlc_encoder/hlc_encoder_matrix.c diff --git a/users/halcyon_modules/config.h b/users/halcyon_modules/config.h index 11e8f2dc..0b88d0db 100644 --- a/users/halcyon_modules/config.h +++ b/users/halcyon_modules/config.h @@ -43,4 +43,34 @@ #define POINTING_DEVICE_CS_PIN GP2 //NOT CONNECTED #endif -#include_next \ No newline at end of file +#include_next + +//// Keyboard redefines + +// Always the same +#define SPLIT_MODS_ENABLE +#define SPLIT_TRANSPORT_MIRROR +#define SPLIT_LED_STATE_ENABLE +#define SPLIT_LAYER_STATE_ENABLE + +// Kyria +#if defined(PRODUCT_ID) && PRODUCT_ID == 0x7FCE + #undef ENCODER_A_PINS + #define ENCODER_A_PINS { GP23, GP27 } + #undef ENCODER_B_PINS + #define ENCODER_B_PINS { GP22, GP26 } + #undef MATRIX_ROWS + #define MATRIX_ROWS 10 + #define LAYOUT_split_3x6_5_hlc(k0G, k0F, k0E, k0D, k0C, k0B, k5B, k5C, k5D, k5E, k5F, k5G, k1G, k1F, k1E, k1D, k1C, k1B, k6B, k6C, k6D, k6E, k6F, k6G, k2G, k2F, k2E, k2D, k2C, k2B, k3D, k2A, k7A, k8D, k7B, k7C, k7D, k7E, k7F, k7G, k3E, k3C, k3B, k3F, k3A, k8A, k8F, k8B, k8C, k8E, k4A, k4B, k4C, k4D, k4E, k9A, k9B, k9C, k9D, k9E) { \ + {KC_NO, k0B, k0C, k0D, k0E, k0F, k0G}, \ + {KC_NO, k1B, k1C, k1D, k1E, k1F, k1G}, \ + {k2A, k2B, k2C, k2D, k2E, k2F, k2G}, \ + {k3A, k3B, k3C, k3D, k3E, k3F, KC_NO}, \ + {k4A, k4B, k4C, k4D, k4E, KC_NO, KC_NO}, \ + {KC_NO, k5B, k5C, k5D, k5E, k5F, k5G}, \ + {KC_NO, k6B, k6C, k6D, k6E, k6F, k6G}, \ + {k7A, k7B, k7C, k7D, k7E, k7F, k7G}, \ + {k8A, k8B, k8C, k8D, k8E, k8F, KC_NO}, \ + {k9A, k9B, k9C, k9D, k9E, KC_NO, KC_NO} \ + } +#endif \ No newline at end of file diff --git a/users/halcyon_modules/halcyon.c b/users/halcyon_modules/halcyon.c index 717d25a0..3b71794e 100644 --- a/users/halcyon_modules/halcyon.c +++ b/users/halcyon_modules/halcyon.c @@ -91,4 +91,42 @@ report_mouse_t pointing_device_task_combined_kb(report_mouse_t left_report, repo left_report.y = -y; } return pointing_device_task_combined_user(left_report, right_report); -} \ No newline at end of file +} + +// Kyria +#if defined(PRODUCT_ID) && PRODUCT_ID == 0x7FCE +#ifdef RGB_MATRIX_ENABLE +#include "rgb_matrix.h" +led_config_t g_led_config = { + { + { NO_LED, 25, 26, 27, 28, 29, 30 }, + { NO_LED, 19, 20, 21, 22, 23, 24 }, + { 11, 13, 14, 15, 16, 17, 18 }, + { 6, 8, 9, 12, 10, 7, NO_LED }, + { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED }, + { NO_LED, 56, 57, 58, 59, 60, 61 }, + { NO_LED, 50, 51, 52, 53, 54, 55 }, + { 42, 44, 45, 46, 47, 48, 49 }, + { 37, 39, 40, 43, 41, 38, NO_LED }, + { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED }, + }, + { {75, 2}, {50, 1}, {14, 4}, {25, 45}, {58, 49}, {94, 53}, {94, 64}, {79, 60}, {65, 53}, {51, 49}, {36, 49}, {101, 49}, {87, 45}, {72, 38}, {58, 34}, {43, 30}, {29, 34}, {14, 41}, {0, 41}, {72, 23}, {58, 19}, {43, 15}, {29, 19}, {14, 26}, {0, 26}, {72, 8}, {58, 4}, {43, 0}, {29, 4}, {14, 11}, {0, 11}, {149, 2}, {174, 1}, {210, 4}, {199, 45}, {166, 49}, {130, 53}, {130, 64}, {145, 60}, {159, 53}, {173, 49}, {188, 49}, {123, 49}, {137, 45}, {152, 38}, {166, 34}, {181, 30}, {195, 34}, {210, 41}, {224, 41}, {152, 23}, {166, 19}, {181, 15}, {195, 19}, {210, 26}, {224, 26}, {152, 8}, {166, 4}, {181, 0}, {195, 4}, {210, 11}, {224, 11} }, + { 2, 2, 2, 2, 2, 2, 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, 2, 2, 2, 2, 2, 2, 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 }, +}; +#endif + +#ifdef MATRIX_MASKED +const matrix_row_t matrix_mask[] = { + 0b1111110, + 0b1111110, + 0b1111111, + 0b0111111, + 0b0011111, + 0b1111110, + 0b1111110, + 0b1111111, + 0b0111111, + 0b0011111, +}; +#endif +#endif \ No newline at end of file diff --git a/users/halcyon_modules/hlc_encoder/config.h b/users/halcyon_modules/hlc_encoder/config.h index 825e51ab..02188489 100644 --- a/users/halcyon_modules/hlc_encoder/config.h +++ b/users/halcyon_modules/hlc_encoder/config.h @@ -5,4 +5,5 @@ #pragma once -#define HLC_ENCODER \ No newline at end of file +#define HLC_ENCODER +#define HLC_ENCODER_BUTTON GP16 \ No newline at end of file diff --git a/users/halcyon_modules/hlc_encoder/hlc_encoder.c b/users/halcyon_modules/hlc_encoder/hlc_encoder.c index f0dfa20e..e32f9b5f 100644 --- a/users/halcyon_modules/hlc_encoder/hlc_encoder.c +++ b/users/halcyon_modules/hlc_encoder/hlc_encoder.c @@ -2,29 +2,139 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include QMK_KEYBOARD_H -#include "encoder.h" -#include "gpio.h" +#include "util.h" +#include "split_util.h" +#include "matrix.h" +#include "debounce.h" +#include "atomic_util.h" -#include "hlc_encoder.h" +#ifdef SPLIT_KEYBOARD +# define ROWS_PER_HAND (MATRIX_ROWS / 2) +#else +# define ROWS_PER_HAND (MATRIX_ROWS) +#endif -static pin_t encoders_pad_a[NUM_ENCODERS_MAX_PER_SIDE] = ENCODER_A_PINS; -static pin_t encoders_pad_b[NUM_ENCODERS_MAX_PER_SIDE] = ENCODER_B_PINS; +#ifdef MATRIX_ROW_PINS_RIGHT +# define SPLIT_MUTABLE_ROW +#else +# define SPLIT_MUTABLE_ROW const +#endif +#ifdef MATRIX_COL_PINS_RIGHT +# define SPLIT_MUTABLE_COL +#else +# define SPLIT_MUTABLE_COL const +#endif -void encoder_quadrature_init_pin(uint8_t index, bool pad_b) { - pin_t pin = pad_b ? encoders_pad_b[index] : encoders_pad_a[index]; - encoders_pad_a[NUM_ENCODERS_MAX_PER_SIDE - 1] = HLC_ENCODER_A; - encoders_pad_b[NUM_ENCODERS_MAX_PER_SIDE - 1] = HLC_ENCODER_B; - if (pin != NO_PIN) { +#ifndef MATRIX_INPUT_PRESSED_STATE +# define MATRIX_INPUT_PRESSED_STATE 0 +#endif + +#ifdef DIRECT_PINS +static SPLIT_MUTABLE pin_t direct_pins[ROWS_PER_HAND][MATRIX_COLS] = DIRECT_PINS; +#elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) +# ifdef MATRIX_ROW_PINS +static SPLIT_MUTABLE_ROW pin_t row_pins[ROWS_PER_HAND] = MATRIX_ROW_PINS; +# endif // MATRIX_ROW_PINS +# ifdef MATRIX_COL_PINS +static SPLIT_MUTABLE_COL pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; +# endif // MATRIX_COL_PINS +#endif + +void matrix_init_kb(void) { + + gpio_set_pin_input_high(HLC_ENCODER_BUTTON); + + // Also need to define here otherwise right half is swapped + if (!isLeftHand) { + # ifdef MATRIX_ROW_PINS_RIGHT + const pin_t row_pins_right[ROWS_PER_HAND] = MATRIX_ROW_PINS_RIGHT; + for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { + row_pins[i] = row_pins_right[i]; + } + # endif + # ifdef MATRIX_COL_PINS_RIGHT + const pin_t col_pins_right[MATRIX_COLS] = MATRIX_COL_PINS_RIGHT; + for (uint8_t i = 0; i < MATRIX_COLS; i++) { + col_pins[i] = col_pins_right[i]; + } + # endif + } +} + +static inline void setPinOutput_writeLow(pin_t pin) { + ATOMIC_BLOCK_FORCEON { + gpio_set_pin_output(pin); + gpio_write_pin_low(pin); + } +} + +static inline void setPinOutput_writeHigh(pin_t pin) { + ATOMIC_BLOCK_FORCEON { + gpio_set_pin_output(pin); + gpio_write_pin_high(pin); + } +} + +static inline void setPinInputHigh_atomic(pin_t pin) { + ATOMIC_BLOCK_FORCEON { gpio_set_pin_input_high(pin); } } -uint8_t encoder_quadrature_read_pin(uint8_t index, bool pad_b) { - pin_t pin = pad_b ? encoders_pad_b[index] : encoders_pad_a[index]; - encoders_pad_a[NUM_ENCODERS_MAX_PER_SIDE - 1] = HLC_ENCODER_A; - encoders_pad_b[NUM_ENCODERS_MAX_PER_SIDE - 1] = HLC_ENCODER_B; +static inline uint8_t readMatrixPin(pin_t pin) { if (pin != NO_PIN) { - return gpio_read_pin(pin) ? 1 : 0; + return (gpio_read_pin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1; + } else { + return 1; } - return 0; +} + +// THIS FUNCTION IS CHANGED, removed NO_PIN check +static bool select_row(uint8_t row) { + pin_t pin = row_pins[row]; + setPinOutput_writeLow(pin); + return true; +} + +static void unselect_row(uint8_t row) { + pin_t pin = row_pins[row]; + if (pin != NO_PIN) { +# ifdef MATRIX_UNSELECT_DRIVE_HIGH + setPinOutput_writeHigh(pin); +# else + setPinInputHigh_atomic(pin); +# endif + } +} + +void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { + // Start with a clear matrix row + matrix_row_t current_row_value = 0; + + if (!select_row(current_row)) { // Select row + return; // skip NO_PIN row + } + matrix_output_select_delay(); + + // ↓↓↓ THIS HAS BEEN ADDED/CHANGED + if (current_row == (ROWS_PER_HAND - 1)) { + current_row_value |= ((!gpio_read_pin(HLC_ENCODER_BUTTON)) & 1) << 0; + } else { + // For each col... + matrix_row_t row_shifter = MATRIX_ROW_SHIFTER; + for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++, row_shifter <<= 1) { + uint8_t pin_state = readMatrixPin(col_pins[col_index]); + + // Populate the matrix row with the state of the col pin + current_row_value |= pin_state ? 0 : row_shifter; + } + } + // ↑↑↑ THIS HAS BEEN ADDED/CHANGED + + // Unselect row + unselect_row(current_row); + matrix_output_unselect_delay(current_row, current_row_value != 0); // wait for all Col signals to go HIGH + + // Update the matrix + current_matrix[current_row] = current_row_value; } \ No newline at end of file diff --git a/users/halcyon_modules/hlc_encoder/hlc_encoder.h b/users/halcyon_modules/hlc_encoder/hlc_encoder.h deleted file mode 100644 index f10fc4ca..00000000 --- a/users/halcyon_modules/hlc_encoder/hlc_encoder.h +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2024 splitkb.com (support@splitkb.com) -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#define HLC_ENCODER_A GP27 -#define HLC_ENCODER_B GP26 - -#define HLC_ENCODER_BUTTON GP16 \ No newline at end of file diff --git a/users/halcyon_modules/hlc_encoder/hlc_encoder_matrix.c b/users/halcyon_modules/hlc_encoder/hlc_encoder_matrix.c deleted file mode 100644 index aed0393c..00000000 --- a/users/halcyon_modules/hlc_encoder/hlc_encoder_matrix.c +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2024 splitkb.com (support@splitkb.com) -// SPDX-License-Identifier: GPL-2.0-or-later - -#include QMK_KEYBOARD_H -#include "util.h" -#include "split_util.h" -#include "matrix.h" -#include "debounce.h" -#include "atomic_util.h" -#include "hlc_encoder.h" - -#ifdef SPLIT_KEYBOARD -# define ROWS_PER_HAND (MATRIX_ROWS / 2) -#else -# define ROWS_PER_HAND (MATRIX_ROWS) -#endif - -#ifdef MATRIX_ROW_PINS_RIGHT -# define SPLIT_MUTABLE_ROW -#else -# define SPLIT_MUTABLE_ROW const -#endif -#ifdef MATRIX_COL_PINS_RIGHT -# define SPLIT_MUTABLE_COL -#else -# define SPLIT_MUTABLE_COL const -#endif - -#ifndef MATRIX_INPUT_PRESSED_STATE -# define MATRIX_INPUT_PRESSED_STATE 0 -#endif - -#ifdef DIRECT_PINS -static SPLIT_MUTABLE pin_t direct_pins[ROWS_PER_HAND][MATRIX_COLS] = DIRECT_PINS; -#elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) -# ifdef MATRIX_ROW_PINS -static SPLIT_MUTABLE_ROW pin_t row_pins[ROWS_PER_HAND] = MATRIX_ROW_PINS; -# endif // MATRIX_ROW_PINS -# ifdef MATRIX_COL_PINS -static SPLIT_MUTABLE_COL pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; -# endif // MATRIX_COL_PINS -#endif - -void matrix_init_kb(void) { - - gpio_set_pin_input_high(HLC_ENCODER_BUTTON); - - // Also need to define here otherwise right half is swapped - if (!isLeftHand) { - # ifdef MATRIX_ROW_PINS_RIGHT - const pin_t row_pins_right[ROWS_PER_HAND] = MATRIX_ROW_PINS_RIGHT; - for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { - row_pins[i] = row_pins_right[i]; - } - # endif - # ifdef MATRIX_COL_PINS_RIGHT - const pin_t col_pins_right[MATRIX_COLS] = MATRIX_COL_PINS_RIGHT; - for (uint8_t i = 0; i < MATRIX_COLS; i++) { - col_pins[i] = col_pins_right[i]; - } - # endif - } -} - -static inline void setPinOutput_writeLow(pin_t pin) { - ATOMIC_BLOCK_FORCEON { - gpio_set_pin_output(pin); - gpio_write_pin_low(pin); - } -} - -static inline void setPinOutput_writeHigh(pin_t pin) { - ATOMIC_BLOCK_FORCEON { - gpio_set_pin_output(pin); - gpio_write_pin_high(pin); - } -} - -static inline void setPinInputHigh_atomic(pin_t pin) { - ATOMIC_BLOCK_FORCEON { - gpio_set_pin_input_high(pin); - } -} - -static inline uint8_t readMatrixPin(pin_t pin) { - if (pin != NO_PIN) { - return (gpio_read_pin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1; - } else { - return 1; - } -} - -// THIS FUNCTION IS CHANGED, removed NO_PIN check -static bool select_row(uint8_t row) { - pin_t pin = row_pins[row]; - setPinOutput_writeLow(pin); - return true; -} - -static void unselect_row(uint8_t row) { - pin_t pin = row_pins[row]; - if (pin != NO_PIN) { -# ifdef MATRIX_UNSELECT_DRIVE_HIGH - setPinOutput_writeHigh(pin); -# else - setPinInputHigh_atomic(pin); -# endif - } -} - -void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { - // Start with a clear matrix row - matrix_row_t current_row_value = 0; - - if (!select_row(current_row)) { // Select row - return; // skip NO_PIN row - } - matrix_output_select_delay(); - - // ↓↓↓ THIS HAS BEEN ADDED/CHANGED - if (current_row == (ROWS_PER_HAND - 1)) { - current_row_value |= ((!gpio_read_pin(HLC_ENCODER_BUTTON)) & 1) << 0; - } else { - // For each col... - matrix_row_t row_shifter = MATRIX_ROW_SHIFTER; - for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++, row_shifter <<= 1) { - uint8_t pin_state = readMatrixPin(col_pins[col_index]); - - // Populate the matrix row with the state of the col pin - current_row_value |= pin_state ? 0 : row_shifter; - } - } - // ↑↑↑ THIS HAS BEEN ADDED/CHANGED - - // Unselect row - unselect_row(current_row); - matrix_output_unselect_delay(current_row, current_row_value != 0); // wait for all Col signals to go HIGH - - // Update the matrix - current_matrix[current_row] = current_row_value; -} \ No newline at end of file diff --git a/users/halcyon_modules/hlc_encoder/rules.mk b/users/halcyon_modules/hlc_encoder/rules.mk index 81d64a69..03fc7e47 100644 --- a/users/halcyon_modules/hlc_encoder/rules.mk +++ b/users/halcyon_modules/hlc_encoder/rules.mk @@ -1,4 +1,4 @@ CURRENT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) -SRC += $(CURRENT_DIR)/hlc_encoder.c $(CURRENT_DIR)/hlc_encoder_matrix.c +SRC += $(CURRENT_DIR)/hlc_encoder.c CONFIG_H += $(CURRENT_DIR)/config.h \ No newline at end of file