Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Keyboard] Add BINEPAD BNK9 #22831

Merged
merged 18 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions keyboards/binepad/bnk9/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2023 binepad (@binepad)
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#define ENCODER_DEFAULT_POS 0x3 // enable 1:1 resolution

#ifdef RGB_MATRIX_ENABLE
#define WS2812_PIO_USE_PIO1

// Timing for SK6812
#define WS2812_T1H 650
#endif
98 changes: 98 additions & 0 deletions keyboards/binepad/bnk9/info.json
vinorodrigues marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"manufacturer": "binepad",
"keyboard_name": "BNK9",
"url": "https://www.binepad.com/product-page/bnk9",
"maintainer": "binepad",
"board": "GENERIC_RP_RP2040",
"processor": "RP2040",
"bootloader": "rp2040",
"bootloader_instructions": "Hold down the key at (0x0) in the matrix (the 'knob' / rotary encoder) and plug in the keyboard.",
"diode_direction": "COL2ROW",
"usb": {
"vid": "0x4249",
"pid": "0x4E39",
"device_version": "1.0.0"
},
"features": {
"bootmagic": true,
"command": false,
"console": false,
vinorodrigues marked this conversation as resolved.
Show resolved Hide resolved
"extrakey": true,
"mousekey": true,
"nkro": true,
"encoder": true,
"rgb_matrix": true,
"sleep_led": false
vinorodrigues marked this conversation as resolved.
Show resolved Hide resolved
},
"ws2812": {
"driver": "vendor",
"pin": "GP11"
},
"matrix_pins": {
"cols": ["GP1", "GP2", "GP3"],
"rows": ["GP12", "GP4", "GP5", "GP6"]
},
"encoder": {
"rotary": [
{
"pin_a": "GP13",
"pin_b": "GP14"
}
]
},
"rgb_matrix": {
"driver": "ws2812",
"animations": {
"solid_color": true,
"breathing": true,
"cycle_all": true,
"cycle_left_right": true,
"cycle_up_down": true,
"cycle_pinwheel": true,
"jellybean_raindrops": true,
"solid_reactive_simple": true,
"solid_reactive": true,
"splash": true,
"solid_splash": true,
"starlight": true,
"starlight_dual_hue": true,
"starlight_dual_sat": true,
"riverflow": true
},
"layout": [
{"flags": 4, "matrix": [1, 0], "x": 80, "y": 0},
{"flags": 4, "matrix": [1, 1], "x": 112, "y": 0},
{"flags": 4, "matrix": [1, 2], "x": 144, "y": 0},

{"flags": 4, "matrix": [2, 2], "x": 144, "y": 32},
{"flags": 4, "matrix": [2, 1], "x": 112, "y": 32},
{"flags": 4, "matrix": [2, 0], "x": 80, "y": 32},

{"flags": 4, "matrix": [3, 0], "x": 80, "y": 64},
{"flags": 4, "matrix": [3, 1], "x": 112, "y": 64},
{"flags": 4, "matrix": [3, 2], "x": 144, "y": 64}
],
"led_process_limit": 9,
"max_brightness": 180,
"sleep": true
}
"layouts": {
"LAYOUT": {
"layout": [
{ "matrix": [0, 0], "label": "Knob", "x": 0, "y": 0, "w": 3, "h": 3 },

{ "matrix": [1, 0], "label": "1", "x": 3.25, "y": 0 },
{ "matrix": [1, 1], "label": "2", "x": 4.25, "y": 0 },
{ "matrix": [1, 2], "label": "3", "x": 5.25, "y": 0 },

{ "matrix": [2, 0], "label": "4", "x": 3.25, "y": 1 },
{ "matrix": [2, 1], "label": "5", "x": 4.25, "y": 1 },
{ "matrix": [2, 2], "label": "6", "x": 5.25, "y": 1 },

{ "matrix": [3, 0], "label": "7", "x": 3.25, "y": 2 },
{ "matrix": [3, 1], "label": "8", "x": 4.25, "y": 2 },
{ "matrix": [3, 2], "label": "9", "x": 5.25, "y": 2 }
]
}
}
}
23 changes: 23 additions & 0 deletions keyboards/binepad/bnk9/keymaps/binepad/bnk9.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2023 binepad (@binepad)
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#ifdef VIA_ENABLE // Only works if VIA is enabled

# define EEPROM_USER_CONFIG_ADDRESS (VIA_EEPROM_CUSTOM_CONFIG_ADDR + 1)

# include "color.h"

typedef struct PACKED {
uint8_t h;
uint8_t s;
} HS;

typedef struct {
HS color[9];
} user_config_t;

extern user_config_t user_config;

#endif // VIA_ENABLE
122 changes: 122 additions & 0 deletions keyboards/binepad/bnk9/keymaps/binepad/bnk9_effect.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright 2023 Binepad (@binpad)
// 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 "quantum/color.h"
#include "eeprom.h"
#include "bnk9.h"

#ifndef EEPROM_USER_CONFIG_ADDRESS
#error EEPROM_USER_CONFIG_ADDRESS not defined
#endif
#if EEPROM_USER_CONFIG_ADDRESS == 0
#error EEPROM_USER_CONFIG_ADDRESS = 0
#endif

#define RGB_PER_KEY_DEFAULT_COLOR { .h = RGB_MATRIX_DEFAULT_HUE, .s = RGB_MATRIX_DEFAULT_SAT }

user_config_t 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,
RGB_PER_KEY_DEFAULT_COLOR
}
};

enum via_per_key_value {
id_custom_color = 1
};

// *** Helpers ***

void bkn9_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];
user_config.color[ i ].h = value_data[1];
user_config.color[ i ].s = value_data[2];
break;
}
}
}

void bkn9_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] = user_config.color[ i ].h;
value_data[2] = user_config.color[ i ].s;
break;
}
}
}

void bkn9_config_load(void) {
eeprom_read_block(
&user_config,
((void*)EEPROM_USER_CONFIG_ADDRESS),
sizeof(user_config_t) );
}

void bkn9_config_save(void) {
eeprom_update_block(
&user_config,
((void*)EEPROM_USER_CONFIG_ADDRESS),
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:
bkn9_config_set_value(value_id_and_data);
break;
case id_custom_get_value:
bkn9_config_get_value(value_id_and_data);
break;
case id_custom_save:
bkn9_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()) {
bkn9_config_load();
} else {
bkn9_config_save();
}
}

#endif // VIA_ENABLE
28 changes: 28 additions & 0 deletions keyboards/binepad/bnk9/keymaps/binepad/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2023 Binepad (@binpad)
// SPDX-License-Identifier: GPL-2.0-or-later

#include QMK_KEYBOARD_H

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT(
KC_MUTE,
KC_P1, KC_P2, KC_P3,
KC_P4, KC_P5, KC_P6,
KC_P7, KC_P8, LT(1, KC_P9)
),
[1] = LAYOUT(
RGB_TOG,
RGB_HUI, RGB_SAI, RGB_SPI,
RGB_HUD, RGB_SAD, RGB_SPD,
RGB_RMOD, 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
39 changes: 39 additions & 0 deletions keyboards/binepad/bnk9/keymaps/binepad/rgb_matrix_kb.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2023 Binepad (@binpad)
// SPDX-License-Identifier: GPL-2.0-or-later

#ifdef VIA_ENABLE

// Declare custom effects using the RGB_MATRIX_EFFECT macro
RGB_MATRIX_EFFECT(bnk9_per_key_effect)

#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

#include "eeprom.h"
#include "eeconfig.h"
#include "via.h"
#include "bnk9.h"

// Per-key color effect

static bool bnk9_per_key_effect(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv;
RGB rgb;

// Assuming `user_config` is set prior

hsv.v = rgb_matrix_get_val();
for (uint8_t i = led_min; i < led_max; i++) {
if (i < 9) {
hsv.h = user_config.color[i].h;
hsv.s = 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
5 changes: 5 additions & 0 deletions keyboards/binepad/bnk9/keymaps/binepad/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VIA_ENABLE = yes
ENCODER_MAP_ENABLE = yes

RGB_MATRIX_CUSTOM_KB = yes
SRC += bnk9_effect.c
28 changes: 28 additions & 0 deletions keyboards/binepad/bnk9/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2023 Binepad (@binpad)
// SPDX-License-Identifier: GPL-2.0-or-later

#include QMK_KEYBOARD_H

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT(
KC_MUTE,
KC_P1, KC_P2, KC_P3,
KC_P4, KC_P5, KC_P6,
KC_P7, KC_P8, LT(1, KC_P9)
),
[1] = LAYOUT(
RGB_TOG,
RGB_HUI, RGB_SAI, RGB_SPI,
RGB_HUD, RGB_SAD, RGB_SPD,
RGB_RMOD, 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
1 change: 1 addition & 0 deletions keyboards/binepad/bnk9/keymaps/default/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENCODER_MAP_ENABLE = yes
28 changes: 28 additions & 0 deletions keyboards/binepad/bnk9/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2023 Binepad (@binpad)
// SPDX-License-Identifier: GPL-2.0-or-later

#include QMK_KEYBOARD_H

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT(
KC_MUTE,
KC_P1, KC_P2, KC_P3,
KC_P4, KC_P5, KC_P6,
KC_P7, KC_P8, LT(1, KC_P9)
),
[1] = LAYOUT(
RGB_TOG,
RGB_HUI, RGB_SAI, RGB_SPI,
RGB_HUD, RGB_SAD, RGB_SPD,
RGB_RMOD, 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
2 changes: 2 additions & 0 deletions keyboards/binepad/bnk9/keymaps/via/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VIA_ENABLE = yes
ENCODER_MAP_ENABLE = yes
Loading