From 7e5dc1893d1c480d5a27200521969578b3aa185c Mon Sep 17 00:00:00 2001 From: Vino Rodrigues Date: Sat, 26 Oct 2024 02:13:12 +1100 Subject: [PATCH 1/3] Added BNK8 --- keyboards/binepad/bnk8/keymaps/via/keymap.c | 35 +++++++++++++++++++++ keyboards/binepad/bnk8/keymaps/via/rules.mk | 2 ++ 2 files changed, 37 insertions(+) create mode 100644 keyboards/binepad/bnk8/keymaps/via/keymap.c create mode 100644 keyboards/binepad/bnk8/keymaps/via/rules.mk diff --git a/keyboards/binepad/bnk8/keymaps/via/keymap.c b/keyboards/binepad/bnk8/keymaps/via/keymap.c new file mode 100644 index 0000000000..121c6a8509 --- /dev/null +++ b/keyboards/binepad/bnk8/keymaps/via/keymap.c @@ -0,0 +1,35 @@ +// Copyright 2024 Binepad (@binepad) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + /* + * ┌───┬───┬───┐ + * │ 1 │ 2 │ K │ + * ├───┼───┼───┤ + * │ 3 │ 4 │ 5 │ + * ├───┼───┼───┤ + * │ 6 │ 7 │ 8 │ + * └───┴───┴───┘ + */ + [0] = LAYOUT_ortho_3x3( + KC_P1, KC_P2, KC_MUTE, + KC_P3, KC_P4, KC_P5, + KC_P6, KC_P7, LT(1, KC_P8) + ), + [1] = LAYOUT_ortho_3x3( + RGB_HUI, RGB_SAI, RGB_SPI, + RGB_HUD, RGB_SAD, RGB_SPD, + RGB_TOG, RGB_MOD, _______ + ) +}; + +#if defined(ENCODER_MAP_ENABLE) + +const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { + [0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) }, + [1] = { ENCODER_CCW_CW(RGB_VAD, RGB_VAI) } +}; + +#endif diff --git a/keyboards/binepad/bnk8/keymaps/via/rules.mk b/keyboards/binepad/bnk8/keymaps/via/rules.mk new file mode 100644 index 0000000000..f1adcab005 --- /dev/null +++ b/keyboards/binepad/bnk8/keymaps/via/rules.mk @@ -0,0 +1,2 @@ +VIA_ENABLE = yes +ENCODER_MAP_ENABLE = yes From 5187fb1efa8ac031a280c72a2cf8d9f352b7f2ff Mon Sep 17 00:00:00 2001 From: Vino Rodrigues <366673+vinorodrigues@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:52:23 +1100 Subject: [PATCH 2/3] RGB_ -> RM_ keycodes after Nov'24 breaking changes --- keyboards/binepad/bnk8/keymaps/via/keymap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/keyboards/binepad/bnk8/keymaps/via/keymap.c b/keyboards/binepad/bnk8/keymaps/via/keymap.c index 121c6a8509..f72c5060d5 100644 --- a/keyboards/binepad/bnk8/keymaps/via/keymap.c +++ b/keyboards/binepad/bnk8/keymaps/via/keymap.c @@ -19,9 +19,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_P6, KC_P7, LT(1, KC_P8) ), [1] = LAYOUT_ortho_3x3( - RGB_HUI, RGB_SAI, RGB_SPI, - RGB_HUD, RGB_SAD, RGB_SPD, - RGB_TOG, RGB_MOD, _______ + RM_HUEU, RM_SATU, RM_SPDU, + RM_HUED, RM_SATD, RM_SPDD, + RM_TOGG, RM_NEXT, _______ ) }; @@ -29,7 +29,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { [0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) }, - [1] = { ENCODER_CCW_CW(RGB_VAD, RGB_VAI) } + [1] = { ENCODER_CCW_CW(RM_VALD, RM_VALD) } }; #endif From f3ba366b32494c2befc1eefd072dfbed2d8cde83 Mon Sep 17 00:00:00 2001 From: Vino Rodrigues <366673+silvinor@users.noreply.github.com> Date: Thu, 2 Jan 2025 08:00:33 +1100 Subject: [PATCH 3/3] Added code used in custom UI elements --- keyboards/binepad/bnk8/keymaps/via/bnk8.h | 35 +++++++ .../binepad/bnk8/keymaps/via/bnk8_effect.c | 95 +++++++++++++++++++ keyboards/binepad/bnk8/keymaps/via/config.c | 6 ++ keyboards/binepad/bnk8/keymaps/via/keymap.c | 68 ++++++++++++- .../bnk8/keymaps/via/rgb_matrix_kb.inc | 39 ++++++++ keyboards/binepad/bnk8/keymaps/via/rules.mk | 16 ++++ 6 files changed, 255 insertions(+), 4 deletions(-) create mode 100755 keyboards/binepad/bnk8/keymaps/via/bnk8.h create mode 100755 keyboards/binepad/bnk8/keymaps/via/bnk8_effect.c create mode 100644 keyboards/binepad/bnk8/keymaps/via/config.c mode change 100644 => 100755 keyboards/binepad/bnk8/keymaps/via/keymap.c create mode 100755 keyboards/binepad/bnk8/keymaps/via/rgb_matrix_kb.inc mode change 100644 => 100755 keyboards/binepad/bnk8/keymaps/via/rules.mk diff --git a/keyboards/binepad/bnk8/keymaps/via/bnk8.h b/keyboards/binepad/bnk8/keymaps/via/bnk8.h new file mode 100755 index 0000000000..ab34b84878 --- /dev/null +++ b/keyboards/binepad/bnk8/keymaps/via/bnk8.h @@ -0,0 +1,35 @@ +// Copyright 2024 binepad (@binepad) +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "quantum.h" +#ifdef VIA_ENABLE // Only works if VIA is enabled +# include "color.h" +#endif + +#ifdef CAFFEINE_ENABLE + +enum bnk8_keyboard { KC_CAFFEINE_TOGGLE = QK_KB_0 }; + +# define KC_COFFEE KC_CAFFEINE_TOGGLE + +#endif // CAFFEINE_ENABLE + +#ifdef VIA_ENABLE // Only works if VIA is enabled + +typedef struct PACKED { + uint8_t h; + uint8_t s; +} HS; + +typedef union { + uint8_t raw[16]; + struct { + HS color[8]; + }; +} user_config_t; + +extern user_config_t g_user_config; + +#endif // VIA_ENABLE diff --git a/keyboards/binepad/bnk8/keymaps/via/bnk8_effect.c b/keyboards/binepad/bnk8/keymaps/via/bnk8_effect.c new file mode 100755 index 0000000000..07e2c2b054 --- /dev/null +++ b/keyboards/binepad/bnk8/keymaps/via/bnk8_effect.c @@ -0,0 +1,95 @@ +// Copyright 2024 Binepad (@binepad) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "quantum.h" + +#ifdef VIA_ENABLE // Only works if VIA is enabled + +# include "color.h" +# include "progmem.h" +# include "eeprom.h" +# include "via.h" +# include "bnk8.h" + +# define RGB_PER_KEY_DEFAULT_COLOR {.h = RGB_MATRIX_DEFAULT_HUE, .s = RGB_MATRIX_DEFAULT_SAT} + +user_config_t g_user_config = {.color = {RGB_PER_KEY_DEFAULT_COLOR, RGB_PER_KEY_DEFAULT_COLOR, RGB_PER_KEY_DEFAULT_COLOR, RGB_PER_KEY_DEFAULT_COLOR, RGB_PER_KEY_DEFAULT_COLOR, RGB_PER_KEY_DEFAULT_COLOR, RGB_PER_KEY_DEFAULT_COLOR, RGB_PER_KEY_DEFAULT_COLOR}}; + +enum via_per_key_value { id_custom_color = 1 }; + +// *** Helpers *** + +void bnk8_config_set_value(uint8_t *data) { + uint8_t *value_id = &(data[0]); + uint8_t *value_data = &(data[1]); + + switch (*value_id) { + case id_custom_color: { + uint8_t i = value_data[0]; + g_user_config.color[i].h = value_data[1]; + g_user_config.color[i].s = value_data[2]; + break; + } + } +} + +void bnk8_config_get_value(uint8_t *data) { + uint8_t *value_id = &(data[0]); + uint8_t *value_data = &(data[1]); + + switch (*value_id) { + case id_custom_color: { + uint8_t i = value_data[0]; + value_data[1] = g_user_config.color[i].h; + value_data[2] = g_user_config.color[i].s; + break; + } + } +} + +void bnk8_config_load(void) { + eeprom_read_block(&g_user_config.raw, EECONFIG_USER, sizeof(user_config_t)); +} + +void bnk8_config_save(void) { + eeprom_update_block(&g_user_config.raw, EECONFIG_USER, sizeof(user_config_t)); +} + +void via_custom_value_command_kb(uint8_t *data, uint8_t length) { + 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: + bnk8_config_set_value(value_id_and_data); + break; + case id_custom_get_value: + bnk8_config_get_value(value_id_and_data); + break; + case id_custom_save: + bnk8_config_save(); + break; + default: + // Unhandled message. + *command_id = id_unhandled; + break; + } + return; + } + + *command_id = id_unhandled; +} + +void via_init_kb(void) { + // This checks both an EEPROM reset (from bootmagic lite, keycodes) + // and also firmware build date (from via_eeprom_is_valid()) + if (eeconfig_is_enabled()) { + bnk8_config_load(); + } else { + bnk8_config_save(); + } +} + +#endif // VIA_ENABLE diff --git a/keyboards/binepad/bnk8/keymaps/via/config.c b/keyboards/binepad/bnk8/keymaps/via/config.c new file mode 100644 index 0000000000..f7d101bad9 --- /dev/null +++ b/keyboards/binepad/bnk8/keymaps/via/config.c @@ -0,0 +1,6 @@ +// Copyright 2024 Binepad (@binepad) +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#define DYNAMIC_KEYMAP_LAYER_COUNT 7 diff --git a/keyboards/binepad/bnk8/keymaps/via/keymap.c b/keyboards/binepad/bnk8/keymaps/via/keymap.c old mode 100644 new mode 100755 index f72c5060d5..e765d0b47d --- a/keyboards/binepad/bnk8/keymaps/via/keymap.c +++ b/keyboards/binepad/bnk8/keymaps/via/keymap.c @@ -3,10 +3,19 @@ #include QMK_KEYBOARD_H +#include "binepad_common.h" +#include "bnk8.h" + +#ifdef CAFFEINE_ENABLE +# include "caffeine.h" +# define COFFEE KC_CAFFEINE_TOGGLE +#endif // CAFFEINE_ENABLE + +// clang-format off const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* * ┌───┬───┬───┐ - * │ 1 │ 2 │ K │ + * │ 1 │ 2 │(K)│ * ├───┼───┼───┤ * │ 3 │ 4 │ 5 │ * ├───┼───┼───┤ @@ -24,12 +33,63 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { RM_TOGG, RM_NEXT, _______ ) }; +// clanf-format on -#if defined(ENCODER_MAP_ENABLE) +#ifdef ENCODER_MAP_ENABLE +// clanf-format off const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { [0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) }, - [1] = { ENCODER_CCW_CW(RM_VALD, RM_VALD) } + [1] = { ENCODER_CCW_CW(RM_VALD, RM_VALU) } }; +// clanf-format on + +#endif // ENCODER_MAP_ENABLE + +// ---------- Optional Add-ons ----------- + +#if defined(CAFFEINE_ENABLE) + +# ifdef RGB_MATRIX_ENABLE + +bool rgb_matrix_indicators_user(void) { +# ifdef CAFFEINE_ENABLE + if (!rgb_matrix_indicators_caffeine()) return false; +# endif + return true; +} + +bool led_update_user(led_t led_state) { +# ifdef CAFFEINE_ENABLE + if (!led_update_caffeine(led_state)) return false; +# endif + return true; +} + +# endif // RGB_MATRIX_ENABLE + +void matrix_scan_user(void) { +# ifdef CAFFEINE_ENABLE + matrix_scan_caffeine(); +# endif +} + +void housekeeping_task_user(void) { +# ifdef CAFFEINE_ENABLE + housekeeping_task_caffeine(); +# endif +} + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { +# ifdef CAFFEINE_ENABLE + case KC_CAFFEINE_TOGGLE: + return caffeine_process_toggle_keycode(record); + break; +# endif + default: break; + } + return true; +} -#endif +#endif // CAFFEINE_ENABLE diff --git a/keyboards/binepad/bnk8/keymaps/via/rgb_matrix_kb.inc b/keyboards/binepad/bnk8/keymaps/via/rgb_matrix_kb.inc new file mode 100755 index 0000000000..4cf6a7b03a --- /dev/null +++ b/keyboards/binepad/bnk8/keymaps/via/rgb_matrix_kb.inc @@ -0,0 +1,39 @@ +// Copyright 2024 Binepad (@binepad) +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifdef VIA_ENABLE + +// Declare custom effects using the RGB_MATRIX_EFFECT macro +RGB_MATRIX_EFFECT(bnk8_per_key_effect) + +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +# include "eeprom.h" +# include "eeconfig.h" +# include "via.h" +# include "bnk8.h" + +// Per-key color effect + +static bool bnk8_per_key_effect(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + HSV hsv; + RGB rgb; + + // Assuming `g_user_config` is set prior + + hsv.v = rgb_matrix_get_val(); + for (uint8_t i = led_min; i < led_max; i++) { + if (i < 8) { + hsv.h = g_user_config.color[i].h; + hsv.s = g_user_config.color[i].s; + rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + } + + return rgb_matrix_check_finished_leds(led_max); +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // VIA_ENABLE diff --git a/keyboards/binepad/bnk8/keymaps/via/rules.mk b/keyboards/binepad/bnk8/keymaps/via/rules.mk old mode 100644 new mode 100755 index f1adcab005..0696d2d8c9 --- a/keyboards/binepad/bnk8/keymaps/via/rules.mk +++ b/keyboards/binepad/bnk8/keymaps/via/rules.mk @@ -1,2 +1,18 @@ +# Copyright 2024 Binepad (@binepad) +# SPDX-License-Identifier: GPL-2.0-or-later + VIA_ENABLE = yes ENCODER_MAP_ENABLE = yes + +RGB_MATRIX_CUSTOM_KB = yes +SRC += bnk8_effect.c + +CAFFEINE_ENABLE = yes + +VPATH += $(QMK_USERSPACE)/keyboards/binepad/common +SRC += binepad_common.c + +ifeq ($(strip $(CAFFEINE_ENABLE)), yes) + SRC += caffeine.c + OPT_DEFS += -DCAFFEINE_ENABLE +endif