]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/infinity60/led_controller.h
revised led controller code to allow for more options
[qmk_firmware.git] / keyboards / infinity60 / led_controller.h
1 /*
2 Copyright 2016 flabbergast <s3+flabbergast@sdfeu.org>
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_CONTROLLER_H_
19 #define _LED_CONTROLLER_H_
20
21 /* =========================
22  *  communication functions
23  * ========================= */
24
25 msg_t is31_write_data(uint8_t page, uint8_t *buffer, uint8_t size);
26 msg_t is31_write_register(uint8_t page, uint8_t reg, uint8_t data);
27 msg_t is31_read_register(uint8_t page, uint8_t reg, uint8_t *result);
28
29 /* ============================
30  *  init functions/definitions
31  * ============================*/
32
33 void led_controller_init(void);
34
35 #define CAPS_LOCK_LED_ADDRESS 0x46
36 #define NUM_LOCK_LED_ADDRESS 0x85
37
38 /* =============================
39  * IS31 chip related definitions
40  * ============================= */
41
42 #define IS31_ADDR_DEFAULT 0x74
43
44 #define IS31_REG_CONFIG  0x00
45 // bits in reg
46 #define IS31_REG_CONFIG_PICTUREMODE 0x00
47 #define IS31_REG_CONFIG_AUTOPLAYMODE 0x08
48 #define IS31_REG_CONFIG_AUDIOPLAYMODE 0x18
49 // D2:D0 bits are starting frame for autoplay mode
50
51 #define IS31_REG_PICTDISP 0x01 // D2:D0 frame select for picture mode
52
53 #define IS31_REG_AUTOPLAYCTRL1 0x02
54 // D6:D4 number of loops (000=infty)
55 // D2:D0 number of frames to be used
56
57 #define IS31_REG_AUTOPLAYCTRL2 0x03 // D5:D0 delay time (*11ms)
58
59 #define IS31_REG_DISPLAYOPT 0x05
60 #define IS31_REG_DISPLAYOPT_INTENSITY_SAME 0x20 // same intensity for all frames
61 #define IS31_REG_DISPLAYOPT_BLINK_ENABLE 0x8
62 // D2:D0 bits blink period time (*0.27s)
63
64 #define IS31_REG_AUDIOSYNC 0x06
65 #define IS31_REG_AUDIOSYNC_ENABLE 0x1
66
67 #define IS31_REG_FRAMESTATE 0x07
68
69 #define IS31_REG_BREATHCTRL1 0x08
70 // D6:D4 fade out time (26ms*2^i)
71 // D2:D0 fade in time (26ms*2^i)
72
73 #define IS31_REG_BREATHCTRL2 0x09
74 #define IS31_REG_BREATHCTRL2_ENABLE 0x10
75 // D2:D0 extinguish time (3.5ms*2^i)
76
77 #define IS31_REG_SHUTDOWN 0x0A
78 #define IS31_REG_SHUTDOWN_ON 0x1
79
80 #define IS31_REG_AGCCTRL 0x0B
81 #define IS31_REG_ADCRATE 0x0C
82
83 #define IS31_COMMANDREGISTER 0xFD
84 #define IS31_FUNCTIONREG 0x0B    // helpfully called 'page nine'
85
86 #define IS31_TIMEOUT 10000 // needs to be long enough to write a whole page
87
88 /* ========================================
89  * LED Thread related definitions/functions
90  * ========================================*/
91
92 extern mailbox_t led_mailbox;
93
94 void set_led_bit (uint8_t *led_control_reg, uint8_t led_msg, uint8_t toggle_on);
95 void set_lock_leds (uint8_t *led_control_reg, uint8_t lock_status);
96 void write_led_page (uint8_t page, const uint8_t *led_array, uint8_t led_count);
97
98 // constants for signaling the LED controller thread
99 enum led_msg_t {
100     KEY_LIGHT,
101     TOGGLE_LED,
102     TOGGLE_ALL,
103     TOGGLE_BACKLIGHT,
104     TOGGLE_LAYER_LEDS,
105     TOGGLE_LOCK_LED,
106     MODE_BREATH,
107     STEP_BRIGHTNESS
108 };
109
110 #endif /* _LED_CONTROLLER_H_ */