Skip to content

Commit

Permalink
Merge pull request #39 from gamaPhy/9-add-per-key-backlight-settings-…
Browse files Browse the repository at this point in the history
…to-via-configurator

9 add per key backlight settings to via configurator
  • Loading branch information
tlietz authored Mar 31, 2024
2 parents c0a1a7d + d3167ef commit 27f9cbf
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 30 deletions.
132 changes: 113 additions & 19 deletions firmware/freedom/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
// Units of dmm (decimillimetre), so a KEY_MAX_dmm value of 40 would mean that
// any key distance measured beyond 4mm would be considered 4mm
#define KEY_MAX_dmm 40
// The amount that the calculated lookup table values are multiplied by.
// Used to create steps between each dmm value in the lookup table.
// The range of values in the lookup table is LOOKUP_TABLE_MULTIPLER *
// Used to create steps between each dmm value in the lookup table,
// so that there is no need for debounce despite noise on HE sensor outputs.
// The max value in the lookup table is LOOKUP_TABLE_MULTIPLER *
// KEY_MAX_dmm
#define LOOKUP_TABLE_MULTIPLIER 2

Expand All @@ -41,26 +41,120 @@
#define EECONFIG_KB_DATA_SIZE 140
#define DEBUG_MATRIX_SCAN_RATE

#define RGBLIGHT_EFFECT_RAINBOW_SWIRL
#define RGBLIGHT_DEFAULT_MODE (RGBLIGHT_MODE_RAINBOW_SWIRL + 5)
// #define RGBLIGHT_DEFAULT_VAL 0

#define WS2812_DI_PIN GP12
#define WS2812_PIO_USE_PIO0
#define RGBLED_NUM 10
#define RGB_MATRIX_LED_COUNT 15

// GPIO corresponding to Rasberry Pi Pico LED
#define PICO_LED GP25

// #define WS2812_PWM_DRIVER PWMD3
// #define WS2812_PWM_CHANNEL 4
// #define WS2812_PWM_PAL_MODE 2
// #define WS2812_DMA_STREAM STM32_DMA1_STREAM2
// #define WS2812_DMA_CHANNEL 5
#define ENABLE_RGB_MATRIX_SOLID_COLOR // Static single hue, no speed support
#define ENABLE_RGB_MATRIX_ALPHAS_MODS
// Static dual hue, speed is hue for secondary hue
#define ENABLE_RGB_MATRIX_GRADIENT_UP_DOWN
// Static gradient top to bottom, speed controls how much gradient changes
#define ENABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT
// Static gradient left to right, speed controls how much gradient changes
#define ENABLE_RGB_MATRIX_BREATHING // Single hue brightness cycling animatio
#define ENABLE_RGB_MATRIX_BAND_SAT
// Single hue band fading saturation scrolling left to right
#define ENABLE_RGB_MATRIX_BAND_VAL
// Single hue band fading brightness scrolling left to right
#define ENABLE_RGB_MATRIX_BAND_PINWHEEL_SAT
// Single hue 3 blade spinning pinwheel fades saturation
#define ENABLE_RGB_MATRIX_BAND_PINWHEEL_VAL
// Single hue 3 blade spinning pinwheel fades brightness
#define ENABLE_RGB_MATRIX_BAND_SPIRAL_SAT
// Single hue spinning spiral fades saturation
#define ENABLE_RGB_MATRIX_BAND_SPIRAL_VAL
// Single hue spinning spiral fades brightness
#define ENABLE_RGB_MATRIX_CYCLE_ALL
// Full keyboard solid hue cycling through full gradient
#define ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
// Full gradient scrolling left to right
#define ENABLE_RGB_MATRIX_CYCLE_UP_DOWN
// Full gradient scrolling top to bottom
#define ENABLE_RGB_MATRIX_CYCLE_OUT_IN , // Full gradient scrolling out to in
#define ENABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL
// Full dual gradients scrolling out to in
#define ENABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
// Full gradient Chevron shapped scrolling left to right
#define ENABLE_RGB_MATRIX_CYCLE_PINWHEEL
// Full gradient spinning pinwheel around center of keyboard
#define ENABLE_RGB_MATRIX_CYCLE_SPIRAL
// Full gradient spinning spiral around center of keyboard
#define ENABLE_RGB_MATRIX_DUAL_BEACON
// Full gradient spinning around center of keyboard
#define ENABLE_RGB_MATRIX_RAINBOW_BEACON
// Full tighter gradient spinning around center of keyboard
#define ENABLE_RGB_MATRIX_RAINBOW_PINWHEELS
// Full dual gradients spinning two halfs of keyboard
#define ENABLE_RGB_MATRIX_FLOWER_BLOOMING
// Full tighter gradient of first half scrolling left to right and second
// half scrolling right to left
#define ENABLE_RGB_MATRIX_RAINDROPS
// Randomly changes a single key's hue
#define ENABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
// Randomly changes a single key's hue and saturation
#define ENABLE_RGB_MATRIX_HUE_BREATHING
// Hue shifts up a slight ammount at the same time, then shifts back
#define ENABLE_RGB_MATRIX_HUE_PENDULUM
// Hue shifts up a slight ammount in a wave to the right, then back to the
// left
#define ENABLE_RGB_MATRIX_HUE_WAVE
// Hue shifts up a slight ammount and then back down in a wave to the
// right
#define ENABLE_RGB_MATRIX_PIXEL_FRACTAL
// Single hue fractal filled keys pulsing horizontally out to edges
#define ENABLE_RGB_MATRIX_PIXEL_FLOW
// Pulsing RGB flow along LED wiring with random hues
#define ENABLE_RGB_MATRIX_PIXEL_RAIN // Randomly light keys with random hues
#define ENABLE_RGB_MATRIX_TYPING_HEATMAP // How hot is your WPM!
#define ENABLE_RGB_MATRIX_DIGITAL_RAIN // That famous computer simulation
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
// Pulses keys hit to hue & value then fades value out
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE
// Static single hue, pulses keys hit to shifted hue then fades to current
// hue
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
// Hue & value pulse near a single key hit then fades value out
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
// Hue & value pulse near multiple key hits then fades value out
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
// Hue & value pulse the same column and row of a single key hit then
// fades value out
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
// Hue & value pulse the same column and row of multiple key hits then
// fade value out
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
// Hue & value pulse away on the same column and row of a single key hit
// then fades value out
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
// Hue & value pulse away on the same column and row of multiple key hits
// then fades value out
#define ENABLE_RGB_MATRIX_SPLASH
// Full gradient & value pulse away from a single key hit then fades value
// out
#define ENABLE_RGB_MATRIX_MULTISPLASH
// Full gradient & value pulse away from multiple key hits then fades
// value out
#define ENABLE_RGB_MATRIX_SOLID_SPLASH
// Hue & value pulse away from a single key hit then fades value out
#define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH
// Hue & value pulse away from multiple key hits then fades value out
#define ENABLE_RGB_MATRIX_STARLIGHT
// LEDs turn on and off at random at varying brightness, maintaining user
// set color
#define ENABLE_RGB_MATRIX_STARLIGHT_DUAL_HUE
// LEDs turn on and off at random at varying brightness, modifies user set
// hue by +- 30
#define ENABLE_RGB_MATRIX_STARLIGHT_DUAL_SAT
// LEDs turn on and off at random at varying brightness, modifies user set
// saturation by +- 30
#define ENABLE_RGB_MATRIX_RIVERFLOW
// Modification to breathing animation, offset's animation depending on
// key location to simulate a river flowing
#define ENABLE_RGB_MATRIX_EFFECT_MAX

// #define WS2812_TIMING 1250
// #define WS2812_T0H 400
// #define WS2812_T1H 800
// #define WS2812_T0L 2050
// #define WS2812_T1L 1650
// #define WS2812_RES_US 100
#define RGB_MATRIX_DEFAULT_SPD 30
#define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_CYCLE_PINWHEEL
36 changes: 28 additions & 8 deletions firmware/freedom/freedom.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@
#include "helpers/lookup_table.h"
#include "helpers/sensor_read.h"

#ifdef RGB_MATRIX_ENABLE
led_config_t g_led_config = { {
{ 12, 13, 14 },
{ NO_LED, NO_LED, NO_LED },
}, {
// Underglow
{112, 15}, {61, 12}, {17, 22}, {12, 38}, {37, 44}, {80, 57}, {112, 43}, {143, 57}, {186, 44}, {211, 38}, {206, 22}, {169, 11},
// Key matrix
{177, 27}, {112, 27}, {46, 27},
}, {
// Underglow
2, 2, 2, 2, 2,
2, 2, 2, 2, 2,
2, 2,
// Key matrix
4, 4, 4,
} };
#endif

kb_config_t kb_config;
sensor_bounds_t running_sensor_bounds[SENSOR_COUNT];
uint8_t sensor_lookup_table[SENSOR_COUNT][MAX_ADC_READING];
Expand Down Expand Up @@ -48,14 +67,14 @@ void eeconfig_init_kb(void) {
kb_config.global_actuation_settings.rapid_trigger = true;
kb_config.global_actuation_settings.actuation_point_dmm = 6;
kb_config.global_actuation_settings.rapid_trigger_press_sensitivity_dmm = 2;
kb_config.global_actuation_settings.rapid_trigger_release_sensitivity_dmm = 5;
kb_config.global_actuation_settings.rapid_trigger_release_sensitivity_dmm = 4;
for (int i = 0; i < SENSOR_COUNT; i++) {
kb_config.per_key_actuation_settings[i].rapid_trigger = true;
kb_config.per_key_actuation_settings[i].actuation_point_dmm = 6;
kb_config.per_key_actuation_settings[i]
.rapid_trigger_press_sensitivity_dmm = 2;
kb_config.per_key_actuation_settings[i]
.rapid_trigger_release_sensitivity_dmm = 5;
.rapid_trigger_release_sensitivity_dmm = 4;
}
for (int row = 0; row < MATRIX_ROWS; row++) {
for (int col = 0; col < MATRIX_COLS; col++) {
Expand Down Expand Up @@ -94,7 +113,7 @@ void keyboard_pre_init_user(void) {
}

void keyboard_post_init_user(void) {
rgblight_sethsv_noeeprom(HSV_BLACK);
rgb_matrix_sethsv_noeeprom(HSV_BLACK);
debug_enable = true;
// have to turn on the rgb again after s min values have been calibrated
eeconfig_read_kb_datablock(&kb_config);
Expand All @@ -116,7 +135,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_CALIBRATE:
if (record->event.pressed) {
rgblight_sethsv_noeeprom(HSV_BLACK);
rgb_matrix_sethsv_noeeprom(HSV_BLACK);
writePinHigh(PICO_LED);

// this will disable analog keys while calibrating
Expand All @@ -134,14 +153,14 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
calibrating_sensors = false;

if (calibration_successful()) {
rgblight_reload_from_eeprom();
rgb_matrix_reload_from_eeprom();
kb_config.calibrated = true;
create_lookup_table(&kb_config, sensor_lookup_table);
kb_config_save();
} else {
if (kb_config.calibrated) {
// return to state before calibration started
rgblight_reload_from_eeprom();
rgb_matrix_reload_from_eeprom();
eeconfig_read_kb_datablock(&kb_config);
}
}
Expand Down Expand Up @@ -197,7 +216,7 @@ void matrix_scan_kb(void) {
}
bootup_calibrated = true;
create_lookup_table(&kb_config, sensor_lookup_table);
rgblight_reload_from_eeprom();
rgb_matrix_reload_from_eeprom();
}
} else {
dprintf("Current reading range within 1 second:\n");
Expand All @@ -206,6 +225,7 @@ void matrix_scan_kb(void) {
running_sensor_bounds[s].max);
}
dprintf("\n\n");
dprintf("Current speed: %i\n", rgb_matrix_get_speed());

dprintf("Key press distance (0 - 80):\n ");
for (int s = 0; s < SENSOR_COUNT; s++) {
Expand All @@ -222,7 +242,7 @@ void matrix_scan_kb(void) {
}

dprintf(
"################################################################\n");
"\n################################################################\n");
}

if (calibrating_sensors) {
Expand Down
4 changes: 2 additions & 2 deletions firmware/freedom/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ WEAR_LEVELING_DRIVER = rp2040_flash
CONSOLE_ENABLE = yes
DEFAULT_FOLDER = gamaphy/freedom/3k

RGBLIGHT_ENABLE = yes
RGBLIGHT_DRIVER = ws2812
RGB_MATRIX_ENABLE = yes
RGB_MATRIX_DRIVER = ws2812
# WS2812_DRIVER = pwm

SRC += matrix.c
Expand Down
2 changes: 1 addition & 1 deletion release/freedom/3k/via/via.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"keycodes": ["qmk_lighting"],
"menus": [
"qmk_rgblight",
"qmk_rgb_matrix",
{
"label": "Actuation settings",
"content": [
Expand Down
68 changes: 68 additions & 0 deletions scripts/calculate_rgb_led_matrix_locations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# All units in mm
import math

# midpoint of pcb in kicad
PCB_MID = 100
# side length of square that could surround the pcb
PCB_DIM = 65


# (x, y)
kicad_positions = (
(100, 83.12),
(114.75, 80.45),
(127.5, 90.5),
(129, 107),
(121.5, 112.5),
(109, 126),
(100, 112),
(91, 126),
(78.5, 112.5),
(71, 107),
(72.5, 90.5),
(83.35, 79.3),
(80.95, 94.95),
(100, 94.95),
(119.05, 94.95),
)

def real_location_mm(location):
return (PCB_DIM/2) + location - PCB_MID


def qmk_transform(x, y):
# on the pcb, x-location is mirrored about the y-axis compared to reality
transform_x = real_location_mm(PCB_MID * 2 - x) * 224 / PCB_DIM
transform_y = real_location_mm(y) * 64 / PCB_DIM
return (math.floor(transform_x), math.floor(transform_y))

#// Underglow
#{112 , 15}, {76 , 22}, {144, 22}, {0 , 28}, {75 , 29},
#{149, 22}, {149, 23}, {149, 23}, {0 , 22}, {76 , 22},
#{144, 22}, {0 , 28},
#// Key matrix
#{0 , 0}, {75 , 0}, {149, 0},

def print_g_led_config(qmk_transform_locations):
underglow_num = 12
key_matrix_printed = False
print("// Underglow")
i = 0
for p in qmk_transform_locations:
print('{' + str(p[0]) + ', ' + str(p[1]) + '}, ', end='')
i = i+1
if i >= underglow_num and not key_matrix_printed:
print("\n// Key matrix")
key_matrix_printed = True
print()

def main():
qmk_positions = []
for position in kicad_positions:
qmk_positions.append(qmk_transform(position[0], position[1]))
print_g_led_config(qmk_positions)


main()


5 changes: 5 additions & 0 deletions scripts/flash_rp2040_from_wsl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
cd ../
./in_qmk.sh qmk compile -kb gamaphy/freedom/3k -km via -e TEST=1
sudo mount -t drvfs F: /mnt/f
cp qmk_firmware/gamaphy_freedom_3k_via.uf2 /mnt/f/

0 comments on commit 27f9cbf

Please sign in to comment.