aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-10-09 14:46:47 +0100
committerGitHub <noreply@github.com>2021-10-09 14:46:47 +0100
commit22cafb9a2046b0c6c7b9df8c719cd515bec4d798 (patch)
tree618cb30bbcbe098f8baed4fb11a7ea4952cdc58a
parent7b753f227ada4c44df1e991b79e03fd6b56f7e69 (diff)
downloadqmk_firmware-22cafb9a2046b0c6c7b9df8c719cd515bec4d798.tar.gz
qmk_firmware-22cafb9a2046b0c6c7b9df8c719cd515bec4d798.zip
Migrate satisfaction75 away from QWIIC_DRIVERS (#14747)
* stash * refactor old draw * refactor old draw - tidy * refactor old draw - tidy * refactor old draw - reorder for diffs * refactor old draw - reorder for diffs
-rw-r--r--keyboards/cannonkeys/satisfaction75/config.h10
-rw-r--r--keyboards/cannonkeys/satisfaction75/rules.mk5
-rw-r--r--keyboards/cannonkeys/satisfaction75/satisfaction75.c33
-rw-r--r--keyboards/cannonkeys/satisfaction75/satisfaction75.h11
-rw-r--r--keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c2
-rw-r--r--keyboards/cannonkeys/satisfaction75/satisfaction_oled.c424
6 files changed, 186 insertions, 299 deletions
diff --git a/keyboards/cannonkeys/satisfaction75/config.h b/keyboards/cannonkeys/satisfaction75/config.h
index 43a872041..7fca7226b 100644
--- a/keyboards/cannonkeys/satisfaction75/config.h
+++ b/keyboards/cannonkeys/satisfaction75/config.h
@@ -71,14 +71,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
71/* Locking resynchronize hack */ 71/* Locking resynchronize hack */
72#define LOCKING_RESYNC_ENABLE 72#define LOCKING_RESYNC_ENABLE
73 73
74#ifdef QWIIC_MICRO_OLED_ENABLE 74// configure oled driver for the 128x32 oled
75 75#define OLED_UPDATE_INTERVAL 66 // ~15fps
76#undef I2C_ADDRESS_SA0_1
77#define I2C_ADDRESS_SA0_1 0b0111100
78#define LCDWIDTH 128
79#define LCDHEIGHT 32
80
81#endif
82 76
83// Custom config starts after VIA's EEPROM usage, 77// Custom config starts after VIA's EEPROM usage,
84// dynamic keymaps start after this. 78// dynamic keymaps start after this.
diff --git a/keyboards/cannonkeys/satisfaction75/rules.mk b/keyboards/cannonkeys/satisfaction75/rules.mk
index 3f0f8cda7..51f1dc52f 100644
--- a/keyboards/cannonkeys/satisfaction75/rules.mk
+++ b/keyboards/cannonkeys/satisfaction75/rules.mk
@@ -23,10 +23,9 @@ CONSOLE_ENABLE = yes # Console for debug
23COMMAND_ENABLE = yes # Commands for debug and configuration 23COMMAND_ENABLE = yes # Commands for debug and configuration
24SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend 24SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
25NKRO_ENABLE = yes # USB Nkey Rollover 25NKRO_ENABLE = yes # USB Nkey Rollover
26CUSTOM_MATRIX = no # Custom matrix file
27ENCODER_ENABLE = yes 26ENCODER_ENABLE = yes
28QWIIC_ENABLE = yes 27OLED_ENABLE = yes
29QWIIC_DRIVERS += MICRO_OLED 28OLED_DRIVER = SSD1306
30#BACKLIGHT_ENABLE = yes 29#BACKLIGHT_ENABLE = yes
31 30
32DEFAULT_FOLDER = cannonkeys/satisfaction75/rev1 31DEFAULT_FOLDER = cannonkeys/satisfaction75/rev1
diff --git a/keyboards/cannonkeys/satisfaction75/satisfaction75.c b/keyboards/cannonkeys/satisfaction75/satisfaction75.c
index 682805f32..304df3325 100644
--- a/keyboards/cannonkeys/satisfaction75/satisfaction75.c
+++ b/keyboards/cannonkeys/satisfaction75/satisfaction75.c
@@ -5,11 +5,6 @@
5#include <ch.h> 5#include <ch.h>
6#include <hal.h> 6#include <hal.h>
7 7
8#ifdef QWIIC_MICRO_OLED_ENABLE
9#include "micro_oled.h"
10#include "qwiic.h"
11#endif
12
13#include "timer.h" 8#include "timer.h"
14 9
15#include "raw_hid.h" 10#include "raw_hid.h"
@@ -20,18 +15,14 @@
20/* Artificial delay added to get media keys to work in the encoder*/ 15/* Artificial delay added to get media keys to work in the encoder*/
21#define MEDIA_KEY_DELAY 10 16#define MEDIA_KEY_DELAY 10
22 17
23uint16_t last_flush;
24
25volatile uint8_t led_numlock = false; 18volatile uint8_t led_numlock = false;
26volatile uint8_t led_capslock = false; 19volatile uint8_t led_capslock = false;
27volatile uint8_t led_scrolllock = false; 20volatile uint8_t led_scrolllock = false;
28 21
29uint8_t layer; 22uint8_t layer;
30 23
31bool queue_for_send = false;
32bool clock_set_mode = false; 24bool clock_set_mode = false;
33uint8_t oled_mode = OLED_DEFAULT; 25uint8_t oled_mode = OLED_DEFAULT;
34bool oled_sleeping = false;
35 26
36uint8_t encoder_value = 32; 27uint8_t encoder_value = 32;
37uint8_t encoder_mode = ENC_MODE_VOLUME; 28uint8_t encoder_mode = ENC_MODE_VOLUME;
@@ -167,7 +158,6 @@ void raw_hid_receive_kb( uint8_t *data, uint8_t length )
167 case id_oled_mode: 158 case id_oled_mode:
168 { 159 {
169 oled_mode = command_data[1]; 160 oled_mode = command_data[1];
170 draw_ui();
171 break; 161 break;
172 } 162 }
173 case id_encoder_modes: 163 case id_encoder_modes:
@@ -247,18 +237,15 @@ void read_host_led_state(void) {
247layer_state_t layer_state_set_kb(layer_state_t state) { 237layer_state_t layer_state_set_kb(layer_state_t state) {
248 state = layer_state_set_user(state); 238 state = layer_state_set_user(state);
249 layer = biton32(state); 239 layer = biton32(state);
250 queue_for_send = true;
251 return state; 240 return state;
252} 241}
253 242
254bool process_record_kb(uint16_t keycode, keyrecord_t *record) { 243bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
255 queue_for_send = true;
256 switch (keycode) { 244 switch (keycode) {
257 case OLED_TOGG: 245 case OLED_TOGG:
258 if(!clock_set_mode){ 246 if(!clock_set_mode){
259 if (record->event.pressed) { 247 if (record->event.pressed) {
260 oled_mode = (oled_mode + 1) % _NUM_OLED_MODES; 248 oled_mode = (oled_mode + 1) % _NUM_OLED_MODES;
261 draw_ui();
262 } 249 }
263 } 250 }
264 return false; 251 return false;
@@ -303,7 +290,6 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
303bool encoder_update_kb(uint8_t index, bool clockwise) { 290bool encoder_update_kb(uint8_t index, bool clockwise) {
304 if (!encoder_update_user(index, clockwise)) return false; 291 if (!encoder_update_user(index, clockwise)) return false;
305 encoder_value = (encoder_value + (clockwise ? 1 : -1)) % 64; 292 encoder_value = (encoder_value + (clockwise ? 1 : -1)) % 64;
306 queue_for_send = true;
307 if (index == 0) { 293 if (index == 0) {
308 if (layer == 0){ 294 if (layer == 0){
309 uint16_t mapped_code = 0; 295 uint16_t mapped_code = 0;
@@ -376,7 +362,6 @@ void matrix_init_kb(void)
376#endif // VIA_ENABLE 362#endif // VIA_ENABLE
377 363
378 rtcGetTime(&RTCD1, &last_timespec); 364 rtcGetTime(&RTCD1, &last_timespec);
379 queue_for_send = true;
380 backlight_init_ports(); 365 backlight_init_ports();
381 matrix_init_user(); 366 matrix_init_user();
382} 367}
@@ -388,22 +373,14 @@ void housekeeping_task_kb(void) {
388 373
389 if (minutes_since_midnight != last_minute){ 374 if (minutes_since_midnight != last_minute){
390 last_minute = minutes_since_midnight; 375 last_minute = minutes_since_midnight;
391 if(!oled_sleeping){
392 queue_for_send = true;
393 }
394 } 376 }
395#ifdef QWIIC_MICRO_OLED_ENABLE 377
396 if (queue_for_send && oled_mode != OLED_OFF) { 378 if((oled_mode == OLED_OFF) && is_oled_on()){
397 oled_sleeping = false; 379 oled_off();
398 read_host_led_state();
399 draw_ui();
400 queue_for_send = false;
401 } 380 }
402 if (timer_elapsed(last_flush) > ScreenOffInterval && !oled_sleeping) { 381 if((oled_mode != OLED_OFF) && !is_oled_on()){
403 send_command(DISPLAYOFF); /* 0xAE */ 382 oled_on();
404 oled_sleeping = true;
405 } 383 }
406#endif
407} 384}
408 385
409// 386//
diff --git a/keyboards/cannonkeys/satisfaction75/satisfaction75.h b/keyboards/cannonkeys/satisfaction75/satisfaction75.h
index 13aaf6888..9d20dd9c9 100644
--- a/keyboards/cannonkeys/satisfaction75/satisfaction75.h
+++ b/keyboards/cannonkeys/satisfaction75/satisfaction75.h
@@ -14,9 +14,6 @@
14#define EEPROM_DEFAULT_OLED (VIA_EEPROM_CUSTOM_CONFIG_ADDR+2) 14#define EEPROM_DEFAULT_OLED (VIA_EEPROM_CUSTOM_CONFIG_ADDR+2)
15#define EEPROM_CUSTOM_ENCODER (VIA_EEPROM_CUSTOM_CONFIG_ADDR+3) 15#define EEPROM_CUSTOM_ENCODER (VIA_EEPROM_CUSTOM_CONFIG_ADDR+3)
16 16
17/* screen off after this many milliseconds */
18#define ScreenOffInterval 60000 /* milliseconds */
19
20typedef union { 17typedef union {
21 uint8_t raw; 18 uint8_t raw;
22 struct { 19 struct {
@@ -74,10 +71,7 @@ extern volatile uint8_t led_scrolllock;
74extern uint8_t layer; 71extern uint8_t layer;
75 72
76// OLED Behavior 73// OLED Behavior
77extern uint16_t last_flush;
78extern bool queue_for_send;
79extern uint8_t oled_mode; 74extern uint8_t oled_mode;
80extern bool oled_sleeping;
81 75
82// Encoder Behavior 76// Encoder Behavior
83extern uint8_t encoder_value; 77extern uint8_t encoder_value;
@@ -113,11 +107,6 @@ void set_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior, uint16_t n
113 107
114void update_time_config(int8_t increment); 108void update_time_config(int8_t increment);
115 109
116__attribute__ ((weak))
117void draw_ui(void);
118void draw_default(void);
119void draw_clock(void);
120
121void backlight_init_ports(void); 110void backlight_init_ports(void);
122void backlight_set(uint8_t level); 111void backlight_set(uint8_t level);
123bool is_breathing(void); 112bool is_breathing(void);
diff --git a/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c b/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c
index 8fcd720e2..cefdbc5f9 100644
--- a/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c
+++ b/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c
@@ -125,7 +125,6 @@ uint16_t handle_encoder_clockwise(){
125#endif 125#endif
126 case ENC_MODE_CLOCK_SET: 126 case ENC_MODE_CLOCK_SET:
127 update_time_config(1); 127 update_time_config(1);
128 queue_for_send = true;
129 break; 128 break;
130 } 129 }
131 return mapped_code; 130 return mapped_code;
@@ -171,7 +170,6 @@ uint16_t handle_encoder_ccw(){
171 170
172 case ENC_MODE_CLOCK_SET: 171 case ENC_MODE_CLOCK_SET:
173 update_time_config(-1); 172 update_time_config(-1);
174 queue_for_send = true;
175 break; 173 break;
176 } 174 }
177 return mapped_code; 175 return mapped_code;
diff --git a/keyboards/cannonkeys/satisfaction75/satisfaction_oled.c b/keyboards/cannonkeys/satisfaction75/satisfaction_oled.c
index 6553bd130..9589ecea8 100644
--- a/keyboards/cannonkeys/satisfaction75/satisfaction_oled.c
+++ b/keyboards/cannonkeys/satisfaction75/satisfaction_oled.c
@@ -1,271 +1,201 @@
1#include "satisfaction75.h" 1#include "satisfaction75.h"
2#include "micro_oled.h" 2
3 3void draw_default(void);
4__attribute__ ((weak)) 4void draw_clock(void);
5void draw_ui() { 5
6#ifdef QWIIC_MICRO_OLED_ENABLE 6#ifdef OLED_ENABLE
7 clear_buffer(); 7
8 last_flush = timer_read(); 8__attribute__((weak)) oled_rotation_t oled_init_user(oled_rotation_t rotation) { return OLED_ROTATION_0; }
9 send_command(DISPLAYON); 9
10 if(clock_set_mode){ 10__attribute__((weak)) void oled_task_user(void) {
11 draw_clock(); 11 if (!is_oled_on()) {
12 return; 12 return;
13 } 13 }
14 switch (oled_mode){ 14 oled_clear();
15 default: 15 if (clock_set_mode) {
16 case OLED_DEFAULT: 16 draw_clock();
17 draw_default(); 17 return;
18 break; 18 }
19 case OLED_TIME: 19 switch (oled_mode) {
20 draw_clock(); 20 default:
21 break; 21 case OLED_DEFAULT:
22 case OLED_OFF: 22 draw_default();
23 send_command(DISPLAYOFF); 23 break;
24 break; 24 case OLED_TIME:
25 } 25 draw_clock();
26#endif 26 break;
27 }
27} 28}
28 29
29void draw_encoder(int8_t startX, int8_t startY, bool show_legend){ 30
30 if(show_legend){ 31static void draw_line_h(uint8_t x, uint8_t y, uint8_t len) {
31 draw_string(startX + 1, startY + 2, "ENC", PIXEL_ON, NORM, 0); 32 for (uint8_t i = 0; i < len; i++) {
32 } else { 33 oled_write_pixel(i + x, y, true);
33 startX -= 22; 34 }
34 }
35 draw_rect_filled_soft(startX + 22, startY + 1, 3 + (3 * 6), 9, PIXEL_ON, NORM);
36 char* mode_string = "";
37 switch(encoder_mode){
38 default:
39 case ENC_MODE_VOLUME:
40 mode_string = "VOL";
41 break;
42 case ENC_MODE_MEDIA:
43 mode_string = "MED";
44 break;
45 case ENC_MODE_SCROLL:
46 mode_string = "SCR";
47 break;
48 case ENC_MODE_BRIGHTNESS:
49 mode_string = "BRT";
50 break;
51 case ENC_MODE_BACKLIGHT:
52 mode_string = "BKL";
53 break;
54 case ENC_MODE_CLOCK_SET:
55 mode_string = "CLK";
56 break;
57 case ENC_MODE_CUSTOM0:
58 mode_string = "CS0";
59 break;
60 case ENC_MODE_CUSTOM1:
61 mode_string = "CS1";
62 break;
63 case ENC_MODE_CUSTOM2:
64 mode_string = "CS2";
65 break;
66 }
67 draw_string(startX + 24, startY + 2, mode_string, PIXEL_ON, XOR, 0);
68} 35}
69 36
70void draw_layer_section(int8_t startX, int8_t startY, bool show_legend){ 37static void draw_line_v(uint8_t x, uint8_t y, uint8_t len) {
71 if(show_legend){ 38 for (uint8_t i = 0; i < len; i++) {
72 draw_string(startX + 1, startY + 2, "LAYER", PIXEL_ON, NORM, 0); 39 oled_write_pixel(x, i + y, true);
73 } else { 40 }
74 startX -= 32;
75 }
76 draw_rect_filled_soft(startX + 32, startY + 1, 9, 9, PIXEL_ON, NORM);
77 draw_char(startX + 34, startY + 2, layer + 0x30, PIXEL_ON, XOR, 0);
78} 41}
79 42
80void draw_default(){ 43static char* get_enc_mode(void) {
81 uint8_t hour = last_minute / 60; 44 switch (encoder_mode) {
82 uint16_t minute = last_minute % 60; 45 default:
46 case ENC_MODE_VOLUME:
47 return "VOL";
48 case ENC_MODE_MEDIA:
49 return "MED";
50 case ENC_MODE_SCROLL:
51 return "SCR";
52 case ENC_MODE_BRIGHTNESS:
53 return "BRT";
54 case ENC_MODE_BACKLIGHT:
55 return "BKL";
56 case ENC_MODE_CLOCK_SET:
57 return "CLK";
58 case ENC_MODE_CUSTOM0:
59 return "CS0";
60 case ENC_MODE_CUSTOM1:
61 return "CS1";
62 case ENC_MODE_CUSTOM2:
63 return "CS2";
64 }
65}
83 66
84 if(encoder_mode == ENC_MODE_CLOCK_SET){ 67static char* get_time(void) {
85 hour = hour_config; 68 uint8_t hour = last_minute / 60;
86 minute = minute_config; 69 uint16_t minute = last_minute % 60;
87 }
88 70
89 bool is_pm = (hour / 12) > 0; 71 if (encoder_mode == ENC_MODE_CLOCK_SET) {
90 hour = hour % 12; 72 hour = hour_config;
91 if (hour == 0){ 73 minute = minute_config;
92 hour = 12; 74 }
93 }
94 char hour_str[3] = "";
95 char min_str[3] = "";
96 75
97 sprintf(hour_str, "%02d", hour); 76 bool is_pm = (hour / 12) > 0;
98 sprintf(min_str, "%02d", minute); 77 hour = hour % 12;
78 if (hour == 0) {
79 hour = 12;
80 }
99 81
100 uint8_t mods = get_mods(); 82 static char time_str[8] = "";
83 sprintf(time_str, "%02d:%02d%s", hour, minute, is_pm ? "pm" : "am");
101 84
102/* Layer indicator is 41 x 10 pixels */ 85 return time_str;
103 draw_layer_section(0,0,true); 86}
104 87
105#define ENCODER_INDICATOR_X 45 88static char* get_date(void) {
106#define ENCODER_INDICATOR_Y 0 89 int16_t year = last_timespec.year + 1980;
107 draw_encoder(ENCODER_INDICATOR_X, ENCODER_INDICATOR_Y, true); 90 int8_t month = last_timespec.month;
108/* Matrix display is 19 x 9 pixels */ 91 int8_t day = last_timespec.day;
109#define MATRIX_DISPLAY_X 0
110#define MATRIX_DISPLAY_Y 18
111 92
112 for (uint8_t x = 0; x < MATRIX_ROWS; x++) { 93 if (encoder_mode == ENC_MODE_CLOCK_SET) {
113 for (uint8_t y = 0; y < MATRIX_COLS; y++) { 94 year = year_config + 1980;
114 draw_pixel(MATRIX_DISPLAY_X + y + 2, MATRIX_DISPLAY_Y + x + 2,(matrix_get_row(x) & (1 << y)) > 0, NORM); 95 month = month_config;
96 day = day_config;
115 } 97 }
116 } 98
117 draw_rect_soft(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y, 19, 9, PIXEL_ON, NORM); 99 static char date_str[11] = "";
118 /* hadron oled location on thumbnail */ 100 sprintf(date_str, "%04d-%02d-%02d", year, month, day);
119 draw_rect_filled_soft(MATRIX_DISPLAY_X + 14, MATRIX_DISPLAY_Y + 2, 3, 1, PIXEL_ON, NORM); 101
120 102 return date_str;
121/* Mod display is 41 x 16 pixels */
122#define MOD_DISPLAY_X 30
123#define MOD_DISPLAY_Y 18
124
125 if (mods & MOD_LSFT) {
126 draw_rect_filled_soft(MOD_DISPLAY_X + 0, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
127 draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_OFF, NORM, 0);
128 } else {
129 draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_ON, NORM, 0);
130 }
131 if (mods & MOD_LCTL) {
132 draw_rect_filled_soft(MOD_DISPLAY_X + 10, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
133 draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_OFF, NORM, 0);
134 } else {
135 draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_ON, NORM, 0);
136 }
137 if (mods & MOD_LALT) {
138 draw_rect_filled_soft(MOD_DISPLAY_X + 20, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
139 draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_OFF, NORM, 0);
140 } else {
141 draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_ON, NORM, 0);
142 }
143 if (mods & MOD_LGUI) {
144 draw_rect_filled_soft(MOD_DISPLAY_X + 30, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
145 draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_OFF, NORM, 0);
146 } else {
147 draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_ON, NORM, 0);
148 }
149
150/* Lock display is 23 x 21 */
151#define LOCK_DISPLAY_X 100
152#define LOCK_DISPLAY_Y 0
153
154 if (led_capslock == true) {
155 draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y, 5 + (3 * 6), 9, PIXEL_ON, NORM);
156 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y +1, "CAP", PIXEL_OFF, NORM, 0);
157 } else if (led_capslock == false) {
158 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y +1, "CAP", PIXEL_ON, NORM, 0);
159 }
160
161 if (led_scrolllock == true) {
162 draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 11, 5 + (3 * 6), 9, PIXEL_ON, NORM);
163 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "SCR", PIXEL_OFF, NORM, 0);
164 } else if (led_scrolllock == false) {
165 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "SCR", PIXEL_ON, NORM, 0);
166 }
167
168#define TIME_DISPLAY_X 82
169#define TIME_DISPLAY_Y 22
170 draw_string(TIME_DISPLAY_X, TIME_DISPLAY_Y, hour_str, PIXEL_ON, NORM, 0);
171 draw_string(TIME_DISPLAY_X + 11, TIME_DISPLAY_Y, ":", PIXEL_ON, NORM, 0);
172 draw_string(TIME_DISPLAY_X + 15, TIME_DISPLAY_Y, min_str, PIXEL_ON, NORM, 0);
173 if(is_pm){
174 draw_string(TIME_DISPLAY_X + 27, TIME_DISPLAY_Y, "pm", PIXEL_ON, NORM, 0);
175 } else{
176 draw_string(TIME_DISPLAY_X + 27, TIME_DISPLAY_Y, "am", PIXEL_ON, NORM, 0);
177 }
178
179 send_buffer();
180} 103}
181 104
182void draw_clock(){ 105void draw_default() {
183 int8_t hour = last_minute / 60; 106 oled_write_P(PSTR("LAYER "), false);
184 int16_t minute = last_minute % 60; 107 oled_write_char(get_highest_layer(layer_state) + 0x30, true);
185 int16_t year = last_timespec.year + 1980; 108
186 int8_t month = last_timespec.month; 109 oled_write_P(PSTR(" ENC "), false);
187 int8_t day = last_timespec.day; 110 oled_write(get_enc_mode(), true);
188 111
189 if(encoder_mode == ENC_MODE_CLOCK_SET){ 112 led_t led_state = host_keyboard_led_state();
190 hour = hour_config; 113 oled_set_cursor(18, 0);
191 minute = minute_config; 114 oled_write_P(PSTR("CAP"), led_state.caps_lock);
192 year = year_config + 1980; 115 oled_set_cursor(18, 1);
193 month = month_config; 116 oled_write_P(PSTR("SCR"), led_state.scroll_lock);
194 day = day_config; 117
195 } 118 uint8_t mod_state = get_mods();
196 119 oled_set_cursor(6, 3);
197 bool is_pm = (hour / 12) > 0; 120 oled_write_P(PSTR("S"), mod_state & MOD_MASK_SHIFT);
198 hour = hour % 12; 121 oled_advance_char();
199 if (hour == 0){ 122 oled_write_P(PSTR("C"), mod_state & MOD_MASK_CTRL);
200 hour = 12; 123 oled_advance_char();
201 } 124 oled_write_P(PSTR("A"), mod_state & MOD_MASK_ALT);
202 char hour_str[3] = ""; 125 oled_advance_char();
203 char min_str[3] = ""; 126 oled_write_P(PSTR("G"), mod_state & MOD_MASK_GUI);
204 char year_str[5] = ""; 127 oled_advance_char();
205 char month_str[3] = ""; 128
206 char day_str[3] = ""; 129 oled_write(get_time(), false);
207 130
208 sprintf(hour_str, "%02d", hour); 131/* Matrix display is 12 x 12 pixels */
209 sprintf(min_str, "%02d", minute); 132#define MATRIX_DISPLAY_X 0
210 sprintf(year_str, "%d", year); 133#define MATRIX_DISPLAY_Y 18
211 sprintf(month_str, "%02d", month);
212 sprintf(day_str, "%02d", day);
213
214
215#define DATE_DISPLAY_X 6
216#define DATE_DISPLAY_Y 0
217 draw_string(DATE_DISPLAY_X, DATE_DISPLAY_Y, year_str, PIXEL_ON, NORM, 0);
218 draw_string(DATE_DISPLAY_X + 25, DATE_DISPLAY_Y, "-", PIXEL_ON, NORM, 0);
219 draw_string(DATE_DISPLAY_X + 31, DATE_DISPLAY_Y, month_str, PIXEL_ON, NORM, 0);
220 draw_string(DATE_DISPLAY_X + 44, DATE_DISPLAY_Y, "-", PIXEL_ON, NORM, 0);
221 draw_string(DATE_DISPLAY_X + 50, DATE_DISPLAY_Y, day_str, PIXEL_ON, NORM, 0);
222
223#define CLOCK_DISPLAY_X 6
224#define CLOCK_DISPLAY_Y 14
225 draw_string(CLOCK_DISPLAY_X, CLOCK_DISPLAY_Y, hour_str, PIXEL_ON, NORM, 1);
226 draw_string(CLOCK_DISPLAY_X + 17, CLOCK_DISPLAY_Y, ":", PIXEL_ON, NORM, 1);
227 draw_string(CLOCK_DISPLAY_X + 25, CLOCK_DISPLAY_Y, min_str, PIXEL_ON, NORM, 1);
228 if(is_pm){
229 draw_string(CLOCK_DISPLAY_X + 41, CLOCK_DISPLAY_Y, "pm", PIXEL_ON, NORM, 1);
230 } else{
231 draw_string(CLOCK_DISPLAY_X + 41, CLOCK_DISPLAY_Y, "am", PIXEL_ON, NORM, 1);
232 }
233
234 if(clock_set_mode){
235 switch(time_config_idx){
236 case 0: // hour
237 default:
238 draw_line(CLOCK_DISPLAY_X, CLOCK_DISPLAY_Y + 17, CLOCK_DISPLAY_X + 16, CLOCK_DISPLAY_Y + 17, PIXEL_ON, NORM);
239 break;
240 case 1: // minute
241 draw_line(CLOCK_DISPLAY_X + 25, CLOCK_DISPLAY_Y + 17, CLOCK_DISPLAY_X + 41, CLOCK_DISPLAY_Y + 17, PIXEL_ON, NORM);
242 break;
243 case 2: // year
244 draw_line(DATE_DISPLAY_X, DATE_DISPLAY_Y + 9, DATE_DISPLAY_X + 23, DATE_DISPLAY_Y + 9, PIXEL_ON, NORM);
245 break;
246 case 3: // month
247 draw_line(DATE_DISPLAY_X + 31, DATE_DISPLAY_Y + 9, DATE_DISPLAY_X + 43, DATE_DISPLAY_Y + 9, PIXEL_ON, NORM);
248 break;
249 case 4: //day
250 draw_line(DATE_DISPLAY_X + 50, DATE_DISPLAY_Y + 9, DATE_DISPLAY_X + 61, DATE_DISPLAY_Y + 9,PIXEL_ON, NORM);
251 break;
252 }
253 }
254 134
255 draw_encoder(80, 0, true); 135 // matrix
256 draw_layer_section(80, 11, true); 136 for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
137 for (uint8_t y = 0; y < MATRIX_COLS; y++) {
138 bool on = (matrix_get_row(x) & (1 << y)) > 0;
139 oled_write_pixel(MATRIX_DISPLAY_X + y + 2, MATRIX_DISPLAY_Y + x + 2, on);
140 }
141 }
257 142
258#define CAPS_DISPLAY_X 86 143 // outline
259#define CAPS_DISPLAY_Y 22 144 draw_line_h(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y, 19);
145 draw_line_h(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y + 9, 19);
146 draw_line_v(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y, 9);
147 draw_line_v(MATRIX_DISPLAY_X + 19, MATRIX_DISPLAY_Y, 9);
260 148
261 if (led_capslock == true) { 149 // oled location
262 draw_rect_filled_soft(CAPS_DISPLAY_X, CAPS_DISPLAY_Y, 5 + (4 * 6), 9, PIXEL_ON, NORM); 150 draw_line_h(MATRIX_DISPLAY_X + 14, MATRIX_DISPLAY_Y + 2, 3);
263 draw_string(CAPS_DISPLAY_X + 3, CAPS_DISPLAY_Y +1, "CAPS", PIXEL_OFF, NORM, 0);
264 } else if (led_capslock == false) {
265 draw_string(CAPS_DISPLAY_X + 3, CAPS_DISPLAY_Y +1, "CAPS", PIXEL_ON, NORM, 0);
266 }
267 151
152 // bodge extra lines for invert layer and enc mode
153 draw_line_v(35, 0, 8);
154 draw_line_v(71, 0, 8);
155}
268 156
269 send_buffer(); 157void draw_clock() {
158 oled_set_cursor(0, 0);
159 oled_write(get_date(), false);
160 oled_set_cursor(0, 2);
161 oled_write(get_time(), false);
162
163 oled_set_cursor(12, 0);
164 oled_write_P(PSTR(" ENC "), false);
165 oled_write(get_enc_mode(), true);
166
167 oled_set_cursor(13, 1);
168 oled_write_P(PSTR("LAYER "), false);
169 oled_write_char(get_highest_layer(layer_state) + 0x30, true);
170
171 led_t led_state = host_keyboard_led_state();
172 oled_set_cursor(15, 3);
173 oled_write_P(PSTR("CAPS"), led_state.caps_lock);
174
175 if (clock_set_mode) {
176 switch (time_config_idx) {
177 case 0: // hour
178 default:
179 draw_line_h(0, 25, 10);
180 break;
181 case 1: // minute
182 draw_line_h(18, 25, 10);
183 break;
184 case 2: // year
185 draw_line_h(0, 9, 24);
186 break;
187 case 3: // month
188 draw_line_h(30, 9, 10);
189 break;
190 case 4: // day
191 draw_line_h(48, 9, 10);
192 break;
193 }
194 }
270 195
196 // bodge extra lines for invert layer and enc mode
197 draw_line_v(101, 0, 8);
198 draw_line_v(113, 8, 8);
271} 199}
200
201#endif