Update Dvorak, Colemak and Workman keycode aliases (#8217)
[jackhill/qmk/firmware.git] / quantum / rgb_matrix.h
CommitLineData
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
b624f32f 30# include "is31fl3731.h"
31#elif defined(IS31FL3733)
32# include "is31fl3733.h"
33#elif defined(IS31FL3737)
34# include "is31fl3737.h"
35#elif defined(WS2812)
36# include "ws2812.h"
fdd0f915 37#endif
38
c98247e3 39#ifndef RGB_MATRIX_LED_FLUSH_LIMIT
b624f32f 40# define RGB_MATRIX_LED_FLUSH_LIMIT 16
c98247e3 41#endif
14b7602a 42
c98247e3 43#ifndef RGB_MATRIX_LED_PROCESS_LIMIT
b624f32f 44# define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5
c98247e3 45#endif
14b7602a 46
c98247e3 47#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
b624f32f 48# define RGB_MATRIX_USE_LIMITS(min, max) \
49 uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \
50 uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \
51 if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
c98247e3 52#else
b624f32f 53# define RGB_MATRIX_USE_LIMITS(min, max) \
54 uint8_t min = 0; \
55 uint8_t max = DRIVER_LED_TOTAL;
c98247e3 56#endif
14b7602a 57
b624f32f 58#define RGB_MATRIX_TEST_LED_FLAGS() \
59 if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue
14b7602a 60
159191a8 61enum rgb_matrix_effects {
b624f32f 62 RGB_MATRIX_NONE = 0,
62ba66d6
X
63
64// --------------------------------------
65// -----Begin rgb effect enum macros-----
66#define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_##name,
67#include "rgb_matrix_animations/rgb_matrix_effects.inc"
68#undef RGB_MATRIX_EFFECT
1d784f0f
DP
69
70#if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER)
b624f32f 71# define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_CUSTOM_##name,
72# ifdef RGB_MATRIX_CUSTOM_KB
73# include "rgb_matrix_kb.inc"
74# endif
75# ifdef RGB_MATRIX_CUSTOM_USER
76# include "rgb_matrix_user.inc"
77# endif
78# undef RGB_MATRIX_EFFECT
1d784f0f 79#endif
b624f32f 80 // --------------------------------------
81 // -----End rgb effect enum macros-------
1d784f0f 82
b624f32f 83 RGB_MATRIX_EFFECT_MAX
14b7602a
JH
84};
85
e2dfb787
X
86void eeconfig_update_rgb_matrix_default(void);
87
88uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i);
b624f32f 89uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i);
c98247e3 90
b624f32f 91void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
92void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
14b7602a 93
e2dfb787
X
94bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record);
95
96void rgb_matrix_task(void);
97
14b7602a
JH
98// This runs after another backlight effect and replaces
99// colors already set
100void rgb_matrix_indicators(void);
101void rgb_matrix_indicators_kb(void);
102void rgb_matrix_indicators_user(void);
103
bad56a4f 104void rgb_matrix_init(void);
14b7602a 105
b624f32f 106void rgb_matrix_set_suspend_state(bool state);
107void rgb_matrix_toggle(void);
108void rgb_matrix_enable(void);
109void rgb_matrix_enable_noeeprom(void);
110void rgb_matrix_disable(void);
111void rgb_matrix_disable_noeeprom(void);
112void rgb_matrix_step(void);
113void rgb_matrix_step_reverse(void);
114void rgb_matrix_increase_hue(void);
115void rgb_matrix_decrease_hue(void);
116void rgb_matrix_increase_sat(void);
117void rgb_matrix_decrease_sat(void);
118void rgb_matrix_increase_val(void);
119void rgb_matrix_decrease_val(void);
120void rgb_matrix_increase_speed(void);
121void rgb_matrix_decrease_speed(void);
a7113c8e 122led_flags_t rgb_matrix_get_flags(void);
b624f32f 123void rgb_matrix_set_flags(led_flags_t flags);
124void rgb_matrix_mode(uint8_t mode);
125void rgb_matrix_mode_noeeprom(uint8_t mode);
126uint8_t rgb_matrix_get_mode(void);
127void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
128void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
da1afe15
DJ
129
130#ifndef RGBLIGHT_ENABLE
ae40fc49
JC
131# define rgblight_toggle rgb_matrix_toggle
132# define rgblight_enable rgb_matrix_enable
133# define rgblight_enable_noeeprom rgb_matrix_enable_noeeprom
134# define rgblight_disable rgb_matrix_disable
135# define rgblight_disable_noeeprom rgb_matrix_disable_noeeprom
136# define rgblight_step rgb_matrix_step
137# define rgblight_sethsv rgb_matrix_sethsv
138# define rgblight_sethsv_noeeprom rgb_matrix_sethsv_noeeprom
139# define rgblight_step_reverse rgb_matrix_step_reverse
140# define rgblight_increase_hue rgb_matrix_increase_hue
141# define rgblight_decrease_hue rgb_matrix_decrease_hue
142# define rgblight_increase_sat rgb_matrix_increase_sat
143# define rgblight_decrease_sat rgb_matrix_decrease_sat
144# define rgblight_increase_val rgb_matrix_increase_val
145# define rgblight_decrease_val rgb_matrix_decrease_val
146# define rgblight_increase_speed rgb_matrix_increase_speed
147# define rgblight_decrease_speed rgb_matrix_decrease_speed
148# define rgblight_mode rgb_matrix_mode
149# define rgblight_mode_noeeprom rgb_matrix_mode_noeeprom
150# define rgblight_get_mode rgb_matrix_get_mode
da1afe15 151#endif
14b7602a 152
f70f45ee
JLW
153typedef struct {
154 /* Perform any initialisation required for the other driver functions to work. */
155 void (*init)(void);
f70f45ee
JLW
156 /* Set the colour of a single LED in the buffer. */
157 void (*set_color)(int index, uint8_t r, uint8_t g, uint8_t b);
158 /* Set the colour of all LEDS on the keyboard in the buffer. */
159 void (*set_color_all)(uint8_t r, uint8_t g, uint8_t b);
160 /* Flush any buffered changes to the hardware. */
161 void (*flush)(void);
162} rgb_matrix_driver_t;
163
164extern const rgb_matrix_driver_t rgb_matrix_driver;
165
62ba66d6
X
166extern rgb_config_t rgb_matrix_config;
167
b624f32f 168extern bool g_suspend_state;
62ba66d6 169extern rgb_counters_t g_rgb_counters;
b624f32f 170extern led_config_t g_led_config;
62ba66d6
X
171#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
172extern last_hit_t g_last_hit_tracker;
173#endif
174#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS
175extern uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS];
176#endif
177
14b7602a 178#endif