Add rules.mk defaults for f103,f072,f042 (#7704)
[jackhill/qmk/firmware.git] / quantum / ledmatrix.h
CommitLineData
fd698c43 1/* Copyright 2017 Jason Williams
2 * Copyright 2017 Jack Humbert
3 * Copyright 2018 Yiancar
4 * Copyright 2019 Clueboard
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LED_MATRIX_H
21#define LED_MATRIX_H
22
bf267060 23#ifndef BACKLIGHT_ENABLE
b624f32f 24# error You must define BACKLIGHT_ENABLE with LED_MATRIX_ENABLE
bf267060 25#endif
26
fd698c43 27typedef struct Point {
b624f32f 28 uint8_t x;
29 uint8_t y;
fd698c43 30} __attribute__((packed)) Point;
31
32typedef struct led_matrix {
b624f32f 33 union {
34 uint8_t raw;
35 struct {
36 uint8_t row : 4; // 16 max
37 uint8_t col : 4; // 16 max
38 };
39 } matrix_co;
40 Point point;
41 uint8_t modifier : 1;
fd698c43 42} __attribute__((packed)) led_matrix;
43
bf267060 44extern const led_matrix g_leds[LED_DRIVER_LED_COUNT];
fd698c43 45
46typedef struct {
b624f32f 47 uint8_t index;
48 uint8_t value;
fd698c43 49} led_indicator;
50
51typedef union {
b624f32f 52 uint32_t raw;
53 struct {
54 bool enable : 1;
55 uint8_t mode : 6;
56 uint8_t hue : 8; // Unused by led_matrix
57 uint8_t sat : 8; // Unused by led_matrix
58 uint8_t val : 8;
59 uint8_t speed : 8; // EECONFIG needs to be increased to support this
60 };
fd698c43 61} led_config_t;
62
63enum led_matrix_effects {
1a680c1d 64 LED_MATRIX_UNIFORM_BRIGHTNESS = 1,
65 // All new effects go above this line
fd698c43 66 LED_MATRIX_EFFECT_MAX
67};
68
69void led_matrix_set_index_value(int index, uint8_t value);
70void led_matrix_set_index_value_all(uint8_t value);
71
72// This runs after another backlight effect and replaces
73// colors already set
74void led_matrix_indicators(void);
75void led_matrix_indicators_kb(void);
76void led_matrix_indicators_user(void);
77
78void led_matrix_init(void);
79void led_matrix_setup_drivers(void);
80
81void led_matrix_set_suspend_state(bool state);
82void led_matrix_set_indicator_state(uint8_t state);
83
84void led_matrix_task(void);
85
86// This should not be called from an interrupt
87// (eg. from a timer interrupt).
88// Call this while idle (in between matrix scans).
89// If the buffer is dirty, it will update the driver with the buffer.
90void led_matrix_update_pwm_buffers(void);
91
92bool process_led_matrix(uint16_t keycode, keyrecord_t *record);
93
94uint32_t led_matrix_get_tick(void);
95
b624f32f 96void led_matrix_toggle(void);
97void led_matrix_enable(void);
98void led_matrix_enable_noeeprom(void);
99void led_matrix_disable(void);
100void led_matrix_disable_noeeprom(void);
101void led_matrix_step(void);
102void led_matrix_step_reverse(void);
103void led_matrix_increase_val(void);
104void led_matrix_decrease_val(void);
105void led_matrix_increase_speed(void);
106void led_matrix_decrease_speed(void);
107void led_matrix_mode(uint8_t mode, bool eeprom_write);
108void led_matrix_mode_noeeprom(uint8_t mode);
fd698c43 109uint8_t led_matrix_get_mode(void);
b624f32f 110void led_matrix_set_value(uint8_t mode);
111void led_matrix_set_value_noeeprom(uint8_t mode);
fd698c43 112
fd698c43 113typedef struct {
114 /* Perform any initialisation required for the other driver functions to work. */
115 void (*init)(void);
116
117 /* Set the brightness of a single LED in the buffer. */
118 void (*set_value)(int index, uint8_t value);
119 /* Set the brightness of all LEDS on the keyboard in the buffer. */
120 void (*set_value_all)(uint8_t value);
121 /* Flush any buffered changes to the hardware. */
122 void (*flush)(void);
123} led_matrix_driver_t;
124
125extern const led_matrix_driver_t led_matrix_driver;
126
127#endif