1 /* Copyright 2019 ishtob
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 const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = {
29 {{1|(3<<4)}, {188, 16}, 0},
30 {{3|(3<<4)}, {187, 48}, 0},
31 {{4|(2<<4)}, {149, 64}, 0},
32 {{4|(1<<4)}, {112, 64}, 0},
33 {{3|(0<<4)}, {37, 48}, 0},
34 {{1|(0<<4)}, {38, 16}, 0}
40 uint16_t counterst = 0;
44 #ifdef QWIIC_MICRO_OLED_ENABLE
46 /* screen off after this many milliseconds */
48 #define ScreenOffInterval 60000 /* milliseconds */
49 static uint16_t last_flush;
51 volatile uint8_t led_numlock = false;
52 volatile uint8_t led_capslock = false;
53 volatile uint8_t led_scrolllock = false;
56 static bool queue_for_send = false;
57 static uint8_t encoder_value = 32;
59 __attribute__ ((weak))
62 last_flush = timer_read();
63 send_command(DISPLAYON);
65 /* Boston MK title is 55 x 10 pixels */
69 draw_string(NAME_X + 1, NAME_Y + 2, "BOSTON MK", PIXEL_ON, NORM, 0);
71 /* Layer indicator is 41 x 10 pixels */
72 #define LAYER_INDICATOR_X 60
73 #define LAYER_INDICATOR_Y 0
75 draw_string(LAYER_INDICATOR_X + 1, LAYER_INDICATOR_Y + 2, "LAYER", PIXEL_ON, NORM, 0);
76 draw_rect_filled_soft(LAYER_INDICATOR_X + 32, LAYER_INDICATOR_Y + 1, 9, 9, PIXEL_ON, NORM);
77 draw_char(LAYER_INDICATOR_X + 34, LAYER_INDICATOR_Y + 2, layer + 0x30, PIXEL_ON, XOR, 0);
79 /* Matrix display is 12 x 12 pixels */
80 #define MATRIX_DISPLAY_X 8
81 #define MATRIX_DISPLAY_Y 16
83 for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
84 for (uint8_t y = 0; y < MATRIX_COLS; y++) {
85 draw_pixel(MATRIX_DISPLAY_X + y + y + 2, MATRIX_DISPLAY_Y + x + x + 2,(matrix_get_row(x) & (1 << y)) > 0, NORM);
86 draw_pixel(MATRIX_DISPLAY_X + y + y + 3, MATRIX_DISPLAY_Y + x + x + 2,(matrix_get_row(x) & (1 << y)) > 0, NORM);
87 draw_pixel(MATRIX_DISPLAY_X + y + y + 2, MATRIX_DISPLAY_Y + x + x + 3,(matrix_get_row(x) & (1 << y)) > 0, NORM);
88 draw_pixel(MATRIX_DISPLAY_X + y + y + 3, MATRIX_DISPLAY_Y + x + x + 3,(matrix_get_row(x) & (1 << y)) > 0, NORM);
92 draw_rect_soft(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y, 12, 12, PIXEL_ON, NORM);
93 /* hadron oled location on thumbnail */
94 draw_rect_filled_soft(MATRIX_DISPLAY_X + 5, MATRIX_DISPLAY_Y + 2, 6, 2, PIXEL_ON, NORM);
96 draw_rect_soft(0, 13, 64, 6, PIXEL_ON, NORM);
97 draw_line_vert(encoder_value, 13, 6, PIXEL_ON, NORM);
101 /* Mod display is 41 x 16 pixels */
102 #define MOD_DISPLAY_X 60
103 #define MOD_DISPLAY_Y 20
105 uint8_t mods = get_mods();
106 if (mods & MOD_LSFT) {
107 draw_rect_filled_soft(MOD_DISPLAY_X + 0, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
108 draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_OFF, NORM, 0);
110 draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_ON, NORM, 0);
112 if (mods & MOD_LCTL) {
113 draw_rect_filled_soft(MOD_DISPLAY_X + 10, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
114 draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_OFF, NORM, 0);
116 draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_ON, NORM, 0);
118 if (mods & MOD_LALT) {
119 draw_rect_filled_soft(MOD_DISPLAY_X + 20, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
120 draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_OFF, NORM, 0);
122 draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_ON, NORM, 0);
124 if (mods & MOD_LGUI) {
125 draw_rect_filled_soft(MOD_DISPLAY_X + 30, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
126 draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_OFF, NORM, 0);
128 draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_ON, NORM, 0);
131 /* Lock display is 23 x 32 */
132 #define LOCK_DISPLAY_X 104
133 #define LOCK_DISPLAY_Y 0
135 if (led_numlock == true) {
136 draw_rect_filled_soft(LOCK_DISPLAY_X, LOCK_DISPLAY_Y, 5 + (3 * 6), 9, PIXEL_ON, NORM);
137 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_OFF, NORM, 0);
138 } else if (led_numlock == false) {
139 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_ON, NORM, 0);
141 if (led_capslock == true) {
142 draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 11, 5 + (3 * 6), 9, PIXEL_ON, NORM);
143 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_OFF, NORM, 0);
144 } else if (led_capslock == false) {
145 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_ON, NORM, 0);
148 if (led_scrolllock == true) {
149 draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 22, 5 + (3 * 6), 9, PIXEL_ON, NORM);
150 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_OFF, NORM, 0);
151 } else if (led_scrolllock == false) {
152 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_ON, NORM, 0);
157 void led_set_user(uint8_t usb_led) {
158 if (IS_LED_ON(usb_led, USB_LED_NUM_LOCK)) {
159 if (led_numlock == false){led_numlock = true;}
161 if (led_numlock == true){led_numlock = false;}
163 if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) {
164 if (led_capslock == false){led_capslock = true;}
166 if (led_capslock == true){led_capslock = false;}
168 if (IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK)) {
169 if (led_scrolllock == false){led_scrolllock = true;}
171 if (led_scrolllock == true){led_scrolllock = false;}
175 uint32_t layer_state_set_kb(uint32_t state) {
176 state = layer_state_set_user(state);
177 layer = biton32(state);
178 queue_for_send = true;
182 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
183 queue_for_send = true;
184 return process_record_user(keycode, record);
187 void encoder_update_kb(uint8_t index, bool clockwise) {
188 encoder_value = (encoder_value + (clockwise ? 1 : -1)) % 64;
189 queue_for_send = true;
194 void matrix_init_kb(void) {
195 queue_for_send = true;
199 void matrix_scan_kb(void) {
200 if (queue_for_send) {
201 #ifdef QWIIC_MICRO_OLED_ENABLE
204 queue_for_send = false;
206 #ifdef QWIIC_MICRO_OLED_ENABLE
207 if (timer_elapsed(last_flush) > ScreenOffInterval) {
208 send_command(DISPLAYOFF); /* 0xAE */
211 if (counterst == 0) {
212 //testPatternFB(o_fb);
214 counterst = (counterst + 1) % 1024;