From e105468d700961e870d2fcd54c00258ab0edbaee Mon Sep 17 00:00:00 2001 From: mawaeg <62243375+mawaeg@users.noreply.github.com> Date: Thu, 27 Feb 2025 20:35:27 +0100 Subject: [PATCH 1/9] Add new macropad Sharkropad --- keyboards/mawaeg/sharkropad/config.h | 22 +++ keyboards/mawaeg/sharkropad/halconf.h | 21 +++ keyboards/mawaeg/sharkropad/keyboard.json | 139 ++++++++++++++++++ .../sharkropad/keymaps/default/keymap.c | 116 +++++++++++++++ .../sharkropad/keymaps/default/rules.mk | 1 + keyboards/mawaeg/sharkropad/mcuconf.h | 22 +++ keyboards/mawaeg/sharkropad/readme.md | 24 +++ 7 files changed, 345 insertions(+) create mode 100644 keyboards/mawaeg/sharkropad/config.h create mode 100755 keyboards/mawaeg/sharkropad/halconf.h create mode 100755 keyboards/mawaeg/sharkropad/keyboard.json create mode 100755 keyboards/mawaeg/sharkropad/keymaps/default/keymap.c create mode 100755 keyboards/mawaeg/sharkropad/keymaps/default/rules.mk create mode 100755 keyboards/mawaeg/sharkropad/mcuconf.h create mode 100755 keyboards/mawaeg/sharkropad/readme.md diff --git a/keyboards/mawaeg/sharkropad/config.h b/keyboards/mawaeg/sharkropad/config.h new file mode 100644 index 00000000000..5472d5b114b --- /dev/null +++ b/keyboards/mawaeg/sharkropad/config.h @@ -0,0 +1,22 @@ +/* Copyright 2025 @mawaeg + * + * 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 . + */ + +#define STM32_FLASH_SECTORS_PER_BANK 128 + +#define I2C1_SCL_PIN A9 +#define I2C1_SDA_PIN A10 + +#define WS2812_BITBANG_NOP_FUDGE 0.4 diff --git a/keyboards/mawaeg/sharkropad/halconf.h b/keyboards/mawaeg/sharkropad/halconf.h new file mode 100755 index 00000000000..abf3acb6307 --- /dev/null +++ b/keyboards/mawaeg/sharkropad/halconf.h @@ -0,0 +1,21 @@ +/* Copyright 2025 @mawaeg + * + * 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 + +#define HAL_USE_I2C TRUE + +#include_next \ No newline at end of file diff --git a/keyboards/mawaeg/sharkropad/keyboard.json b/keyboards/mawaeg/sharkropad/keyboard.json new file mode 100755 index 00000000000..44f6107ef5e --- /dev/null +++ b/keyboards/mawaeg/sharkropad/keyboard.json @@ -0,0 +1,139 @@ +{ + "manufacturer": "mawaeg", + "keyboard_name": "Sharkropad", + "maintainer": "mawaeg", + "bootloader": "stm32-dfu", + "bootmagic": { + "matrix": [0, 3] + }, + "diode_direction": "COL2ROW", + "encoder": { + "enabled": true, + "rotary": [ + {"pin_a": "A0", "pin_b": "A1"} + ] + }, + "features": { + "bootmagic": true, + "command": false, + "console": false, + "extrakey": true, + "mousekey": false, + "nkro": true, + "oled": true, + "rgb_matrix": true + }, + "matrix_pins": { + "cols": ["B1", "B0", "A4", "A2"], + "rows": ["A3", "A7", "A6", "A5"] + }, + "processor": "STM32L432", + "rgb_matrix": { + "animations": { + "alphas_mods": true, + "band_pinwheel_sat": true, + "band_pinwheel_val": true, + "band_sat": true, + "band_spiral_sat": true, + "band_spiral_val": true, + "band_val": true, + "breathing": true, + "cycle_all": true, + "cycle_left_right": true, + "cycle_out_in": true, + "cycle_out_in_dual": true, + "cycle_pinwheel": true, + "cycle_spiral": true, + "cycle_up_down": true, + "digital_rain": true, + "dual_beacon": true, + "effect_max": true, + "flower_blooming": true, + "gradient_left_right": true, + "gradient_up_down": true, + "hue_breathing": true, + "hue_pendulum": true, + "hue_wave": true, + "jellybean_raindrops": true, + "multisplash": true, + "pixel_flow": true, + "pixel_fractal": true, + "pixel_rain": true, + "rainbow_beacon": true, + "rainbow_moving_chevron": true, + "rainbow_pinwheels": true, + "raindrops": true, + "riverflow": true, + "solid_multisplash": true, + "solid_reactive": true, + "solid_reactive_cross": true, + "solid_reactive_multicross": true, + "solid_reactive_multinexus": true, + "solid_reactive_multiwide": true, + "solid_reactive_nexus": true, + "solid_reactive_simple": true, + "solid_reactive_wide": true, + "solid_splash": true, + "splash": true, + "starlight": true, + "starlight_dual_hue": true, + "starlight_dual_sat": true, + "typing_heatmap": true + }, + "default": { + "animation": "gradient_up_down" + }, + "driver": "ws2812", + "layout": [ + {"matrix": [1, 0], "x": 189, "y": 27, "flags": 4}, + {"matrix": [1, 1], "x": 137, "y": 27, "flags": 4}, + {"matrix": [1, 2], "x": 86, "y": 27, "flags": 4}, + {"matrix": [1, 3], "x": 35, "y": 27, "flags": 4}, + {"matrix": [2, 0], "x": 189, "y": 41, "flags": 4}, + {"matrix": [2, 1], "x": 137, "y": 41, "flags": 4}, + {"matrix": [2, 2], "x": 86, "y": 41, "flags": 4}, + {"matrix": [2, 3], "x": 35, "y": 41, "flags": 4}, + {"matrix": [3, 0], "x": 189, "y": 55, "flags": 4}, + {"matrix": [3, 1], "x": 137, "y": 55, "flags": 4}, + {"matrix": [3, 2], "x": 86, "y": 55, "flags": 4}, + {"matrix": [3, 3], "x": 35, "y": 55, "flags": 4}, + {"x": 76, "y": 3, "flags": 2}, + {"x": 148, "y": 3, "flags": 2}, + {"x": 216, "y": 17, "flags": 2}, + {"x": 216, "y": 45, "flags": 2}, + {"x": 224, "y": 61, "flags": 2}, + {"x": 60, "y": 61, "flags": 2}, + {"x": 8, "y": 45, "flags": 2}, + {"x": 8, "y": 17, "flags": 2} + ], + "maximum_brightness": 180 + }, + "url": "https://github.com/mawaeg/sharkropad", + "usb": { + "device_version": "1.0.0", + "pid": "0xAFFE", + "vid": "0x6D73" + }, + "ws2812": { + "pin": "B3" + }, + "layouts": { + "LAYOUT_numpad_4x4": { + "layout": [ + {"matrix": [0, 3], "x": 3, "y": 0}, + {"matrix": [1, 0], "x": 0, "y": 1}, + {"matrix": [1, 1], "x": 1, "y": 1}, + {"matrix": [1, 2], "x": 2, "y": 1}, + {"matrix": [1, 3], "x": 3, "y": 1}, + {"matrix": [2, 0], "x": 0, "y": 2}, + {"matrix": [2, 1], "x": 1, "y": 2}, + {"matrix": [2, 2], "x": 2, "y": 2}, + {"matrix": [2, 3], "x": 3, "y": 2}, + {"matrix": [3, 0], "x": 0, "y": 3}, + {"matrix": [3, 1], "x": 1, "y": 3}, + {"matrix": [3, 2], "x": 2, "y": 3}, + {"matrix": [3, 3], "x": 3, "y": 3} + ] + } + } +} diff --git a/keyboards/mawaeg/sharkropad/keymaps/default/keymap.c b/keyboards/mawaeg/sharkropad/keymaps/default/keymap.c new file mode 100755 index 00000000000..5d8337076aa --- /dev/null +++ b/keyboards/mawaeg/sharkropad/keymaps/default/keymap.c @@ -0,0 +1,116 @@ +/* Copyright 2025 @mawaeg + * + * 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 QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + // clang-format off + /* + * ┌────────────┐ + * │ RGB_MOD │ + * ┌───┬───┬───┼────────────┤ + * │ 7 │ 8 │ 9 │ RGB_TOGGLE │ + * ├───┼───┼───┼────────────┤ + * │ 4 │ 5 │ 6 │ NUM │ + * ├───┼───┼───┼────────────┤ + * │ 1 │ 2 │ 3 │ 0 │ + * └───┴───┴───┴────────────┘ + */ + [0] = LAYOUT_numpad_4x4( + RGB_MOD, + KC_P7, KC_P8, KC_P9, RGB_TOG, + KC_P4, KC_P5, KC_P6, KC_NUM, + KC_P1, KC_P2, KC_P3, KC_P0 + ) + // clang-format on +}; + +#ifdef ENCODER_MAP_ENABLE +const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { + [0] = { ENCODER_CCW_CW(RGB_SPD, RGB_SPI)}, +}; +#endif + +#ifdef OLED_ENABLE + +const char *rgb_matrix_effect_names[] = { + "None", + "Solid Color", + "Alphas Mods", + "Gradient Up/Down", + "Gradient Left/Right", + "Breathing", + "Band Saturation", + "Band Value", + "Band Pinwheel Sat", + "Band Pinwheel Val", + "Band Spiral Sat", + "Band Spiral Val", + "Cycle All", + "Cycle Left/Right", + "Cycle Up/Down", + "Cycle Out/In", + "Cycle Out/In Dual", + "Rainbow Chevron", + "Cycle Pinwheel", + "Cycle Spiral", + "Dual Beacon", + "Rainbow Beacon", + "Rainbow Pinwheels", + "Flower Blooming", + "Raindrops", + "Jellybean Raindrops", + "Hue Breathing", + "Hue Pendulum", + "Hue Wave", + "Pixel Fractal", + "Pixel Flow", + "Pixel Rain", + "Typing Heatmap", + "Digital Rain", + "Reactive Simple", + "Reactive", + "Reactive Wide", + "Reactive Multiwide", + "Reactive Cross", + "Reactive Multicross", + "Reactive Nexus", + "Reactive Multinexus", + "Splash", + "Multisplash", + "Solid Splash", + "Solid Multisplash", + "Starlight", + "Starlight Dual Hue", + "Starlight Dual Sat", + "Riverflow", + "Effect Max" +}; + +bool oled_task_user(void) { + + oled_write_ln_P(PSTR("Mode: "), false); + oled_write_ln(rgb_matrix_effect_names[rgb_matrix_get_mode()], false); + + oled_write_ln_P(PSTR("RGB Speed: "), false); + char speedBuffer[4]; + uint8_t speedPercentage = (uint8_t)(((float)rgb_matrix_get_speed() / 255.0) * 100.0); // Proper float division + sprintf(speedBuffer, "%d", speedPercentage); + oled_write(speedBuffer, false); + oled_write("% ", false); + return false; +} +#endif diff --git a/keyboards/mawaeg/sharkropad/keymaps/default/rules.mk b/keyboards/mawaeg/sharkropad/keymaps/default/rules.mk new file mode 100755 index 00000000000..a40474b4d5c --- /dev/null +++ b/keyboards/mawaeg/sharkropad/keymaps/default/rules.mk @@ -0,0 +1 @@ +ENCODER_MAP_ENABLE = yes \ No newline at end of file diff --git a/keyboards/mawaeg/sharkropad/mcuconf.h b/keyboards/mawaeg/sharkropad/mcuconf.h new file mode 100755 index 00000000000..a557cedb35f --- /dev/null +++ b/keyboards/mawaeg/sharkropad/mcuconf.h @@ -0,0 +1,22 @@ +/* Copyright 2025 @mawaeg + * + * 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_next + +#undef STM32_I2C_USE_I2C1 +#define STM32_I2C_USE_I2C1 TRUE \ No newline at end of file diff --git a/keyboards/mawaeg/sharkropad/readme.md b/keyboards/mawaeg/sharkropad/readme.md new file mode 100755 index 00000000000..dc607076251 --- /dev/null +++ b/keyboards/mawaeg/sharkropad/readme.md @@ -0,0 +1,24 @@ +# sharkropad + +![sharkropad](https://i.imgur.com/qatvstX.jpeg) + +**Sharkropad** is an open-source hotswappable macropad. + +* Keyboard Maintainer: [Marek Schmitt](https://github.com/mawaeg) +* Hardware Supported: PCB included in the [Sharkropad repository](https://github.com/mawaeg/sharkropad). +* Hardware Availability: PCB has to be sourced yourserlf + +Make example for this keyboard (after setting up your build environment): + + make mawaeg/sharkropad:default + +Flashing example for this keyboard: + + make mawaeg/sharkropad: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: +* **Bootmagic reset**: Hold down the rotary encoder knob and plug in the keyboard From cd974d00c845f2a51ddb1b6cc60cc4d29d621180 Mon Sep 17 00:00:00 2001 From: Marek Schmitt <62243375+mawaeg@users.noreply.github.com> Date: Sat, 1 Mar 2025 16:52:01 +0100 Subject: [PATCH 2/9] Apply suggestions from code review Co-authored-by: Drashna Jaelre --- keyboards/mawaeg/sharkropad/halconf.h | 2 +- keyboards/mawaeg/sharkropad/keyboard.json | 4 ++-- keyboards/mawaeg/sharkropad/keymaps/default/keymap.c | 2 +- keyboards/mawaeg/sharkropad/keymaps/default/rules.mk | 2 +- keyboards/mawaeg/sharkropad/mcuconf.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/keyboards/mawaeg/sharkropad/halconf.h b/keyboards/mawaeg/sharkropad/halconf.h index abf3acb6307..fbeb632aa7b 100755 --- a/keyboards/mawaeg/sharkropad/halconf.h +++ b/keyboards/mawaeg/sharkropad/halconf.h @@ -18,4 +18,4 @@ #define HAL_USE_I2C TRUE -#include_next \ No newline at end of file +#include_next diff --git a/keyboards/mawaeg/sharkropad/keyboard.json b/keyboards/mawaeg/sharkropad/keyboard.json index 44f6107ef5e..3082cef4532 100755 --- a/keyboards/mawaeg/sharkropad/keyboard.json +++ b/keyboards/mawaeg/sharkropad/keyboard.json @@ -8,7 +8,6 @@ }, "diode_direction": "COL2ROW", "encoder": { - "enabled": true, "rotary": [ {"pin_a": "A0", "pin_b": "A1"} ] @@ -17,6 +16,7 @@ "bootmagic": true, "command": false, "console": false, + "encoder": true, "extrakey": true, "mousekey": false, "nkro": true, @@ -118,7 +118,7 @@ "pin": "B3" }, "layouts": { - "LAYOUT_numpad_4x4": { + "LAYOUT": { "layout": [ {"matrix": [0, 3], "x": 3, "y": 0}, {"matrix": [1, 0], "x": 0, "y": 1}, diff --git a/keyboards/mawaeg/sharkropad/keymaps/default/keymap.c b/keyboards/mawaeg/sharkropad/keymaps/default/keymap.c index 5d8337076aa..02fd4a97019 100755 --- a/keyboards/mawaeg/sharkropad/keymaps/default/keymap.c +++ b/keyboards/mawaeg/sharkropad/keymaps/default/keymap.c @@ -29,7 +29,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * │ 1 │ 2 │ 3 │ 0 │ * └───┴───┴───┴────────────┘ */ - [0] = LAYOUT_numpad_4x4( + [0] = LAYOUT( RGB_MOD, KC_P7, KC_P8, KC_P9, RGB_TOG, KC_P4, KC_P5, KC_P6, KC_NUM, diff --git a/keyboards/mawaeg/sharkropad/keymaps/default/rules.mk b/keyboards/mawaeg/sharkropad/keymaps/default/rules.mk index a40474b4d5c..ee325681483 100755 --- a/keyboards/mawaeg/sharkropad/keymaps/default/rules.mk +++ b/keyboards/mawaeg/sharkropad/keymaps/default/rules.mk @@ -1 +1 @@ -ENCODER_MAP_ENABLE = yes \ No newline at end of file +ENCODER_MAP_ENABLE = yes diff --git a/keyboards/mawaeg/sharkropad/mcuconf.h b/keyboards/mawaeg/sharkropad/mcuconf.h index a557cedb35f..3991841cb72 100755 --- a/keyboards/mawaeg/sharkropad/mcuconf.h +++ b/keyboards/mawaeg/sharkropad/mcuconf.h @@ -19,4 +19,4 @@ #include_next #undef STM32_I2C_USE_I2C1 -#define STM32_I2C_USE_I2C1 TRUE \ No newline at end of file +#define STM32_I2C_USE_I2C1 TRUE From 9af623764c1f9ab2d7fec219b99e47fc58f7dc63 Mon Sep 17 00:00:00 2001 From: Marek Schmitt <62243375+mawaeg@users.noreply.github.com> Date: Sun, 2 Mar 2025 20:13:55 +0100 Subject: [PATCH 3/9] Apply suggestions from code review Co-authored-by: jack --- keyboards/mawaeg/sharkropad/keyboard.json | 3 --- keyboards/mawaeg/sharkropad/keymaps/default/keymap.c | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/keyboards/mawaeg/sharkropad/keyboard.json b/keyboards/mawaeg/sharkropad/keyboard.json index 3082cef4532..0946843ec4b 100755 --- a/keyboards/mawaeg/sharkropad/keyboard.json +++ b/keyboards/mawaeg/sharkropad/keyboard.json @@ -14,11 +14,8 @@ }, "features": { "bootmagic": true, - "command": false, - "console": false, "encoder": true, "extrakey": true, - "mousekey": false, "nkro": true, "oled": true, "rgb_matrix": true diff --git a/keyboards/mawaeg/sharkropad/keymaps/default/keymap.c b/keyboards/mawaeg/sharkropad/keymaps/default/keymap.c index 02fd4a97019..9c7be00d97f 100755 --- a/keyboards/mawaeg/sharkropad/keymaps/default/keymap.c +++ b/keyboards/mawaeg/sharkropad/keymaps/default/keymap.c @@ -30,8 +30,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * └───┴───┴───┴────────────┘ */ [0] = LAYOUT( - RGB_MOD, - KC_P7, KC_P8, KC_P9, RGB_TOG, + RM_NEXT, + KC_P7, KC_P8, KC_P9, RM_TOGG, KC_P4, KC_P5, KC_P6, KC_NUM, KC_P1, KC_P2, KC_P3, KC_P0 ) @@ -40,7 +40,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { #ifdef ENCODER_MAP_ENABLE const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { - [0] = { ENCODER_CCW_CW(RGB_SPD, RGB_SPI)}, + [0] = { ENCODER_CCW_CW(RM_SPDD, RM_SPDU)}, }; #endif From aa754da13d0b9630b4e2a8d80b652dbb999d7b55 Mon Sep 17 00:00:00 2001 From: mawaeg <62243375+mawaeg@users.noreply.github.com> Date: Sun, 2 Mar 2025 20:18:51 +0100 Subject: [PATCH 4/9] Use PWM driver for ws2812 --- keyboards/mawaeg/sharkropad/chconf.h | 22 ++++++++++++++++++++++ keyboards/mawaeg/sharkropad/config.h | 6 +++++- keyboards/mawaeg/sharkropad/halconf.h | 1 + keyboards/mawaeg/sharkropad/keyboard.json | 1 + keyboards/mawaeg/sharkropad/mcuconf.h | 6 ++++++ 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 keyboards/mawaeg/sharkropad/chconf.h diff --git a/keyboards/mawaeg/sharkropad/chconf.h b/keyboards/mawaeg/sharkropad/chconf.h new file mode 100644 index 00000000000..c0a23232343 --- /dev/null +++ b/keyboards/mawaeg/sharkropad/chconf.h @@ -0,0 +1,22 @@ +/* Copyright 2025 @mawaeg + * + * 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 + +#define CH_CFG_ST_RESOLUTION 16 +#define CH_CFG_ST_FREQUENCY 10000 + +#include_next diff --git a/keyboards/mawaeg/sharkropad/config.h b/keyboards/mawaeg/sharkropad/config.h index 5472d5b114b..950f63860d0 100644 --- a/keyboards/mawaeg/sharkropad/config.h +++ b/keyboards/mawaeg/sharkropad/config.h @@ -19,4 +19,8 @@ #define I2C1_SCL_PIN A9 #define I2C1_SDA_PIN A10 -#define WS2812_BITBANG_NOP_FUDGE 0.4 +#define WS2812_PWM_DRIVER PWMD2 +#define WS2812_PWM_CHANNEL 2 +#define WS2812_PWM_PAL_MODE 1 +#define WS2812_PWM_DMA_STREAM STM32_DMA1_STREAM2 +#define WS2812_PWM_DMA_CHANNEL 4 diff --git a/keyboards/mawaeg/sharkropad/halconf.h b/keyboards/mawaeg/sharkropad/halconf.h index fbeb632aa7b..9f0b5737322 100755 --- a/keyboards/mawaeg/sharkropad/halconf.h +++ b/keyboards/mawaeg/sharkropad/halconf.h @@ -17,5 +17,6 @@ #pragma once #define HAL_USE_I2C TRUE +#define HAL_USE_PWM TRUE #include_next diff --git a/keyboards/mawaeg/sharkropad/keyboard.json b/keyboards/mawaeg/sharkropad/keyboard.json index 0946843ec4b..b95d42e4589 100755 --- a/keyboards/mawaeg/sharkropad/keyboard.json +++ b/keyboards/mawaeg/sharkropad/keyboard.json @@ -112,6 +112,7 @@ "vid": "0x6D73" }, "ws2812": { + "driver": "pwm", "pin": "B3" }, "layouts": { diff --git a/keyboards/mawaeg/sharkropad/mcuconf.h b/keyboards/mawaeg/sharkropad/mcuconf.h index 3991841cb72..2a66cc8d7b5 100755 --- a/keyboards/mawaeg/sharkropad/mcuconf.h +++ b/keyboards/mawaeg/sharkropad/mcuconf.h @@ -20,3 +20,9 @@ #undef STM32_I2C_USE_I2C1 #define STM32_I2C_USE_I2C1 TRUE + +#undef STM32_PWM_USE_TIM2 +#define STM32_PWM_USE_TIM2 TRUE + +#undef STM32_ST_USE_TIMER +#define STM32_ST_USE_TIMER 15 From ffd8acf7cc05fcfe611bb029bdd1b0b03789a72e Mon Sep 17 00:00:00 2001 From: mawaeg <62243375+mawaeg@users.noreply.github.com> Date: Wed, 5 Mar 2025 20:08:48 +0100 Subject: [PATCH 5/9] Move oled logic, adapt file permissions --- keyboards/mawaeg/sharkropad/halconf.h | 0 keyboards/mawaeg/sharkropad/keyboard.json | 2 +- .../sharkropad/keymaps/default/keymap.c | 71 ----------- .../sharkropad/keymaps/default/rules.mk | 0 keyboards/mawaeg/sharkropad/mcuconf.h | 0 keyboards/mawaeg/sharkropad/readme.md | 0 keyboards/mawaeg/sharkropad/sharkropad.c | 119 ++++++++++++++++++ 7 files changed, 120 insertions(+), 72 deletions(-) mode change 100755 => 100644 keyboards/mawaeg/sharkropad/halconf.h mode change 100755 => 100644 keyboards/mawaeg/sharkropad/keyboard.json mode change 100755 => 100644 keyboards/mawaeg/sharkropad/keymaps/default/keymap.c mode change 100755 => 100644 keyboards/mawaeg/sharkropad/keymaps/default/rules.mk mode change 100755 => 100644 keyboards/mawaeg/sharkropad/mcuconf.h mode change 100755 => 100644 keyboards/mawaeg/sharkropad/readme.md create mode 100644 keyboards/mawaeg/sharkropad/sharkropad.c diff --git a/keyboards/mawaeg/sharkropad/halconf.h b/keyboards/mawaeg/sharkropad/halconf.h old mode 100755 new mode 100644 diff --git a/keyboards/mawaeg/sharkropad/keyboard.json b/keyboards/mawaeg/sharkropad/keyboard.json old mode 100755 new mode 100644 index b95d42e4589..ee6715d3723 --- a/keyboards/mawaeg/sharkropad/keyboard.json +++ b/keyboards/mawaeg/sharkropad/keyboard.json @@ -78,7 +78,7 @@ "typing_heatmap": true }, "default": { - "animation": "gradient_up_down" + "animation": "cycle_up_down" }, "driver": "ws2812", "layout": [ diff --git a/keyboards/mawaeg/sharkropad/keymaps/default/keymap.c b/keyboards/mawaeg/sharkropad/keymaps/default/keymap.c old mode 100755 new mode 100644 index 9c7be00d97f..6a95257a1ca --- a/keyboards/mawaeg/sharkropad/keymaps/default/keymap.c +++ b/keyboards/mawaeg/sharkropad/keymaps/default/keymap.c @@ -43,74 +43,3 @@ const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { [0] = { ENCODER_CCW_CW(RM_SPDD, RM_SPDU)}, }; #endif - -#ifdef OLED_ENABLE - -const char *rgb_matrix_effect_names[] = { - "None", - "Solid Color", - "Alphas Mods", - "Gradient Up/Down", - "Gradient Left/Right", - "Breathing", - "Band Saturation", - "Band Value", - "Band Pinwheel Sat", - "Band Pinwheel Val", - "Band Spiral Sat", - "Band Spiral Val", - "Cycle All", - "Cycle Left/Right", - "Cycle Up/Down", - "Cycle Out/In", - "Cycle Out/In Dual", - "Rainbow Chevron", - "Cycle Pinwheel", - "Cycle Spiral", - "Dual Beacon", - "Rainbow Beacon", - "Rainbow Pinwheels", - "Flower Blooming", - "Raindrops", - "Jellybean Raindrops", - "Hue Breathing", - "Hue Pendulum", - "Hue Wave", - "Pixel Fractal", - "Pixel Flow", - "Pixel Rain", - "Typing Heatmap", - "Digital Rain", - "Reactive Simple", - "Reactive", - "Reactive Wide", - "Reactive Multiwide", - "Reactive Cross", - "Reactive Multicross", - "Reactive Nexus", - "Reactive Multinexus", - "Splash", - "Multisplash", - "Solid Splash", - "Solid Multisplash", - "Starlight", - "Starlight Dual Hue", - "Starlight Dual Sat", - "Riverflow", - "Effect Max" -}; - -bool oled_task_user(void) { - - oled_write_ln_P(PSTR("Mode: "), false); - oled_write_ln(rgb_matrix_effect_names[rgb_matrix_get_mode()], false); - - oled_write_ln_P(PSTR("RGB Speed: "), false); - char speedBuffer[4]; - uint8_t speedPercentage = (uint8_t)(((float)rgb_matrix_get_speed() / 255.0) * 100.0); // Proper float division - sprintf(speedBuffer, "%d", speedPercentage); - oled_write(speedBuffer, false); - oled_write("% ", false); - return false; -} -#endif diff --git a/keyboards/mawaeg/sharkropad/keymaps/default/rules.mk b/keyboards/mawaeg/sharkropad/keymaps/default/rules.mk old mode 100755 new mode 100644 diff --git a/keyboards/mawaeg/sharkropad/mcuconf.h b/keyboards/mawaeg/sharkropad/mcuconf.h old mode 100755 new mode 100644 diff --git a/keyboards/mawaeg/sharkropad/readme.md b/keyboards/mawaeg/sharkropad/readme.md old mode 100755 new mode 100644 diff --git a/keyboards/mawaeg/sharkropad/sharkropad.c b/keyboards/mawaeg/sharkropad/sharkropad.c new file mode 100644 index 00000000000..a228d7c530a --- /dev/null +++ b/keyboards/mawaeg/sharkropad/sharkropad.c @@ -0,0 +1,119 @@ +/* Copyright 2025 @mawaeg + * + * 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 "quantum.h" +#include +#include + +#if defined(RGB_MATRIX_EFFECT) +# undef RGB_MATRIX_EFFECT +#endif // defined(RGB_MATRIX_EFFECT) + +#define RGB_MATRIX_EFFECT(x) RGB_MATRIX_EFFECT_##x, +enum { + RGB_MATRIX_EFFECT_NONE, +#include "rgb_matrix_effects.inc" +#ifdef RGB_MATRIX_CUSTOM_KB +# include "rgb_matrix_kb.inc" +#endif // RGB_MATRIX_CUSTOM_KB +#ifdef RGB_MATRIX_CUSTOM_USER +# include "rgb_matrix_user.inc" +#endif // RGB_MATRIX_CUSTOM_USER +#undef RGB_MATRIX_EFFECT +}; + +#define RGB_MATRIX_EFFECT(x) \ + case RGB_MATRIX_EFFECT_##x: \ + return #x; +const char *rgb_matrix_name(uint8_t effect) { + switch (effect) { + case RGB_MATRIX_EFFECT_NONE: + return "NONE"; +#include "rgb_matrix_effects.inc" +#ifdef RGB_MATRIX_CUSTOM_KB +# include "rgb_matrix_kb.inc" +#endif // RGB_MATRIX_CUSTOM_KB +#ifdef RGB_MATRIX_CUSTOM_USER +# include "rgb_matrix_user.inc" +#endif // RGB_MATRIX_CUSTOM_USER +#undef RGB_MATRIX_EFFECT + default: + return "UNKNOWN"; + } +} + +static uint8_t effect_name_len = 0; + +const char *rgb_matrix_get_effect_name(void) { + static char buf[32] = {0}; + + snprintf(buf, sizeof(buf), "%s", rgb_matrix_name(rgb_matrix_get_mode())); + for (uint8_t i = 1; i < sizeof(buf); ++i) { + if (buf[i] == 0) { + effect_name_len = i; + break; + } else if (buf[i] == '_') + buf[i] = ' '; + else if (buf[i - 1] == ' ') + buf[i] = toupper(buf[i]); + else if (buf[i - 1] != ' ') + buf[i] = tolower(buf[i]); + } + return buf; +} + +bool oled_task_user(void) { + static uint8_t last_effect = 0; + static uint8_t last_speed = 0; + static uint16_t key_timer = 0; + static uint8_t start_index = 0; + + uint8_t speedPercentage = (uint8_t)(((float)rgb_matrix_get_speed() / 255.0) * 100.0); + + if (last_effect != rgb_matrix_get_mode() || last_speed != speedPercentage || timer_elapsed(key_timer) > 200) { + last_effect = rgb_matrix_get_mode(); + last_speed = speedPercentage; + key_timer = timer_read(); + + oled_write_ln_P(PSTR("Mode: "), false); + const char *name = rgb_matrix_get_effect_name(); + if (effect_name_len > 21) { + if (start_index > effect_name_len) { + start_index = 0; + } + for (uint8_t char_index = 0; char_index < 21; char_index++) { + if ((start_index + char_index) % effect_name_len == 0 && char_index != 0) { + oled_write_char(' ', false); + } else { + oled_write_char(name[(start_index + char_index) % (effect_name_len + 1)], false); + } + } + start_index += 1; + } else { + oled_write_ln(name, false); + start_index = 0; + } + + oled_set_cursor(0, 2); + oled_write_ln_P(PSTR("RGB Speed: "), false); + char speedBuffer[4]; + sprintf(speedBuffer, "%d", speedPercentage); + oled_write(speedBuffer, false); + oled_write("% ", false); + } + + return false; +} From a91035ef9804aafe95b461c905a2d128398ad9ad Mon Sep 17 00:00:00 2001 From: mawaeg <62243375+mawaeg@users.noreply.github.com> Date: Wed, 5 Mar 2025 20:49:59 +0100 Subject: [PATCH 6/9] Correctly handle scrolling when adjusting effect speed --- keyboards/mawaeg/sharkropad/sharkropad.c | 212 ++++++++++++----------- 1 file changed, 109 insertions(+), 103 deletions(-) diff --git a/keyboards/mawaeg/sharkropad/sharkropad.c b/keyboards/mawaeg/sharkropad/sharkropad.c index a228d7c530a..e7b23f2f41c 100644 --- a/keyboards/mawaeg/sharkropad/sharkropad.c +++ b/keyboards/mawaeg/sharkropad/sharkropad.c @@ -14,106 +14,112 @@ * along with this program. If not, see . */ -#include "quantum.h" -#include -#include - -#if defined(RGB_MATRIX_EFFECT) -# undef RGB_MATRIX_EFFECT -#endif // defined(RGB_MATRIX_EFFECT) - -#define RGB_MATRIX_EFFECT(x) RGB_MATRIX_EFFECT_##x, -enum { - RGB_MATRIX_EFFECT_NONE, -#include "rgb_matrix_effects.inc" -#ifdef RGB_MATRIX_CUSTOM_KB -# include "rgb_matrix_kb.inc" -#endif // RGB_MATRIX_CUSTOM_KB -#ifdef RGB_MATRIX_CUSTOM_USER -# include "rgb_matrix_user.inc" -#endif // RGB_MATRIX_CUSTOM_USER -#undef RGB_MATRIX_EFFECT -}; - -#define RGB_MATRIX_EFFECT(x) \ - case RGB_MATRIX_EFFECT_##x: \ - return #x; -const char *rgb_matrix_name(uint8_t effect) { - switch (effect) { - case RGB_MATRIX_EFFECT_NONE: - return "NONE"; -#include "rgb_matrix_effects.inc" -#ifdef RGB_MATRIX_CUSTOM_KB -# include "rgb_matrix_kb.inc" -#endif // RGB_MATRIX_CUSTOM_KB -#ifdef RGB_MATRIX_CUSTOM_USER -# include "rgb_matrix_user.inc" -#endif // RGB_MATRIX_CUSTOM_USER -#undef RGB_MATRIX_EFFECT - default: - return "UNKNOWN"; - } -} - -static uint8_t effect_name_len = 0; - -const char *rgb_matrix_get_effect_name(void) { - static char buf[32] = {0}; - - snprintf(buf, sizeof(buf), "%s", rgb_matrix_name(rgb_matrix_get_mode())); - for (uint8_t i = 1; i < sizeof(buf); ++i) { - if (buf[i] == 0) { - effect_name_len = i; - break; - } else if (buf[i] == '_') - buf[i] = ' '; - else if (buf[i - 1] == ' ') - buf[i] = toupper(buf[i]); - else if (buf[i - 1] != ' ') - buf[i] = tolower(buf[i]); - } - return buf; -} - -bool oled_task_user(void) { - static uint8_t last_effect = 0; - static uint8_t last_speed = 0; - static uint16_t key_timer = 0; - static uint8_t start_index = 0; - - uint8_t speedPercentage = (uint8_t)(((float)rgb_matrix_get_speed() / 255.0) * 100.0); - - if (last_effect != rgb_matrix_get_mode() || last_speed != speedPercentage || timer_elapsed(key_timer) > 200) { - last_effect = rgb_matrix_get_mode(); - last_speed = speedPercentage; - key_timer = timer_read(); - - oled_write_ln_P(PSTR("Mode: "), false); - const char *name = rgb_matrix_get_effect_name(); - if (effect_name_len > 21) { - if (start_index > effect_name_len) { - start_index = 0; - } - for (uint8_t char_index = 0; char_index < 21; char_index++) { - if ((start_index + char_index) % effect_name_len == 0 && char_index != 0) { - oled_write_char(' ', false); - } else { - oled_write_char(name[(start_index + char_index) % (effect_name_len + 1)], false); - } - } - start_index += 1; - } else { - oled_write_ln(name, false); - start_index = 0; - } - - oled_set_cursor(0, 2); - oled_write_ln_P(PSTR("RGB Speed: "), false); - char speedBuffer[4]; - sprintf(speedBuffer, "%d", speedPercentage); - oled_write(speedBuffer, false); - oled_write("% ", false); - } - - return false; -} + #include "quantum.h" + #include + #include + + #if defined(RGB_MATRIX_EFFECT) + # undef RGB_MATRIX_EFFECT + #endif // defined(RGB_MATRIX_EFFECT) + + #define RGB_MATRIX_EFFECT(x) RGB_MATRIX_EFFECT_##x, + enum { + RGB_MATRIX_EFFECT_NONE, + #include "rgb_matrix_effects.inc" + #ifdef RGB_MATRIX_CUSTOM_KB + # include "rgb_matrix_kb.inc" + #endif // RGB_MATRIX_CUSTOM_KB + #ifdef RGB_MATRIX_CUSTOM_USER + # include "rgb_matrix_user.inc" + #endif // RGB_MATRIX_CUSTOM_USER + #undef RGB_MATRIX_EFFECT + }; + + #define RGB_MATRIX_EFFECT(x) \ + case RGB_MATRIX_EFFECT_##x: \ + return #x; + const char *rgb_matrix_name(uint8_t effect) { + switch (effect) { + case RGB_MATRIX_EFFECT_NONE: + return "NONE"; + #include "rgb_matrix_effects.inc" + #ifdef RGB_MATRIX_CUSTOM_KB + # include "rgb_matrix_kb.inc" + #endif // RGB_MATRIX_CUSTOM_KB + #ifdef RGB_MATRIX_CUSTOM_USER + # include "rgb_matrix_user.inc" + #endif // RGB_MATRIX_CUSTOM_USER + #undef RGB_MATRIX_EFFECT + default: + return "UNKNOWN"; + } + } + + static uint8_t effect_name_len = 0; + + const char *rgb_matrix_get_effect_name(void) { + static char buf[32] = {0}; + + snprintf(buf, sizeof(buf), "%s", rgb_matrix_name(rgb_matrix_get_mode())); + for (uint8_t i = 1; i < sizeof(buf); ++i) { + if (buf[i] == 0) { + effect_name_len = i; + break; + } else if (buf[i] == '_') + buf[i] = ' '; + else if (buf[i - 1] == ' ') + buf[i] = toupper(buf[i]); + else if (buf[i - 1] != ' ') + buf[i] = tolower(buf[i]); + } + return buf; + } + + bool oled_task_user(void) { + static uint8_t last_effect = 0; + static uint8_t last_speed = 0; + static uint16_t key_timer = 0; + static uint8_t start_index = 0; + + uint8_t speedPercentage = (uint8_t)(((float)rgb_matrix_get_speed() / 255.0) * 100.0); + bool is_timer_elapsed = timer_elapsed(key_timer) > 200; + + if (last_effect != rgb_matrix_get_mode() || last_speed != speedPercentage || is_timer_elapsed) { + last_effect = rgb_matrix_get_mode(); + last_speed = speedPercentage; + + oled_write_ln_P(PSTR("Mode: "), false); + const char *name = rgb_matrix_get_effect_name(); + if (effect_name_len > 21) { + if (!is_timer_elapsed && start_index != 0) { + start_index -= 1; + } else { + key_timer = timer_read(); + } + if (start_index > effect_name_len) { + start_index = 0; + } + for (uint8_t char_index = 0; char_index < 21; char_index++) { + if ((start_index + char_index) % effect_name_len == 0 && char_index != 0) { + oled_write_char(' ', false); + } else { + oled_write_char(name[(start_index + char_index) % (effect_name_len + 1)], false); + } + } + start_index += 1; + } else { + oled_write_ln(name, false); + start_index = 0; + } + + oled_set_cursor(0, 2); + oled_write_ln_P(PSTR("RGB Speed: "), false); + char speedBuffer[4]; + sprintf(speedBuffer, "%d", speedPercentage); + oled_write(speedBuffer, false); + oled_write("% ", false); + } + + return false; + } + \ No newline at end of file From ad2eb9aa21f8b72617a0fb4b7f4149923e6b5db8 Mon Sep 17 00:00:00 2001 From: Marek Schmitt <62243375+mawaeg@users.noreply.github.com> Date: Sat, 8 Mar 2025 17:56:04 +0100 Subject: [PATCH 7/9] Apply suggestions from code review Co-authored-by: Joel Challis --- keyboards/mawaeg/sharkropad/config.h | 2 ++ keyboards/mawaeg/sharkropad/keyboard.json | 2 +- keyboards/mawaeg/sharkropad/sharkropad.c | 9 +++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/keyboards/mawaeg/sharkropad/config.h b/keyboards/mawaeg/sharkropad/config.h index 950f63860d0..da88e14a375 100644 --- a/keyboards/mawaeg/sharkropad/config.h +++ b/keyboards/mawaeg/sharkropad/config.h @@ -14,6 +14,8 @@ * along with this program. If not, see . */ +#pragma once + #define STM32_FLASH_SECTORS_PER_BANK 128 #define I2C1_SCL_PIN A9 diff --git a/keyboards/mawaeg/sharkropad/keyboard.json b/keyboards/mawaeg/sharkropad/keyboard.json index ee6715d3723..140fec46a24 100644 --- a/keyboards/mawaeg/sharkropad/keyboard.json +++ b/keyboards/mawaeg/sharkropad/keyboard.json @@ -103,7 +103,7 @@ {"x": 8, "y": 45, "flags": 2}, {"x": 8, "y": 17, "flags": 2} ], - "maximum_brightness": 180 + "max_brightness": 180 }, "url": "https://github.com/mawaeg/sharkropad", "usb": { diff --git a/keyboards/mawaeg/sharkropad/sharkropad.c b/keyboards/mawaeg/sharkropad/sharkropad.c index e7b23f2f41c..b5999d84059 100644 --- a/keyboards/mawaeg/sharkropad/sharkropad.c +++ b/keyboards/mawaeg/sharkropad/sharkropad.c @@ -75,7 +75,9 @@ return buf; } - bool oled_task_user(void) { +bool oled_task_kb(void) { + if (!oled_task_user()) { return false; } + static uint8_t last_effect = 0; static uint8_t last_speed = 0; static uint16_t key_timer = 0; @@ -120,6 +122,5 @@ oled_write("% ", false); } - return false; - } - \ No newline at end of file + return true; +} From b1c22b210796998f3f7def113128972af8a40625 Mon Sep 17 00:00:00 2001 From: mawaeg <62243375+mawaeg@users.noreply.github.com> Date: Sun, 9 Mar 2025 20:17:28 +0100 Subject: [PATCH 8/9] Improve oled_task_kb based on review Co-authored-by: Drashna Jaelre --- keyboards/mawaeg/sharkropad/sharkropad.c | 211 +++++++++++------------ 1 file changed, 105 insertions(+), 106 deletions(-) diff --git a/keyboards/mawaeg/sharkropad/sharkropad.c b/keyboards/mawaeg/sharkropad/sharkropad.c index b5999d84059..d0ee405321b 100644 --- a/keyboards/mawaeg/sharkropad/sharkropad.c +++ b/keyboards/mawaeg/sharkropad/sharkropad.c @@ -14,113 +14,112 @@ * along with this program. If not, see . */ - #include "quantum.h" - #include - #include - - #if defined(RGB_MATRIX_EFFECT) - # undef RGB_MATRIX_EFFECT - #endif // defined(RGB_MATRIX_EFFECT) - - #define RGB_MATRIX_EFFECT(x) RGB_MATRIX_EFFECT_##x, - enum { - RGB_MATRIX_EFFECT_NONE, - #include "rgb_matrix_effects.inc" - #ifdef RGB_MATRIX_CUSTOM_KB - # include "rgb_matrix_kb.inc" - #endif // RGB_MATRIX_CUSTOM_KB - #ifdef RGB_MATRIX_CUSTOM_USER - # include "rgb_matrix_user.inc" - #endif // RGB_MATRIX_CUSTOM_USER - #undef RGB_MATRIX_EFFECT - }; - - #define RGB_MATRIX_EFFECT(x) \ - case RGB_MATRIX_EFFECT_##x: \ - return #x; - const char *rgb_matrix_name(uint8_t effect) { - switch (effect) { - case RGB_MATRIX_EFFECT_NONE: - return "NONE"; - #include "rgb_matrix_effects.inc" - #ifdef RGB_MATRIX_CUSTOM_KB - # include "rgb_matrix_kb.inc" - #endif // RGB_MATRIX_CUSTOM_KB - #ifdef RGB_MATRIX_CUSTOM_USER - # include "rgb_matrix_user.inc" - #endif // RGB_MATRIX_CUSTOM_USER - #undef RGB_MATRIX_EFFECT - default: - return "UNKNOWN"; - } - } - - static uint8_t effect_name_len = 0; - - const char *rgb_matrix_get_effect_name(void) { - static char buf[32] = {0}; - - snprintf(buf, sizeof(buf), "%s", rgb_matrix_name(rgb_matrix_get_mode())); - for (uint8_t i = 1; i < sizeof(buf); ++i) { - if (buf[i] == 0) { - effect_name_len = i; - break; - } else if (buf[i] == '_') - buf[i] = ' '; - else if (buf[i - 1] == ' ') - buf[i] = toupper(buf[i]); - else if (buf[i - 1] != ' ') - buf[i] = tolower(buf[i]); - } - return buf; - } - +#include "quantum.h" +#include +#include +#include + +#if defined(RGB_MATRIX_EFFECT) +# undef RGB_MATRIX_EFFECT +#endif // defined(RGB_MATRIX_EFFECT) + +#define RGB_MATRIX_EFFECT(x) RGB_MATRIX_EFFECT_##x, +enum { + RGB_MATRIX_EFFECT_NONE, +#include "rgb_matrix_effects.inc" +#ifdef RGB_MATRIX_CUSTOM_KB +# include "rgb_matrix_kb.inc" +#endif // RGB_MATRIX_CUSTOM_KB +#ifdef RGB_MATRIX_CUSTOM_USER +# include "rgb_matrix_user.inc" +#endif // RGB_MATRIX_CUSTOM_USER +#undef RGB_MATRIX_EFFECT +}; + +#define RGB_MATRIX_EFFECT(x) \ + case RGB_MATRIX_EFFECT_##x: \ + return #x; +const char *rgb_matrix_name(uint8_t effect) { + switch (effect) { + case RGB_MATRIX_EFFECT_NONE: + return "NONE"; +#include "rgb_matrix_effects.inc" +#ifdef RGB_MATRIX_CUSTOM_KB +# include "rgb_matrix_kb.inc" +#endif // RGB_MATRIX_CUSTOM_KB +#ifdef RGB_MATRIX_CUSTOM_USER +# include "rgb_matrix_user.inc" +#endif // RGB_MATRIX_CUSTOM_USER +#undef RGB_MATRIX_EFFECT + default: + return "UNKNOWN"; + } +} + +static uint8_t effect_name_len = 0; + +const char *rgb_matrix_get_effect_name(void) { + static char buf[32] = {0}; + + snprintf(buf, sizeof(buf), "%s", rgb_matrix_name(rgb_matrix_get_mode())); + for (uint8_t i = 1; i < sizeof(buf); ++i) { + if (buf[i] == 0) { + effect_name_len = i; + break; + } else if (buf[i] == '_') + buf[i] = ' '; + else if (buf[i - 1] == ' ') + buf[i] = toupper(buf[i]); + else if (buf[i - 1] != ' ') + buf[i] = tolower(buf[i]); + } + return buf; +} + bool oled_task_kb(void) { if (!oled_task_user()) { return false; } - static uint8_t last_effect = 0; - static uint8_t last_speed = 0; - static uint16_t key_timer = 0; - static uint8_t start_index = 0; - - uint8_t speedPercentage = (uint8_t)(((float)rgb_matrix_get_speed() / 255.0) * 100.0); - bool is_timer_elapsed = timer_elapsed(key_timer) > 200; - - if (last_effect != rgb_matrix_get_mode() || last_speed != speedPercentage || is_timer_elapsed) { - last_effect = rgb_matrix_get_mode(); - last_speed = speedPercentage; - - oled_write_ln_P(PSTR("Mode: "), false); - const char *name = rgb_matrix_get_effect_name(); - if (effect_name_len > 21) { - if (!is_timer_elapsed && start_index != 0) { - start_index -= 1; - } else { - key_timer = timer_read(); - } - if (start_index > effect_name_len) { - start_index = 0; - } - for (uint8_t char_index = 0; char_index < 21; char_index++) { - if ((start_index + char_index) % effect_name_len == 0 && char_index != 0) { - oled_write_char(' ', false); - } else { - oled_write_char(name[(start_index + char_index) % (effect_name_len + 1)], false); - } - } - start_index += 1; - } else { - oled_write_ln(name, false); - start_index = 0; - } - - oled_set_cursor(0, 2); - oled_write_ln_P(PSTR("RGB Speed: "), false); - char speedBuffer[4]; - sprintf(speedBuffer, "%d", speedPercentage); - oled_write(speedBuffer, false); - oled_write("% ", false); - } - - return true; + static uint8_t last_effect = 0; + static uint8_t last_speed = 0; + static uint16_t key_timer = 0; + static uint8_t start_index = 0; + + uint8_t speedPercentage = scale8(rgb_matrix_get_speed(), 100); + bool is_timer_elapsed = timer_elapsed(key_timer) > 200; + + if (last_effect != rgb_matrix_get_mode() || last_speed != speedPercentage || is_timer_elapsed) { + last_effect = rgb_matrix_get_mode(); + last_speed = speedPercentage; + + oled_write_ln_P(PSTR("Mode: "), false); + const char *name = rgb_matrix_get_effect_name(); + if (effect_name_len > 21) { + if (!is_timer_elapsed && start_index != 0) { + start_index -= 1; + } else { + key_timer = timer_read(); + } + if (start_index > effect_name_len) { + start_index = 0; + } + for (uint8_t char_index = 0; char_index < 21; char_index++) { + if ((start_index + char_index) % effect_name_len == 0 && char_index != 0) { + oled_write_char(' ', false); + } else { + oled_write_char(name[(start_index + char_index) % (effect_name_len + 1)], false); + } + } + start_index += 1; + } else { + oled_write_ln(name, false); + start_index = 0; + } + + oled_set_cursor(0, 2); + oled_write_ln_P(PSTR("RGB Speed: "), false); + oled_write(get_u8_str(speedPercentage, ' '), false); + oled_write("%", false); + } + + return true; } From 8a8a180558c89afa09a448ad279e7166b1976532 Mon Sep 17 00:00:00 2001 From: mawaeg <62243375+mawaeg@users.noreply.github.com> Date: Sun, 29 Jun 2025 17:44:09 +0200 Subject: [PATCH 9/9] Use rgb_matrix_get_mode_name instead of name generation --- keyboards/mawaeg/sharkropad/config.h | 2 ++ keyboards/mawaeg/sharkropad/sharkropad.c | 43 +++--------------------- 2 files changed, 6 insertions(+), 39 deletions(-) diff --git a/keyboards/mawaeg/sharkropad/config.h b/keyboards/mawaeg/sharkropad/config.h index da88e14a375..2e57c56f0f0 100644 --- a/keyboards/mawaeg/sharkropad/config.h +++ b/keyboards/mawaeg/sharkropad/config.h @@ -26,3 +26,5 @@ #define WS2812_PWM_PAL_MODE 1 #define WS2812_PWM_DMA_STREAM STM32_DMA1_STREAM2 #define WS2812_PWM_DMA_CHANNEL 4 + +#define RGB_MATRIX_MODE_NAME_ENABLE diff --git a/keyboards/mawaeg/sharkropad/sharkropad.c b/keyboards/mawaeg/sharkropad/sharkropad.c index d0ee405321b..391f59800ba 100644 --- a/keyboards/mawaeg/sharkropad/sharkropad.c +++ b/keyboards/mawaeg/sharkropad/sharkropad.c @@ -19,49 +19,12 @@ #include #include -#if defined(RGB_MATRIX_EFFECT) -# undef RGB_MATRIX_EFFECT -#endif // defined(RGB_MATRIX_EFFECT) - -#define RGB_MATRIX_EFFECT(x) RGB_MATRIX_EFFECT_##x, -enum { - RGB_MATRIX_EFFECT_NONE, -#include "rgb_matrix_effects.inc" -#ifdef RGB_MATRIX_CUSTOM_KB -# include "rgb_matrix_kb.inc" -#endif // RGB_MATRIX_CUSTOM_KB -#ifdef RGB_MATRIX_CUSTOM_USER -# include "rgb_matrix_user.inc" -#endif // RGB_MATRIX_CUSTOM_USER -#undef RGB_MATRIX_EFFECT -}; - -#define RGB_MATRIX_EFFECT(x) \ - case RGB_MATRIX_EFFECT_##x: \ - return #x; -const char *rgb_matrix_name(uint8_t effect) { - switch (effect) { - case RGB_MATRIX_EFFECT_NONE: - return "NONE"; -#include "rgb_matrix_effects.inc" -#ifdef RGB_MATRIX_CUSTOM_KB -# include "rgb_matrix_kb.inc" -#endif // RGB_MATRIX_CUSTOM_KB -#ifdef RGB_MATRIX_CUSTOM_USER -# include "rgb_matrix_user.inc" -#endif // RGB_MATRIX_CUSTOM_USER -#undef RGB_MATRIX_EFFECT - default: - return "UNKNOWN"; - } -} - static uint8_t effect_name_len = 0; const char *rgb_matrix_get_effect_name(void) { static char buf[32] = {0}; - snprintf(buf, sizeof(buf), "%s", rgb_matrix_name(rgb_matrix_get_mode())); + snprintf(buf, sizeof(buf), "%s", rgb_matrix_get_mode_name(rgb_matrix_get_mode())); for (uint8_t i = 1; i < sizeof(buf); ++i) { if (buf[i] == 0) { effect_name_len = i; @@ -77,7 +40,9 @@ const char *rgb_matrix_get_effect_name(void) { } bool oled_task_kb(void) { - if (!oled_task_user()) { return false; } + if (!oled_task_user()) { + return false; + } static uint8_t last_effect = 0; static uint8_t last_speed = 0;