Commit | Line | Data |
---|---|---|
14b7602a JH |
1 | /* Copyright 2017 Jason Williams |
2 | * Copyright 2017 Jack Humbert | |
fdd0f915 | 3 | * Copyright 2018 Yiancar |
14b7602a JH |
4 | * |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #ifndef RGB_MATRIX_H | |
20 | #define RGB_MATRIX_H | |
21 | ||
22 | #include <stdint.h> | |
23 | #include <stdbool.h> | |
c98247e3 | 24 | #include "rgb_matrix_types.h" |
14b7602a | 25 | #include "color.h" |
14b7602a | 26 | #include "quantum.h" |
066818f5 | 27 | #include "rgblight_list.h" |
14b7602a | 28 | |
fdd0f915 | 29 | #ifdef IS31FL3731 |
c98247e3 | 30 | #include "is31fl3731.h" |
fdd0f915 | 31 | #elif defined (IS31FL3733) |
5fcd744d | 32 | #include "is31fl3733.h" |
fa4052c2 | 33 | #elif defined (IS31FL3737) |
5fcd744d X |
34 | #include "is31fl3737.h" |
35 | #elif defined (WS2812) | |
36 | #include "ws2812.h" | |
fdd0f915 | 37 | #endif |
38 | ||
c98247e3 X |
39 | #ifndef RGB_MATRIX_LED_FLUSH_LIMIT |
40 | #define RGB_MATRIX_LED_FLUSH_LIMIT 16 | |
41 | #endif | |
14b7602a | 42 | |
c98247e3 X |
43 | #ifndef RGB_MATRIX_LED_PROCESS_LIMIT |
44 | #define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 | |
45 | #endif | |
14b7602a | 46 | |
c98247e3 X |
47 | #if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL |
48 | #define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \ | |
49 | uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ | |
50 | if (max > DRIVER_LED_TOTAL) \ | |
51 | max = DRIVER_LED_TOTAL; | |
52 | #else | |
53 | #define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = 0; \ | |
54 | uint8_t max = DRIVER_LED_TOTAL; | |
55 | #endif | |
14b7602a | 56 | |
af89752b | 57 | #define RGB_MATRIX_TEST_LED_FLAGS() if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue |
14b7602a | 58 | |
159191a8 | 59 | enum rgb_matrix_effects { |
c98247e3 | 60 | RGB_MATRIX_NONE = 0, |
62ba66d6 X |
61 | |
62 | // -------------------------------------- | |
63 | // -----Begin rgb effect enum macros----- | |
64 | #define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_##name, | |
65 | #include "rgb_matrix_animations/rgb_matrix_effects.inc" | |
66 | #undef RGB_MATRIX_EFFECT | |
1d784f0f DP |
67 | |
68 | #if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER) | |
69 | #define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_CUSTOM_##name, | |
70 | #ifdef RGB_MATRIX_CUSTOM_KB | |
71 | #include "rgb_matrix_kb.inc" | |
72 | #endif | |
73 | #ifdef RGB_MATRIX_CUSTOM_USER | |
74 | #include "rgb_matrix_user.inc" | |
75 | #endif | |
76 | #undef RGB_MATRIX_EFFECT | |
77 | #endif | |
62ba66d6 X |
78 | // -------------------------------------- |
79 | // -----End rgb effect enum macros------- | |
1d784f0f | 80 | |
c98247e3 | 81 | RGB_MATRIX_EFFECT_MAX |
14b7602a JH |
82 | }; |
83 | ||
e2dfb787 X |
84 | void eeconfig_update_rgb_matrix_default(void); |
85 | ||
86 | uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i); | |
c98247e3 X |
87 | uint8_t rgb_matrix_map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i); |
88 | ||
14b7602a | 89 | void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ); |
da1afe15 | 90 | void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ); |
14b7602a | 91 | |
e2dfb787 X |
92 | bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record); |
93 | ||
94 | void rgb_matrix_task(void); | |
95 | ||
14b7602a JH |
96 | // This runs after another backlight effect and replaces |
97 | // colors already set | |
98 | void rgb_matrix_indicators(void); | |
99 | void rgb_matrix_indicators_kb(void); | |
100 | void rgb_matrix_indicators_user(void); | |
101 | ||
bad56a4f | 102 | void rgb_matrix_init(void); |
14b7602a JH |
103 | |
104 | void rgb_matrix_set_suspend_state(bool state); | |
da1afe15 DJ |
105 | void rgb_matrix_toggle(void); |
106 | void rgb_matrix_enable(void); | |
107 | void rgb_matrix_enable_noeeprom(void); | |
108 | void rgb_matrix_disable(void); | |
109 | void rgb_matrix_disable_noeeprom(void); | |
110 | void rgb_matrix_step(void); | |
da1afe15 DJ |
111 | void rgb_matrix_step_reverse(void); |
112 | void rgb_matrix_increase_hue(void); | |
113 | void rgb_matrix_decrease_hue(void); | |
114 | void rgb_matrix_increase_sat(void); | |
115 | void rgb_matrix_decrease_sat(void); | |
116 | void rgb_matrix_increase_val(void); | |
117 | void rgb_matrix_decrease_val(void); | |
118 | void rgb_matrix_increase_speed(void); | |
119 | void rgb_matrix_decrease_speed(void); | |
a7113c8e X |
120 | led_flags_t rgb_matrix_get_flags(void); |
121 | void rgb_matrix_set_flags(led_flags_t flags); | |
da1afe15 DJ |
122 | void rgb_matrix_mode(uint8_t mode); |
123 | void rgb_matrix_mode_noeeprom(uint8_t mode); | |
b7688590 | 124 | uint8_t rgb_matrix_get_mode(void); |
e2dfb787 X |
125 | void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val); |
126 | void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val); | |
da1afe15 DJ |
127 | |
128 | #ifndef RGBLIGHT_ENABLE | |
129 | #define rgblight_toggle() rgb_matrix_toggle() | |
130 | #define rgblight_enable() rgb_matrix_enable() | |
131 | #define rgblight_enable_noeeprom() rgb_matrix_enable_noeeprom() | |
132 | #define rgblight_disable() rgb_matrix_disable() | |
133 | #define rgblight_disable_noeeprom() rgb_matrix_disable_noeeprom() | |
134 | #define rgblight_step() rgb_matrix_step() | |
135 | #define rgblight_sethsv(hue, sat, val) rgb_matrix_sethsv(hue, sat, val) | |
136 | #define rgblight_sethsv_noeeprom(hue, sat, val) rgb_matrix_sethsv_noeeprom(hue, sat, val) | |
137 | #define rgblight_step_reverse() rgb_matrix_step_reverse() | |
138 | #define rgblight_increase_hue() rgb_matrix_increase_hue() | |
139 | #define rgblight_decrease_hue() rgb_matrix_decrease_hue() | |
140 | #define rgblight_increase_sat() rgb_matrix_increase_sat() | |
141 | #define rgblight_decrease_sat() rgb_matrix_decrease_sat() | |
142 | #define rgblight_increase_val() rgb_matrix_increase_val() | |
143 | #define rgblight_decrease_val() rgb_matrix_decrease_val() | |
144 | #define rgblight_increase_speed() rgb_matrix_increase_speed() | |
145 | #define rgblight_decrease_speed() rgb_matrix_decrease_speed() | |
146 | #define rgblight_mode(mode) rgb_matrix_mode(mode) | |
147 | #define rgblight_mode_noeeprom(mode) rgb_matrix_mode_noeeprom(mode) | |
148 | #define rgblight_get_mode() rgb_matrix_get_mode() | |
da1afe15 | 149 | #endif |
14b7602a | 150 | |
f70f45ee JLW |
151 | typedef struct { |
152 | /* Perform any initialisation required for the other driver functions to work. */ | |
153 | void (*init)(void); | |
f70f45ee JLW |
154 | /* Set the colour of a single LED in the buffer. */ |
155 | void (*set_color)(int index, uint8_t r, uint8_t g, uint8_t b); | |
156 | /* Set the colour of all LEDS on the keyboard in the buffer. */ | |
157 | void (*set_color_all)(uint8_t r, uint8_t g, uint8_t b); | |
158 | /* Flush any buffered changes to the hardware. */ | |
159 | void (*flush)(void); | |
160 | } rgb_matrix_driver_t; | |
161 | ||
162 | extern const rgb_matrix_driver_t rgb_matrix_driver; | |
163 | ||
62ba66d6 X |
164 | extern rgb_config_t rgb_matrix_config; |
165 | ||
166 | extern bool g_suspend_state; | |
167 | extern rgb_counters_t g_rgb_counters; | |
168 | extern led_config_t g_led_config; | |
169 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | |
170 | extern last_hit_t g_last_hit_tracker; | |
171 | #endif | |
172 | #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS | |
173 | extern uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS]; | |
174 | #endif | |
175 | ||
14b7602a | 176 | #endif |