diff options
Diffstat (limited to 'quantum/process_keycode')
| -rw-r--r-- | quantum/process_keycode/process_rgb.c | 141 | ||||
| -rw-r--r-- | quantum/process_keycode/process_rgb.h | 20 |
2 files changed, 161 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_rgb.c b/quantum/process_keycode/process_rgb.c new file mode 100644 index 000000000..c76166342 --- /dev/null +++ b/quantum/process_keycode/process_rgb.c | |||
| @@ -0,0 +1,141 @@ | |||
| 1 | /* Copyright 2019 | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #include "process_rgb.h" | ||
| 17 | #include "rgb.h" | ||
| 18 | |||
| 19 | typedef void (*rgb_func_pointer)(void); | ||
| 20 | |||
| 21 | /** | ||
| 22 | * Wrapper for inc/dec rgb keycode | ||
| 23 | * | ||
| 24 | * noinline to optimise for firmware size not speed (not in hot path) | ||
| 25 | */ | ||
| 26 | static void __attribute__((noinline)) handleKeycodeRGB(const uint8_t is_shifted, const rgb_func_pointer inc_func, const rgb_func_pointer dec_func) { | ||
| 27 | if (is_shifted) { | ||
| 28 | dec_func(); | ||
| 29 | } else { | ||
| 30 | inc_func(); | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | /** | ||
| 35 | * Wrapper for animation mode | ||
| 36 | * - if not in animation family -> jump to that animation | ||
| 37 | * - otherwise -> wrap round animation speed | ||
| 38 | * | ||
| 39 | * noinline to optimise for firmware size not speed (not in hot path) | ||
| 40 | */ | ||
| 41 | static void __attribute__((noinline,unused)) handleKeycodeRGBMode(const uint8_t start, const uint8_t end) { | ||
| 42 | if ((start <= rgblight_get_mode()) && (rgblight_get_mode() < end)) { | ||
| 43 | rgblight_step(); | ||
| 44 | } else { | ||
| 45 | rgblight_mode(start); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | /** | ||
| 50 | * Handle keycodes for both rgblight and rgbmatrix | ||
| 51 | */ | ||
| 52 | bool process_rgb(const uint16_t keycode, const keyrecord_t *record) { | ||
| 53 | #ifndef SPLIT_KEYBOARD | ||
| 54 | if (record->event.pressed) { | ||
| 55 | #else | ||
| 56 | // Split keyboards need to trigger on key-up for edge-case issue | ||
| 57 | if (!record->event.pressed) { | ||
| 58 | #endif | ||
| 59 | uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)); | ||
| 60 | switch (keycode) { | ||
| 61 | case RGB_TOG: | ||
| 62 | rgblight_toggle(); | ||
| 63 | return false; | ||
| 64 | case RGB_MODE_FORWARD: | ||
| 65 | handleKeycodeRGB(shifted, rgblight_step, rgblight_step_reverse); | ||
| 66 | return false; | ||
| 67 | case RGB_MODE_REVERSE: | ||
| 68 | handleKeycodeRGB(shifted, rgblight_step_reverse, rgblight_step); | ||
| 69 | return false; | ||
| 70 | case RGB_HUI: | ||
| 71 | handleKeycodeRGB(shifted, rgblight_increase_hue, rgblight_decrease_hue); | ||
| 72 | return false; | ||
| 73 | case RGB_HUD: | ||
| 74 | handleKeycodeRGB(shifted, rgblight_decrease_hue, rgblight_increase_hue); | ||
| 75 | return false; | ||
| 76 | case RGB_SAI: | ||
| 77 | handleKeycodeRGB(shifted, rgblight_increase_sat, rgblight_decrease_sat); | ||
| 78 | return false; | ||
| 79 | case RGB_SAD: | ||
| 80 | handleKeycodeRGB(shifted, rgblight_decrease_sat, rgblight_increase_sat); | ||
| 81 | return false; | ||
| 82 | case RGB_VAI: | ||
| 83 | handleKeycodeRGB(shifted, rgblight_increase_val, rgblight_decrease_val); | ||
| 84 | return false; | ||
| 85 | case RGB_VAD: | ||
| 86 | handleKeycodeRGB(shifted, rgblight_decrease_val, rgblight_increase_val); | ||
| 87 | return false; | ||
| 88 | case RGB_SPI: | ||
| 89 | handleKeycodeRGB(shifted, rgblight_increase_speed, rgblight_decrease_speed); | ||
| 90 | return false; | ||
| 91 | case RGB_SPD: | ||
| 92 | handleKeycodeRGB(shifted, rgblight_decrease_speed, rgblight_increase_speed); | ||
| 93 | return false; | ||
| 94 | case RGB_MODE_PLAIN: | ||
| 95 | rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); | ||
| 96 | return false; | ||
| 97 | case RGB_MODE_BREATHE: | ||
| 98 | #ifdef RGBLIGHT_EFFECT_BREATHING | ||
| 99 | handleKeycodeRGBMode(RGBLIGHT_MODE_BREATHING, RGBLIGHT_MODE_BREATHING_end); | ||
| 100 | #endif | ||
| 101 | return false; | ||
| 102 | case RGB_MODE_RAINBOW: | ||
| 103 | #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD | ||
| 104 | handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_MOOD, RGBLIGHT_MODE_RAINBOW_MOOD_end); | ||
| 105 | #endif | ||
| 106 | return false; | ||
| 107 | case RGB_MODE_SWIRL: | ||
| 108 | #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL | ||
| 109 | handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_SWIRL, RGBLIGHT_MODE_RAINBOW_SWIRL_end); | ||
| 110 | #endif | ||
| 111 | return false; | ||
| 112 | case RGB_MODE_SNAKE: | ||
| 113 | #ifdef RGBLIGHT_EFFECT_SNAKE | ||
| 114 | handleKeycodeRGBMode(RGBLIGHT_MODE_SNAKE, RGBLIGHT_MODE_SNAKE_end); | ||
| 115 | #endif | ||
| 116 | return false; | ||
| 117 | case RGB_MODE_KNIGHT: | ||
| 118 | #ifdef RGBLIGHT_EFFECT_KNIGHT | ||
| 119 | handleKeycodeRGBMode(RGBLIGHT_MODE_KNIGHT, RGBLIGHT_MODE_KNIGHT_end); | ||
| 120 | #endif | ||
| 121 | return false; | ||
| 122 | case RGB_MODE_XMAS: | ||
| 123 | #ifdef RGBLIGHT_EFFECT_CHRISTMAS | ||
| 124 | rgblight_mode(RGBLIGHT_MODE_CHRISTMAS); | ||
| 125 | #endif | ||
| 126 | return false; | ||
| 127 | case RGB_MODE_GRADIENT: | ||
| 128 | #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT | ||
| 129 | handleKeycodeRGBMode(RGBLIGHT_MODE_STATIC_GRADIENT, RGBLIGHT_MODE_STATIC_GRADIENT_end); | ||
| 130 | #endif | ||
| 131 | return false; | ||
| 132 | case RGB_MODE_RGBTEST: | ||
| 133 | #ifdef RGBLIGHT_EFFECT_RGB_TEST | ||
| 134 | rgblight_mode(RGBLIGHT_MODE_RGB_TEST); | ||
| 135 | #endif | ||
| 136 | return false; | ||
| 137 | } | ||
| 138 | } | ||
| 139 | |||
| 140 | return true; | ||
| 141 | } | ||
diff --git a/quantum/process_keycode/process_rgb.h b/quantum/process_keycode/process_rgb.h new file mode 100644 index 000000000..26aca4689 --- /dev/null +++ b/quantum/process_keycode/process_rgb.h | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | /* Copyright 2019 | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #pragma once | ||
| 17 | |||
| 18 | #include "quantum.h" | ||
| 19 | |||
| 20 | bool process_rgb(const uint16_t keycode, const keyrecord_t *record); | ||
