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
22 #include "rgb_matrix.h"
24 led_config_t g_led_config = { {
25 { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED },
26 { NO_LED, 6, NO_LED, NO_LED, 7, NO_LED, NO_LED, 8, NO_LED, NO_LED, 9, NO_LED, NO_LED, 0, NO_LED },
27 { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED },
28 { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED },
29 { NO_LED, 5, NO_LED, NO_LED, 4, NO_LED, NO_LED, 3, NO_LED, NO_LED, 2, NO_LED, NO_LED, 1, NO_LED }
31 { 195, 3 }, { 195, 16 }, { 150, 16 }, { 105, 16 }, { 60, 16 }, { 15, 16 }, { 15, 3 }, { 60, 3 }, { 105, 3 }, { 150, 3 }
33 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
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 /* Layer indicator is 41 x 10 pixels */
66 #define LAYER_INDICATOR_X 5
67 #define LAYER_INDICATOR_Y 0
69 draw_string(LAYER_INDICATOR_X + 1, LAYER_INDICATOR_Y + 2, "LAYER", PIXEL_ON, NORM, 0);
70 draw_rect_filled_soft(LAYER_INDICATOR_X + 32, LAYER_INDICATOR_Y + 1, 9, 9, PIXEL_ON, NORM);
71 draw_char(LAYER_INDICATOR_X + 34, LAYER_INDICATOR_Y + 2, layer + 0x30, PIXEL_ON, XOR, 0);
73 /* Matrix display is 19 x 9 pixels */
74 #define MATRIX_DISPLAY_X 5
75 #define MATRIX_DISPLAY_Y 18
77 for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
78 for (uint8_t y = 0; y < MATRIX_COLS; y++) {
79 draw_pixel(MATRIX_DISPLAY_X + y + 2, MATRIX_DISPLAY_Y + x + 2,(matrix_get_row(x) & (1 << y)) > 0, NORM);
82 draw_rect_soft(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y, 19, 9, PIXEL_ON, NORM);
83 /* hadron oled location on thumbnail */
84 draw_rect_filled_soft(MATRIX_DISPLAY_X + 14, MATRIX_DISPLAY_Y + 2, 3, 1, PIXEL_ON, NORM);
86 draw_rect_soft(0, 13, 64, 6, PIXEL_ON, NORM);
87 draw_line_vert(encoder_value, 13, 6, PIXEL_ON, NORM);
91 /* Mod display is 41 x 16 pixels */
92 #define MOD_DISPLAY_X 30
93 #define MOD_DISPLAY_Y 18
95 uint8_t mods = get_mods();
96 if (mods & MOD_LSFT) {
97 draw_rect_filled_soft(MOD_DISPLAY_X + 0, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
98 draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_OFF, NORM, 0);
100 draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_ON, NORM, 0);
102 if (mods & MOD_LCTL) {
103 draw_rect_filled_soft(MOD_DISPLAY_X + 10, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
104 draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_OFF, NORM, 0);
106 draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_ON, NORM, 0);
108 if (mods & MOD_LALT) {
109 draw_rect_filled_soft(MOD_DISPLAY_X + 20, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
110 draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_OFF, NORM, 0);
112 draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_ON, NORM, 0);
114 if (mods & MOD_LGUI) {
115 draw_rect_filled_soft(MOD_DISPLAY_X + 30, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
116 draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_OFF, NORM, 0);
118 draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_ON, NORM, 0);
121 /* Lock display is 23 x 32 */
122 #define LOCK_DISPLAY_X 100
123 #define LOCK_DISPLAY_Y 0
125 if (led_numlock == true) {
126 draw_rect_filled_soft(LOCK_DISPLAY_X, LOCK_DISPLAY_Y, 5 + (3 * 6), 9, PIXEL_ON, NORM);
127 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_OFF, NORM, 0);
128 } else if (led_numlock == false) {
129 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_ON, NORM, 0);
131 if (led_capslock == true) {
132 draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 11, 5 + (3 * 6), 9, PIXEL_ON, NORM);
133 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_OFF, NORM, 0);
134 } else if (led_capslock == false) {
135 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_ON, NORM, 0);
138 if (led_scrolllock == true) {
139 draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 22, 5 + (3 * 6), 9, PIXEL_ON, NORM);
140 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_OFF, NORM, 0);
141 } else if (led_scrolllock == false) {
142 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_ON, NORM, 0);
147 void read_host_led_state(void) {
148 uint8_t leds = host_keyboard_leds();
149 if (leds & (1 << USB_LED_NUM_LOCK)) {
150 if (led_numlock == false){
153 if (led_numlock == true){
154 led_numlock = false;}
156 if (leds & (1 << USB_LED_CAPS_LOCK)) {
157 if (led_capslock == false){
158 led_capslock = true;}
160 if (led_capslock == true){
161 led_capslock = false;}
163 if (leds & (1 << USB_LED_SCROLL_LOCK)) {
164 if (led_scrolllock == false){
165 led_scrolllock = true;}
167 if (led_scrolllock == true){
168 led_scrolllock = false;}
172 uint32_t layer_state_set_kb(uint32_t state) {
173 state = layer_state_set_user(state);
174 layer = biton32(state);
175 queue_for_send = true;
179 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
180 queue_for_send = true;
181 return process_record_user(keycode, record);
184 void encoder_update_kb(uint8_t index, bool clockwise) {
185 encoder_value = (encoder_value + (clockwise ? 1 : -1)) % 64;
186 queue_for_send = true;
191 void matrix_init_kb(void) {
192 queue_for_send = true;
196 void matrix_scan_kb(void) {
197 if (queue_for_send) {
198 #ifdef QWIIC_MICRO_OLED_ENABLE
199 read_host_led_state();
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;