1 /* Copyright 2017 Jason Williams
2 * Copyright 2017 Jack Humbert
3 * Copyright 2018 Yiancar
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.
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.
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/>.
24 #include "rgb_matrix_types.h"
27 #include "rgblight_list.h"
30 #include "is31fl3731.h"
31 #elif defined (IS31FL3733)
32 #include "is31fl3733.h"
33 #elif defined (IS31FL3737)
34 #include "is31fl3737.h"
35 #elif defined (WS2812)
39 #ifndef RGB_MATRIX_LED_FLUSH_LIMIT
40 #define RGB_MATRIX_LED_FLUSH_LIMIT 16
43 #ifndef RGB_MATRIX_LED_PROCESS_LIMIT
44 #define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5
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;
53 #define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = 0; \
54 uint8_t max = DRIVER_LED_TOTAL;
57 #define RGB_MATRIX_TEST_LED_FLAGS() if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue
65 enum rgb_matrix_effects {
68 // --------------------------------------
69 // -----Begin rgb effect enum macros-----
70 #define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_##name,
71 #include "rgb_matrix_animations/rgb_matrix_effects.inc"
72 #undef RGB_MATRIX_EFFECT
74 #if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER)
75 #define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_CUSTOM_##name,
76 #ifdef RGB_MATRIX_CUSTOM_KB
77 #include "rgb_matrix_kb.inc"
79 #ifdef RGB_MATRIX_CUSTOM_USER
80 #include "rgb_matrix_user.inc"
82 #undef RGB_MATRIX_EFFECT
84 // --------------------------------------
85 // -----End rgb effect enum macros-------
90 uint8_t rgb_matrix_map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i);
92 void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
93 void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
95 // This runs after another backlight effect and replaces
97 void rgb_matrix_indicators(void);
98 void rgb_matrix_indicators_kb(void);
99 void rgb_matrix_indicators_user(void);
101 void rgb_matrix_init(void);
102 void rgb_matrix_setup_drivers(void);
104 void rgb_matrix_set_suspend_state(bool state);
105 void rgb_matrix_set_indicator_state(uint8_t state);
108 void rgb_matrix_task(void);
110 // This should not be called from an interrupt
111 // (eg. from a timer interrupt).
112 // Call this while idle (in between matrix scans).
113 // If the buffer is dirty, it will update the driver with the buffer.
114 void rgb_matrix_update_pwm_buffers(void);
116 bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record);
118 void rgb_matrix_increase(void);
119 void rgb_matrix_decrease(void);
121 // void *backlight_get_key_color_eeprom_address(uint8_t led);
122 // void backlight_get_key_color( uint8_t led, HSV *hsv );
123 // void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv );
125 void rgb_matrix_toggle(void);
126 void rgb_matrix_enable(void);
127 void rgb_matrix_enable_noeeprom(void);
128 void rgb_matrix_disable(void);
129 void rgb_matrix_disable_noeeprom(void);
130 void rgb_matrix_step(void);
131 void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
132 void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
133 void rgb_matrix_step_reverse(void);
134 void rgb_matrix_increase_hue(void);
135 void rgb_matrix_decrease_hue(void);
136 void rgb_matrix_increase_sat(void);
137 void rgb_matrix_decrease_sat(void);
138 void rgb_matrix_increase_val(void);
139 void rgb_matrix_decrease_val(void);
140 void rgb_matrix_increase_speed(void);
141 void rgb_matrix_decrease_speed(void);
142 led_flags_t rgb_matrix_get_flags(void);
143 void rgb_matrix_set_flags(led_flags_t flags);
144 void rgb_matrix_mode(uint8_t mode);
145 void rgb_matrix_mode_noeeprom(uint8_t mode);
146 uint8_t rgb_matrix_get_mode(void);
148 #ifndef RGBLIGHT_ENABLE
149 #define rgblight_toggle() rgb_matrix_toggle()
150 #define rgblight_enable() rgb_matrix_enable()
151 #define rgblight_enable_noeeprom() rgb_matrix_enable_noeeprom()
152 #define rgblight_disable() rgb_matrix_disable()
153 #define rgblight_disable_noeeprom() rgb_matrix_disable_noeeprom()
154 #define rgblight_step() rgb_matrix_step()
155 #define rgblight_sethsv(hue, sat, val) rgb_matrix_sethsv(hue, sat, val)
156 #define rgblight_sethsv_noeeprom(hue, sat, val) rgb_matrix_sethsv_noeeprom(hue, sat, val)
157 #define rgblight_step_reverse() rgb_matrix_step_reverse()
158 #define rgblight_increase_hue() rgb_matrix_increase_hue()
159 #define rgblight_decrease_hue() rgb_matrix_decrease_hue()
160 #define rgblight_increase_sat() rgb_matrix_increase_sat()
161 #define rgblight_decrease_sat() rgb_matrix_decrease_sat()
162 #define rgblight_increase_val() rgb_matrix_increase_val()
163 #define rgblight_decrease_val() rgb_matrix_decrease_val()
164 #define rgblight_increase_speed() rgb_matrix_increase_speed()
165 #define rgblight_decrease_speed() rgb_matrix_decrease_speed()
166 #define rgblight_mode(mode) rgb_matrix_mode(mode)
167 #define rgblight_mode_noeeprom(mode) rgb_matrix_mode_noeeprom(mode)
168 #define rgblight_get_mode() rgb_matrix_get_mode()
173 /* Perform any initialisation required for the other driver functions to work. */
175 /* Set the colour of a single LED in the buffer. */
176 void (*set_color)(int index, uint8_t r, uint8_t g, uint8_t b);
177 /* Set the colour of all LEDS on the keyboard in the buffer. */
178 void (*set_color_all)(uint8_t r, uint8_t g, uint8_t b);
179 /* Flush any buffered changes to the hardware. */
181 } rgb_matrix_driver_t;
183 extern const rgb_matrix_driver_t rgb_matrix_driver;
185 extern rgb_config_t rgb_matrix_config;
187 extern bool g_suspend_state;
188 extern rgb_counters_t g_rgb_counters;
189 extern led_config_t g_led_config;
190 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
191 extern last_hit_t g_last_hit_tracker;
193 #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS
194 extern uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS];