aboutsummaryrefslogtreecommitdiffstats
path: root/keyboards/crkbd/keymaps/rs/oled.c
diff options
context:
space:
mode:
authorGravatar Olivier Poitrey <rs@rhapsodyk.net>2019-05-07 10:43:08 -0700
committerGravatar Drashna Jaelre <drashna@live.com>2019-05-07 10:43:08 -0700
commit2d5c16dfd4ef193c4f692722157aa2b526a4c877 (patch)
tree527c5e5f51cf75c4476616a3c6ed91e385f1e1b2 /keyboards/crkbd/keymaps/rs/oled.c
parent3b132599427a648b1f14aaf30312f05f855625ea (diff)
downloadqmk_firmware-2d5c16dfd4ef193c4f692722157aa2b526a4c877.tar.gz
[Keymap] crkbd/keymaps/rs: add rs keymap to corne keyboard and adapt others (#5181)
Update all my keymaps to work with 40 keys. Refactor code using Userspace.
Diffstat (limited to 'keyboards/crkbd/keymaps/rs/oled.c')
-rw-r--r--keyboards/crkbd/keymaps/rs/oled.c104
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..c94dff9ed
--- /dev/null
+++ b/keyboards/crkbd/keymaps/rs/oled.c
@@ -0,0 +1,104 @@
+#ifdef SSD1306OLED
+#include QMK_KEYBOARD_H
+#include "ssd1306.h"
+#ifdef PROTOCOL_LUFA
+#include "lufa.h"
+#include "split_util.h"
+#endif
+
+extern uint8_t is_master;
+
+// When add source files to SRC in rules.mk, you can use functions.
+const char *read_logo(void);
+const char *read_keylog(void);
+const char *read_keylogs(void);
+void set_keylog(uint16_t keycode, keyrecord_t *record);
+
+void matrix_scan_user(void) { iota_gfx_task(); }
+
+typedef struct {
+ uint8_t state;
+ char name[8];
+} LAYER_DISPLAY_NAME;
+
+#define LAYER_DISPLAY_MAX 5
+const LAYER_DISPLAY_NAME layer_display_name[LAYER_DISPLAY_MAX] = {
+ {0, "Base"},
+ {2, "Code"},
+ {4, "Fn"},
+ {6, "Fn+Code"},
+ {__UINT8_MAX__, "?"},
+};
+static uint8_t layer_name_idx;
+static char layer_status_buf[24] = "Layer: Base\n";
+
+#ifdef RGBLIGHT_ENABLE
+// Following line allows macro to read current RGB settings
+extern rgblight_config_t rgblight_config;
+void update_keymap_status(void) {
+ snprintf(layer_status_buf, sizeof(layer_status_buf) - 1, "Layer:%s RGB: %d\n",
+ layer_display_name[layer_name_idx].name, rgblight_config.mode);
+}
+#else
+void update_keymap_status(void) {
+ snprintf(layer_status_buf, sizeof(layer_status_buf) - 1, "Layer:%s\n",
+ layer_display_name[layer_name_idx].name);
+}
+#endif
+
+void matrix_init_user(void) {
+ iota_gfx_init(!has_usb()); // turns on the display
+ update_keymap_status();
+}
+
+// declared in users/rs/rs.c
+void rgb_mod_changed_keymap(void) {
+ update_keymap_status();
+}
+
+// declared in users/rs/rs.c
+void keylog_set_keymap(uint16_t keycode, keyrecord_t *record) {
+ set_keylog(keycode, record);
+}
+
+uint32_t layer_state_set_user(uint32_t state) {
+ for (layer_name_idx = 0; layer_name_idx < LAYER_DISPLAY_MAX; ++layer_name_idx) {
+ if (state == 0 && layer_display_name[layer_name_idx].state == default_layer_state) {
+ break;
+ } else if (state != 0 && layer_display_name[layer_name_idx].state == state) {
+ break;
+ }
+ }
+ update_keymap_status();
+ return state;
+}
+
+static inline void render_keymap_status(struct CharacterMatrix *matrix) {
+ matrix_write(matrix, layer_status_buf);
+}
+
+void matrix_render_user(struct CharacterMatrix *matrix) {
+ if (is_master) {
+ render_keymap_status(matrix);
+ matrix_write_ln(matrix, read_keylog());
+ matrix_write_ln(matrix, read_keylogs());
+ } else {
+ matrix_write(matrix, read_logo());
+ }
+}
+
+void matrix_update(struct CharacterMatrix *dest, const struct CharacterMatrix *source) {
+ if (memcmp(dest->display, source->display, sizeof(dest->display))) {
+ memcpy(dest->display, source->display, sizeof(dest->display));
+ dest->dirty = true;
+ }
+}
+
+void iota_gfx_task_user(void) {
+ struct CharacterMatrix matrix;
+ matrix_clear(&matrix);
+ matrix_render_user(&matrix);
+ matrix_update(&display, &matrix);
+}
+
+#endif