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
22 #include "rgb_matrix.h"
24 led_config_t g_led_config = { {
25 { 5, NO_LED, NO_LED, 0 },
26 { NO_LED, NO_LED, NO_LED, NO_LED },
27 { 4, NO_LED, NO_LED, 1 },
28 { 3, NO_LED, NO_LED, 2 }
30 { 188, 16 }, { 187, 48 }, { 149, 64 }, { 112, 64 }, { 37, 48 }, { 38, 16 }
38 uint16_t counterst = 0;
42 #ifdef QWIIC_MICRO_OLED_ENABLE
44 /* screen off after this many milliseconds */
46 #define ScreenOffInterval 60000 /* milliseconds */
47 static uint16_t last_flush;
49 volatile uint8_t led_numlock = false;
50 volatile uint8_t led_capslock = false;
51 volatile uint8_t led_scrolllock = false;
54 static bool queue_for_send = false;
55 static uint8_t encoder_value = 32;
57 __attribute__ ((weak))
60 last_flush = timer_read();
61 send_command(DISPLAYON);
63 /* Boston MK title is 55 x 10 pixels */
67 draw_string(NAME_X + 1, NAME_Y + 2, "BOSTON MK", PIXEL_ON, NORM, 0);
69 /* Layer indicator is 41 x 10 pixels */
70 #define LAYER_INDICATOR_X 60
71 #define LAYER_INDICATOR_Y 0
73 draw_string(LAYER_INDICATOR_X + 1, LAYER_INDICATOR_Y + 2, "LAYER", PIXEL_ON, NORM, 0);
74 draw_rect_filled_soft(LAYER_INDICATOR_X + 32, LAYER_INDICATOR_Y + 1, 9, 9, PIXEL_ON, NORM);
75 draw_char(LAYER_INDICATOR_X + 34, LAYER_INDICATOR_Y + 2, layer + 0x30, PIXEL_ON, XOR, 0);
77 /* Matrix display is 12 x 12 pixels */
78 #define MATRIX_DISPLAY_X 8
79 #define MATRIX_DISPLAY_Y 16
81 for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
82 for (uint8_t y = 0; y < MATRIX_COLS; y++) {
83 draw_pixel(MATRIX_DISPLAY_X + y + y + 2, MATRIX_DISPLAY_Y + x + x + 2,(matrix_get_row(x) & (1 << y)) > 0, NORM);
84 draw_pixel(MATRIX_DISPLAY_X + y + y + 3, MATRIX_DISPLAY_Y + x + x + 2,(matrix_get_row(x) & (1 << y)) > 0, NORM);
85 draw_pixel(MATRIX_DISPLAY_X + y + y + 2, MATRIX_DISPLAY_Y + x + x + 3,(matrix_get_row(x) & (1 << y)) > 0, NORM);
86 draw_pixel(MATRIX_DISPLAY_X + y + y + 3, MATRIX_DISPLAY_Y + x + x + 3,(matrix_get_row(x) & (1 << y)) > 0, NORM);
90 draw_rect_soft(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y, 12, 12, PIXEL_ON, NORM);
91 /* hadron oled location on thumbnail */
92 draw_rect_filled_soft(MATRIX_DISPLAY_X + 5, MATRIX_DISPLAY_Y + 2, 6, 2, PIXEL_ON, NORM);
94 draw_rect_soft(0, 13, 64, 6, PIXEL_ON, NORM);
95 draw_line_vert(encoder_value, 13, 6, PIXEL_ON, NORM);
99 /* Mod display is 41 x 16 pixels */
100 #define MOD_DISPLAY_X 60
101 #define MOD_DISPLAY_Y 20
103 uint8_t mods = get_mods();
104 if (mods & MOD_LSFT) {
105 draw_rect_filled_soft(MOD_DISPLAY_X + 0, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
106 draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_OFF, NORM, 0);
108 draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_ON, NORM, 0);
110 if (mods & MOD_LCTL) {
111 draw_rect_filled_soft(MOD_DISPLAY_X + 10, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
112 draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_OFF, NORM, 0);
114 draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_ON, NORM, 0);
116 if (mods & MOD_LALT) {
117 draw_rect_filled_soft(MOD_DISPLAY_X + 20, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
118 draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_OFF, NORM, 0);
120 draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_ON, NORM, 0);
122 if (mods & MOD_LGUI) {
123 draw_rect_filled_soft(MOD_DISPLAY_X + 30, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
124 draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_OFF, NORM, 0);
126 draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_ON, NORM, 0);
129 /* Lock display is 23 x 32 */
130 #define LOCK_DISPLAY_X 104
131 #define LOCK_DISPLAY_Y 0
133 if (led_numlock == true) {
134 draw_rect_filled_soft(LOCK_DISPLAY_X, LOCK_DISPLAY_Y, 5 + (3 * 6), 9, PIXEL_ON, NORM);
135 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_OFF, NORM, 0);
136 } else if (led_numlock == false) {
137 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_ON, NORM, 0);
139 if (led_capslock == true) {
140 draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 11, 5 + (3 * 6), 9, PIXEL_ON, NORM);
141 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_OFF, NORM, 0);
142 } else if (led_capslock == false) {
143 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_ON, NORM, 0);
146 if (led_scrolllock == true) {
147 draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 22, 5 + (3 * 6), 9, PIXEL_ON, NORM);
148 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_OFF, NORM, 0);
149 } else if (led_scrolllock == false) {
150 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_ON, NORM, 0);
155 void led_set_user(uint8_t usb_led) {
156 if (IS_LED_ON(usb_led, USB_LED_NUM_LOCK)) {
157 if (led_numlock == false){led_numlock = true;}
159 if (led_numlock == true){led_numlock = false;}
161 if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) {
162 if (led_capslock == false){led_capslock = true;}
164 if (led_capslock == true){led_capslock = false;}
166 if (IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK)) {
167 if (led_scrolllock == false){led_scrolllock = true;}
169 if (led_scrolllock == true){led_scrolllock = false;}
173 uint32_t layer_state_set_kb(uint32_t state) {
174 state = layer_state_set_user(state);
175 layer = biton32(state);
176 queue_for_send = true;
180 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
181 queue_for_send = true;
182 return process_record_user(keycode, record);
185 void encoder_update_kb(uint8_t index, bool clockwise) {
186 encoder_value = (encoder_value + (clockwise ? 1 : -1)) % 64;
187 queue_for_send = true;
192 void matrix_init_kb(void) {
193 queue_for_send = true;
197 void matrix_scan_kb(void) {
198 if (queue_for_send) {
199 #ifdef QWIIC_MICRO_OLED_ENABLE
202 queue_for_send = false;
204 #ifdef QWIIC_MICRO_OLED_ENABLE
205 if (timer_elapsed(last_flush) > ScreenOffInterval) {
206 send_command(DISPLAYOFF); /* 0xAE */
209 if (counterst == 0) {
210 //testPatternFB(o_fb);
212 counterst = (counterst + 1) % 1024;