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 new file mode 100755 index 0000000000..e765d0b47d --- /dev/null +++ b/keyboards/binepad/bnk8/keymaps/via/keymap.c @@ -0,0 +1,95 @@ +// Copyright 2024 Binepad (@binepad) +// SPDX-License-Identifier: GPL-2.0-or-later + +#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)│ + * ├───┼───┼───┤ + * │ 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( + RM_HUEU, RM_SATU, RM_SPDU, + RM_HUED, RM_SATD, RM_SPDD, + RM_TOGG, RM_NEXT, _______ + ) +}; +// clanf-format on + +#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_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 // 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 new file mode 100755 index 0000000000..0696d2d8c9 --- /dev/null +++ b/keyboards/binepad/bnk8/keymaps/via/rules.mk @@ -0,0 +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