diff options
Diffstat (limited to 'keyboards/stront/keymaps/hid')
-rw-r--r-- | keyboards/stront/keymaps/hid/config.h | 7 | ||||
-rw-r--r-- | keyboards/stront/keymaps/hid/hid_display.c | 240 | ||||
-rw-r--r-- | keyboards/stront/keymaps/hid/hid_display.h | 29 | ||||
-rw-r--r-- | keyboards/stront/keymaps/hid/keymap.c | 187 | ||||
-rw-r--r-- | keyboards/stront/keymaps/hid/lv_conf.h | 15 | ||||
-rw-r--r-- | keyboards/stront/keymaps/hid/rules.mk | 5 |
6 files changed, 483 insertions, 0 deletions
diff --git a/keyboards/stront/keymaps/hid/config.h b/keyboards/stront/keymaps/hid/config.h new file mode 100644 index 0000000000..e96512f93f --- /dev/null +++ b/keyboards/stront/keymaps/hid/config.h @@ -0,0 +1,7 @@ +// Copyright 2022 zzeneg (@zzeneg) +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#define SPLIT_TRANSACTION_IDS_USER RPC_ID_USER_HID_SYNC, RPC_ID_USER_CAPS_WORD_SYNC, RPC_ID_USER_LAYER_SYNC +#define QUANTUM_PAINTER_DISPLAY_TIMEOUT 0 diff --git a/keyboards/stront/keymaps/hid/hid_display.c b/keyboards/stront/keymaps/hid/hid_display.c new file mode 100644 index 0000000000..a1e1311713 --- /dev/null +++ b/keyboards/stront/keymaps/hid/hid_display.c @@ -0,0 +1,240 @@ +// Copyright 2023 zzeneg (@zzeneg) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "hid_display.h" +#include "display.h" +#include "raw_hid.h" +#include "lvgl_helpers.h" + +uint16_t home_screen_timer = 0; + +/* screens */ +static lv_obj_t *screen_home; +static lv_obj_t *screen_volume; +static lv_obj_t *screen_media; + +/* home screen content */ +static lv_obj_t *label_time; +static lv_obj_t *label_volume_home; +static lv_obj_t *label_shift; +static lv_obj_t *label_ctrl; +static lv_obj_t *label_alt; +static lv_obj_t *label_gui; +static lv_obj_t *label_layer; +static lv_obj_t *label_caps; +#ifdef CAPS_WORD_ENABLE +static lv_obj_t *label_caps_word; +#endif +static lv_obj_t *label_layout; + +/* volume screen content */ +static lv_obj_t *arc_volume; +static lv_obj_t *label_volume_arc; + +/* media screen content */ +static lv_obj_t *label_media_artist; +static lv_obj_t *label_media_title; + +enum layout { _EN = 0, _RU }; +void set_layout_label(uint8_t layout) { + switch (layout) { + case _EN: + lv_label_set_text(label_layout, "EN"); + break; + + case _RU: + lv_label_set_text(label_layout, "RU"); + break; + } +} + +void read_string(uint8_t *data, char *string_data) { + uint8_t data_length = data[1]; + memcpy(string_data, data + 2, data_length); + string_data[data_length] = '\0'; +} + +void start_home_screen_timer(void) { + dprint("start_home_screen_timer\n"); + home_screen_timer = timer_read(); +} + +void init_screen_home_custom(void) { + screen_home = lv_scr_act(); + lv_obj_add_style(screen_home, &style_screen, 0); + use_flex_column(screen_home); + + label_volume_home = lv_label_create(screen_home); + lv_label_set_text(label_volume_home, ""); + + lv_obj_t *mods = lv_obj_create(screen_home); + lv_obj_add_style(mods, &style_container, 0); + use_flex_row(mods); + + label_gui = create_button(mods, "GUI", &style_button, &style_button_active); + label_alt = create_button(mods, "ALT", &style_button, &style_button_active); + label_ctrl = create_button(mods, "CTL", &style_button, &style_button_active); + label_shift = create_button(mods, "SFT", &style_button, &style_button_active); + + label_time = lv_label_create(screen_home); + lv_label_set_text(label_time, "00:00"); + lv_obj_set_style_text_font(label_time, &lv_font_montserrat_48, LV_PART_MAIN); + + lv_obj_t *caps = lv_obj_create(screen_home); + lv_obj_add_style(caps, &style_container, 0); + use_flex_row(caps); + + label_caps = create_button(caps, "CAPS", &style_button, &style_button_active); +#ifdef CAPS_WORD_ENABLE + label_caps_word = create_button(caps, "CAPS WORD", &style_button, &style_button_active); +#endif + + lv_obj_t *bottom_row = lv_obj_create(screen_home); + lv_obj_add_style(bottom_row, &style_container, 0); + + label_layer = lv_label_create(bottom_row); + lv_label_set_text(label_layer, ""); + lv_obj_align(label_layer, LV_ALIGN_LEFT_MID, 10, 0); + display_process_layer_state(0); + + label_layout = lv_label_create(bottom_row); + lv_label_set_text(label_layout, ""); + lv_obj_align(label_layout, LV_ALIGN_RIGHT_MID, -10, 0); + set_layout_label(0); +} + +void init_screen_volume(void) { + screen_volume = lv_obj_create(NULL); + lv_obj_add_style(screen_volume, &style_screen, 0); + + arc_volume = lv_arc_create(screen_volume); + lv_obj_set_size(arc_volume, 200, 200); + lv_obj_center(arc_volume); + + label_volume_arc = lv_label_create(screen_volume); + lv_label_set_text(label_volume_arc, "00"); + lv_obj_set_style_text_font(label_volume_arc, &lv_font_montserrat_48, LV_PART_MAIN); + lv_obj_center(label_volume_arc); + + lv_obj_t *volume_text_label = lv_label_create(screen_volume); + lv_label_set_text(volume_text_label, "Volume"); + lv_obj_align(volume_text_label, LV_ALIGN_BOTTOM_MID, 0, -10); +} + +void init_screen_media(void) { + screen_media = lv_obj_create(NULL); + lv_obj_add_style(screen_media, &style_screen, 0); + use_flex_column(screen_media); + lv_obj_set_flex_align(screen_media, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); + + label_media_artist = lv_label_create(screen_media); + lv_label_set_text(label_media_artist, "N/A"); + lv_label_set_long_mode(label_media_artist, LV_LABEL_LONG_WRAP); + lv_obj_set_width(label_media_artist, lv_pct(90)); + lv_obj_set_style_text_align(label_media_artist, LV_TEXT_ALIGN_CENTER, 0); + + label_media_title = lv_label_create(screen_media); + lv_label_set_text(label_media_title, "N/A"); + lv_label_set_long_mode(label_media_title, LV_LABEL_LONG_WRAP); + lv_obj_set_width(label_media_title, lv_pct(90)); + lv_obj_set_style_text_align(label_media_title, LV_TEXT_ALIGN_CENTER, 0); +} + +bool display_init_user(void) { + init_screen_home_custom(); + init_screen_volume(); + init_screen_media(); + + return false; +} + +void display_process_raw_hid_data(uint8_t *data, uint8_t length) { + uint8_t data_type = data[0]; + char string_data[length - 2]; + dprintf("display_process_raw_hid_data - received data_type %u \n", data_type); + switch (data_type) { + case _TIME: + dprintf("time %02d:%02d\n", data[1], data[2]); + lv_label_set_text_fmt(label_time, "%02d:%02d", data[1], data[2]); + break; + + case _VOLUME: + dprintf("volume %d\n", data[1]); + lv_label_set_text_fmt(label_volume_home, "Volume: %02d%%", data[1]); + lv_label_set_text_fmt(label_volume_arc, "%02d", data[1]); + lv_arc_set_value(arc_volume, data[1]); + lv_scr_load(screen_volume); + start_home_screen_timer(); + break; + + case _LAYOUT: + dprintf("layout %d\n", data[1]); + set_layout_label(data[1]); + break; + + case _MEDIA_ARTIST: + read_string(data, string_data); + dprintf("media artist %s\n", string_data); + lv_label_set_text(label_media_artist, string_data); + lv_scr_load(screen_media); + start_home_screen_timer(); + break; + + case _MEDIA_TITLE: + read_string(data, string_data); + dprintf("media title %s\n", string_data); + lv_label_set_text(label_media_title, string_data); + lv_scr_load(screen_media); + start_home_screen_timer(); + break; + } +} + +void display_process_layer_state(uint8_t layer) { + switch (layer) { + case _QWERTY: + lv_label_set_text(label_layer, "QWERTY"); + break; + case _GAME: + lv_label_set_text(label_layer, "GAME"); + break; + case _NAV: + lv_label_set_text(label_layer, "NAV"); + break; + case _NUMBER: + lv_label_set_text(label_layer, "NUMBER"); + break; + case _SYMBOL: + lv_label_set_text(label_layer, "SYMBOL"); + break; + case _FUNC: + lv_label_set_text(label_layer, "FUNC"); + break; + case _SYS: + lv_label_set_text(label_layer, "SYSTEM"); + break; + } +} + +void display_housekeeping_task(void) { + if (home_screen_timer && timer_elapsed(home_screen_timer) > 5000) { + home_screen_timer = 0; + lv_scr_load(screen_home); + } + + toggle_state(label_shift, LV_STATE_PRESSED, MODS_SHIFT); + toggle_state(label_ctrl, LV_STATE_PRESSED, MODS_CTRL); + toggle_state(label_alt, LV_STATE_PRESSED, MODS_ALT); + toggle_state(label_gui, LV_STATE_PRESSED, MODS_GUI); +} + +void display_process_caps(bool active) { + toggle_state(label_caps, LV_STATE_PRESSED, active); +} + +#ifdef CAPS_WORD_ENABLE +void display_process_caps_word(bool active) { + dprint("display_process_caps_word\n"); + toggle_state(label_caps_word, LV_STATE_PRESSED, active); +} +#endif diff --git a/keyboards/stront/keymaps/hid/hid_display.h b/keyboards/stront/keymaps/hid/hid_display.h new file mode 100644 index 0000000000..b93bf64716 --- /dev/null +++ b/keyboards/stront/keymaps/hid/hid_display.h @@ -0,0 +1,29 @@ +// Copyright 2023 zzeneg (@zzeneg) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "quantum.h" + +typedef enum { + _QWERTY = 0, + _GAME, + _EU, + _NAV, + _NUMBER, + _SYMBOL, + _FUNC, + _SYS, +} layer_number; + +typedef enum { + _TIME = 0, + _VOLUME, + _LAYOUT, + _MEDIA_ARTIST, + _MEDIA_TITLE, +} hid_data_type; + +void display_process_raw_hid_data(uint8_t *data, uint8_t length); +void display_process_layer_state(uint8_t layer); +#ifdef CAPS_WORD_ENABLE +void display_process_caps_word(bool active); +#endif diff --git a/keyboards/stront/keymaps/hid/keymap.c b/keyboards/stront/keymaps/hid/keymap.c new file mode 100644 index 0000000000..11cb89c48e --- /dev/null +++ b/keyboards/stront/keymaps/hid/keymap.c @@ -0,0 +1,187 @@ +// Copyright 2022 zzeneg (@zzeneg) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include QMK_KEYBOARD_H + +#include "hid_display.h" +#include "raw_hid.h" +#include "transactions.h" + +// Left-hand home row mods +#define HOME_A LGUI_T(KC_A) +#define HOME_S LALT_T(KC_S) +#define HOME_D LCTL_T(KC_D) +#define HOME_F LSFT_T(KC_F) + +// Right-hand home row mods +#define HOME_J RSFT_T(KC_J) +#define HOME_K RCTL_T(KC_K) +#define HOME_L LALT_T(KC_L) +#define HOME_SCLN RGUI_T(KC_SCLN) + +// bottom mods +#define SYM_SPC LT(_SYMBOL, KC_SPC) +#define NUM_TAB LT(_NUMBER, KC_TAB) +#define FUNC_ESC LT(_FUNC, KC_ESC) +#define FUNC_ENT LT(_FUNC, KC_ENT) +#define NAV_BSPC LT(_NAV, KC_BSPC) +#define RALT_DEL LALT_T(KC_DEL) + +// game layer mods +#define LALT_Q LALT_T(KC_Q) +#define LSFT_MINS LSFT_T(KC_MINS) +#define LCTL_ESC LCTL_T(KC_ESC) +#define LGUI_QUOT LGUI_T(KC_QUOT) + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + /* QWERTY + * .---------------------------. .---------------------------. + * | W | E | R | T | | Y | U | I | O | + * .------+------+------+------+------+------| |------+------+------+------+------+------. + * | Q | A | S | D | F | G | | H | J | K | L | P | ; | + * |------+------+------+------+------+------| |------+------+------+------+------+------| + * | - | Z | X | C | V | B |--------. .--------| N | M | , | . | / | ' | + * '-----------------------------------------/ / \ \-----------------------------------------' + * | Esc | Tab | / Space / \ Enter \ | Bsps | Del | + * |_FUNC | _NUM | /_SYMBOL/ \ _FUNC \ | _NAV | RAlt | + * `-------------''-------' '-------''-------------' + */ + // clang-format off + [_QWERTY] = LAYOUT( + KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, + KC_Q, HOME_A, HOME_S, HOME_D, HOME_F, KC_G, KC_H, HOME_J, HOME_K, HOME_L, HOME_SCLN, KC_P, + KC_MINS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_QUOT, + FUNC_ESC, NUM_TAB, SYM_SPC, FUNC_ENT, NAV_BSPC, RALT_DEL + ), + + [_GAME] = LAYOUT( + KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, + LALT_Q, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_P, + LSFT_MINS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, LGUI_QUOT, + LCTL_ESC, NUM_TAB, SYM_SPC, FUNC_ENT, NAV_BSPC, RALT_DEL + ), + + [_NAV] = LAYOUT( + XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_PGDN, KC_PGUP, + XXXXXXX, KC_LGUI, KC_LALT, KC_LCTL, KC_LSFT, XXXXXXX, XXXXXXX, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, KC_PAUS, + XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_HOME, KC_END, KC_INS, KC_APP, XXXXXXX, + FUNC_ESC, NUM_TAB, SYM_SPC, XXXXXXX, _______, RALT_DEL + ), + + [_NUMBER] = LAYOUT( + KC_7, KC_8, KC_9, KC_GRV, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + KC_EQL, KC_0, KC_4, KC_5, KC_6, KC_LBRC, XXXXXXX, KC_RSFT, KC_RCTL, KC_LALT, KC_RGUI, XXXXXXX, + KC_MINS, KC_BSLS, KC_1, KC_2, KC_3, KC_RBRC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + KC_ENT, _______, TG(_GAME), FUNC_ENT, NAV_BSPC, RALT_DEL + ), + + [_SYMBOL] = LAYOUT( + LSFT(KC_7), LSFT(KC_8), LSFT(KC_9), LSFT(KC_GRV), XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + LSFT(KC_EQL), LSFT(KC_0), LSFT(KC_4), LSFT(KC_5), LSFT(KC_6), LSFT(KC_LBRC), XXXXXXX, KC_RSFT, KC_RCTL, KC_LALT, KC_RGUI, XXXXXXX, + LSFT(KC_MINS), LSFT(KC_BSLS), LSFT(KC_1), LSFT(KC_2), LSFT(KC_3), LSFT(KC_RBRC), XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + MO(_SYS), KC_BSPC, _______, FUNC_ENT, NAV_BSPC, RALT_DEL + ), + + [_FUNC] = LAYOUT( + KC_F7, KC_F8, KC_F9, KC_CAPS, XXXXXXX, KC_PSCR, KC_SCRL, KC_NUM, + KC_F12, KC_F11, KC_F4, KC_F5, KC_F6, KC_F12, XXXXXXX, KC_RSFT, KC_RCTL, KC_LALT, KC_RGUI, XXXXXXX, + XXXXXXX, KC_F10, KC_F1, KC_F2, KC_F3, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + _______, KC_MNXT, KC_MPLY, _______, XXXXXXX, MO(_SYS) + ), + + [_SYS] = LAYOUT( + BL_DOWN, BL_UP, BL_TOGG, XXXXXXX, XXXXXXX, RGB_TOG, RGB_MOD, RGB_RMOD, + XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_HUI, RGB_SAI, RGB_VAI, RGB_SPI, RGB_M_P, + EH_LEFT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, EH_RGHT, EH_RGHT, RGB_HUD, RGB_SAD, RGB_VAD, RGB_SPD, EH_LEFT, + _______, QK_BOOT, _______, _______, QK_BOOT, _______ + ) + // clang-format on +}; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + dprintf("process_record_user %u %s %s %d\n", keycode, record->event.pressed ? "pressed" : "depressed", record->tap.interrupted ? "interrupted" : "not interrupted", record->tap.count); + + if (record->event.pressed) { + uint8_t data[32]; + data[0] = 0; + + switch (keycode) { + // send hid commands + case KC_VOLU: + case KC_VOLD: + data[0] = _VOLUME; + break; + } + + if (data[0]) { + dprintf("raw_hid_send %u\n", data[0]); + raw_hid_send(data, sizeof(data)); + } + } + + return true; +} + +/* Caps Word processing */ +#ifdef CAPS_WORD_ENABLE +void caps_word_set_user(bool active) { + if (is_display_enabled()) { + display_process_caps_word(active); + } else if (is_keyboard_master() && !is_keyboard_left()) { + dprintf("RPC_ID_USER_CAPS_WORD_SYNC: %s\n", active ? "active" : "inactive"); + transaction_rpc_send(RPC_ID_USER_CAPS_WORD_SYNC, 1, &active); + } +} +#endif + +/* Active Layer processing */ +layer_state_t layer_state_set_user(layer_state_t state) { + if (is_display_enabled()) { + display_process_layer_state(get_highest_layer(state)); + } else if (is_keyboard_master() && !is_keyboard_left()) { + uint8_t layer = get_highest_layer(state); + dprintf("RPC_ID_USER_LAYER_SYNC: %u\n", layer); + transaction_rpc_send(RPC_ID_USER_LAYER_SYNC, 1, &layer); + } + + return state; +} + +/* Raw HID processing*/ +void raw_hid_receive(uint8_t *data, uint8_t length) { + dprintf("raw_hid_receive - received %u bytes \n", length); + + if (is_display_enabled()) { + display_process_raw_hid_data(data, length); + } else if (is_keyboard_master() && !is_keyboard_left()) { + dprint("RPC_ID_USER_HID_SYNC \n"); + transaction_rpc_send(RPC_ID_USER_HID_SYNC, length, data); + } +} + +void hid_sync(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer) { + if (is_display_enabled()) { + display_process_raw_hid_data((uint8_t *)initiator2target_buffer, initiator2target_buffer_size); + } +} + +void layer_sync(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer) { + if (is_display_enabled()) { + display_process_layer_state(*(uint8_t *)initiator2target_buffer); + } +} + +void caps_word_sync(uint8_t initiator2target_buffer_size, const void *initiator2target_buffer, uint8_t target2initiator_buffer_size, void *target2initiator_buffer) { + if (is_display_enabled()) { + display_process_caps_word(*(bool *)initiator2target_buffer); + } +} + +void keyboard_post_init_user() { + // sync received hid data + transaction_register_rpc(RPC_ID_USER_HID_SYNC, hid_sync); + // sync highest layer (a bit more performant than standard SPLIT_LAYER_STATE_ENABLE) + transaction_register_rpc(RPC_ID_USER_LAYER_SYNC, layer_sync); + // sync caps word state + transaction_register_rpc(RPC_ID_USER_CAPS_WORD_SYNC, caps_word_sync); +} diff --git a/keyboards/stront/keymaps/hid/lv_conf.h b/keyboards/stront/keymaps/hid/lv_conf.h new file mode 100644 index 0000000000..f8f93b7c9e --- /dev/null +++ b/keyboards/stront/keymaps/hid/lv_conf.h @@ -0,0 +1,15 @@ +// Copyright 2023 zzeneg (@zzeneg) +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include_next <lv_conf.h> + +#undef LV_FONT_DEFAULT +#define LV_FONT_DEFAULT &lv_font_montserrat_20 + +#undef LV_FONT_MONTSERRAT_20 +#define LV_FONT_MONTSERRAT_20 1 + +#undef LV_FONT_MONTSERRAT_28 +#define LV_FONT_MONTSERRAT_28 0 diff --git a/keyboards/stront/keymaps/hid/rules.mk b/keyboards/stront/keymaps/hid/rules.mk new file mode 100644 index 0000000000..beaf344b66 --- /dev/null +++ b/keyboards/stront/keymaps/hid/rules.mk @@ -0,0 +1,5 @@ +CAPS_WORD_ENABLE = yes + +RAW_ENABLE = yes + +SRC += hid_display.c |