From 48e22477560754c8f781e18b208fa61f19d1cecd Mon Sep 17 00:00:00 2001 From: Choi Byungyoon Date: Sun, 29 Sep 2024 11:17:29 +0900 Subject: [PATCH] Add initial version of TrueStrike42 --- keyboards/truestrike42/config.h | 36 ++ keyboards/truestrike42/eeprom_tools.h | 26 ++ keyboards/truestrike42/graphics/display.c | 235 ++++++++++++ keyboards/truestrike42/graphics/display.h | 7 + .../truestrike42/graphics/quinquefive.qff.c | 65 ++++ .../truestrike42/graphics/quinquefive.qff.h | 11 + keyboards/truestrike42/he_switch_matrix.c | 226 +++++++++++ keyboards/truestrike42/he_switch_matrix.h | 66 ++++ keyboards/truestrike42/keyboard.json | 186 +++++++++ .../truestrike42/keymaps/default/keymap.c | 33 ++ keyboards/truestrike42/matrix.c | 36 ++ keyboards/truestrike42/readme.md | 27 ++ keyboards/truestrike42/rules.mk | 5 + keyboards/truestrike42/truestrike42.c | 83 ++++ keyboards/truestrike42/via_he.c | 363 ++++++++++++++++++ 15 files changed, 1405 insertions(+) create mode 100644 keyboards/truestrike42/config.h create mode 100644 keyboards/truestrike42/eeprom_tools.h create mode 100644 keyboards/truestrike42/graphics/display.c create mode 100644 keyboards/truestrike42/graphics/display.h create mode 100644 keyboards/truestrike42/graphics/quinquefive.qff.c create mode 100644 keyboards/truestrike42/graphics/quinquefive.qff.h create mode 100644 keyboards/truestrike42/he_switch_matrix.c create mode 100644 keyboards/truestrike42/he_switch_matrix.h create mode 100644 keyboards/truestrike42/keyboard.json create mode 100644 keyboards/truestrike42/keymaps/default/keymap.c create mode 100644 keyboards/truestrike42/matrix.c create mode 100644 keyboards/truestrike42/readme.md create mode 100644 keyboards/truestrike42/rules.mk create mode 100644 keyboards/truestrike42/truestrike42.c create mode 100644 keyboards/truestrike42/via_he.c diff --git a/keyboards/truestrike42/config.h b/keyboards/truestrike42/config.h new file mode 100644 index 00000000000..5a42d84964e --- /dev/null +++ b/keyboards/truestrike42/config.h @@ -0,0 +1,36 @@ +#pragma once + +#define MATRIX_ROWS 4 +#define MATRIX_COLS 12 + +#define MATRIX_ROW_PINS \ + { GP26, GP27, GP28, GP29 } + +#define ROWS_PER_COL \ + { 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3 } + +#define AMUX_MAX_COLS_COUNT 12 + +#define AMUX_SEL_PINS \ + { GP4, GP5, GP6, GP7, GP8, GP9 } +#define AMUX_COL_CHANNELS \ + { 0, 1, 2, 3, 4, 5, 56, 57, 58, 59, 60, 61 } + +#define DEFAULT_ACTUATION_MODE 0 +#define DEFAULT_MODE_0_ACTUATION_LEVEL 350 +#define DEFAULT_MODE_0_RELEASE_LEVEL 400 +#define DEFAULT_MODE_1_INITIAL_DEADZONE_OFFSET DEFAULT_MODE_0_ACTUATION_LEVEL +#define DEFAULT_MODE_1_ACTUATION_OFFSET 70 +#define DEFAULT_MODE_1_RELEASE_OFFSET 70 +#define DEFAULT_EXTREMUM 1023 +#define NOISE_CEILING_THRESHOLD 50 +#define BOTTOMING_CALIBRATION_THRESHOLD 50 +#define DEFAULT_NOISE_CEILING_SAMPLING_COUNT 30 +#define DEFAULT_BOTTOMING_READING 0 +#define DEFAULT_CALIBRATION_STARTER true + +#define EECONFIG_KB_DATA_SIZE 256 + +#define DEBUG_MATRIX_SCAN_RATE + +#define QUANTUM_PAINTER_DISPLAY_TIMEOUT 0 diff --git a/keyboards/truestrike42/eeprom_tools.h b/keyboards/truestrike42/eeprom_tools.h new file mode 100644 index 00000000000..b3c90d87592 --- /dev/null +++ b/keyboards/truestrike42/eeprom_tools.h @@ -0,0 +1,26 @@ +/* Copyright 2023 Cipulot + * + * 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 3 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 . + */ +#pragma once + +#include "eeprom.h" + +#if (EECONFIG_KB_DATA_SIZE) > 0 +# define EEPROM_KB_PARTIAL_UPDATE(__struct, __field) eeprom_update_block(&(__struct.__field), (void *)((void *)(EECONFIG_KB_DATABLOCK) + offsetof(typeof(__struct), __field)), sizeof(__struct.__field)) +#endif + +#if (EECONFIG_USER_DATA_SIZE) > 0 +# define EEPROM_USER_PARTIAL_UPDATE(__struct, __field) eeprom_update_block(&(__struct.__field), (void *)((void *)(EECONFIG_USER_DATABLOCK) + offsetof(typeof(__struct), __field)), sizeof(__struct.__field)) +#endif diff --git a/keyboards/truestrike42/graphics/display.c b/keyboards/truestrike42/graphics/display.c new file mode 100644 index 00000000000..ba7371f4639 --- /dev/null +++ b/keyboards/truestrike42/graphics/display.c @@ -0,0 +1,235 @@ +// Copyright 2023 Dasky (@daskygit), 2024 Choi Byungyoon (@byungyoonc) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "graphics/display.h" +#include "graphics/quinquefive.qff.h" +#include +#include "he_switch_matrix.h" + +static deferred_token freq_display_task_token; +static deferred_token stat_display_task_token; +static deferred_token mods_display_task_token; + +static painter_device_t display; +static painter_font_handle_t font; + +#define KEYPRESS_BIN_NUM 128 +static uint8_t key_press_bin[KEYPRESS_BIN_NUM]; +static uint8_t current_bin_number = 0; +static bool last_nkro = false; +static uint8_t last_mod_state = UINT8_MAX; + +void freq_graph_display(void); +void display_mod_update(uint8_t mod_state, uint8_t oneshot_mod_state); + +uint32_t freq_graph_callback(uint32_t trigger_time, void *cb_arg) { + freq_graph_display(); + return 1000; +} + +uint32_t stat_draw_callback(uint32_t trigger_time, void *cb_arg) { + display_task_kb(); + return 1000; +} + +uint32_t mods_draw_callback(uint32_t trigger_time, void *cb_arg) { + display_mod_update(get_mods(), get_oneshot_mods()); + return 16; +} + +void display_init_kb(void) { + display = qp_sh1106_make_i2c_device(128, 64, 0x3c); + qp_init(display, QP_ROTATION_180); + font = qp_load_font_mem(font_quinquefive); + if (!display_init_user()) { + return; + } + for (uint8_t bin = 0; bin < KEYPRESS_BIN_NUM; ++bin) { + key_press_bin[bin] = 0; + } + char buffer[40] = "Powered by QMK Ψ"; + uint16_t width = qp_textwidth(font, buffer); + uint8_t height = font->line_height + 2; + qp_drawtext(display, 64-width/2, 33 - height, font, buffer); + snprintf(buffer, sizeof(buffer), "TrueStrike42"); + width = qp_textwidth(font, buffer); + qp_drawtext(display, 64-width/2, 33, font, buffer); + qp_flush(display); + mods_display_task_token = defer_exec(2000, mods_draw_callback, NULL); + stat_display_task_token = defer_exec(2000, stat_draw_callback, NULL); + freq_display_task_token = defer_exec(2000, freq_graph_callback, NULL); +} + +__attribute__((weak)) bool display_init_user(void) { + return true; +} + +void freq_graph_display(void) { + uint8_t freq_graph_height = 28; + uint8_t line_height = MIN(key_press_bin[current_bin_number], freq_graph_height); + qp_line(display, current_bin_number, 61, current_bin_number, 61 - line_height, 0, 0, 255); + qp_line(display, current_bin_number, 63, current_bin_number, 62, 0, 0, 0); + uint8_t next_bin = current_bin_number + 1; + if (KEYPRESS_BIN_NUM <= next_bin) { + next_bin = 0; + } + qp_line(display, next_bin, 61-freq_graph_height, next_bin, 61, 0, 0, 0); + qp_line(display, next_bin, 63, next_bin, 62, 0, 0, 255); + qp_flush(display); + + current_bin_number++; + if (KEYPRESS_BIN_NUM <= current_bin_number) { + current_bin_number = 0; + } + key_press_bin[current_bin_number] = 0; + + return; +} + +void display_layer_state(layer_state_t state) { + uint16_t highest_layer = get_highest_layer(state); + + char buffer[5] = {0}; + + snprintf(buffer, sizeof(buffer), "%4d", highest_layer); + qp_drawtext(display, 100, 14, font, buffer); +} + +void display_led_state(led_t state) { + qp_rect(display, 2, 2, 10, 10, 0, 0, 255, state.num_lock); + if (!state.num_lock) { + qp_rect(display, 3, 3, 9, 9, 0, 0, 0, true); + } + qp_drawtext_recolor(display, 4, 4, font, "N", 0, 0, state.num_lock ? 0 : 255, 0, 0, state.num_lock ? 255 : 0); + qp_rect(display, 13, 2, 21, 10, 0, 0, 255, state.caps_lock); + if (!state.caps_lock) { + qp_rect(display, 14, 3, 20, 9, 0, 0, 0, true); + } + qp_drawtext_recolor(display, 15, 4, font, "C", 0, 0, state.caps_lock ? 0 : 255, 0, 0, state.caps_lock ? 255 : 0); + qp_rect(display, 24, 2, 32, 10, 0, 0, 255, state.scroll_lock); + if (!state.scroll_lock) { + qp_rect(display, 25, 3, 31, 9, 0, 0, 0, true); + } + qp_drawtext_recolor(display, 26, 4, font, "S", 0, 0, state.scroll_lock ? 0 : 255, 0, 0, state.scroll_lock ? 255 : 0); +} + +void display_nkro_state(bool nkro) { + qp_rect(display, 35, 2, 61, 10, 0, 0, 255, nkro); + if (!nkro) { + qp_rect(display, 36, 3, 60, 9, 0, 0, 0, true); + } + qp_drawtext_recolor(display, 37, 4, font, "NKRO", 0, 0, nkro ? 0 : 255, 0, 0, nkro ? 255 : 0); +} + +void display_mod_state(uint8_t mod_state, uint8_t oneshot_mod_state) { + if (mod_state & MOD_MASK_CTRL) { + qp_drawtext(display, 86, 4, font, "C"); + } else { + qp_drawtext(display, 86, 4, font, " "); + } + if (mod_state & MOD_MASK_ALT) { + qp_drawtext(display, 97, 4, font, "A"); + } else { + qp_drawtext(display, 97, 4, font, " "); + } + if (mod_state & MOD_MASK_GUI) { + qp_drawtext(display, 108, 4, font, "G"); + } else { + qp_drawtext(display, 108, 4, font, " "); + } + if (mod_state & MOD_MASK_SHIFT) { + qp_drawtext(display, 119, 4, font, "S"); + } else { + qp_drawtext(display, 119, 4, font, " "); + } +} + +void display_task_kb(void) { + if (!display_task_user()) { + return; + } + + static bool first_draw = true; + static uint32_t last_scan_rate = 0; + static uint8_t last_actuation_mode = UINT8_MAX; + bool diff = false; + + if (first_draw) { + qp_clear(display); + qp_drawtext(display, 4, 14, font, "Active Layer ="); + qp_drawtext(display, 4, 21, font, "Scan Rate ="); + qp_drawtext(display, 4, 28, font, "Rapid Trigger ="); + display_led_state(host_keyboard_led_state()); + display_layer_state(layer_state); + display_nkro_state(keymap_config.nkro); + last_nkro = keymap_config.nkro; + first_draw = false; + diff = true; + } + + char buffer[5] = {0}; + + uint32_t scan_rate = get_matrix_scan_rate(); + if (last_scan_rate != scan_rate) { + snprintf(buffer, sizeof(buffer), "%4ld", scan_rate); + //int16_t width = qp_textwidth(font, buffer); + qp_drawtext(display, 100, 21, font, buffer); + last_scan_rate = scan_rate; + diff = true; + } + + if (last_actuation_mode != he_config.actuation_mode) { + if (he_config.actuation_mode == 0) { + qp_drawtext(display, 106, 28, font, "OFF"); + } else { + qp_drawtext(display, 106, 28, font, " ON"); + } + last_actuation_mode = he_config.actuation_mode; + diff = true; + } + + if (diff) { + qp_flush(display); + } +} + +layer_state_t layer_state_set_kb(layer_state_t state) { + state = layer_state_set_user(state); + display_layer_state(state); + qp_flush(display); + return state; +} + +bool led_update_kb(led_t led_state) { + bool res = led_update_user(led_state); + if (res) { + display_led_state(led_state); + qp_flush(display); + } + return res; +} + +__attribute__((weak)) bool display_task_user(void) { + return true; +} + +void display_key_counter(void) { + key_press_bin[current_bin_number]++; +} + +void display_mod_update(uint8_t mod_state, uint8_t oneshot_mod_state) { + bool diff = false; + if (last_mod_state != mod_state) { + display_mod_state(mod_state, oneshot_mod_state); + diff = true; + last_mod_state = mod_state; + } + if (last_nkro != keymap_config.nkro) { + display_nkro_state(keymap_config.nkro); + diff = true; + last_nkro = keymap_config.nkro; + } + if (diff) { + qp_flush(display); + } +} diff --git a/keyboards/truestrike42/graphics/display.h b/keyboards/truestrike42/graphics/display.h new file mode 100644 index 00000000000..90219d0bf3a --- /dev/null +++ b/keyboards/truestrike42/graphics/display.h @@ -0,0 +1,7 @@ +#pragma once + +void display_key_counter(void); +void display_init_kb(void); +bool display_init_user(void); +void display_task_kb(void); +bool display_task_user(void); diff --git a/keyboards/truestrike42/graphics/quinquefive.qff.c b/keyboards/truestrike42/graphics/quinquefive.qff.c new file mode 100644 index 00000000000..a0c2d5c84e2 --- /dev/null +++ b/keyboards/truestrike42/graphics/quinquefive.qff.c @@ -0,0 +1,65 @@ +// Copyright 2024 QMK -- generated source code only, font retains original copyright +// SPDX-License-Identifier: GPL-2.0-or-later + +// This file was auto-generated by `qmk painter-convert-font-image --input /home/kevincby/qmk_firmware/keyboards/truestrike42/graphics/quinquefive.png --output /home/kevincby/qmk_firmware/keyboards/truestrike42/graphics --no-ascii False --unicode-glyphs Ψ←→↑↓ --format mono2 --no-rle False` + +// Font's metadata +// --------------- +// Glyphs: , !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, ;, <, =, >, ?, @, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, [, \, ], ^, _, `, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, {, |, }, ~, Ψ, ←, ↑, →, ↓ + +#include + +const uint32_t font_quinquefive_length = 755; + +// clang-format off +const uint8_t font_quinquefive[755] = { + 0x00, 0xFF, 0x14, 0x00, 0x00, 0x51, 0x46, 0x46, 0x01, 0xF3, 0x02, 0x00, 0x00, 0x0C, 0xFD, 0xFF, + 0xFF, 0x05, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x01, 0xFE, 0x1D, 0x01, 0x00, 0x06, 0x00, + 0x00, 0x06, 0x01, 0x00, 0x06, 0x02, 0x00, 0x06, 0x03, 0x00, 0x06, 0x04, 0x00, 0x06, 0x05, 0x00, + 0x06, 0x06, 0x00, 0x06, 0x07, 0x00, 0x06, 0x08, 0x00, 0x06, 0x09, 0x00, 0x06, 0x0A, 0x00, 0x06, + 0x0B, 0x00, 0x06, 0x0C, 0x00, 0x06, 0x0D, 0x00, 0x06, 0x0E, 0x00, 0x06, 0x0F, 0x00, 0x06, 0x10, + 0x00, 0x06, 0x11, 0x00, 0x06, 0x12, 0x00, 0x06, 0x13, 0x00, 0x06, 0x14, 0x00, 0x06, 0x15, 0x00, + 0x06, 0x16, 0x00, 0x06, 0x17, 0x00, 0x06, 0x18, 0x00, 0x06, 0x19, 0x00, 0x06, 0x1A, 0x00, 0x06, + 0x1B, 0x00, 0x06, 0x1C, 0x00, 0x06, 0x1D, 0x00, 0x06, 0x1E, 0x00, 0x06, 0x1F, 0x00, 0x06, 0x20, + 0x00, 0x06, 0x21, 0x00, 0x06, 0x22, 0x00, 0x06, 0x23, 0x00, 0x06, 0x24, 0x00, 0x06, 0x25, 0x00, + 0x06, 0x26, 0x00, 0x06, 0x27, 0x00, 0x06, 0x28, 0x00, 0x06, 0x29, 0x00, 0x06, 0x2A, 0x00, 0x06, + 0x2B, 0x00, 0x06, 0x2C, 0x00, 0x06, 0x2D, 0x00, 0x06, 0x2E, 0x00, 0x06, 0x2F, 0x00, 0x06, 0x30, + 0x00, 0x06, 0x31, 0x00, 0x06, 0x32, 0x00, 0x06, 0x33, 0x00, 0x06, 0x34, 0x00, 0x06, 0x35, 0x00, + 0x06, 0x36, 0x00, 0x06, 0x37, 0x00, 0x06, 0x38, 0x00, 0x06, 0x39, 0x00, 0x06, 0x3A, 0x00, 0x06, + 0x3B, 0x00, 0x06, 0x3C, 0x00, 0x06, 0x3D, 0x00, 0x06, 0x3E, 0x00, 0x06, 0x3F, 0x00, 0x06, 0x40, + 0x00, 0x06, 0x41, 0x00, 0x06, 0x42, 0x00, 0x06, 0x43, 0x00, 0x06, 0x44, 0x00, 0x06, 0x45, 0x00, + 0x06, 0x46, 0x00, 0x06, 0x47, 0x00, 0x06, 0x48, 0x00, 0x06, 0x49, 0x00, 0x06, 0x4A, 0x00, 0x06, + 0x4B, 0x00, 0x06, 0x4C, 0x00, 0x06, 0x4D, 0x00, 0x06, 0x4E, 0x00, 0x06, 0x4F, 0x00, 0x06, 0x50, + 0x00, 0x06, 0x51, 0x00, 0x06, 0x52, 0x00, 0x06, 0x53, 0x00, 0x06, 0x54, 0x00, 0x06, 0x55, 0x00, + 0x06, 0x56, 0x00, 0x06, 0x57, 0x00, 0x06, 0x58, 0x00, 0x06, 0x59, 0x00, 0x06, 0x5A, 0x00, 0x06, + 0x5B, 0x00, 0x06, 0x5C, 0x00, 0x06, 0x5D, 0x00, 0x06, 0x5E, 0x00, 0x02, 0xFD, 0x1E, 0x00, 0x00, + 0xA8, 0x03, 0x00, 0x06, 0x5F, 0x00, 0x90, 0x21, 0x00, 0x06, 0x60, 0x00, 0x91, 0x21, 0x00, 0x06, + 0x61, 0x00, 0x92, 0x21, 0x00, 0x06, 0x62, 0x00, 0x93, 0x21, 0x00, 0x06, 0x63, 0x00, 0x04, 0xFB, + 0x90, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x41, 0x00, 0x04, 0x8A, 0x02, 0x00, 0x00, 0xCA, + 0xA7, 0x7C, 0x0A, 0x5E, 0xE1, 0x50, 0x0F, 0x11, 0x42, 0x08, 0x11, 0x46, 0x60, 0x25, 0x16, 0x04, + 0x01, 0x00, 0x00, 0x8C, 0x20, 0x08, 0x0C, 0x06, 0x82, 0x20, 0x06, 0x0A, 0xA1, 0x00, 0x00, 0x04, + 0xF1, 0x11, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0xF0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x10, + 0x42, 0x08, 0x01, 0x5F, 0x14, 0x45, 0x1F, 0x46, 0x41, 0x10, 0x1F, 0x0F, 0xC4, 0x08, 0x1F, 0x1F, + 0xE4, 0x41, 0x1F, 0x51, 0xF4, 0x41, 0x10, 0x5F, 0xF0, 0x41, 0x1F, 0x5F, 0xF0, 0x45, 0x1F, 0x1F, + 0x84, 0x10, 0x02, 0x5F, 0xF4, 0x45, 0x1F, 0x5F, 0xF4, 0x41, 0x1F, 0x00, 0x01, 0x10, 0x00, 0x00, + 0x01, 0x10, 0x04, 0x98, 0x11, 0x18, 0x18, 0xC0, 0x07, 0x7C, 0x00, 0x03, 0x03, 0x31, 0x03, 0x0E, + 0x42, 0x00, 0x04, 0x4E, 0x54, 0x65, 0x02, 0x4E, 0x14, 0x7D, 0x11, 0x4F, 0xF4, 0x44, 0x0F, 0x5E, + 0x10, 0x04, 0x1E, 0x4F, 0x14, 0x45, 0x0F, 0x5F, 0xF0, 0x04, 0x1F, 0x5F, 0xF0, 0x04, 0x01, 0x5E, + 0xD0, 0x45, 0x1E, 0x51, 0xF4, 0x45, 0x11, 0x1F, 0x41, 0x10, 0x1F, 0x10, 0x14, 0x45, 0x0E, 0x51, + 0x72, 0x24, 0x11, 0x41, 0x10, 0x04, 0x1F, 0xD1, 0x56, 0x55, 0x11, 0xD1, 0x54, 0x65, 0x11, 0x4E, + 0x14, 0x45, 0x0E, 0x4F, 0xF4, 0x04, 0x01, 0x4E, 0x14, 0x25, 0x16, 0x4F, 0xF4, 0x24, 0x11, 0x5E, + 0xE0, 0x40, 0x0F, 0x1F, 0x41, 0x10, 0x04, 0x51, 0x14, 0x45, 0x0E, 0x51, 0x14, 0x29, 0x04, 0x51, + 0x55, 0x55, 0x0E, 0x91, 0x42, 0x28, 0x11, 0x51, 0xE4, 0x10, 0x04, 0x1F, 0x42, 0x08, 0x1F, 0x8E, + 0x20, 0x08, 0x0E, 0x81, 0x40, 0x20, 0x10, 0x0E, 0x82, 0x20, 0x0E, 0x84, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x1F, 0x02, 0x01, 0x00, 0x00, 0x4E, 0x14, 0x7D, 0x11, 0x4F, 0xF4, 0x44, 0x0F, 0x5E, + 0x10, 0x04, 0x1E, 0x4F, 0x14, 0x45, 0x0F, 0x5F, 0xF0, 0x04, 0x1F, 0x5F, 0xF0, 0x04, 0x01, 0x5E, + 0xD0, 0x45, 0x1E, 0x51, 0xF4, 0x45, 0x11, 0x1F, 0x41, 0x10, 0x1F, 0x10, 0x14, 0x45, 0x0E, 0x51, + 0x72, 0x24, 0x11, 0x41, 0x10, 0x04, 0x1F, 0xD1, 0x56, 0x55, 0x11, 0xD1, 0x54, 0x65, 0x11, 0x4E, + 0x14, 0x45, 0x0E, 0x4F, 0xF4, 0x04, 0x01, 0x4E, 0x14, 0x25, 0x16, 0x4F, 0xF4, 0x24, 0x11, 0x5E, + 0xE0, 0x40, 0x0F, 0x1F, 0x41, 0x10, 0x04, 0x51, 0x14, 0x45, 0x0E, 0x51, 0x14, 0x29, 0x04, 0x51, + 0x55, 0x55, 0x0E, 0x91, 0x42, 0x28, 0x11, 0x51, 0xE4, 0x10, 0x04, 0x1F, 0x42, 0x08, 0x1F, 0x8E, + 0x30, 0x08, 0x0E, 0x04, 0x41, 0x10, 0x04, 0x0E, 0x82, 0x21, 0x0E, 0x80, 0x50, 0x21, 0x00, 0x55, + 0xE5, 0x10, 0x04, 0x84, 0xF0, 0x09, 0x04, 0x84, 0x53, 0x11, 0x04, 0x04, 0xF2, 0x21, 0x04, 0x04, + 0x51, 0x39, 0x04, +}; +// clang-format on diff --git a/keyboards/truestrike42/graphics/quinquefive.qff.h b/keyboards/truestrike42/graphics/quinquefive.qff.h new file mode 100644 index 00000000000..59154077c11 --- /dev/null +++ b/keyboards/truestrike42/graphics/quinquefive.qff.h @@ -0,0 +1,11 @@ +// Copyright 2024 QMK -- generated source code only, font retains original copyright +// SPDX-License-Identifier: GPL-2.0-or-later + +// This file was auto-generated by `qmk painter-convert-font-image --input /home/kevincby/qmk_firmware/keyboards/truestrike42/graphics/quinquefive.png --output /home/kevincby/qmk_firmware/keyboards/truestrike42/graphics --no-ascii False --unicode-glyphs Ψ←→↑↓ --format mono2 --no-rle False` + +#pragma once + +#include + +extern const uint32_t font_quinquefive_length; +extern const uint8_t font_quinquefive[755]; diff --git a/keyboards/truestrike42/he_switch_matrix.c b/keyboards/truestrike42/he_switch_matrix.c new file mode 100644 index 00000000000..c10f5444ee8 --- /dev/null +++ b/keyboards/truestrike42/he_switch_matrix.c @@ -0,0 +1,226 @@ +/* Copyright 2023 Cipulot, 2024 byungyoonc + * + * 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 3 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 . + */ + +#include "he_switch_matrix.h" +#include "analog.h" +#include "print.h" +#include "wait.h" + +#if defined(__AVR__) +# error "AVR platforms not supported due to a variety of reasons. Among them there are limited memory, limited number of pins and ADC not being able to give satisfactory results." +#endif + +eeprom_he_config_t eeprom_he_config; +he_config_t he_config; + +// Pin and port array +const pin_t row_pins[] = MATRIX_ROW_PINS; +const pin_t amux_sel_pins[] = AMUX_SEL_PINS; +const pin_t amux_n_col_channels[AMUX_MAX_COLS_COUNT] = AMUX_COL_CHANNELS; +const uint8_t rows_per_col[] = ROWS_PER_COL; + +#define AMUX_SEL_PINS_COUNT ARRAY_SIZE(amux_sel_pins) + +static uint16_t sw_value[MATRIX_ROWS][MATRIX_COLS]; +static adc_mux adcMux[MATRIX_ROWS]; + +void init_row(void) { + // Set all row pins to analog input + for (uint8_t idx = 0; idx < MATRIX_ROWS; ++idx) { + palSetLineMode(row_pins[idx], PAL_MODE_INPUT_ANALOG); + adcMux[idx] = pinToMux(row_pins[idx]); + } +} + +void init_amux(void) { + // Set all AMUX SEL pins to GPIO output + for (uint8_t idx = 0; idx < AMUX_SEL_PINS_COUNT; ++idx) { + gpio_set_pin_output(amux_sel_pins[idx]); + } +} + +void select_amux(uint8_t col) { + uint8_t ch = amux_n_col_channels[col]; + // Select the multiplexer channel + for (uint8_t idx = 0; idx < AMUX_SEL_PINS_COUNT; ++idx) { + gpio_write_pin(amux_sel_pins[idx], ch & (1 << idx)); + } +} + +int he_init(void) { + init_row(); + + init_amux(); + + return 0; +} + +// Get the noise ceiling +void he_noise_ceiling(void) { + // Initialize the noise ceiling + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + he_config.noise_ceiling[row][col] = 0; + } + } + + // Sample the noise ceiling + for (uint8_t i = 0; i < DEFAULT_NOISE_CEILING_SAMPLING_COUNT; i++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + select_amux(col); + for (uint8_t row = 0; row < rows_per_col[col]; row++) { + he_config.noise_ceiling[row][col] += he_readkey_raw(row); + } + } + wait_ms(5); + } + + // Average the noise ceiling + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + he_config.noise_ceiling[row][col] /= DEFAULT_NOISE_CEILING_SAMPLING_COUNT; + } + } +} + +// Scan key values and update matrix state +bool he_matrix_scan(matrix_row_t current_matrix[]) { + bool updated = false; + + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + select_amux(col); + for (uint8_t row = 0; row < rows_per_col[col]; row++) { + sw_value[row][col] = he_readkey_raw(row); + if (he_config.bottoming_calibration) { + if (he_config.bottoming_calibration_starter[row][col]) { + he_config.bottoming_reading[row][col] = sw_value[row][col]; + he_config.bottoming_calibration_starter[row][col] = false; + } else if (sw_value[row][col] < he_config.bottoming_reading[row][col]) { + he_config.bottoming_reading[row][col] = sw_value[row][col]; + } + } else { + updated |= he_update_key(¤t_matrix[row], row, col, sw_value[row][col]); + } + } + } + + return he_config.bottoming_calibration ? false : updated; +} + +// Read the Hall effect sensor value +uint16_t he_readkey_raw(uint8_t row) { + uint16_t sw_value = 0; + + // Read the ADC value + sw_value = adc_read(adcMux[row]); + + return sw_value; +} + +// Update press/release state of key +bool he_update_key(matrix_row_t* current_row, uint8_t row, uint8_t col, uint16_t sw_value) { + bool current_state = (*current_row >> col) & 1; + + // Real Time Noise Floor Calibration + if ((he_config.noise_ceiling[row][col] + NOISE_CEILING_THRESHOLD) < sw_value) { + uprintf("Noise Floor Change: %d, %d, %d\n", row, col, sw_value); + he_config.noise_ceiling[row][col] = sw_value; + he_config.rescaled_mode_0_actuation_threshold[row][col] = rescale(he_config.mode_0_actuation_threshold, 0, 1023, he_config.noise_ceiling[row][col], eeprom_he_config.bottoming_reading[row][col]); + he_config.rescaled_mode_0_release_threshold[row][col] = rescale(he_config.mode_0_release_threshold, 0, 1023, he_config.noise_ceiling[row][col], eeprom_he_config.bottoming_reading[row][col]); + he_config.rescaled_mode_1_initial_deadzone_offset[row][col] = rescale(he_config.mode_1_initial_deadzone_offset, 0, 1023, he_config.noise_ceiling[row][col], eeprom_he_config.bottoming_reading[row][col]); + } + + // Normal board-wide APC + if (he_config.actuation_mode == 0) { + if (current_state && he_config.rescaled_mode_0_release_threshold[row][col] < sw_value) { + *current_row &= ~(1 << col); + uprintf("Key released: %d, %d, %d\n", row, col, sw_value); + return true; + } + if ((!current_state) && sw_value < he_config.rescaled_mode_0_actuation_threshold[row][col]) { + *current_row |= (1 << col); + uprintf("Key pressed: %d, %d, %d\n", row, col, sw_value); + return true; + } + } + + // Rapid Trigger + else if (he_config.actuation_mode == 1) { + // Is key in active zone? + if (sw_value < he_config.rescaled_mode_1_initial_deadzone_offset[row][col]) { + // Is key pressed while in active zone? + if (current_state) { + // Is the key still moving down? + if (sw_value < he_config.extremum[row][col]) { + he_config.extremum[row][col] = sw_value; + //uprintf("Key going down: %d, %d, %d\n", row, col, sw_value); + } + // Has key moved up enough to be released? + else if (he_config.extremum[row][col] + he_config.mode_1_release_offset < sw_value) { + he_config.extremum[row][col] = sw_value; + *current_row &= ~(1 << col); + uprintf("Key released: %d, %d, %d\n", row, col, sw_value); + return true; + } + } + // Key is not pressed while in active zone + else { + // Is the key still moving up? + if (he_config.extremum[row][col] < sw_value) { + he_config.extremum[row][col] = sw_value; + } + // Has key moved down enough to be pressed? + else if (sw_value < he_config.extremum[row][col] - he_config.mode_1_actuation_offset) { + he_config.extremum[row][col] = sw_value; + *current_row |= (1 << col); + uprintf("Key pressed: %d, %d, %d\n", row, col, sw_value); + return true; + } + } + } + // Key is not in active zone + else { + // Check to avoid key being stuck in pressed state near the active zone threshold + if (he_config.extremum[row][col] < sw_value) { + he_config.extremum[row][col] = sw_value; + *current_row &= ~(1 << col); + return true; + } + } + } + return false; +} + +// Print the matrix values +void he_print_matrix(void) { + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + uint8_t last_col = 0; + for (uint8_t col = 0; col < MATRIX_COLS - 1; col++) { + if (row < rows_per_col[col]) + { + uprintf("%4d,", sw_value[row][col]); + last_col = col; + } + } + uprintf("%4d\n", sw_value[row][last_col + 1]); + } + print("\n"); +} + +// Rescale the value to a different range +uint16_t rescale(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max) { + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +} diff --git a/keyboards/truestrike42/he_switch_matrix.h b/keyboards/truestrike42/he_switch_matrix.h new file mode 100644 index 00000000000..98421a14e89 --- /dev/null +++ b/keyboards/truestrike42/he_switch_matrix.h @@ -0,0 +1,66 @@ +/* Copyright 2023 Cipulot, 2024 byungyoonc + * + * 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 3 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 . + */ + +#pragma once + +#include +#include +#include "matrix.h" +#include "eeconfig.h" +#include "util.h" + +typedef struct PACKED { + uint8_t actuation_mode; // 0: normal board-wide APC, 1: Rapid trigger from specific board-wide actuation point, 2: Rapid trigger from resting point + uint16_t mode_0_actuation_threshold; // threshold for key press in mode 0 + uint16_t mode_0_release_threshold; // threshold for key release in mode 0 + uint16_t mode_1_initial_deadzone_offset; // threshold for key press in mode 1 + uint8_t mode_1_actuation_offset; // offset for key press in mode 1 and 2 (1-255) + uint8_t mode_1_release_offset; // offset for key release in mode 1 and 2 (1-255) + uint16_t bottoming_reading[MATRIX_ROWS][MATRIX_COLS]; // bottoming reading +} eeprom_he_config_t; + +typedef struct { + uint8_t actuation_mode; // 0: normal board-wide APC, 1: Rapid trigger from specific board-wide actuation point (it can be very near that baseline noise and be "full travel") + uint16_t mode_0_actuation_threshold; // threshold for key press in mode 0 + uint16_t mode_0_release_threshold; // threshold for key release in mode 0 + uint16_t mode_1_initial_deadzone_offset; // threshold for key press in mode 1 (initial deadzone) + uint16_t rescaled_mode_0_actuation_threshold[MATRIX_ROWS][MATRIX_COLS]; // threshold for key press in mode 0 rescaled to actual scale + uint16_t rescaled_mode_0_release_threshold[MATRIX_ROWS][MATRIX_COLS]; // threshold for key release in mode 0 rescaled to actual scale + uint16_t rescaled_mode_1_initial_deadzone_offset[MATRIX_ROWS][MATRIX_COLS]; // threshold for key press in mode 1 (initial deadzone) rescaled to actual scale + uint8_t mode_1_actuation_offset; // offset for key press in mode 1 (1-255) + uint8_t mode_1_release_offset; // offset for key release in mode 1 (1-255) + uint16_t extremum[MATRIX_ROWS][MATRIX_COLS]; // extremum values for mode 1 + uint16_t noise_ceiling[MATRIX_ROWS][MATRIX_COLS]; // noise ceiling detected during startup + bool bottoming_calibration; // calibration mode for bottoming out values (true: calibration mode, false: normal mode) + bool bottoming_calibration_starter[MATRIX_ROWS][MATRIX_COLS]; // calibration mode for bottoming out values (true: calibration mode, false: normal mode) + uint16_t bottoming_reading[MATRIX_ROWS][MATRIX_COLS]; // bottoming reading +} he_config_t; + +extern eeprom_he_config_t eeprom_he_config; +extern he_config_t he_config; + +void init_row(void); +void init_amux(void); +void select_amux(uint8_t col); + +int he_init(void); +void he_noise_ceiling(void); +bool he_matrix_scan(matrix_row_t current_matrix[]); +uint16_t he_readkey_raw(uint8_t row); +bool he_update_key(matrix_row_t* current_row, uint8_t row, uint8_t col, uint16_t sw_value); +void he_print_matrix(void); + +uint16_t rescale(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max); diff --git a/keyboards/truestrike42/keyboard.json b/keyboards/truestrike42/keyboard.json new file mode 100644 index 00000000000..80f393ff0e9 --- /dev/null +++ b/keyboards/truestrike42/keyboard.json @@ -0,0 +1,186 @@ +{ + "manufacturer": "byungyoonc", + "keyboard_name": "TrueStrike42", + "maintainer": "byungyoonc", + "bootloader": "rp2040", + "processor": "RP2040", + "build": { + "debounce_type": "asym_eager_defer_pk" + }, + "features": { + "bootmagic": true, + "command": false, + "console": true, + "extrakey": true, + "mousekey": true, + "nkro": true, + "rgb_matrix": true + }, + "diode_direction": "COL2ROW", + "url": "", + "usb": { + "device_version": "1.0.0", + "pid": "0x0000", + "vid": "0x5A53" + }, + "matrix": { + "debounce": 100 + }, + "dynamic_keymap": { + "layer_count": 10 + }, + "ws2812": { + "pin": "GP0", + "driver": "vendor" + }, + "layouts": { + "LAYOUT_split_3x6_3": { + "layout": [ + {"matrix": [0, 0], "x": 0, "y": 0.25}, + {"matrix": [0, 1], "x": 1, "y": 0.25}, + {"matrix": [0, 2], "x": 2, "y": 0.125}, + {"matrix": [0, 3], "x": 3, "y": 0}, + {"matrix": [0, 4], "x": 4, "y": 0.125}, + {"matrix": [0, 5], "x": 5, "y": 0.25}, + + {"matrix": [1, 6], "x": 8, "y": 0.25}, + {"matrix": [1, 7], "x": 9, "y": 0.125}, + {"matrix": [1, 8], "x": 10, "y": 0}, + {"matrix": [1, 9], "x": 11, "y": 0.125}, + {"matrix": [1, 10], "x": 12, "y": 0.25}, + {"matrix": [1, 11], "x": 13, "y": 0.25}, + + {"matrix": [0, 6], "x": 0, "y": 1.25}, + {"matrix": [0, 7], "x": 1, "y": 1.25}, + {"matrix": [0, 8], "x": 2, "y": 1.125}, + {"matrix": [0, 9], "x": 3, "y": 1}, + {"matrix": [0, 10], "x": 4, "y": 1.125}, + {"matrix": [0, 11], "x": 5, "y": 1.25}, + + {"matrix": [2, 0], "x": 8, "y": 1.25}, + {"matrix": [2, 1], "x": 9, "y": 1.125}, + {"matrix": [2, 2], "x": 10, "y": 1}, + {"matrix": [2, 3], "x": 11, "y": 1.125}, + {"matrix": [2, 4], "x": 12, "y": 1.25}, + {"matrix": [2, 5], "x": 13, "y": 1.25}, + + {"matrix": [1, 0], "x": 0, "y": 2.25}, + {"matrix": [1, 1], "x": 1, "y": 2.25}, + {"matrix": [1, 2], "x": 2, "y": 2.125}, + {"matrix": [1, 3], "x": 3, "y": 2}, + {"matrix": [1, 4], "x": 4, "y": 2.125}, + {"matrix": [1, 5], "x": 5, "y": 2.25}, + + {"matrix": [2, 6], "x": 8, "y": 2.25}, + {"matrix": [2, 7], "x": 9, "y": 2.125}, + {"matrix": [2, 8], "x": 10, "y": 2}, + {"matrix": [2, 9], "x": 11, "y": 2.125}, + {"matrix": [2, 10], "x": 12, "y": 2.25}, + {"matrix": [2, 11], "x": 13, "y": 2.25}, + + {"matrix": [3, 0], "x": 3.5, "y": 3.25}, + {"matrix": [3, 1], "x": 4.5, "y": 3.5}, + {"matrix": [3, 2], "x": 5.5, "y": 3.75}, + {"matrix": [3, 3], "x": 7.5, "y": 3.75}, + {"matrix": [3, 4], "x": 8.5, "y": 3.5}, + {"matrix": [3, 5], "x": 9.5, "y": 3.25} + ] + } + }, + "rgb_matrix": { + "animations": { + "alphas_mods": true, + "gradient_up_down": true, + "gradient_left_right": true, + "breathing": true, + "band_sat": true, + "band_val": true, + "band_pinwheel_sat": true, + "band_pinwheel_val": true, + "band_spiral_sat": true, + "band_spiral_val": true, + "cycle_all": true, + "cycle_left_right": true, + "cycle_up_down": true, + "rainbow_moving_chevron": true, + "cycle_out_in": true, + "cycle_out_in_dual": true, + "cycle_pinwheel": true, + "cycle_spiral": true, + "dual_beacon": true, + "rainbow_beacon": true, + "rainbow_pinwheels": true, + "raindrops": true, + "jellybean_raindrops": true, + "hue_breathing": true, + "hue_pendulum": true, + "hue_wave": true, + "pixel_rain": true, + "pixel_flow": true, + "pixel_fractal": true, + "typing_heatmap": true, + "digital_rain": true, + "solid_reactive_simple": true, + "solid_reactive": true, + "solid_reactive_wide": true, + "solid_reactive_multiwide": true, + "solid_reactive_cross": true, + "solid_reactive_multicross": true, + "solid_reactive_nexus": true, + "solid_reactive_multinexus": true, + "splash": true, + "multisplash": true, + "solid_splash": true, + "solid_multisplash": true + }, + "default": { + "animation": "alphas_mods" + }, + "max_brightness": 255, + "driver": "ws2812", + "layout": [ + {"matrix": [0, 5], "x": 86, "y": 4, "flags": 4}, + {"matrix": [0, 4], "x": 68, "y": 2, "flags": 4}, + {"matrix": [0, 3], "x": 51, "y": 0, "flags": 4}, + {"matrix": [0, 2], "x": 34, "y": 2, "flags": 4}, + {"matrix": [0, 1], "x": 17, "y": 4, "flags": 4}, + {"matrix": [0, 0], "x": 0, "y": 4, "flags": 1}, + {"matrix": [0, 6], "x": 0, "y": 21, "flags": 1}, + {"matrix": [0, 7], "x": 17, "y": 21, "flags": 4}, + {"matrix": [0, 8], "x": 34, "y": 19, "flags": 4}, + {"matrix": [0, 9], "x": 51, "y": 17, "flags": 4}, + {"matrix": [0, 10], "x": 68, "y": 19, "flags": 4}, + {"matrix": [0, 11], "x": 86, "y": 21, "flags": 4}, + {"matrix": [1, 5], "x": 86, "y": 38, "flags": 4}, + {"matrix": [1, 4], "x": 68, "y": 36, "flags": 4}, + {"matrix": [1, 3], "x": 51, "y": 34, "flags": 4}, + {"matrix": [1, 2], "x": 34, "y": 36, "flags": 4}, + {"matrix": [1, 1], "x": 17, "y": 38, "flags": 4}, + {"matrix": [1, 0], "x": 0, "y": 38, "flags": 1}, + {"matrix": [3, 0], "x": 60, "y": 55, "flags": 1}, + {"matrix": [3, 1], "x": 77, "y": 59, "flags": 1}, + {"matrix": [3, 2], "x": 94, "y": 64, "flags": 4}, + {"matrix": [3, 3], "x": 129, "y": 64, "flags": 4}, + {"matrix": [3, 4], "x": 146, "y": 59, "flags": 1}, + {"matrix": [3, 5], "x": 163, "y": 55, "flags": 1}, + {"matrix": [2, 11], "x": 224, "y": 38, "flags": 1}, + {"matrix": [2, 10], "x": 206, "y": 38, "flags": 4}, + {"matrix": [2, 9], "x": 189, "y": 36, "flags": 4}, + {"matrix": [2, 8], "x": 172, "y": 34, "flags": 4}, + {"matrix": [2, 7], "x": 155, "y": 36, "flags": 4}, + {"matrix": [2, 6], "x": 137, "y": 38, "flags": 4}, + {"matrix": [2, 0], "x": 137, "y": 21, "flags": 4}, + {"matrix": [2, 1], "x": 155, "y": 19, "flags": 4}, + {"matrix": [2, 2], "x": 172, "y": 17, "flags": 4}, + {"matrix": [2, 3], "x": 189, "y": 19, "flags": 4}, + {"matrix": [2, 4], "x": 206, "y": 21, "flags": 4}, + {"matrix": [2, 5], "x": 224, "y": 21, "flags": 1}, + {"matrix": [1, 11], "x": 224, "y": 4, "flags": 1}, + {"matrix": [1, 10], "x": 206, "y": 4, "flags": 4}, + {"matrix": [1, 9], "x": 189, "y": 2, "flags": 4}, + {"matrix": [1, 8], "x": 172, "y": 0, "flags": 4}, + {"matrix": [1, 7], "x": 155, "y": 2, "flags": 4}, + {"matrix": [1, 6], "x": 137, "y": 4, "flags": 4} + ] + } +} diff --git a/keyboards/truestrike42/keymaps/default/keymap.c b/keyboards/truestrike42/keymaps/default/keymap.c new file mode 100644 index 00000000000..a6a0f64ac0c --- /dev/null +++ b/keyboards/truestrike42/keymaps/default/keymap.c @@ -0,0 +1,33 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + /* + * ┌───┬───┬───┬───┬───┬───┐ ┌───┬───┬───┬───┬───┬───┐ + * │Tab│ Q │ W │ E │ R │ T │ │ Y │ U │ I │ O │ P │Bsp│ + * ├───┼───┼───┼───┼───┼───┤ ├───┼───┼───┼───┼───┼───┤ + * │Ctl│ A │ S │ D │ F │ G │ │ H │ J │ K │ L │ ; │ ' │ + * ├───┼───┼───┼───┼───┼───┤ ├───┼───┼───┼───┼───┼───┤ + * │Sft│ Z │ X │ C │ V │ B │ │ N │ M │ , │ . │ / │Sft│ + * └───┴───┴───┴───┴───┴───┘ └───┴───┴───┴───┴───┴───┘ + * ┌───┐ ┌───┐ + * │GUI├───┐ ┌───┤Alt│ + * └───┤Bsp├───┐ ┌───┤Ent├───┘ + * └───┤ │ │ ├───┘ + * └───┘ └───┘ + */ + [0] = LAYOUT_split_3x6_3( + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, + KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, + 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_LGUI, MO(1), KC_SPC, KC_SPC, KC_ENT, KC_RALT + ), + [1] = LAYOUT_split_3x6_3( + KC_TAB, QK_BOOT, EE_CLR, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, + KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, + 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_LGUI, _______, KC_SPC, KC_SPC, KC_ENT, KC_RALT + ) +}; diff --git a/keyboards/truestrike42/matrix.c b/keyboards/truestrike42/matrix.c new file mode 100644 index 00000000000..9f42ab3710b --- /dev/null +++ b/keyboards/truestrike42/matrix.c @@ -0,0 +1,36 @@ +/* Copyright 2023 Cipulot, 2024 byungyoonc + * + * 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 3 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 . + */ + +#include "he_switch_matrix.h" +#include "matrix.h" +#include "print.h" + +extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values +extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values + +void matrix_init_custom(void) { + // Initialize HE + he_init(); + + // Get the noise ceiling at boot + he_noise_ceiling(); +} + +bool matrix_scan_custom(matrix_row_t current_matrix[]) { + bool matrix_has_changed = he_matrix_scan(current_matrix); + + return matrix_has_changed; +} diff --git a/keyboards/truestrike42/readme.md b/keyboards/truestrike42/readme.md new file mode 100644 index 00000000000..6deddd85a33 --- /dev/null +++ b/keyboards/truestrike42/readme.md @@ -0,0 +1,27 @@ +# truestrike42 + +![truestrike42](imgur.com image replace me!) + +*A short description of the keyboard/project* + +* Keyboard Maintainer: [Choi Byungyoon](https://github.com/Choi Byungyoon) +* Hardware Supported: *The PCBs, controllers supported* +* Hardware Availability: *Links to where you can find this hardware* + +Make example for this keyboard (after setting up your build environment): + + make truestrike42:default + +Flashing example for this keyboard: + + make truestrike42:default:flash + +See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). + +## Bootloader + +Enter the bootloader in 3 ways: + +* **Bootmagic reset**: Hold down the key at (0,0) in the matrix (usually the top left key or Escape) and plug in the keyboard +* **Physical reset button**: Briefly press the button on the back of the PCB - some may have pads you must short instead +* **Keycode in layout**: Press the key mapped to `QK_BOOT` if it is available diff --git a/keyboards/truestrike42/rules.mk b/keyboards/truestrike42/rules.mk new file mode 100644 index 00000000000..93c09500423 --- /dev/null +++ b/keyboards/truestrike42/rules.mk @@ -0,0 +1,5 @@ +SRC += matrix.c he_switch_matrix.c via_he.c graphics/display.c graphics/quinquefive.qff.c +CUSTOM_MATRIX = lite +ANALOG_DRIVER_REQUIRED = yes +QUANTUM_PAINTER_ENABLE = yes +QUANTUM_PAINTER_DRIVERS += sh1106_i2c diff --git a/keyboards/truestrike42/truestrike42.c b/keyboards/truestrike42/truestrike42.c new file mode 100644 index 00000000000..df9dce9308e --- /dev/null +++ b/keyboards/truestrike42/truestrike42.c @@ -0,0 +1,83 @@ +/* Copyright 2023 Cipulot, 2024 byungyoonc + * + * 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 3 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 . + */ + +// Copyright 2023 Dasky (@daskygit) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "quantum.h" +#include "graphics/display.h" +#include "he_switch_matrix.h" +#include "keyboard.h" +#include "rgb_matrix.h" +#include "he_switch_matrix.h" + +void eeconfig_init_kb(void) { + // Default values + eeprom_he_config.actuation_mode = DEFAULT_ACTUATION_MODE; + eeprom_he_config.mode_0_actuation_threshold = DEFAULT_MODE_0_ACTUATION_LEVEL; + eeprom_he_config.mode_0_release_threshold = DEFAULT_MODE_0_RELEASE_LEVEL; + eeprom_he_config.mode_1_initial_deadzone_offset = DEFAULT_MODE_1_INITIAL_DEADZONE_OFFSET; + eeprom_he_config.mode_1_actuation_offset = DEFAULT_MODE_1_ACTUATION_OFFSET; + eeprom_he_config.mode_1_release_offset = DEFAULT_MODE_1_RELEASE_OFFSET; + + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + eeprom_he_config.bottoming_reading[row][col] = DEFAULT_BOTTOMING_READING; + } + } + // Write default value to EEPROM now + eeconfig_update_kb_datablock(&eeprom_he_config); + + eeconfig_init_user(); +} + +// On Keyboard startup +void keyboard_post_init_kb(void) { + display_init_kb(); + keyboard_post_init_user(); + + // Read custom menu variables from memory + eeconfig_read_kb_datablock(&eeprom_he_config); + + // Set runtime values to EEPROM values + he_config.actuation_mode = eeprom_he_config.actuation_mode; + he_config.mode_0_actuation_threshold = eeprom_he_config.mode_0_actuation_threshold; + he_config.mode_0_release_threshold = eeprom_he_config.mode_0_release_threshold; + he_config.mode_1_initial_deadzone_offset = eeprom_he_config.mode_1_initial_deadzone_offset; + he_config.mode_1_actuation_offset = eeprom_he_config.mode_1_actuation_offset; + he_config.mode_1_release_offset = eeprom_he_config.mode_1_release_offset; + he_config.bottoming_calibration = false; + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + he_config.bottoming_calibration_starter[row][col] = true; + he_config.bottoming_reading[row][col] = eeprom_he_config.bottoming_reading[row][col]; + he_config.rescaled_mode_0_actuation_threshold[row][col] = rescale(he_config.mode_0_actuation_threshold, 0, 1023, he_config.noise_ceiling[row][col], eeprom_he_config.bottoming_reading[row][col]); + he_config.rescaled_mode_0_release_threshold[row][col] = rescale(he_config.mode_0_release_threshold, 0, 1023, he_config.noise_ceiling[row][col], eeprom_he_config.bottoming_reading[row][col]); + he_config.rescaled_mode_1_initial_deadzone_offset[row][col] = rescale(he_config.mode_1_initial_deadzone_offset, 0, 1023, he_config.noise_ceiling[row][col], eeprom_he_config.bottoming_reading[row][col]); + } + } + + rgb_matrix_set_flags(LED_FLAG_ALL); + + keyboard_post_init_user(); +} + +bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + if (record->event.pressed) { + display_key_counter(); + } + return process_record_user(keycode, record); +} diff --git a/keyboards/truestrike42/via_he.c b/keyboards/truestrike42/via_he.c new file mode 100644 index 00000000000..145d7f8e8db --- /dev/null +++ b/keyboards/truestrike42/via_he.c @@ -0,0 +1,363 @@ +/* Copyright 2023 Cipulot, 2024 byungyoonc + * + * 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 3 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 . + */ +#include "eeprom_tools.h" +#include "he_switch_matrix.h" +#include "action.h" +#include "print.h" +#include "via.h" + +#ifdef VIA_ENABLE + +void he_rescale_values(uint8_t item); +void he_save_threshold_data(uint8_t option); +void he_save_bottoming_reading(void); +void he_show_calibration_data(void); +void he_clear_bottoming_calibration_data(void); + +// Declaring enums for VIA config menu +enum via_enums { + // clang-format off + id_actuation_mode = 1, + id_mode_0_actuation_threshold = 2, + id_mode_0_release_threshold = 3, + id_save_threshold_data = 4, + id_mode_1_initial_deadzone_offset = 5, + id_mode_1_actuation_offset = 6, + id_mode_1_release_offset = 7, + id_bottoming_calibration = 8, + id_noise_ceiling_calibration = 9, + id_show_calibration_data = 10, + id_clear_bottoming_calibration_data = 11 + // clang-format on +}; + +// Handle the data received by the keyboard from the VIA menus +void via_config_set_value(uint8_t *data) { + // data = [ value_id, value_data ] + uint8_t *value_id = &(data[0]); + uint8_t *value_data = &(data[1]); + + switch (*value_id) { + case id_actuation_mode: { + eeprom_he_config.actuation_mode = value_data[0]; + he_config.actuation_mode = eeprom_he_config.actuation_mode; + if (he_config.actuation_mode == 0) { + uprintf("#########################\n"); + uprintf("# Actuation Mode: APC #\n"); + uprintf("#########################\n"); + } else if (he_config.actuation_mode == 1) { + uprintf("#################################\n"); + uprintf("# Actuation Mode: Rapid Trigger #\n"); + uprintf("#################################\n"); + } + EEPROM_KB_PARTIAL_UPDATE(eeprom_he_config, actuation_mode); + break; + } + case id_mode_0_actuation_threshold: { + he_config.mode_0_actuation_threshold = value_data[1] | (value_data[0] << 8); + uprintf("APC Mode Actuation Threshold: %d\n", he_config.mode_0_actuation_threshold); + break; + } + case id_mode_0_release_threshold: { + he_config.mode_0_release_threshold = value_data[1] | (value_data[0] << 8); + uprintf("APC Mode Release Threshold: %d\n", he_config.mode_0_release_threshold); + break; + } + case id_mode_1_initial_deadzone_offset: { + he_config.mode_1_initial_deadzone_offset = value_data[1] | (value_data[0] << 8); + uprintf("Rapid Trigger Mode Initial Deadzone Offset: %d\n", he_config.mode_1_initial_deadzone_offset); + break; + } + case id_mode_1_actuation_offset: { + he_config.mode_1_actuation_offset = value_data[0]; + uprintf("Rapid Trigger Mode Actuation Offset: %d\n", he_config.mode_1_actuation_offset); + break; + } + case id_mode_1_release_offset: { + he_config.mode_1_release_offset = value_data[0]; + uprintf("Rapid Trigger Mode Release Offset: %d\n", he_config.mode_1_release_offset); + break; + } + case id_bottoming_calibration: { + if (value_data[0] == 1) { + he_config.bottoming_calibration = true; + uprintf("##############################\n"); + uprintf("# Bottoming calibration mode #\n"); + uprintf("##############################\n"); + } else { + he_config.bottoming_calibration = false; + he_save_bottoming_reading(); + uprintf("## Bottoming calibration done ##\n"); + he_show_calibration_data(); + } + break; + } + case id_save_threshold_data: { + he_save_threshold_data(value_data[0]); + break; + } + case id_noise_ceiling_calibration: { + if (value_data[0] == 0) { + he_noise_ceiling(); + he_rescale_values(0); + he_rescale_values(1); + he_rescale_values(2); + uprintf("#############################\n"); + uprintf("# Noise floor data acquired #\n"); + uprintf("#############################\n"); + break; + } + } + case id_show_calibration_data: { + if (value_data[0] == 0) { + he_show_calibration_data(); + break; + } + } + case id_clear_bottoming_calibration_data: { + if (value_data[0] == 0) { + he_clear_bottoming_calibration_data(); + } + } + default: { + // Unhandled value. + break; + } + } +} + +// Handle the data sent by the keyboard to the VIA menus +void via_config_get_value(uint8_t *data) { + // data = [ value_id, value_data ] + uint8_t *value_id = &(data[0]); + uint8_t *value_data = &(data[1]); + + switch (*value_id) { + case id_actuation_mode: { + value_data[0] = eeprom_he_config.actuation_mode; + break; + } + case id_mode_0_actuation_threshold: { + value_data[0] = eeprom_he_config.mode_0_actuation_threshold >> 8; + value_data[1] = eeprom_he_config.mode_0_actuation_threshold & 0xFF; + break; + } + case id_mode_0_release_threshold: { + value_data[0] = eeprom_he_config.mode_0_release_threshold >> 8; + value_data[1] = eeprom_he_config.mode_0_release_threshold & 0xFF; + break; + } + case id_mode_1_initial_deadzone_offset: { + value_data[0] = eeprom_he_config.mode_1_initial_deadzone_offset >> 8; + value_data[1] = eeprom_he_config.mode_1_initial_deadzone_offset & 0xFF; + break; + } + case id_mode_1_actuation_offset: { + value_data[0] = eeprom_he_config.mode_1_actuation_offset; + break; + } + case id_mode_1_release_offset: { + value_data[0] = eeprom_he_config.mode_1_release_offset; + break; + } + default: { + // Unhandled value. + break; + } + } +} + +// Handle the commands sent and received by the keyboard with VIA +void via_custom_value_command_kb(uint8_t *data, uint8_t length) { + // data = [ command_id, channel_id, value_id, value_data ] + uint8_t *command_id = &(data[0]); + uint8_t *channel_id = &(data[1]); + uint8_t *value_id_and_data = &(data[2]); + + if (*channel_id == id_custom_channel) { + switch (*command_id) { + case id_custom_set_value: { + via_config_set_value(value_id_and_data); + break; + } + case id_custom_get_value: { + via_config_get_value(value_id_and_data); + break; + } + case id_custom_save: { + // Bypass the save function in favor of pinpointed saves + break; + } + default: { + // Unhandled message. + *command_id = id_unhandled; + break; + } + } + return; + } + + *command_id = id_unhandled; +} + +// Rescale the values received by VIA to fit the new range +void he_rescale_values(uint8_t item) { + switch (item) { + // Rescale the APC mode actuation thresholds + case 0: + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + he_config.rescaled_mode_0_actuation_threshold[row][col] = rescale(he_config.mode_0_actuation_threshold, 0, 1023, he_config.noise_ceiling[row][col], eeprom_he_config.bottoming_reading[row][col]); + } + } + break; + // Rescale the APC mode release thresholds + case 1: + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + he_config.rescaled_mode_0_release_threshold[row][col] = rescale(he_config.mode_0_release_threshold, 0, 1023, he_config.noise_ceiling[row][col], eeprom_he_config.bottoming_reading[row][col]); + } + } + break; + // Rescale the Rapid Trigger mode initial deadzone offsets + case 2: + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + he_config.rescaled_mode_1_initial_deadzone_offset[row][col] = rescale(he_config.mode_1_initial_deadzone_offset, 0, 1023, he_config.noise_ceiling[row][col], eeprom_he_config.bottoming_reading[row][col]); + } + } + break; + + default: + // Unhandled item. + break; + } +} + +void he_save_threshold_data(uint8_t option) { + // Save APC mode thresholds and rescale them for runtime usage + if (option == 0) { + eeprom_he_config.mode_0_actuation_threshold = he_config.mode_0_actuation_threshold; + eeprom_he_config.mode_0_release_threshold = he_config.mode_0_release_threshold; + he_rescale_values(0); + he_rescale_values(1); + } + // Save Rapid Trigger mode thresholds and rescale them for runtime usage + else if (option == 1) { + eeprom_he_config.mode_1_initial_deadzone_offset = he_config.mode_1_initial_deadzone_offset; + eeprom_he_config.mode_1_actuation_offset = he_config.mode_1_actuation_offset; + eeprom_he_config.mode_1_release_offset = he_config.mode_1_release_offset; + he_rescale_values(2); + } + eeconfig_update_kb_datablock(&eeprom_he_config); + uprintf("####################################\n"); + uprintf("# New thresholds applied and saved #\n"); + uprintf("####################################\n"); +} + +// Save the bottoming reading +void he_save_bottoming_reading(void) { + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + // If the bottom reading doesn't go under the noise ceiling by BOTTOMING_CALIBRATION_THRESHOLD, it is likely that: + // 1. The key is not actually in the matrix + // 2. The key is on an alternative layout, therefore not being pressed + // 3. The key in in the current layout but not being pressed + if ((he_config.noise_ceiling[row][col] - BOTTOMING_CALIBRATION_THRESHOLD) < he_config.bottoming_reading[row][col]) { + eeprom_he_config.bottoming_reading[row][col] = 0; + } else { + eeprom_he_config.bottoming_reading[row][col] = he_config.bottoming_reading[row][col]; + } + } + } + // Rescale the values to fit the new range for runtime usage + he_rescale_values(0); + he_rescale_values(1); + he_rescale_values(2); + eeconfig_update_kb_datablock(&eeprom_he_config); +} + +// Show the calibration data +void he_show_calibration_data(void) { + uprintf("\n###############\n"); + uprintf("# Noise Ceiling #\n"); + uprintf("###############\n"); + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS - 1; col++) { + uprintf("%4d,", he_config.noise_ceiling[row][col]); + } + uprintf("%4d\n", he_config.noise_ceiling[row][MATRIX_COLS - 1]); + } + + uprintf("\n######################\n"); + uprintf("# Bottoming Readings #\n"); + uprintf("######################\n"); + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS - 1; col++) { + uprintf("%4d,", eeprom_he_config.bottoming_reading[row][col]); + } + uprintf("%4d\n", eeprom_he_config.bottoming_reading[row][MATRIX_COLS - 1]); + } + + uprintf("\n######################################\n"); + uprintf("# Rescaled APC Mode Actuation Points #\n"); + uprintf("######################################\n"); + uprintf("Original APC Mode Actuation Point: %4d\n", he_config.mode_0_actuation_threshold); + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS - 1; col++) { + uprintf("%4d,", he_config.rescaled_mode_0_actuation_threshold[row][col]); + } + uprintf("%4d\n", he_config.rescaled_mode_0_actuation_threshold[row][MATRIX_COLS - 1]); + } + + uprintf("\n######################################\n"); + uprintf("# Rescaled APC Mode Release Points #\n"); + uprintf("######################################\n"); + uprintf("Original APC Mode Release Point: %4d\n", he_config.mode_0_release_threshold); + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS - 1; col++) { + uprintf("%4d,", he_config.rescaled_mode_0_release_threshold[row][col]); + } + uprintf("%4d\n", he_config.rescaled_mode_0_release_threshold[row][MATRIX_COLS - 1]); + } + + uprintf("\n#######################################################\n"); + uprintf("# Rescaled Rapid Trigger Mode Initial Deadzone Offset #\n"); + uprintf("#######################################################\n"); + uprintf("Original Rapid Trigger Mode Initial Deadzone Offset: %4d\n", he_config.mode_1_initial_deadzone_offset); + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS - 1; col++) { + uprintf("%4d,", he_config.rescaled_mode_1_initial_deadzone_offset[row][col]); + } + uprintf("%4d\n", he_config.rescaled_mode_1_initial_deadzone_offset[row][MATRIX_COLS - 1]); + } + print("\n"); +} + +// Clear the calibration data +void he_clear_bottoming_calibration_data(void) { + // Clear the EEPROM data + eeconfig_init_kb(); + + // Reset the runtime values to the EEPROM values + keyboard_post_init_kb(); + + uprintf("######################################\n"); + uprintf("# Bottoming calibration data cleared #\n"); + uprintf("######################################\n"); +} + +#endif // VIA_ENABLE