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 |
27 | typedef struct Point { |
b624f32f |
28 | uint8_t x; |
29 | uint8_t y; |
fd698c43 |
30 | } __attribute__((packed)) Point; |
31 | |
32 | typedef 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 |
44 | extern const led_matrix g_leds[LED_DRIVER_LED_COUNT]; |
fd698c43 |
45 | |
46 | typedef struct { |
b624f32f |
47 | uint8_t index; |
48 | uint8_t value; |
fd698c43 |
49 | } led_indicator; |
50 | |
51 | typedef 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 | |
63 | enum 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 | |
69 | void led_matrix_set_index_value(int index, uint8_t value); |
70 | void led_matrix_set_index_value_all(uint8_t value); |
71 | |
72 | // This runs after another backlight effect and replaces |
73 | // colors already set |
74 | void led_matrix_indicators(void); |
75 | void led_matrix_indicators_kb(void); |
76 | void led_matrix_indicators_user(void); |
77 | |
78 | void led_matrix_init(void); |
79 | void led_matrix_setup_drivers(void); |
80 | |
81 | void led_matrix_set_suspend_state(bool state); |
82 | void led_matrix_set_indicator_state(uint8_t state); |
83 | |
84 | void 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. |
90 | void led_matrix_update_pwm_buffers(void); |
91 | |
92 | bool process_led_matrix(uint16_t keycode, keyrecord_t *record); |
93 | |
94 | uint32_t led_matrix_get_tick(void); |
95 | |
b624f32f |
96 | void led_matrix_toggle(void); |
97 | void led_matrix_enable(void); |
98 | void led_matrix_enable_noeeprom(void); |
99 | void led_matrix_disable(void); |
100 | void led_matrix_disable_noeeprom(void); |
101 | void led_matrix_step(void); |
102 | void led_matrix_step_reverse(void); |
103 | void led_matrix_increase_val(void); |
104 | void led_matrix_decrease_val(void); |
105 | void led_matrix_increase_speed(void); |
106 | void led_matrix_decrease_speed(void); |
107 | void led_matrix_mode(uint8_t mode, bool eeprom_write); |
108 | void led_matrix_mode_noeeprom(uint8_t mode); |
fd698c43 |
109 | uint8_t led_matrix_get_mode(void); |
b624f32f |
110 | void led_matrix_set_value(uint8_t mode); |
111 | void led_matrix_set_value_noeeprom(uint8_t mode); |
fd698c43 |
112 | |
fd698c43 |
113 | typedef 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 | |
125 | extern const led_matrix_driver_t led_matrix_driver; |
126 | |
127 | #endif |