]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/infinity60/led_controller.h
several improvements for mitosis:datagrok (#1960)
[qmk_firmware.git] / keyboards / infinity60 / led_controller.h
1 /*
2 Copyright 2016 flabbergast <s3+flabbergast@sdfeu.org>
3 Copyright 2017 jpetermans <tibcmhhm@gmail.com>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef _LED_CONTROLLER_H_
20 #define _LED_CONTROLLER_H_
21
22 /* =========================
23  *  communication functions
24  * ========================= */
25
26 msg_t is31_write_data(uint8_t page, uint8_t *buffer, uint8_t size);
27 msg_t is31_write_register(uint8_t page, uint8_t reg, uint8_t data);
28 msg_t is31_read_register(uint8_t page, uint8_t reg, uint8_t *result);
29
30 /* ============================
31  *  init functions/definitions
32  * ============================*/
33
34 void led_controller_init(void);
35
36 #define CAPS_LOCK_LED_ADDRESS 46 //pin matrix location
37 #define NUM_LOCK_LED_ADDRESS 85
38
39 /* =============================
40  * IS31 chip related definitions
41  * ============================= */
42
43 #define IS31_ADDR_DEFAULT 0x74
44
45 #define IS31_REG_CONFIG  0x00
46 // bits in reg
47 #define IS31_REG_CONFIG_PICTUREMODE 0x00
48 #define IS31_REG_CONFIG_AUTOPLAYMODE 0x08
49 #define IS31_REG_CONFIG_AUDIOPLAYMODE 0x18
50 // D2:D0 bits are starting frame for autoplay mode
51
52 #define IS31_REG_PICTDISP 0x01 // D2:D0 frame select for picture mode
53
54 #define IS31_REG_AUTOPLAYCTRL1 0x02
55 // D6:D4 number of loops (000=infty)
56 // D2:D0 number of frames to be used
57
58 #define IS31_REG_AUTOPLAYCTRL2 0x03 // D5:D0 delay time (*11ms)
59
60 #define IS31_REG_DISPLAYOPT 0x05
61 #define IS31_REG_DISPLAYOPT_INTENSITY_SAME 0x20 // same intensity for all frames
62 #define IS31_REG_DISPLAYOPT_BLINK_ENABLE 0x08
63 // D2:D0 bits blink period time (*0.27s)
64
65 #define IS31_REG_AUDIOSYNC 0x06
66 #define IS31_REG_AUDIOSYNC_ENABLE 0x1
67
68 #define IS31_REG_FRAMESTATE 0x07
69
70 #define IS31_REG_BREATHCTRL1 0x08
71 // D6:D4 fade out time (26ms*2^i)
72 // D2:D0 fade in time (26ms*2^i)
73
74 #define IS31_REG_BREATHCTRL2 0x09
75 #define IS31_REG_BREATHCTRL2_ENABLE 0x10
76 // D2:D0 extinguish time (3.5ms*2^i)
77
78 #define IS31_REG_SHUTDOWN 0x0A
79 #define IS31_REG_SHUTDOWN_OFF 0x1
80 #define IS31_REG_SHUTDOWN_ON 0x0
81
82 #define IS31_REG_AGCCTRL 0x0B
83 #define IS31_REG_ADCRATE 0x0C
84
85 #define IS31_COMMANDREGISTER 0xFD
86 #define IS31_FUNCTIONREG 0x0B    // helpfully called 'page nine'
87
88 #define IS31_TIMEOUT 10000 // needs to be long enough to write a whole page
89
90 /* ========================================
91  * LED Thread related items
92  * ========================================*/
93
94 extern mailbox_t led_mailbox;
95
96 void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint8_t action);
97 void set_lock_leds (uint8_t led_addr, uint8_t led_action, uint8_t page);
98 void write_led_byte (uint8_t page, uint8_t row, uint8_t led_byte);
99 void write_led_page (uint8_t page, uint8_t *led_array, uint8_t led_count);
100
101 // constants for signaling the LED controller thread
102 enum led_msg_t {
103     KEY_LIGHT,
104     SET_FULL_ROW,
105     OFF_LED,
106     ON_LED,
107     TOGGLE_LED,
108     BLINK_OFF_LED,
109     BLINK_ON_LED,
110     BLINK_TOGGLE_LED,
111     TOGGLE_ALL,
112     TOGGLE_BACKLIGHT,
113     DISPLAY_PAGE,
114     RESET_PAGE,
115     TOGGLE_NUM_LOCK,
116     TOGGLE_CAPS_LOCK,
117     TOGGLE_BREATH,
118     STEP_BRIGHTNESS
119 };
120
121 #endif /* _LED_CONTROLLER_H_ */