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"
29 #include "is31fl3731.h"
30 #elif defined (IS31FL3733)
31 #include "is31fl3733.h"
34 #ifndef RGB_MATRIX_LED_FLUSH_LIMIT
35 #define RGB_MATRIX_LED_FLUSH_LIMIT 16
38 #ifndef RGB_MATRIX_LED_PROCESS_LIMIT
39 #define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5
42 #if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
43 #define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \
44 uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \
45 if (max > DRIVER_LED_TOTAL) \
46 max = DRIVER_LED_TOTAL;
48 #define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = 0; \
49 uint8_t max = DRIVER_LED_TOTAL;
52 extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
60 enum rgb_matrix_effects {
62 RGB_MATRIX_SOLID_COLOR = 1,
63 #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS
64 RGB_MATRIX_ALPHAS_MODS,
65 #endif // DISABLE_RGB_MATRIX_ALPHAS_MODS
66 #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
67 RGB_MATRIX_GRADIENT_UP_DOWN,
68 #endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
69 #ifndef DISABLE_RGB_MATRIX_BREATHING
71 #endif // DISABLE_RGB_MATRIX_BREATHING
72 #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
74 #endif // DISABLE_RGB_MATRIX_CYCLE_ALL
75 #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
76 RGB_MATRIX_CYCLE_LEFT_RIGHT,
77 #endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
78 #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
79 RGB_MATRIX_CYCLE_UP_DOWN,
80 #endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
81 #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
82 RGB_MATRIX_RAINBOW_MOVING_CHEVRON,
83 #endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
84 #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON
85 RGB_MATRIX_DUAL_BEACON,
86 #endif // DISABLE_RGB_MATRIX_DUAL_BEACON
87 #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON
88 RGB_MATRIX_RAINBOW_BEACON,
89 #endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON
90 #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
91 RGB_MATRIX_RAINBOW_PINWHEELS,
92 #endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
93 #ifndef DISABLE_RGB_MATRIX_RAINDROPS
95 #endif // DISABLE_RGB_MATRIX_RAINDROPS
96 #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
97 RGB_MATRIX_JELLYBEAN_RAINDROPS,
98 #endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
99 #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN
100 RGB_MATRIX_DIGITAL_RAIN,
101 #endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN
102 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
103 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
104 RGB_MATRIX_SOLID_REACTIVE_SIMPLE,
105 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
106 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
107 RGB_MATRIX_SOLID_REACTIVE,
108 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE
109 #ifndef DISABLE_RGB_MATRIX_SPLASH
111 #endif // DISABLE_RGB_MATRIX_SPLASH
112 #ifndef DISABLE_RGB_MATRIX_MULTISPLASH
113 RGB_MATRIX_MULTISPLASH,
114 #endif // DISABLE_RGB_MATRIX_MULTISPLASH
115 #ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
116 RGB_MATRIX_SOLID_SPLASH,
117 #endif // DISABLE_RGB_MATRIX_SOLID_SPLASH
118 #ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
119 RGB_MATRIX_SOLID_MULTISPLASH,
120 #endif // DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
121 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
122 RGB_MATRIX_EFFECT_MAX
125 uint8_t rgb_matrix_map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i);
127 void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
128 void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
130 // This runs after another backlight effect and replaces
131 // colors already set
132 void rgb_matrix_indicators(void);
133 void rgb_matrix_indicators_kb(void);
134 void rgb_matrix_indicators_user(void);
136 void rgb_matrix_init(void);
137 void rgb_matrix_setup_drivers(void);
139 void rgb_matrix_set_suspend_state(bool state);
140 void rgb_matrix_set_indicator_state(uint8_t state);
143 void rgb_matrix_task(void);
145 // This should not be called from an interrupt
146 // (eg. from a timer interrupt).
147 // Call this while idle (in between matrix scans).
148 // If the buffer is dirty, it will update the driver with the buffer.
149 void rgb_matrix_update_pwm_buffers(void);
151 bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record);
153 void rgb_matrix_increase(void);
154 void rgb_matrix_decrease(void);
156 // void *backlight_get_key_color_eeprom_address(uint8_t led);
157 // void backlight_get_key_color( uint8_t led, HSV *hsv );
158 // void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv );
160 void rgb_matrix_toggle(void);
161 void rgb_matrix_enable(void);
162 void rgb_matrix_enable_noeeprom(void);
163 void rgb_matrix_disable(void);
164 void rgb_matrix_disable_noeeprom(void);
165 void rgb_matrix_step(void);
166 void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
167 void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
168 void rgb_matrix_step_reverse(void);
169 void rgb_matrix_increase_hue(void);
170 void rgb_matrix_decrease_hue(void);
171 void rgb_matrix_increase_sat(void);
172 void rgb_matrix_decrease_sat(void);
173 void rgb_matrix_increase_val(void);
174 void rgb_matrix_decrease_val(void);
175 void rgb_matrix_increase_speed(void);
176 void rgb_matrix_decrease_speed(void);
177 void rgb_matrix_mode(uint8_t mode);
178 void rgb_matrix_mode_noeeprom(uint8_t mode);
179 uint8_t rgb_matrix_get_mode(void);
181 #ifndef RGBLIGHT_ENABLE
182 #define rgblight_toggle() rgb_matrix_toggle()
183 #define rgblight_enable() rgb_matrix_enable()
184 #define rgblight_enable_noeeprom() rgb_matrix_enable_noeeprom()
185 #define rgblight_disable() rgb_matrix_disable()
186 #define rgblight_disable_noeeprom() rgb_matrix_disable_noeeprom()
187 #define rgblight_step() rgb_matrix_step()
188 #define rgblight_sethsv(hue, sat, val) rgb_matrix_sethsv(hue, sat, val)
189 #define rgblight_sethsv_noeeprom(hue, sat, val) rgb_matrix_sethsv_noeeprom(hue, sat, val)
190 #define rgblight_step_reverse() rgb_matrix_step_reverse()
191 #define rgblight_increase_hue() rgb_matrix_increase_hue()
192 #define rgblight_decrease_hue() rgb_matrix_decrease_hue()
193 #define rgblight_increase_sat() rgb_matrix_increase_sat()
194 #define rgblight_decrease_sat() rgb_matrix_decrease_sat()
195 #define rgblight_increase_val() rgb_matrix_increase_val()
196 #define rgblight_decrease_val() rgb_matrix_decrease_val()
197 #define rgblight_increase_speed() rgb_matrix_increase_speed()
198 #define rgblight_decrease_speed() rgb_matrix_decrease_speed()
199 #define rgblight_mode(mode) rgb_matrix_mode(mode)
200 #define rgblight_mode_noeeprom(mode) rgb_matrix_mode_noeeprom(mode)
201 #define rgblight_get_mode() rgb_matrix_get_mode()
206 /* Perform any initialisation required for the other driver functions to work. */
208 /* Set the colour of a single LED in the buffer. */
209 void (*set_color)(int index, uint8_t r, uint8_t g, uint8_t b);
210 /* Set the colour of all LEDS on the keyboard in the buffer. */
211 void (*set_color_all)(uint8_t r, uint8_t g, uint8_t b);
212 /* Flush any buffered changes to the hardware. */
214 } rgb_matrix_driver_t;
216 extern const rgb_matrix_driver_t rgb_matrix_driver;