1 /* Copyright 2018 Jack Humbert <jack.humb@gmail.com>
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "action_layer.h"
21 #ifdef RGB_MATRIX_ENABLE
24 rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = {
29 {{1|(13<<4)}, {195, 3}, 4},
30 {{4|(13<<4)}, {195, 16}, 4},
31 {{4|(10<<4)}, {150, 16}, 4},
32 {{4|(7<<4)}, {105, 16}, 4},
33 {{4|(4<<4)}, {60, 16}, 4},
34 {{4|(1<<4)}, {15, 16}, 4},
35 {{1|(1<<4)}, {15, 3}, 4},
36 {{1|(4<<4)}, {60, 3}, 4},
37 {{1|(7<<4)}, {105, 3}, 4},
38 {{1|(10<<4)}, {150, 3}, 4}
45 uint16_t counterst = 0;
49 #ifdef QWIIC_MICRO_OLED_ENABLE
51 /* screen off after this many milliseconds */
53 #define ScreenOffInterval 60000 /* milliseconds */
54 static uint16_t last_flush;
56 volatile uint8_t led_numlock = false;
57 volatile uint8_t led_capslock = false;
58 volatile uint8_t led_scrolllock = false;
61 static bool queue_for_send = false;
62 static uint8_t encoder_value = 32;
64 __attribute__ ((weak))
67 last_flush = timer_read();
68 send_command(DISPLAYON);
70 /* Layer indicator is 41 x 10 pixels */
71 #define LAYER_INDICATOR_X 5
72 #define LAYER_INDICATOR_Y 0
74 draw_string(LAYER_INDICATOR_X + 1, LAYER_INDICATOR_Y + 2, "LAYER", PIXEL_ON, NORM, 0);
75 draw_rect_filled_soft(LAYER_INDICATOR_X + 32, LAYER_INDICATOR_Y + 1, 9, 9, PIXEL_ON, NORM);
76 draw_char(LAYER_INDICATOR_X + 34, LAYER_INDICATOR_Y + 2, layer + 0x30, PIXEL_ON, XOR, 0);
78 /* Matrix display is 19 x 9 pixels */
79 #define MATRIX_DISPLAY_X 5
80 #define MATRIX_DISPLAY_Y 18
82 for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
83 for (uint8_t y = 0; y < MATRIX_COLS; y++) {
84 draw_pixel(MATRIX_DISPLAY_X + y + 2, MATRIX_DISPLAY_Y + x + 2,(matrix_get_row(x) & (1 << y)) > 0, NORM);
87 draw_rect_soft(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y, 19, 9, PIXEL_ON, NORM);
88 /* hadron oled location on thumbnail */
89 draw_rect_filled_soft(MATRIX_DISPLAY_X + 14, MATRIX_DISPLAY_Y + 2, 3, 1, PIXEL_ON, NORM);
91 draw_rect_soft(0, 13, 64, 6, PIXEL_ON, NORM);
92 draw_line_vert(encoder_value, 13, 6, PIXEL_ON, NORM);
96 /* Mod display is 41 x 16 pixels */
97 #define MOD_DISPLAY_X 30
98 #define MOD_DISPLAY_Y 18
100 uint8_t mods = get_mods();
101 if (mods & MOD_LSFT) {
102 draw_rect_filled_soft(MOD_DISPLAY_X + 0, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
103 draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_OFF, NORM, 0);
105 draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_ON, NORM, 0);
107 if (mods & MOD_LCTL) {
108 draw_rect_filled_soft(MOD_DISPLAY_X + 10, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
109 draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_OFF, NORM, 0);
111 draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_ON, NORM, 0);
113 if (mods & MOD_LALT) {
114 draw_rect_filled_soft(MOD_DISPLAY_X + 20, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
115 draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_OFF, NORM, 0);
117 draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_ON, NORM, 0);
119 if (mods & MOD_LGUI) {
120 draw_rect_filled_soft(MOD_DISPLAY_X + 30, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
121 draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_OFF, NORM, 0);
123 draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_ON, NORM, 0);
126 /* Lock display is 23 x 32 */
127 #define LOCK_DISPLAY_X 100
128 #define LOCK_DISPLAY_Y 0
130 if (led_numlock == true) {
131 draw_rect_filled_soft(LOCK_DISPLAY_X, LOCK_DISPLAY_Y, 5 + (3 * 6), 9, PIXEL_ON, NORM);
132 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_OFF, NORM, 0);
133 } else if (led_numlock == false) {
134 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_ON, NORM, 0);
136 if (led_capslock == true) {
137 draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 11, 5 + (3 * 6), 9, PIXEL_ON, NORM);
138 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_OFF, NORM, 0);
139 } else if (led_capslock == false) {
140 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_ON, NORM, 0);
143 if (led_scrolllock == true) {
144 draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 22, 5 + (3 * 6), 9, PIXEL_ON, NORM);
145 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_OFF, NORM, 0);
146 } else if (led_scrolllock == false) {
147 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_ON, NORM, 0);
152 void read_host_led_state(void) {
153 uint8_t leds = host_keyboard_leds();
154 if (leds & (1 << USB_LED_NUM_LOCK)) {
155 if (led_numlock == false){
158 if (led_numlock == true){
159 led_numlock = false;}
161 if (leds & (1 << USB_LED_CAPS_LOCK)) {
162 if (led_capslock == false){
163 led_capslock = true;}
165 if (led_capslock == true){
166 led_capslock = false;}
168 if (leds & (1 << USB_LED_SCROLL_LOCK)) {
169 if (led_scrolllock == false){
170 led_scrolllock = true;}
172 if (led_scrolllock == true){
173 led_scrolllock = false;}
177 uint32_t layer_state_set_kb(uint32_t state) {
178 state = layer_state_set_user(state);
179 layer = biton32(state);
180 queue_for_send = true;
184 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
185 queue_for_send = true;
186 return process_record_user(keycode, record);
189 void encoder_update_kb(uint8_t index, bool clockwise) {
190 encoder_value = (encoder_value + (clockwise ? 1 : -1)) % 64;
191 queue_for_send = true;
196 void matrix_init_kb(void) {
197 queue_for_send = true;
201 void matrix_scan_kb(void) {
202 if (queue_for_send) {
203 #ifdef QWIIC_MICRO_OLED_ENABLE
204 read_host_led_state();
207 queue_for_send = false;
209 #ifdef QWIIC_MICRO_OLED_ENABLE
210 if (timer_elapsed(last_flush) > ScreenOffInterval) {
211 send_command(DISPLAYOFF); /* 0xAE */
214 if (counterst == 0) {
215 //testPatternFB(o_fb);
217 counterst = (counterst + 1) % 1024;