aboutsummaryrefslogtreecommitdiff
path: root/keyboards/helix/rev2/keymaps/default/oled_display.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/helix/rev2/keymaps/default/oled_display.c')
-rw-r--r--keyboards/helix/rev2/keymaps/default/oled_display.c228
1 files changed, 228 insertions, 0 deletions
diff --git a/keyboards/helix/rev2/keymaps/default/oled_display.c b/keyboards/helix/rev2/keymaps/default/oled_display.c
new file mode 100644
index 000000000..502b62c3c
--- /dev/null
+++ b/keyboards/helix/rev2/keymaps/default/oled_display.c
@@ -0,0 +1,228 @@
1/* Copyright 2020 yushakobo
2 *
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.
7 *
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.
12 *
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/>.
15 */
16
17#include <stdio.h>
18#include <string.h>
19#include QMK_KEYBOARD_H
20
21#ifdef SSD1306OLED
22 #include "ssd1306.h"
23#endif
24
25// Each layer gets a name for readability, which is then used in the keymap matrix below.
26// The underscores don't mean anything - you can have a layer called STUFF or any other name.
27// Layer names don't all need to be of the same length, obviously, and you can also skip them
28// entirely and just use numbers.
29enum layer_number {
30 _QWERTY = 0,
31 _COLEMAK,
32 _DVORAK,
33 _LOWER,
34 _RAISE,
35 _ADJUST
36};
37
38//SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h
39#if defined(SSD1306OLED) || defined(OLED_DRIVER_ENABLE)
40
41# if defined(OLED_DRIVER_ENABLE)
42oled_rotation_t oled_init_user(oled_rotation_t rotation) {
43 if (is_keyboard_master()) {
44 return OLED_ROTATION_0;
45 } else {
46 return OLED_ROTATION_180;
47 }
48}
49# else
50# define oled_write(data,flag) matrix_write(matrix, data)
51# define oled_write_P(data,flag) matrix_write_P(matrix, data)
52# endif
53
54# ifdef SSD1306OLED
55void matrix_scan_user(void) {
56 iota_gfx_task(); // this is what updates the display continuously
57}
58
59void matrix_update(struct CharacterMatrix *dest,
60 const struct CharacterMatrix *source) {
61 if (memcmp(dest->display, source->display, sizeof(dest->display))) {
62 memcpy(dest->display, source->display, sizeof(dest->display));
63 dest->dirty = true;
64 }
65}
66# endif
67
68//assign the right code to your layers for OLED display
69#define L_BASE 0
70#define L_LOWER (1<<_LOWER)
71#define L_RAISE (1<<_RAISE)
72#define L_ADJUST (1<<_ADJUST)
73#define L_ADJUST_TRI (L_ADJUST|L_RAISE|L_LOWER)
74
75# ifdef SSD1306OLED
76static void render_logo(struct CharacterMatrix *matrix) {
77# else
78static void render_logo(void) {
79# endif
80
81 static const char helix_logo[] PROGMEM ={
82 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
83 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
84 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,
85 0};
86 oled_write_P(helix_logo, false);
87}
88
89# ifdef SSD1306OLED
90static void render_rgbled_status(bool full, struct CharacterMatrix *matrix) {
91# else
92static void render_rgbled_status(bool full) {
93# endif
94# ifdef RGBLIGHT_ENABLE
95 char buf[30];
96 if (RGBLIGHT_MODES > 1 && rgblight_is_enabled()) {
97 if (full) {
98 snprintf(buf, sizeof(buf), " LED %2d: %d,%d,%d ",
99 rgblight_get_mode(),
100 rgblight_get_hue()/RGBLIGHT_HUE_STEP,
101 rgblight_get_sat()/RGBLIGHT_SAT_STEP,
102 rgblight_get_val()/RGBLIGHT_VAL_STEP);
103 } else {
104 snprintf(buf, sizeof(buf), "[%2d] ", rgblight_get_mode());
105 }
106 oled_write(buf, false);
107 }
108# endif
109}
110
111# ifdef SSD1306OLED
112static void render_layer_status(struct CharacterMatrix *matrix) {
113# else
114static void render_layer_status(void) {
115# endif
116 // Define layers here, Have not worked out how to have text displayed for each layer. Copy down the number you see and add a case for it below
117 char buf[10];
118 oled_write_P(PSTR("Layer: "), false);
119 switch (layer_state) {
120 case L_BASE:
121 oled_write_P(PSTR("Default"), false);
122 break;
123 case L_RAISE:
124 oled_write_P(PSTR("Raise"), false);
125 break;
126 case L_LOWER:
127 oled_write_P(PSTR("Lower"), false);
128 break;
129 case L_ADJUST:
130 case L_ADJUST_TRI:
131 oled_write_P(PSTR("Adjust"), false);
132 break;
133 default:
134 oled_write_P(PSTR("Undef-"), false);
135 snprintf(buf,sizeof(buf), "%ld", layer_state);
136 oled_write(buf, false);
137 }
138}
139
140# ifdef SSD1306OLED
141void render_status(struct CharacterMatrix *matrix) {
142# else
143void render_status(void) {
144# endif
145 // Render to mode icon
146 static const char os_logo[][2][3] PROGMEM = {{{0x95,0x96,0},{0xb5,0xb6,0}},{{0x97,0x98,0},{0xb7,0xb8,0}}};
147 if (is_mac_mode()) {
148 oled_write_P(os_logo[0][0], false);
149 oled_write_P(PSTR("\n"), false);
150 oled_write_P(os_logo[0][1], false);
151 } else {
152 oled_write_P(os_logo[1][0], false);
153 oled_write_P(PSTR("\n"), false);
154 oled_write_P(os_logo[1][1], false);
155 }
156
157 oled_write_P(PSTR(" "), false);
158# ifdef SSD1306OLED
159 render_layer_status(matrix);
160# else
161 render_layer_status();
162# endif
163 oled_write_P(PSTR("\n"), false);
164
165 // Host Keyboard LED Status
166 led_t led_state = host_keyboard_led_state();
167 oled_write_P(led_state.num_lock ? PSTR("NUMLOCK") : PSTR(" "), false);
168 oled_write_P(led_state.caps_lock ? PSTR("CAPS") : PSTR(" "), false);
169 oled_write_P(led_state.scroll_lock ? PSTR("SCLK") : PSTR(" "), false);
170 oled_write_P(PSTR("\n"), false);
171# ifdef SSD1306OLED
172 render_rgbled_status(true, matrix);
173# else
174 render_rgbled_status(true);
175 oled_write_P(PSTR("\n"), false);
176# endif
177}
178
179
180# ifdef SSD1306OLED
181# if OLED_UPDATE_INTERVAL > 0
182uint16_t oled_update_timeout;
183# endif
184
185void iota_gfx_task_user(void) {
186 struct CharacterMatrix matrix;
187
188# if DEBUG_TO_SCREEN
189 if (debug_enable) {
190 return;
191 }
192# endif
193
194#if OLED_UPDATE_INTERVAL > 0
195 if (timer_elapsed(oled_update_timeout) < OLED_UPDATE_INTERVAL) {
196 return;
197 }
198 oled_update_timeout = timer_read();
199#endif
200 matrix_clear(&matrix);
201 if (is_keyboard_master()) {
202 render_status(&matrix);
203 } else {
204 render_logo(&matrix);
205 render_rgbled_status(false, &matrix);
206 render_layer_status(&matrix);
207 }
208 matrix_update(&display, &matrix);
209}
210# else
211void oled_task_user(void) {
212
213# if DEBUG_TO_SCREEN
214 if (debug_enable) {
215 return;
216 }
217# endif
218
219 if (is_keyboard_master()) {
220 render_status();
221 } else {
222 render_logo();
223 render_rgbled_status(false);
224 render_layer_status();
225 }
226}
227# endif
228#endif