]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/protocol/arm_atsam/led_matrix.h
Usbasploader bootloader option addition (#6304)
[qmk_firmware.git] / tmk_core / protocol / arm_atsam / led_matrix.h
1 /*
2 Copyright 2018 Massdrop Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef _LED_MATRIX_H_
19 #define _LED_MATRIX_H_
20
21 #include "quantum.h"
22
23 //From keyboard
24 #include "config_led.h"
25
26 //CS1-CS16 Current Source "Col"
27 #define ISSI3733_CS_COUNT 16
28
29 //SW1-SW12 Switch "Row"
30 #define ISSI3733_SW_COUNT 12
31
32 #define ISSI3733_LED_RGB_COUNT ISSI3733_CS_COUNT * ISSI3733_SW_COUNT
33 #define ISSI3733_PG0_BYTES ISSI3733_LED_RGB_COUNT / 8 + 1       //+1 for first byte being memory start offset for I2C transfer
34 #define ISSI3733_PG1_BYTES ISSI3733_LED_RGB_COUNT + 1           //+1 for first byte being memory start offset for I2C transfer
35 #define ISSI3733_PG2_BYTES ISSI3733_LED_RGB_COUNT + 1           //+1 for first byte being memory start offset for I2C transfer
36 #define ISSI3733_PG3_BYTES 18 + 1                               //+1 for first byte being memory start offset for I2C transfer
37
38 #define ISSI3733_PG_ONOFF_BYTES ISSI3733_PG0_BYTES
39 #define ISSI3733_PG_OR_BYTES ISSI3733_PG0_BYTES
40 #define ISSI3733_PG_SR_BYTES ISSI3733_PG0_BYTES
41 #define ISSI3733_PG_PWM_BYTES ISSI3733_PG1_BYTES
42 #define ISSI3733_PG_ABM_BYTES ISSI3733_PG2_BYTES
43 #define ISSI3733_PG_FN_BYTES ISSI3733_PG3_BYTES
44
45 typedef struct issi3733_driver_s {
46     uint8_t addr; //Address of the driver according to wiring "ISSI3733: Table 1 Slave Address"
47     uint8_t onoff[ISSI3733_PG_ONOFF_BYTES]; //PG0 - LED Control Register - LED On/Off Register
48     uint8_t open[ISSI3733_PG_OR_BYTES];     //PG0 - LED Control Register - LED Open Register
49     uint8_t shrt[ISSI3733_PG_SR_BYTES];     //PG0 - LED Control Register - LED Short Register
50     uint8_t pwm[ISSI3733_PG_PWM_BYTES];     //PG1 - PWM Register
51     uint8_t abm[ISSI3733_PG_ABM_BYTES];     //PG2 - Auto Breath Mode Register
52     uint8_t conf[ISSI3733_PG_FN_BYTES];     //PG3 - Function Register
53 } issi3733_driver_t;
54
55 typedef struct issi3733_rgb_s {
56     uint8_t *r;         //Direct access into PWM data
57     uint8_t *g;         //Direct access into PWM data
58     uint8_t *b;         //Direct access into PWM data
59 } issi3733_rgb_t;
60
61 typedef struct issi3733_rgb_adr_s {
62     uint8_t drv;        //Driver from given list
63     uint8_t cs;         //CS
64     uint8_t swr;        //SW Red
65     uint8_t swg;        //SW Green
66     uint8_t swb;        //SW Blue
67 } issi3733_rgb_adr_t;
68
69 typedef struct issi3733_led_s {
70     uint8_t id;                 //According to PCB ref
71     issi3733_rgb_t rgb;         //PWM settings of R G B
72     issi3733_rgb_adr_t adr;     //Hardware addresses
73     float x;                    //Physical position X
74     float y;                    //Physical position Y
75     float px;                   //Physical position X in percent
76     float py;                   //Physical position Y in percent
77     uint8_t scan;               //Key scan code from wiring (set 0xFF if no key)
78 } issi3733_led_t;
79
80 extern issi3733_driver_t issidrv[ISSI3733_DRIVER_COUNT];
81
82 extern uint8_t gcr_desired;
83 extern uint8_t gcr_breathe;
84 extern uint8_t gcr_actual;
85 extern uint8_t gcr_actual_last;
86
87 void gcr_compute(void);
88
89 void led_matrix_indicators(void);
90
91 /*-------------------------  Legacy Lighting Support  ------------------------*/
92
93 #ifdef USE_MASSDROP_CONFIGURATOR
94
95 #define EF_NONE         0x00000000  //No effect
96 #define EF_OVER         0x00000001  //Overwrite any previous color information with new
97 #define EF_SCR_L        0x00000002  //Scroll left
98 #define EF_SCR_R        0x00000004  //Scroll right
99 #define EF_SUBTRACT     0x00000008  //Subtract color values
100
101 typedef struct led_setup_s {
102   float hs;         //Band begin at percent
103   float he;         //Band end at percent
104   uint8_t rs;       //Red start value
105   uint8_t re;       //Red end value
106   uint8_t gs;       //Green start value
107   uint8_t ge;       //Green end value
108   uint8_t bs;       //Blue start value
109   uint8_t be;       //Blue end value
110   uint32_t ef;      //Animation and color effects
111   uint8_t end;      //Set to signal end of the setup
112 } led_setup_t;
113
114 extern const uint8_t led_setups_count;
115 extern void *led_setups[];
116
117 //LED Extra Instructions
118 #define LED_FLAG_NULL                0x00       //Matching and coloring not used (default)
119 #define LED_FLAG_MATCH_ID            0x01       //Match on the ID of the LED (set id#'s to desired bit pattern, first LED is id 1)
120 #define LED_FLAG_MATCH_LAYER         0x02       //Match on the current active layer (set layer to desired match layer)
121 #define LED_FLAG_USE_RGB             0x10       //Use a specific RGB value (set r, g, b to desired output color values)
122 #define LED_FLAG_USE_PATTERN         0x20       //Use a specific pattern ID (set pattern_id to desired output pattern)
123 #define LED_FLAG_USE_ROTATE_PATTERN  0x40       //Use pattern the user has cycled to manually
124
125 typedef struct led_instruction_s {
126     uint16_t flags; // Bitfield for LED instructions
127     uint32_t id0; // Bitwise id, IDs 0-31
128     uint32_t id1; // Bitwise id, IDs 32-63
129     uint32_t id2; // Bitwise id, IDs 64-95
130     uint32_t id3; // Bitwise id, IDs 96-127
131     uint8_t layer;
132     uint8_t r;
133     uint8_t g;
134     uint8_t b;
135     uint8_t pattern_id;
136     uint8_t end;
137 } led_instruction_t;
138
139 extern led_instruction_t led_instructions[];
140
141 extern uint8_t led_animation_breathing;
142 extern uint8_t led_animation_id;
143 extern float led_animation_speed;
144 extern uint8_t led_lighting_mode;
145 extern uint8_t led_enabled;
146 extern uint8_t led_animation_breathe_cur;
147 extern uint8_t led_animation_direction;
148 extern uint8_t breathe_dir;
149
150 #define LED_MODE_NORMAL             0   //Must be 0
151 #define LED_MODE_KEYS_ONLY          1
152 #define LED_MODE_NON_KEYS_ONLY      2
153 #define LED_MODE_INDICATORS_ONLY    3
154 #define LED_MODE_MAX_INDEX          LED_MODE_INDICATORS_ONLY   //Must be highest value
155
156 #endif // USE_MASSDROP_CONFIGURATOR
157
158 #endif //_LED_MATRIX_H_