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