diff options
Diffstat (limited to 'quantum/ledmatrix.h')
-rw-r--r-- | quantum/ledmatrix.h | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/quantum/ledmatrix.h b/quantum/ledmatrix.h new file mode 100644 index 000000000..618c5d676 --- /dev/null +++ b/quantum/ledmatrix.h | |||
@@ -0,0 +1,129 @@ | |||
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 | |||
23 | |||
24 | #ifndef BACKLIGHT_ENABLE | ||
25 | #error You must define BACKLIGHT_ENABLE with LED_MATRIX_ENABLE | ||
26 | #endif | ||
27 | |||
28 | |||
29 | typedef struct Point { | ||
30 | uint8_t x; | ||
31 | uint8_t y; | ||
32 | } __attribute__((packed)) Point; | ||
33 | |||
34 | typedef struct led_matrix { | ||
35 | union { | ||
36 | uint8_t raw; | ||
37 | struct { | ||
38 | uint8_t row:4; // 16 max | ||
39 | uint8_t col:4; // 16 max | ||
40 | }; | ||
41 | } matrix_co; | ||
42 | Point point; | ||
43 | uint8_t modifier:1; | ||
44 | } __attribute__((packed)) led_matrix; | ||
45 | |||
46 | extern const led_matrix g_leds[LED_DRIVER_LED_COUNT]; | ||
47 | |||
48 | typedef struct { | ||
49 | uint8_t index; | ||
50 | uint8_t value; | ||
51 | } led_indicator; | ||
52 | |||
53 | typedef union { | ||
54 | uint32_t raw; | ||
55 | struct { | ||
56 | bool enable :1; | ||
57 | uint8_t mode :6; | ||
58 | uint8_t hue :8; // Unused by led_matrix | ||
59 | uint8_t sat :8; // Unused by led_matrix | ||
60 | uint8_t val :8; | ||
61 | uint8_t speed :8;//EECONFIG needs to be increased to support this | ||
62 | }; | ||
63 | } led_config_t; | ||
64 | |||
65 | enum led_matrix_effects { | ||
66 | LED_MATRIX_UNIFORM_BRIGHTNESS = 1, | ||
67 | // All new effects go above this line | ||
68 | LED_MATRIX_EFFECT_MAX | ||
69 | }; | ||
70 | |||
71 | void led_matrix_set_index_value(int index, uint8_t value); | ||
72 | void led_matrix_set_index_value_all(uint8_t value); | ||
73 | |||
74 | // This runs after another backlight effect and replaces | ||
75 | // colors already set | ||
76 | void led_matrix_indicators(void); | ||
77 | void led_matrix_indicators_kb(void); | ||
78 | void led_matrix_indicators_user(void); | ||
79 | |||
80 | void led_matrix_init(void); | ||
81 | void led_matrix_setup_drivers(void); | ||
82 | |||
83 | void led_matrix_set_suspend_state(bool state); | ||
84 | void led_matrix_set_indicator_state(uint8_t state); | ||
85 | |||
86 | void led_matrix_task(void); | ||
87 | |||
88 | // This should not be called from an interrupt | ||
89 | // (eg. from a timer interrupt). | ||
90 | // Call this while idle (in between matrix scans). | ||
91 | // If the buffer is dirty, it will update the driver with the buffer. | ||
92 | void led_matrix_update_pwm_buffers(void); | ||
93 | |||
94 | bool process_led_matrix(uint16_t keycode, keyrecord_t *record); | ||
95 | |||
96 | uint32_t led_matrix_get_tick(void); | ||
97 | |||
98 | void led_matrix_toggle(void); | ||
99 | void led_matrix_enable(void); | ||
100 | void led_matrix_enable_noeeprom(void); | ||
101 | void led_matrix_disable(void); | ||
102 | void led_matrix_disable_noeeprom(void); | ||
103 | void led_matrix_step(void); | ||
104 | void led_matrix_step_reverse(void); | ||
105 | void led_matrix_increase_val(void); | ||
106 | void led_matrix_decrease_val(void); | ||
107 | void led_matrix_increase_speed(void); | ||
108 | void led_matrix_decrease_speed(void); | ||
109 | void led_matrix_mode(uint8_t mode, bool eeprom_write); | ||
110 | void led_matrix_mode_noeeprom(uint8_t mode); | ||
111 | uint8_t led_matrix_get_mode(void); | ||
112 | void led_matrix_set_value(uint8_t mode); | ||
113 | void led_matrix_set_value_noeeprom(uint8_t mode); | ||
114 | |||
115 | typedef struct { | ||
116 | /* Perform any initialisation required for the other driver functions to work. */ | ||
117 | void (*init)(void); | ||
118 | |||
119 | /* Set the brightness of a single LED in the buffer. */ | ||
120 | void (*set_value)(int index, uint8_t value); | ||
121 | /* Set the brightness of all LEDS on the keyboard in the buffer. */ | ||
122 | void (*set_value_all)(uint8_t value); | ||
123 | /* Flush any buffered changes to the hardware. */ | ||
124 | void (*flush)(void); | ||
125 | } led_matrix_driver_t; | ||
126 | |||
127 | extern const led_matrix_driver_t led_matrix_driver; | ||
128 | |||
129 | #endif | ||