diff options
Diffstat (limited to 'keyboards/crkbd/keymaps/rs/oled.c')
-rw-r--r-- | keyboards/crkbd/keymaps/rs/oled.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/keyboards/crkbd/keymaps/rs/oled.c b/keyboards/crkbd/keymaps/rs/oled.c new file mode 100644 index 000000000..bd8ae7d29 --- /dev/null +++ b/keyboards/crkbd/keymaps/rs/oled.c | |||
@@ -0,0 +1,104 @@ | |||
1 | #ifdef SSD1306OLED | ||
2 | #include QMK_KEYBOARD_H | ||
3 | #include "ssd1306.h" | ||
4 | #ifdef PROTOCOL_LUFA | ||
5 | #include "lufa.h" | ||
6 | #include "split_util.h" | ||
7 | #endif | ||
8 | |||
9 | extern uint8_t is_master; | ||
10 | |||
11 | // When add source files to SRC in rules.mk, you can use functions. | ||
12 | const char *read_logo(void); | ||
13 | const char *read_keylog(void); | ||
14 | const char *read_keylogs(void); | ||
15 | void set_keylog(uint16_t keycode, keyrecord_t *record); | ||
16 | |||
17 | void matrix_scan_user(void) { iota_gfx_task(); } | ||
18 | |||
19 | typedef struct { | ||
20 | uint8_t state; | ||
21 | char name[8]; | ||
22 | } LAYER_DISPLAY_NAME; | ||
23 | |||
24 | #define LAYER_DISPLAY_MAX 5 | ||
25 | const LAYER_DISPLAY_NAME layer_display_name[LAYER_DISPLAY_MAX] = { | ||
26 | {0, "Base"}, | ||
27 | {2, "Code"}, | ||
28 | {4, "Fn"}, | ||
29 | {6, "Fn+Code"}, | ||
30 | {__UINT8_MAX__, "?"}, | ||
31 | }; | ||
32 | static uint8_t layer_name_idx; | ||
33 | static char layer_status_buf[24] = "Layer: Base\n"; | ||
34 | |||
35 | #ifdef RGBLIGHT_ENABLE | ||
36 | // Following line allows macro to read current RGB settings | ||
37 | extern rgblight_config_t rgblight_config; | ||
38 | void update_keymap_status(void) { | ||
39 | snprintf(layer_status_buf, sizeof(layer_status_buf) - 1, "Layer:%s RGB: %d\n", | ||
40 | layer_display_name[layer_name_idx].name, rgblight_config.mode); | ||
41 | } | ||
42 | #else | ||
43 | void update_keymap_status(void) { | ||
44 | snprintf(layer_status_buf, sizeof(layer_status_buf) - 1, "Layer:%s\n", | ||
45 | layer_display_name[layer_name_idx].name); | ||
46 | } | ||
47 | #endif | ||
48 | |||
49 | void matrix_init_user(void) { | ||
50 | iota_gfx_init(!has_usb()); // turns on the display | ||
51 | update_keymap_status(); | ||
52 | } | ||
53 | |||
54 | // declared in users/rs/rs.c | ||
55 | void rgb_mod_changed_keymap(void) { | ||
56 | update_keymap_status(); | ||
57 | } | ||
58 | |||
59 | // declared in users/rs/rs.c | ||
60 | void keylog_set_keymap(uint16_t keycode, keyrecord_t *record) { | ||
61 | set_keylog(keycode, record); | ||
62 | } | ||
63 | |||
64 | layer_state_t layer_state_set_user(layer_state_t state) { | ||
65 | for (layer_name_idx = 0; layer_name_idx < LAYER_DISPLAY_MAX; ++layer_name_idx) { | ||
66 | if (state == 0 && layer_display_name[layer_name_idx].state == default_layer_state) { | ||
67 | break; | ||
68 | } else if (state != 0 && layer_display_name[layer_name_idx].state == state) { | ||
69 | break; | ||
70 | } | ||
71 | } | ||
72 | update_keymap_status(); | ||
73 | return state; | ||
74 | } | ||
75 | |||
76 | static inline void render_keymap_status(struct CharacterMatrix *matrix) { | ||
77 | matrix_write(matrix, layer_status_buf); | ||
78 | } | ||
79 | |||
80 | void matrix_render_user(struct CharacterMatrix *matrix) { | ||
81 | if (is_master) { | ||
82 | render_keymap_status(matrix); | ||
83 | matrix_write_ln(matrix, read_keylog()); | ||
84 | matrix_write_ln(matrix, read_keylogs()); | ||
85 | } else { | ||
86 | matrix_write(matrix, read_logo()); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | void matrix_update(struct CharacterMatrix *dest, const struct CharacterMatrix *source) { | ||
91 | if (memcmp(dest->display, source->display, sizeof(dest->display))) { | ||
92 | memcpy(dest->display, source->display, sizeof(dest->display)); | ||
93 | dest->dirty = true; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | void iota_gfx_task_user(void) { | ||
98 | struct CharacterMatrix matrix; | ||
99 | matrix_clear(&matrix); | ||
100 | matrix_render_user(&matrix); | ||
101 | matrix_update(&display, &matrix); | ||
102 | } | ||
103 | |||
104 | #endif | ||