From 8084c71552797182497c9538be1d27fdaf9fbc25 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Sat, 19 Jun 2021 21:54:04 -0500 Subject: [PATCH 01/23] Add script to build all bcat keymaps at once --- users/bcat/compile.sh | 51 +++++++++++++++++++++++++++++++++++++++++++ users/bcat/readme.md | 2 ++ 2 files changed, 53 insertions(+) create mode 100755 users/bcat/compile.sh diff --git a/users/bcat/compile.sh b/users/bcat/compile.sh new file mode 100755 index 000000000000..81551f0ec086 --- /dev/null +++ b/users/bcat/compile.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +set -o errexit -o nounset + +usage () { + printf "\ +usage: ./users/bcat/compile.sh [-c] [-j N] + +Compiles all keyboards for which bcat maintains keymaps. + +optional arguments: + -c performs a clean build + -j N runs N make tasks in parallel + -v shows verbose output +" +} + +compile () { + local keyboard=$1 layout=${2:-} + FORCE_LAYOUT="$layout" SILENT="$opt_silent" make -j "$opt_parallel" "$keyboard":bcat +} + +opt_parallel=1 +opt_silent=true + +while getopts :chj:v opt; do + case $opt in + c) opt_clean=1 ;; + j) opt_parallel=$OPTARG ;; + v) opt_silent=false ;; + h) usage; exit 0 ;; + \?) usage >&2; exit 2 ;; + esac +done + +if [[ -n ${opt_clean:-} ]]; then + SILENT="$opt_silent" make clean +fi + +compile 9key +compile ai03/polaris 60_tsangan_hhkb +compile cannonkeys/an_c 60_tsangan_hhkb +compile cannonkeys/instant60 60_tsangan_hhkb +compile crkbd/rev1 split_3x6_3 +compile dz60 60_ansi_split_bs_rshift +compile dz60 60_tsangan_hhkb +compile eco/rev2 +compile kbdfans/kbd67/hotswap 65_ansi_blocker_split_bs +compile keebio/bdn9/rev1 +compile keebio/quefrency/rev1 +compile lily58/rev1 diff --git a/users/bcat/readme.md b/users/bcat/readme.md index 1922f95f4a18..bb73a53bf855 100644 --- a/users/bcat/readme.md +++ b/users/bcat/readme.md @@ -6,6 +6,8 @@ keyboard-specific keymaps for boards without standard layout support. I derive my keymaps from two canonical ones (preferred for typing and gaming, respectively). +You can build all keymaps I maintain at once using `./users/bcat/compile.sh`. + ## Canonical keymaps * [Split 3x6 + 3 thumb From 8083630fc299adb2424c2b47e14b605235ee3cb3 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Sat, 19 Jun 2021 21:56:48 -0500 Subject: [PATCH 02/23] Move userspace RGB to separate source file --- users/bcat/bcat.c | 5 ----- users/bcat/bcat_rgblight.c | 22 ++++++++++++++++++++++ users/bcat/rules.mk | 18 ++++++++++++++---- 3 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 users/bcat/bcat_rgblight.c diff --git a/users/bcat/bcat.c b/users/bcat/bcat.c index f21d282e43f6..ea496ce5535d 100644 --- a/users/bcat/bcat.c +++ b/users/bcat/bcat.c @@ -16,11 +16,6 @@ #include "bcat.h" -#if defined(RGBLIGHT_ENABLE) -/* Adjust RGB static hue ranges for shorter gradients than default. */ -const uint8_t RGBLED_GRADIENT_RANGES[] PROGMEM = {255, 127, 63, 31, 15}; -#endif - static int8_t alt_tab_layer = -1; __attribute__((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { return true; } diff --git a/users/bcat/bcat_rgblight.c b/users/bcat/bcat_rgblight.c new file mode 100644 index 000000000000..cd6222262bd8 --- /dev/null +++ b/users/bcat/bcat_rgblight.c @@ -0,0 +1,22 @@ +/* Copyright 2021 Jonathan Rascher + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "progmem.h" + +/* Adjust RGB static hue ranges for shorter gradients than default. */ +const uint8_t RGBLED_GRADIENT_RANGES[] PROGMEM = {255, 127, 63, 31, 15}; diff --git a/users/bcat/rules.mk b/users/bcat/rules.mk index 12c9a89bf4ae..b6fd54cd0836 100644 --- a/users/bcat/rules.mk +++ b/users/bcat/rules.mk @@ -1,5 +1,3 @@ -SRC += bcat.c - # Enable Bootmagic Lite to consistently reset to bootloader and clear EEPROM. BOOTMAGIC_ENABLE = yes # Enable Bootmagic Lite @@ -16,13 +14,25 @@ NKRO_ENABLE = yes # Enable link-time optimization to reduce binary size. LTO_ENABLE = yes -# Disable unused build options on all keyboards. +# Include common utilities shared across all our keymaps. +SRC += bcat.c + +# Include additional utilities that extend optional QMK features only enabled +# on some keyboards. +ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) + SRC += bcat_rgblight.c +endif + +# Disable unwanted build options on all keyboards. (Mouse keys are turned off +# due to https://github.com/qmk/qmk_firmware/issues/8323, and the rest are +# turned off to reduce firmware size.) COMMAND_ENABLE = no CONSOLE_ENABLE = no MOUSEKEY_ENABLE = no TERMINAL_ENABLE = no -# Disable unused hardware options on all keyboards. +# Disable unwanted hardware options on all keyboards. (Some keyboards turn +# these features on by default even though they aren't actually required.) MIDI_ENABLE = no SLEEP_LED_ENABLE = no From fb732473d8e7a28f1431ed8423806fa113001058 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Sat, 19 Jun 2021 22:22:48 -0500 Subject: [PATCH 03/23] Move layer handling logic into userspace --- keyboards/9key/keymaps/bcat/keymap.c | 12 +++++------ keyboards/eco/keymaps/bcat/config.h | 2 ++ keyboards/eco/keymaps/bcat/keymap.c | 9 --------- keyboards/keebio/bdn9/keymaps/bcat/keymap.c | 13 +++++------- .../keebio/quefrency/keymaps/bcat/keymap.c | 11 ++++------ keyboards/lily58/keymaps/bcat/config.h | 2 ++ keyboards/lily58/keymaps/bcat/keymap.c | 9 --------- .../60_ansi_split_bs_rshift/bcat/keymap.c | 6 +----- .../community/60_tsangan_hhkb/bcat/keymap.c | 6 +----- .../65_ansi_blocker_split_bs/bcat/keymap.c | 11 ++++------ layouts/community/split_3x6_3/bcat/config.h | 2 ++ layouts/community/split_3x6_3/bcat/keymap.c | 9 --------- users/bcat/bcat.c | 11 ++++++++++ users/bcat/bcat.h | 20 ++++++++++++++++++- 14 files changed, 56 insertions(+), 67 deletions(-) diff --git a/keyboards/9key/keymaps/bcat/keymap.c b/keyboards/9key/keymaps/bcat/keymap.c index 5c08a42a56bf..fa8678f31200 100644 --- a/keyboards/9key/keymaps/bcat/keymap.c +++ b/keyboards/9key/keymaps/bcat/keymap.c @@ -16,12 +16,10 @@ #include QMK_KEYBOARD_H -enum layer { - LAYER_DEFAULT, - LAYER_FUNCTION, -}; +#include "bcat.h" + +#define LY_FN1 MO(LAYER_FUNCTION_1) -#define LY_FUNC MO(LAYER_FUNCTION) #define KY_LOCK LCA(KC_L) /* Cinnamon lock screen */ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { @@ -29,9 +27,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [LAYER_DEFAULT] = LAYOUT( KC_MPLY, KC_VOLU, KC_MSTP, KC_MPRV, KC_VOLD, KC_MNXT, - KY_LOCK, KC_MUTE, LY_FUNC + KY_LOCK, KC_MUTE, LY_FN1 ), - [LAYER_FUNCTION] = LAYOUT( + [LAYER_FUNCTION_1] = LAYOUT( EEP_RST, _______, RESET, _______, _______, _______, _______, _______, _______ diff --git a/keyboards/eco/keymaps/bcat/config.h b/keyboards/eco/keymaps/bcat/config.h index dffdc7b40a85..f2d51c324afb 100644 --- a/keyboards/eco/keymaps/bcat/config.h +++ b/keyboards/eco/keymaps/bcat/config.h @@ -16,6 +16,8 @@ #pragma once +#define BCAT_ORTHO_LAYERS + /* WS2812B RGB LED strip hand wired to Elite-C. */ #define RGB_DI_PIN B7 #define RGBLED_NUM 15 diff --git a/keyboards/eco/keymaps/bcat/keymap.c b/keyboards/eco/keymaps/bcat/keymap.c index d46a7d416b25..be1aa89c8d89 100644 --- a/keyboards/eco/keymaps/bcat/keymap.c +++ b/keyboards/eco/keymaps/bcat/keymap.c @@ -18,13 +18,6 @@ #include "bcat.h" -enum layer { - LAYER_DEFAULT, - LAYER_LOWER, - LAYER_RAISE, - LAYER_ADJUST, -}; - #define LY_LWR MO(LAYER_LOWER) #define LY_RSE MO(LAYER_RAISE) @@ -65,5 +58,3 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ), // clang-format on }; - -layer_state_t layer_state_set_keymap(layer_state_t state) { return update_tri_layer_state(state, LAYER_LOWER, LAYER_RAISE, LAYER_ADJUST); } diff --git a/keyboards/keebio/bdn9/keymaps/bcat/keymap.c b/keyboards/keebio/bdn9/keymaps/bcat/keymap.c index c64f702b2029..3c1415099813 100644 --- a/keyboards/keebio/bdn9/keymaps/bcat/keymap.c +++ b/keyboards/keebio/bdn9/keymaps/bcat/keymap.c @@ -16,21 +16,18 @@ #include QMK_KEYBOARD_H -enum layer { - LAYER_FIRST, - LAYER_SECOND, -}; +#include "bcat.h" -#define LY_SECND MO(LAYER_SECOND) +#define LY_FN1 MO(LAYER_FUNCTION_1) const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // clang-format off - [LAYER_FIRST] = LAYOUT( - KC_MUTE, LY_SECND, BL_BRTG, + [LAYER_DEFAULT] = LAYOUT( + KC_MUTE, LY_FN1, BL_BRTG, KC_F4, KC_F5, KC_F6, KC_F1, KC_F2, KC_F3 ), - [LAYER_SECOND] = LAYOUT( + [LAYER_FUNCTION_1] = LAYOUT( EEP_RST, _______, RESET, KC_F10, KC_F11, KC_F12, KC_F7, KC_F8, KC_F9 diff --git a/keyboards/keebio/quefrency/keymaps/bcat/keymap.c b/keyboards/keebio/quefrency/keymaps/bcat/keymap.c index d28a5083ac80..ce4c9e8f648a 100644 --- a/keyboards/keebio/quefrency/keymaps/bcat/keymap.c +++ b/keyboards/keebio/quefrency/keymaps/bcat/keymap.c @@ -16,12 +16,9 @@ #include QMK_KEYBOARD_H -enum layer { - LAYER_DEFAULT, - LAYER_FUNCTION, -}; +#include "bcat.h" -#define LY_FN MO(LAYER_FUNCTION) +#define LY_FN1 MO(LAYER_FUNCTION_1) const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // clang-format off @@ -31,10 +28,10 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSPC, KC_PGUP, KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGDN, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_END, - KC_LCTL, KC_LGUI, KC_LALT, LY_FN, KC_SPC, KC_SPC, XXXXXXX, KC_RALT, LY_FN, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT + KC_LCTL, KC_LGUI, KC_LALT, LY_FN1, KC_SPC, KC_SPC, XXXXXXX, KC_RALT, LY_FN1, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT ), /* Function layer: http://www.keyboard-layout-editor.com/#/gists/59636898946da51f91fb290f8e078b4d */ - [LAYER_FUNCTION] = LAYOUT_65( + [LAYER_FUNCTION_1] = LAYOUT_65( _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_DEL, RGB_HUI, KC_CAPS, NK_TOGG, KC_MPLY, KC_VOLU, KC_MSTP, _______, EEP_RST, RESET, KC_PSCR, KC_SLCK, KC_PAUS, _______, _______, _______, RGB_SAI, _______, _______, KC_MPRV, KC_VOLD, KC_MNXT, _______, _______, _______, _______, _______, _______, _______, RGB_TOG, RGB_SAD, diff --git a/keyboards/lily58/keymaps/bcat/config.h b/keyboards/lily58/keymaps/bcat/config.h index dbe724d56b96..2ee0071bda2f 100644 --- a/keyboards/lily58/keymaps/bcat/config.h +++ b/keyboards/lily58/keymaps/bcat/config.h @@ -16,4 +16,6 @@ #pragma once +#define BCAT_ORTHO_LAYERS + #define EE_HANDS diff --git a/keyboards/lily58/keymaps/bcat/keymap.c b/keyboards/lily58/keymaps/bcat/keymap.c index 69af2ca003c0..4545f72b6900 100644 --- a/keyboards/lily58/keymaps/bcat/keymap.c +++ b/keyboards/lily58/keymaps/bcat/keymap.c @@ -18,13 +18,6 @@ #include "bcat.h" -enum layer { - LAYER_DEFAULT, - LAYER_LOWER, - LAYER_RAISE, - LAYER_ADJUST, -}; - #define LY_LWR MO(LAYER_LOWER) #define LY_RSE MO(LAYER_RAISE) @@ -69,5 +62,3 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ), // clang-format on }; - -layer_state_t layer_state_set_keymap(layer_state_t state) { return update_tri_layer_state(state, LAYER_LOWER, LAYER_RAISE, LAYER_ADJUST); } diff --git a/layouts/community/60_ansi_split_bs_rshift/bcat/keymap.c b/layouts/community/60_ansi_split_bs_rshift/bcat/keymap.c index 6bfafc332521..553bf13fd85b 100644 --- a/layouts/community/60_ansi_split_bs_rshift/bcat/keymap.c +++ b/layouts/community/60_ansi_split_bs_rshift/bcat/keymap.c @@ -16,11 +16,7 @@ #include QMK_KEYBOARD_H -enum layer { - LAYER_DEFAULT, - LAYER_FUNCTION_1, - LAYER_FUNCTION_2, -}; +#include "bcat.h" #define LY_FN1 MO(LAYER_FUNCTION_1) #define LY_FN2 MO(LAYER_FUNCTION_2) diff --git a/layouts/community/60_tsangan_hhkb/bcat/keymap.c b/layouts/community/60_tsangan_hhkb/bcat/keymap.c index 05e6462d9037..01ac0bcad1d5 100644 --- a/layouts/community/60_tsangan_hhkb/bcat/keymap.c +++ b/layouts/community/60_tsangan_hhkb/bcat/keymap.c @@ -16,11 +16,7 @@ #include QMK_KEYBOARD_H -enum layer { - LAYER_DEFAULT, - LAYER_FUNCTION_1, - LAYER_FUNCTION_2, -}; +#include "bcat.h" #define LY_FN1 MO(LAYER_FUNCTION_1) #define LY_FN2 MO(LAYER_FUNCTION_2) diff --git a/layouts/community/65_ansi_blocker_split_bs/bcat/keymap.c b/layouts/community/65_ansi_blocker_split_bs/bcat/keymap.c index c91a1b0eaddf..7979a3bcdae7 100644 --- a/layouts/community/65_ansi_blocker_split_bs/bcat/keymap.c +++ b/layouts/community/65_ansi_blocker_split_bs/bcat/keymap.c @@ -16,12 +16,9 @@ #include QMK_KEYBOARD_H -enum layer { - LAYER_DEFAULT, - LAYER_FUNCTION, -}; +#include "bcat.h" -#define LY_FN MO(LAYER_FUNCTION) +#define LY_FN1 MO(LAYER_FUNCTION_1) const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // clang-format off @@ -31,11 +28,11 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSPC, KC_PGUP, KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGDN, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_END, - KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, LY_FN, KC_LEFT, KC_DOWN, KC_RGHT + KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, LY_FN1, KC_LEFT, KC_DOWN, KC_RGHT ), /* Function layer: http://www.keyboard-layout-editor.com/#/gists/f29128427f674c43777f045e363d1b44 */ - [LAYER_FUNCTION] = LAYOUT_65_ansi_blocker_split_bs( + [LAYER_FUNCTION_1] = LAYOUT_65_ansi_blocker_split_bs( _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_DEL, _______, KC_CAPS, NK_TOGG, KC_MPLY, KC_VOLU, KC_MSTP, _______, EEP_RST, RESET, KC_PSCR, KC_SLCK, KC_PAUS, _______, _______, _______, _______, _______, _______, KC_MPRV, KC_VOLD, KC_MNXT, _______, _______, _______, _______, _______, _______, _______, _______, _______, diff --git a/layouts/community/split_3x6_3/bcat/config.h b/layouts/community/split_3x6_3/bcat/config.h index b8743429cf4f..27c91d9a6064 100644 --- a/layouts/community/split_3x6_3/bcat/config.h +++ b/layouts/community/split_3x6_3/bcat/config.h @@ -16,6 +16,8 @@ #pragma once +#define BCAT_ORTHO_LAYERS + #if defined(KEYBOARD_crkbd_rev1) # define EE_HANDS diff --git a/layouts/community/split_3x6_3/bcat/keymap.c b/layouts/community/split_3x6_3/bcat/keymap.c index 4f68c8f84315..ea68993f51f1 100644 --- a/layouts/community/split_3x6_3/bcat/keymap.c +++ b/layouts/community/split_3x6_3/bcat/keymap.c @@ -18,13 +18,6 @@ #include "bcat.h" -enum layer { - LAYER_DEFAULT, - LAYER_LOWER, - LAYER_RAISE, - LAYER_ADJUST, -}; - #define LY_LWR MO(LAYER_LOWER) #define LY_RSE MO(LAYER_RAISE) @@ -65,5 +58,3 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ), // clang-format on }; - -layer_state_t layer_state_set_keymap(layer_state_t state) { return update_tri_layer_state(state, LAYER_LOWER, LAYER_RAISE, LAYER_ADJUST); } diff --git a/users/bcat/bcat.c b/users/bcat/bcat.c index ea496ce5535d..aac8ed0f2a8e 100644 --- a/users/bcat/bcat.c +++ b/users/bcat/bcat.c @@ -16,6 +16,14 @@ #include "bcat.h" +#include +#include + +#include "action.h" +#include "action_layer.h" +#include "keycode.h" +#include "quantum.h" + static int8_t alt_tab_layer = -1; __attribute__((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { return true; } @@ -46,6 +54,9 @@ __attribute__((weak)) layer_state_t layer_state_set_keymap(layer_state_t state) layer_state_t layer_state_set_user(layer_state_t state) { state = layer_state_set_keymap(state); +#if defined(BCAT_ORTHO_LAYERS) + state = update_tri_layer_state(state, LAYER_LOWER, LAYER_RAISE, LAYER_ADJUST); +#endif if (alt_tab_layer >= 0 && !layer_state_cmp(state, alt_tab_layer)) { unregister_code(KC_LALT); alt_tab_layer = -1; diff --git a/users/bcat/bcat.h b/users/bcat/bcat.h index 0dae774ec538..9580b5c76bdf 100644 --- a/users/bcat/bcat.h +++ b/users/bcat/bcat.h @@ -16,8 +16,26 @@ #pragma once -#include "quantum.h" +#include "keymap.h" +/* Layer numbers shared across keymaps. */ +enum user_layer { + /* Base layers: */ + LAYER_DEFAULT, + +#if defined(BCAT_ORTHO_LAYERS) + /* Function layers for ortho (and ergo) boards: */ + LAYER_LOWER, + LAYER_RAISE, + LAYER_ADJUST, +#else + /* Function layers for traditional boards: */ + LAYER_FUNCTION_1, + LAYER_FUNCTION_2, +#endif +}; + +/* Custom keycodes shared across keymaps. */ enum user_keycode { MC_ALTT = SAFE_RANGE, KEYMAP_SAFE_RANGE, From 0e27a3e1ebcff6bcb5fc38fb959b2092d1b98d32 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Sat, 19 Jun 2021 22:30:21 -0500 Subject: [PATCH 04/23] Move keycap aliases into userspace --- keyboards/9key/keymaps/bcat/keymap.c | 2 -- keyboards/eco/keymaps/bcat/keymap.c | 8 -------- keyboards/keebio/bdn9/keymaps/bcat/keymap.c | 2 -- keyboards/keebio/quefrency/keymaps/bcat/keymap.c | 2 -- keyboards/lily58/keymaps/bcat/keymap.c | 8 -------- .../60_ansi_split_bs_rshift/bcat/keymap.c | 3 --- layouts/community/60_tsangan_hhkb/bcat/keymap.c | 3 --- .../65_ansi_blocker_split_bs/bcat/keymap.c | 2 -- layouts/community/split_3x6_3/bcat/keymap.c | 8 -------- users/bcat/bcat.h | 14 ++++++++++++++ 10 files changed, 14 insertions(+), 38 deletions(-) diff --git a/keyboards/9key/keymaps/bcat/keymap.c b/keyboards/9key/keymaps/bcat/keymap.c index fa8678f31200..151d91719ba7 100644 --- a/keyboards/9key/keymaps/bcat/keymap.c +++ b/keyboards/9key/keymaps/bcat/keymap.c @@ -18,8 +18,6 @@ #include "bcat.h" -#define LY_FN1 MO(LAYER_FUNCTION_1) - #define KY_LOCK LCA(KC_L) /* Cinnamon lock screen */ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { diff --git a/keyboards/eco/keymaps/bcat/keymap.c b/keyboards/eco/keymaps/bcat/keymap.c index be1aa89c8d89..cdc8859b3e76 100644 --- a/keyboards/eco/keymaps/bcat/keymap.c +++ b/keyboards/eco/keymaps/bcat/keymap.c @@ -18,14 +18,6 @@ #include "bcat.h" -#define LY_LWR MO(LAYER_LOWER) -#define LY_RSE MO(LAYER_RAISE) - -#define KY_CSPC LCTL(KC_SPC) -#define KY_ZMIN LCTL(KC_EQL) -#define KY_ZMOUT LCTL(KC_MINS) -#define KY_ZMRST LCTL(KC_0) - const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // clang-format off /* Default layer: http://www.keyboard-layout-editor.com/#/gists/2c11371c7a5f7cd08a0132631d3d3281 */ diff --git a/keyboards/keebio/bdn9/keymaps/bcat/keymap.c b/keyboards/keebio/bdn9/keymaps/bcat/keymap.c index 3c1415099813..2028deb4f1a2 100644 --- a/keyboards/keebio/bdn9/keymaps/bcat/keymap.c +++ b/keyboards/keebio/bdn9/keymaps/bcat/keymap.c @@ -18,8 +18,6 @@ #include "bcat.h" -#define LY_FN1 MO(LAYER_FUNCTION_1) - const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // clang-format off [LAYER_DEFAULT] = LAYOUT( diff --git a/keyboards/keebio/quefrency/keymaps/bcat/keymap.c b/keyboards/keebio/quefrency/keymaps/bcat/keymap.c index ce4c9e8f648a..c57e4e79bd39 100644 --- a/keyboards/keebio/quefrency/keymaps/bcat/keymap.c +++ b/keyboards/keebio/quefrency/keymaps/bcat/keymap.c @@ -18,8 +18,6 @@ #include "bcat.h" -#define LY_FN1 MO(LAYER_FUNCTION_1) - const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // clang-format off /* Default layer: http://www.keyboard-layout-editor.com/#/gists/60a262432bb340b37d364a4424f3037b */ diff --git a/keyboards/lily58/keymaps/bcat/keymap.c b/keyboards/lily58/keymaps/bcat/keymap.c index 4545f72b6900..ec524bc9b8ae 100644 --- a/keyboards/lily58/keymaps/bcat/keymap.c +++ b/keyboards/lily58/keymaps/bcat/keymap.c @@ -18,14 +18,6 @@ #include "bcat.h" -#define LY_LWR MO(LAYER_LOWER) -#define LY_RSE MO(LAYER_RAISE) - -#define KY_CSPC LCTL(KC_SPC) -#define KY_ZMIN LCTL(KC_EQL) -#define KY_ZMOUT LCTL(KC_MINS) -#define KY_ZMRST LCTL(KC_0) - const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // clang-format off /* Default layer: http://www.keyboard-layout-editor.com/#/gists/e0eb3af65961e9fd612dcff3ddd88e4f */ diff --git a/layouts/community/60_ansi_split_bs_rshift/bcat/keymap.c b/layouts/community/60_ansi_split_bs_rshift/bcat/keymap.c index 553bf13fd85b..dd2576ea53dd 100644 --- a/layouts/community/60_ansi_split_bs_rshift/bcat/keymap.c +++ b/layouts/community/60_ansi_split_bs_rshift/bcat/keymap.c @@ -18,9 +18,6 @@ #include "bcat.h" -#define LY_FN1 MO(LAYER_FUNCTION_1) -#define LY_FN2 MO(LAYER_FUNCTION_2) - const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // clang-format off /* Default layer: http://www.keyboard-layout-editor.com/#/gists/327b41b5a933b3d44bf60ca9822e85dc */ diff --git a/layouts/community/60_tsangan_hhkb/bcat/keymap.c b/layouts/community/60_tsangan_hhkb/bcat/keymap.c index 01ac0bcad1d5..c1119661a50d 100644 --- a/layouts/community/60_tsangan_hhkb/bcat/keymap.c +++ b/layouts/community/60_tsangan_hhkb/bcat/keymap.c @@ -18,9 +18,6 @@ #include "bcat.h" -#define LY_FN1 MO(LAYER_FUNCTION_1) -#define LY_FN2 MO(LAYER_FUNCTION_2) - const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // clang-format off /* Default layer: http://www.keyboard-layout-editor.com/#/gists/86b33d75aa6f56d8781ab3d8475f4e77 */ diff --git a/layouts/community/65_ansi_blocker_split_bs/bcat/keymap.c b/layouts/community/65_ansi_blocker_split_bs/bcat/keymap.c index 7979a3bcdae7..31876770f6b8 100644 --- a/layouts/community/65_ansi_blocker_split_bs/bcat/keymap.c +++ b/layouts/community/65_ansi_blocker_split_bs/bcat/keymap.c @@ -18,8 +18,6 @@ #include "bcat.h" -#define LY_FN1 MO(LAYER_FUNCTION_1) - const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // clang-format off /* Default layer: http://www.keyboard-layout-editor.com/#/gists/dd675b40cc4df2c7bb78847ac29f5988 */ diff --git a/layouts/community/split_3x6_3/bcat/keymap.c b/layouts/community/split_3x6_3/bcat/keymap.c index ea68993f51f1..72dca7410680 100644 --- a/layouts/community/split_3x6_3/bcat/keymap.c +++ b/layouts/community/split_3x6_3/bcat/keymap.c @@ -18,14 +18,6 @@ #include "bcat.h" -#define LY_LWR MO(LAYER_LOWER) -#define LY_RSE MO(LAYER_RAISE) - -#define KY_CSPC LCTL(KC_SPC) -#define KY_ZMIN LCTL(KC_EQL) -#define KY_ZMOUT LCTL(KC_MINS) -#define KY_ZMRST LCTL(KC_0) - const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // clang-format off /* Default layer: http://www.keyboard-layout-editor.com/#/gists/08d9827d916662a9414f48805aa895a5 */ diff --git a/users/bcat/bcat.h b/users/bcat/bcat.h index 9580b5c76bdf..d2f1e7410394 100644 --- a/users/bcat/bcat.h +++ b/users/bcat/bcat.h @@ -40,3 +40,17 @@ enum user_keycode { MC_ALTT = SAFE_RANGE, KEYMAP_SAFE_RANGE, }; + +/* Keycode aliases shared across keymaps. */ +#define KY_CSPC LCTL(KC_SPC) +#define KY_ZMIN LCTL(KC_EQL) +#define KY_ZMOUT LCTL(KC_MINS) +#define KY_ZMRST LCTL(KC_0) + +#if defined(BCAT_ORTHO_LAYERS) +# define LY_LWR MO(LAYER_LOWER) +# define LY_RSE MO(LAYER_RAISE) +#else +# define LY_FN1 MO(LAYER_FUNCTION_1) +# define LY_FN2 MO(LAYER_FUNCTION_2) +#endif From 38eaf306dceb47a8efdd1e26f1e15a400c499167 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Sat, 19 Jun 2021 22:48:33 -0500 Subject: [PATCH 05/23] Add OLED userspace library and Lily58 OLED setup --- keyboards/lily58/keymaps/bcat/keymap.c | 21 +++++ users/bcat/bcat_oled.c | 108 +++++++++++++++++++++++++ users/bcat/bcat_oled.h | 36 +++++++++ users/bcat/rules.mk | 4 + 4 files changed, 169 insertions(+) create mode 100644 users/bcat/bcat_oled.c create mode 100644 users/bcat/bcat_oled.h diff --git a/keyboards/lily58/keymaps/bcat/keymap.c b/keyboards/lily58/keymaps/bcat/keymap.c index ec524bc9b8ae..2c0a95e8b393 100644 --- a/keyboards/lily58/keymaps/bcat/keymap.c +++ b/keyboards/lily58/keymaps/bcat/keymap.c @@ -18,6 +18,10 @@ #include "bcat.h" +#if defined(OLED_ENABLE) +# include "bcat_oled.h" +#endif + const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // clang-format off /* Default layer: http://www.keyboard-layout-editor.com/#/gists/e0eb3af65961e9fd612dcff3ddd88e4f */ @@ -54,3 +58,20 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ), // clang-format on }; + +#if defined(OLED_ENABLE) +oled_rotation_t oled_init_user(oled_rotation_t rotation) { return is_keyboard_master() ? OLED_ROTATION_270 : OLED_ROTATION_180; } + +void oled_task_user(void) { + if (is_keyboard_master()) { + render_oled_layers(); + oled_advance_page(/*clearPageRemainder=*/false); + render_oled_indicators(); + oled_advance_page(/*clearPageRemainder=*/false); + oled_advance_page(/*clearPageRemainder=*/false); + render_oled_wpm(); + } else { + render_oled_logo(); + } +} +#endif diff --git a/users/bcat/bcat_oled.c b/users/bcat/bcat_oled.c new file mode 100644 index 000000000000..9ed9faa29532 --- /dev/null +++ b/users/bcat/bcat_oled.c @@ -0,0 +1,108 @@ +/* Copyright 2021 Jonathan Rascher + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "bcat_oled.h" + +#include +#include + +#include "bcat.h" +#include "led.h" +#include "oled_driver.h" +#include "progmem.h" +#include "quantum.h" +#include "timer.h" +#include "wpm.h" + +static const char TRIANGLE_UP = 0x1e; +static const char TRIANGLE_DOWN = 0x1f; + +void render_oled_logo(void) { + static const char PROGMEM logo[] = { + // clang-format off + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, + 0x00, + // clang-format on + }; + + oled_write_P(logo, /*invert=*/false); +} + +void render_oled_layers(void) { + oled_advance_char(); + oled_advance_char(); +#if defined(BCAT_ORTHO_LAYERS) + oled_write_char(IS_LAYER_ON(LAYER_LOWER) ? TRIANGLE_DOWN : ' ', /*invert=*/false); + oled_advance_char(); + oled_write_char(IS_LAYER_ON(LAYER_RAISE) ? TRIANGLE_UP : ' ', /*invert=*/false); +#else + switch (get_highest_layer(layer_state)) { + case LAYER_FUNCTION_1: + oled_write_P(PSTR("FN1"), /*invert=*/false); + break; + case LAYER_FUNCTION_2: + oled_write_P(PSTR("FN2"), /*invert=*/false); + break; + default: + oled_write_P(PSTR(" "), /*invert=*/false); + break; + } +#endif +} + +void render_oled_indicators(void) { + led_t led_state = host_keyboard_led_state(); + oled_advance_char(); + oled_advance_char(); + oled_write_P(led_state.num_lock ? PSTR("NUM") : PSTR(" "), /*invert=*/false); + oled_advance_char(); + oled_advance_char(); + oled_write_P(led_state.caps_lock ? PSTR("CAP") : PSTR(" "), /*invert=*/false); + oled_advance_char(); + oled_advance_char(); + oled_write_P(led_state.scroll_lock ? PSTR("SCR") : PSTR(" "), /*invert=*/false); +} + +void render_oled_wpm(void) { + static const uint16_t UPDATE_INTERVAL_MILLIS = 100; + static uint32_t update_timeout = 0; + + if (timer_expired32(timer_read32(), update_timeout)) { + uint8_t wpm = get_current_wpm(); + + char wpm_str[] = " "; + if (wpm > 0) { + wpm_str[2] = '0' + wpm % 10; + } + if (wpm >= 10) { + wpm_str[1] = '0' + wpm / 10 % 10; + } + if (wpm >= 100) { + wpm_str[0] = '0' + wpm / 100 % 10; + } + + oled_advance_char(); + oled_advance_char(); + oled_write_P(wpm > 0 ? PSTR("WPM") : PSTR(" "), /*invert=*/false); + oled_advance_char(); + oled_advance_char(); + oled_write(wpm_str, /*invert=*/false); + + update_timeout = timer_read32() + UPDATE_INTERVAL_MILLIS; + } +} diff --git a/users/bcat/bcat_oled.h b/users/bcat/bcat_oled.h new file mode 100644 index 000000000000..398a00e1416b --- /dev/null +++ b/users/bcat/bcat_oled.h @@ -0,0 +1,36 @@ +/* Copyright 2021 Jonathan Rascher + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +/* Renders the logo embedded at the "standard" location in the OLED font at the + * cursor. By default, this is a "QMK Firmware" logo, but many keyboards put + * their own logo here instead. Occupies 21x3 character cells. + */ +void render_oled_logo(void); + +/* Note: Functions below assume a vertical OLED that is 32px (5 chars) wide. */ + +/* Renders layer status at the cursor. Occupies 5x1 character cells. */ +void render_oled_layers(void); + +/* Renders LED indicators (Num/Caps/Scroll Lock) at the cursor. Occupies 5x3 + * character cells. + */ +void render_oled_indicators(void); + +/* Renders calculated WPM count at the cursor. Occupies 5x2 character cells. */ +void render_oled_wpm(void); diff --git a/users/bcat/rules.mk b/users/bcat/rules.mk index b6fd54cd0836..9a376e0907fd 100644 --- a/users/bcat/rules.mk +++ b/users/bcat/rules.mk @@ -19,6 +19,10 @@ SRC += bcat.c # Include additional utilities that extend optional QMK features only enabled # on some keyboards. +ifeq ($(strip $(OLED_ENABLE)), yes) + SRC += bcat_oled.c + WPM_ENABLE = yes # for WPM and animated "keyboard pet" widgets +endif ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) SRC += bcat_rgblight.c endif From 2c940d50121591e5579c897c581f58e8ddfef965 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Sun, 20 Jun 2021 02:52:19 -0500 Subject: [PATCH 06/23] Add Luna keyboard pet, generic OLED pet framework Luna artwork and original implementation by HellSingCoder, licensed under GPL v2.0. See also: https://github.com/qmk/qmk_firmware/blob/6dfe915e26d7147e6c2bed495d3b01cf5b21e6ec/keyboards/sofle/keymaps/helltm/keymap.c --- keyboards/lily58/keymaps/bcat/keymap.c | 10 +- keyboards/lily58/keymaps/bcat/rules.mk | 2 + users/bcat/bcat.c | 2 + users/bcat/bcat.h | 2 + users/bcat/bcat_oled.c | 120 ++++++++++++++++--- users/bcat/bcat_oled.h | 23 +++- users/bcat/bcat_oled_pet.h | 68 +++++++++++ users/bcat/bcat_oled_pet_luna.c | 156 +++++++++++++++++++++++++ users/bcat/rules.mk | 8 ++ 9 files changed, 373 insertions(+), 18 deletions(-) create mode 100644 users/bcat/bcat_oled_pet.h create mode 100644 users/bcat/bcat_oled_pet_luna.c diff --git a/keyboards/lily58/keymaps/bcat/keymap.c b/keyboards/lily58/keymaps/bcat/keymap.c index 2c0a95e8b393..e32e6cd30de5 100644 --- a/keyboards/lily58/keymaps/bcat/keymap.c +++ b/keyboards/lily58/keymaps/bcat/keymap.c @@ -64,12 +64,18 @@ oled_rotation_t oled_init_user(oled_rotation_t rotation) { return is_keyboard_ma void oled_task_user(void) { if (is_keyboard_master()) { + uint8_t mods = get_mods(); + led_t leds = host_keyboard_led_state(); + uint8_t wpm = get_current_wpm(); + render_oled_layers(); oled_advance_page(/*clearPageRemainder=*/false); - render_oled_indicators(); + render_oled_indicators(leds); oled_advance_page(/*clearPageRemainder=*/false); oled_advance_page(/*clearPageRemainder=*/false); - render_oled_wpm(); + render_oled_wpm(wpm); + + render_oled_pet(/*col=*/0, /*line=*/12, mods, leds, wpm); } else { render_oled_logo(); } diff --git a/keyboards/lily58/keymaps/bcat/rules.mk b/keyboards/lily58/keymaps/bcat/rules.mk index c87b447c1e3d..62d1007a54d6 100644 --- a/keyboards/lily58/keymaps/bcat/rules.mk +++ b/keyboards/lily58/keymaps/bcat/rules.mk @@ -1 +1,3 @@ +BCAT_OLED_PET = luna + BOOTLOADER = atmel-dfu # Elite-C diff --git a/users/bcat/bcat.c b/users/bcat/bcat.c index aac8ed0f2a8e..53a628154604 100644 --- a/users/bcat/bcat.c +++ b/users/bcat/bcat.c @@ -26,9 +26,11 @@ static int8_t alt_tab_layer = -1; +__attribute__((weak)) void process_record_oled(uint16_t keycode, const keyrecord_t *record) {} __attribute__((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { return true; } bool process_record_user(uint16_t keycode, keyrecord_t *record) { + process_record_oled(keycode, record); if (!process_record_keymap(keycode, record)) { return false; } diff --git a/users/bcat/bcat.h b/users/bcat/bcat.h index d2f1e7410394..4a88acba7d93 100644 --- a/users/bcat/bcat.h +++ b/users/bcat/bcat.h @@ -16,6 +16,8 @@ #pragma once +#include + #include "keymap.h" /* Layer numbers shared across keymaps. */ diff --git a/users/bcat/bcat_oled.c b/users/bcat/bcat_oled.c index 9ed9faa29532..373f9ca37633 100644 --- a/users/bcat/bcat_oled.c +++ b/users/bcat/bcat_oled.c @@ -20,15 +20,23 @@ #include #include "bcat.h" +#include "keycode.h" #include "led.h" #include "oled_driver.h" #include "progmem.h" #include "quantum.h" #include "timer.h" -#include "wpm.h" -static const char TRIANGLE_UP = 0x1e; -static const char TRIANGLE_DOWN = 0x1f; +#if defined(BCAT_OLED_PET) +# include "bcat_oled_pet.h" +#endif + +#define TRIANGLE_UP 0x1e +#define TRIANGLE_DOWN 0x1f + +#if defined(BCAT_OLED_PET) +static bool oled_pet_should_jump = false; +#endif void render_oled_logo(void) { static const char PROGMEM logo[] = { @@ -65,26 +73,23 @@ void render_oled_layers(void) { #endif } -void render_oled_indicators(void) { - led_t led_state = host_keyboard_led_state(); +void render_oled_indicators(led_t leds) { oled_advance_char(); oled_advance_char(); - oled_write_P(led_state.num_lock ? PSTR("NUM") : PSTR(" "), /*invert=*/false); + oled_write_P(leds.num_lock ? PSTR("NUM") : PSTR(" "), /*invert=*/false); oled_advance_char(); oled_advance_char(); - oled_write_P(led_state.caps_lock ? PSTR("CAP") : PSTR(" "), /*invert=*/false); + oled_write_P(leds.caps_lock ? PSTR("CAP") : PSTR(" "), /*invert=*/false); oled_advance_char(); oled_advance_char(); - oled_write_P(led_state.scroll_lock ? PSTR("SCR") : PSTR(" "), /*invert=*/false); + oled_write_P(leds.scroll_lock ? PSTR("SCR") : PSTR(" "), /*invert=*/false); } -void render_oled_wpm(void) { - static const uint16_t UPDATE_INTERVAL_MILLIS = 100; - static uint32_t update_timeout = 0; +void render_oled_wpm(uint8_t wpm) { + static const uint16_t UPDATE_MILLIS = 100; + static uint32_t update_timeout = 0; if (timer_expired32(timer_read32(), update_timeout)) { - uint8_t wpm = get_current_wpm(); - char wpm_str[] = " "; if (wpm > 0) { wpm_str[2] = '0' + wpm % 10; @@ -103,6 +108,93 @@ void render_oled_wpm(void) { oled_advance_char(); oled_write(wpm_str, /*invert=*/false); - update_timeout = timer_read32() + UPDATE_INTERVAL_MILLIS; + update_timeout = timer_read32() + UPDATE_MILLIS; + } +} + +#if defined(BCAT_OLED_PET) +void process_record_oled(uint16_t keycode, const keyrecord_t *record) { + switch (keycode) { + case KC_SPACE: + if (oled_pet_can_jump()) { + oled_pet_should_jump = record->event.pressed; + } + break; + default: + break; + } +} + +static void redraw_oled_pet(uint8_t col, uint8_t line, bool jumping, oled_pet_state_t state, uint8_t frame) { + oled_set_cursor(col, line); + if (jumping) { + oled_write_raw_P(oled_pet_frame(state, frame), oled_pet_frame_bytes()); + oled_set_cursor(col, line + oled_pet_frame_lines()); + oled_advance_page(/*clearPageRemainder=*/true); + } else { + oled_advance_page(/*clearPageRemainder=*/true); + oled_write_raw_P(oled_pet_frame(state, frame), oled_pet_frame_bytes()); + oled_set_cursor(col, line + oled_pet_frame_lines() + 1); + } +} + +bool render_oled_pet(uint8_t col, uint8_t line, uint8_t mods, led_t leds, uint8_t wpm) { + /* Whether or not the animation state or frame has changed since the pet + * was last drawn. We track this to avoid redrawing the same frame + * repeatedly during idle. This allows the caller to draw on top of the pet + * without preventing the OLED from ever going to sleep. + */ + static bool animation_changed = true; + + /* Current animation state and frame to redraw. */ + static oled_pet_state_t state = OLED_PET_IDLE; + static uint8_t frame = 0; + + /* Minimum time until the pet comes down after jumping. */ + static const uint16_t JUMP_MILLIS = 200; + static bool jumping = false; + static uint32_t jump_timeout = 0; + + /* Time until next animation state/frame change. */ + static uint32_t update_timeout = 0; + + /* If the user pressed the jump key, immediately redraw instead of waiting + * for the animation frame to update. That way, the pet appears to respond + * to jump commands quickly rather than lagging. If the user released the + * jump key, wait for the jump timeout to avoid overly brief jumps. + */ + bool redraw = animation_changed; + if (oled_pet_should_jump && !jumping) { + redraw = true; + jumping = true; + jump_timeout = timer_read32() + JUMP_MILLIS; + } else if (!oled_pet_should_jump && jumping && timer_expired32(timer_read32(), jump_timeout)) { + redraw = true; + jumping = false; + } + + if (redraw) { + redraw_oled_pet(col, line, jumping, state, frame); } + + /* If the update timer expired, recompute the pet's animation state and + * possibly advance to the next frame. + */ + animation_changed = false; + if (timer_expired32(timer_read32(), update_timeout)) { + oled_pet_state_t new_state = oled_pet_state(mods, leds, wpm); + if (state != new_state) { + state = new_state; + animation_changed = true; + } + /* If the user stopped typing, cycle around to the initial frame. */ + if (wpm > 0 || state != OLED_PET_IDLE || frame != 0) { + frame = (frame + 1) % oled_pet_num_frames(); + update_timeout = timer_read32() + oled_pet_update_millis(wpm); + animation_changed = true; + } + } + + return redraw; } +#endif diff --git a/users/bcat/bcat_oled.h b/users/bcat/bcat_oled.h index 398a00e1416b..d2962e37f312 100644 --- a/users/bcat/bcat_oled.h +++ b/users/bcat/bcat_oled.h @@ -16,6 +16,11 @@ #pragma once +#include +#include + +#include "led.h" + /* Renders the logo embedded at the "standard" location in the OLED font at the * cursor. By default, this is a "QMK Firmware" logo, but many keyboards put * their own logo here instead. Occupies 21x3 character cells. @@ -30,7 +35,21 @@ void render_oled_layers(void); /* Renders LED indicators (Num/Caps/Scroll Lock) at the cursor. Occupies 5x3 * character cells. */ -void render_oled_indicators(void); +void render_oled_indicators(led_t leds); /* Renders calculated WPM count at the cursor. Occupies 5x2 character cells. */ -void render_oled_wpm(void); +void render_oled_wpm(uint8_t wpm); + +#if defined(BCAT_OLED_PET) +/* Renders an animated critter at the cursor that can respond to keystrokes, + * typing speed, etc. Should be about 5 character cells wide, but exact height + * varies depending on the specific OLED pet implementation linked in. + * + * The rendered image will be one line taller than the OLED pet's animation + * frame height to accommodate pets that "jump" when the spacebar is pressed. + * + * Returns whether or not a new frame of the animation was displayed, in case + * the caller wants to draw atop the pet animation (e.g., in empty space). + */ +bool render_oled_pet(uint8_t col, uint8_t line, uint8_t mods, led_t leds, uint8_t wpm); +#endif diff --git a/users/bcat/bcat_oled_pet.h b/users/bcat/bcat_oled_pet.h new file mode 100644 index 000000000000..a67024e7a176 --- /dev/null +++ b/users/bcat/bcat_oled_pet.h @@ -0,0 +1,68 @@ +/* Copyright 2021 Jonathan Rascher + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* Common interface for an OLED pet (animated critter that reacts to typing). + * Please link exactly one accompanying .c file to implement these functions. + */ + +#pragma once + +#include +#include + +#include "led.h" + +/* Opaque token identifying what animation state the pet is currently in. */ +typedef uint8_t oled_pet_state_t; + +/* The default animation state that every OLED pet must support. */ +#define OLED_PET_IDLE 0 + +/* Returns the number of frames in the animation. Note that every state the pet + * supports is expected to have the same number of frames. + */ +uint8_t oled_pet_num_frames(void); + +/* Returns the number of bytes used to represent the animation frame (in + * oled_write_raw_P format). Note that every state the pet supports is expected + * to have the same frame size. + */ +uint16_t oled_pet_frame_bytes(void); + +/* Returns the number of lines of the OLED occupied by the animation. Note that + * every state the pet supports is expected to have the same frame size. The + * returned value does not include the one line of padding that render_oled_pet + * uses to account for "jumping". + */ +uint8_t oled_pet_frame_lines(void); + +/* Returns whether or not the OLED pet should "jump" when the spacebar is + * pressed. (The render_oled_pet implementation shifts the animation frame up + * one line when this happens.) + */ +bool oled_pet_can_jump(void); + +/* Returns the current state to be animated based on current keyboard state. */ +oled_pet_state_t oled_pet_state(uint8_t mods, led_t leds, uint8_t wpm); + +/* Returns the delay before the next animation frame should be displayed. */ +uint16_t oled_pet_update_millis(uint8_t wpm); + +/* Returns a PROGMEM pointer to the specified animation frame buffer for the + * specified state. The animation frame has length given by + * oled_pet_frame_bytes and is formatted as expected by oled_write_raw_P. + */ +const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame); diff --git a/users/bcat/bcat_oled_pet_luna.c b/users/bcat/bcat_oled_pet_luna.c new file mode 100644 index 000000000000..e45793e5858c --- /dev/null +++ b/users/bcat/bcat_oled_pet_luna.c @@ -0,0 +1,156 @@ +/* Copyright 2021 HellSingCoder + * Copyright 2021 Jonathan Rascher + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* OLED pet "Luna" (animated doggo) originally by HellSingCoder + * (https://www.simonepellegrino.com/) and licensed under GPL v2.0, adapted to + * fit the OLED pet framework in bcat's userspace. + * + * The animation is 32x24 pixels (3 lines tall). + * + * Walks or runs in response to typing speed. Sneaks when Ctrl is pressed and + * barks when Caps Lock is on. Jumps when space is pressed. + * + * Original source: + * https://github.com/qmk/qmk_firmware/blob/6dfe915e26d7147e6c2bed495d3b01cf5b21e6ec/keyboards/sofle/keymaps/helltm/keymap.c + */ + +#include "bcat_oled_pet.h" + +#include +#include + +#include "keycode.h" +#include "led.h" +#include "progmem.h" + +enum state { + OLED_PET_WALK = OLED_PET_IDLE + 1, + OLED_PET_RUN, + OLED_PET_SNEAK, + OLED_PET_BARK, +}; + +#define NUM_FRAMES 2 +#define FRAME_BYTES 96 /* (32 pixel) * (24 pixel) / (8 pixel/byte) */ + +uint8_t oled_pet_num_frames(void) { return NUM_FRAMES; } +uint16_t oled_pet_frame_bytes(void) { return FRAME_BYTES; } +uint8_t oled_pet_frame_lines(void) { return 3 /* (24 pixel) / (8 pixel/line) */; } +bool oled_pet_can_jump(void) { return true; } + +oled_pet_state_t oled_pet_state(uint8_t mods, led_t led_state, uint8_t wpm) { + if (led_state.caps_lock) { + return OLED_PET_BARK; + } + if (mods & MOD_MASK_CTRL) { + return OLED_PET_SNEAK; + } + if (wpm >= 100) { + return OLED_PET_RUN; + } + if (wpm >= 25) { + return OLED_PET_WALK; + } + return OLED_PET_IDLE; +} + +uint16_t oled_pet_update_millis(uint8_t wpm) { return 200; } + +const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame) { + static const char PROGMEM IDLE_FRAMES[NUM_FRAMES][FRAME_BYTES] = { + // clang-format off + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x1c, 0x02, 0x05, 0x02, 0x24, 0x04, 0x04, 0x02, 0xa9, 0x1e, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x10, 0x08, 0x68, 0x10, 0x08, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x82, 0x7c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x0c, 0x10, 0x10, 0x20, 0x20, 0x20, 0x28, 0x3e, 0x1c, 0x20, 0x20, 0x3e, 0x0f, 0x11, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x1c, 0x02, 0x05, 0x02, 0x24, 0x04, 0x04, 0x02, 0xa9, 0x1e, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x90, 0x08, 0x18, 0x60, 0x10, 0x08, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x0e, 0x82, 0x7c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x0c, 0x10, 0x10, 0x20, 0x20, 0x20, 0x28, 0x3e, 0x1c, 0x20, 0x20, 0x3e, 0x0f, 0x11, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + // clang-format on + }; + static const char PROGMEM WALK_FRAMES[NUM_FRAMES][FRAME_BYTES] = { + // clang-format off + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x90, 0x90, 0x90, 0xa0, 0xc0, 0x80, 0x80, 0x80, 0x70, 0x08, 0x14, 0x08, 0x90, 0x10, 0x10, 0x08, 0xa4, 0x78, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x08, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0xea, 0x10, 0x0f, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1c, 0x20, 0x20, 0x3c, 0x0f, 0x11, 0x1f, 0x03, 0x06, 0x18, 0x20, 0x20, 0x3c, 0x0c, 0x12, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x20, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x10, 0x28, 0x10, 0x20, 0x20, 0x20, 0x10, 0x48, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x20, 0xf8, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x30, 0xd5, 0x20, 0x1f, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x20, 0x30, 0x0c, 0x02, 0x05, 0x09, 0x12, 0x1e, 0x02, 0x1c, 0x14, 0x08, 0x10, 0x20, 0x2c, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + // clang-format on + }; + static const char PROGMEM RUN_FRAMES[NUM_FRAMES][FRAME_BYTES] = { + // clang-format off + { + 0x00, 0x00, 0x00, 0x00, 0xe0, 0x10, 0x08, 0x08, 0xc8, 0xb0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x40, 0x40, 0x3c, 0x14, 0x04, 0x08, 0x90, 0x18, 0x04, 0x08, 0xb0, 0x40, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0xc4, 0xa4, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc8, 0x58, 0x28, 0x2a, 0x10, 0x0f, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x09, 0x04, 0x04, 0x04, 0x04, 0x02, 0x03, 0x02, 0x01, 0x01, 0x02, 0x02, 0x04, 0x08, 0x10, 0x26, 0x2b, 0x32, 0x04, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + { + 0x00, 0x00, 0x00, 0xe0, 0x10, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x78, 0x28, 0x08, 0x10, 0x20, 0x30, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x04, 0x08, 0x10, 0x11, 0xf9, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0xb0, 0x50, 0x55, 0x20, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x0c, 0x10, 0x20, 0x28, 0x37, 0x02, 0x1e, 0x20, 0x20, 0x18, 0x0c, 0x14, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + // clang-format on + }; + static const char PROGMEM SNEAK_FRAMES[NUM_FRAMES][FRAME_BYTES] = { + // clang-format off + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x40, 0x40, 0x80, 0x00, 0x80, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1e, 0x21, 0xf0, 0x04, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 0x04, 0x04, 0x04, 0x03, 0x01, 0x00, 0x00, 0x09, 0x01, 0x80, 0x80, 0xab, 0x04, 0xf8, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1c, 0x20, 0x20, 0x3c, 0x0f, 0x11, 0x1f, 0x02, 0x06, 0x18, 0x20, 0x20, 0x38, 0x08, 0x10, 0x18, 0x04, 0x04, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xa0, 0x20, 0x40, 0x80, 0xc0, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x3e, 0x41, 0xf0, 0x04, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x40, 0x40, 0x55, 0x82, 0x7c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x20, 0x30, 0x0c, 0x02, 0x05, 0x09, 0x12, 0x1e, 0x04, 0x18, 0x10, 0x08, 0x10, 0x20, 0x28, 0x34, 0x06, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + // clang-format on + }; + static const char PROGMEM BARK_FRAMES[NUM_FRAMES][FRAME_BYTES] = { + // clang-format off + { + 0x00, 0xc0, 0x20, 0x10, 0xd0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x3c, 0x14, 0x04, 0x08, 0x90, 0x18, 0x04, 0x08, 0xb0, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x04, 0x08, 0x10, 0x11, 0xf9, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc8, 0x48, 0x28, 0x2a, 0x10, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x0c, 0x10, 0x20, 0x28, 0x37, 0x02, 0x02, 0x04, 0x08, 0x10, 0x26, 0x2b, 0x32, 0x04, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + { + 0x00, 0xe0, 0x10, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x2c, 0x14, 0x04, 0x08, 0x90, 0x18, 0x04, 0x08, 0xb0, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x04, 0x08, 0x10, 0x11, 0xf9, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0x48, 0x28, 0x2a, 0x10, 0x0f, 0x20, 0x4a, 0x09, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x0c, 0x10, 0x20, 0x28, 0x37, 0x02, 0x02, 0x04, 0x08, 0x10, 0x26, 0x2b, 0x32, 0x04, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + // clang-format on + }; + switch (state) { + case OLED_PET_WALK: + return WALK_FRAMES[frame]; + case OLED_PET_RUN: + return RUN_FRAMES[frame]; + case OLED_PET_SNEAK: + return SNEAK_FRAMES[frame]; + case OLED_PET_BARK: + return BARK_FRAMES[frame]; + default: + return IDLE_FRAMES[frame]; + } +} diff --git a/users/bcat/rules.mk b/users/bcat/rules.mk index 9a376e0907fd..29977d15a769 100644 --- a/users/bcat/rules.mk +++ b/users/bcat/rules.mk @@ -22,7 +22,15 @@ SRC += bcat.c ifeq ($(strip $(OLED_ENABLE)), yes) SRC += bcat_oled.c WPM_ENABLE = yes # for WPM and animated "keyboard pet" widgets + + # OLED pets (animated critters that react to typing) take up a lot of + # firmware space, so only compile one, and only if requested. + ifeq ($(strip $(BCAT_OLED_PET)), luna) + SRC += bcat_oled_pet_luna.c + OPT_DEFS += -DBCAT_OLED_PET + endif endif + ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) SRC += bcat_rgblight.c endif From d42d56782fe8b9f327f43d0e0eedf753da58dc63 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Sun, 20 Jun 2021 17:04:52 -0500 Subject: [PATCH 07/23] Use OLED on bcat's Crkbd I had to turn off a few unused features to address firmware size limits. --- layouts/community/split_3x6_3/bcat/config.h | 5 ++++ layouts/community/split_3x6_3/bcat/keymap.c | 27 +++++++++++++++++++++ layouts/community/split_3x6_3/bcat/rules.mk | 4 +++ users/bcat/config.h | 17 +++++++++++-- users/bcat/rules.mk | 3 +++ 5 files changed, 54 insertions(+), 2 deletions(-) diff --git a/layouts/community/split_3x6_3/bcat/config.h b/layouts/community/split_3x6_3/bcat/config.h index 27c91d9a6064..81377ba16813 100644 --- a/layouts/community/split_3x6_3/bcat/config.h +++ b/layouts/community/split_3x6_3/bcat/config.h @@ -21,6 +21,11 @@ #if defined(KEYBOARD_crkbd_rev1) # define EE_HANDS +# if defined(OLED_ENABLE) +# undef OLED_FONT_H +# define OLED_FONT_H "lib/glcdfont.c" +# endif + # if defined(RGB_MATRIX_ENABLE) /* Limit max RGB LED current to avoid tripping controller fuse. */ # undef RGB_MATRIX_MAXIMUM_BRIGHTNESS diff --git a/layouts/community/split_3x6_3/bcat/keymap.c b/layouts/community/split_3x6_3/bcat/keymap.c index 72dca7410680..58a5ae9bf88c 100644 --- a/layouts/community/split_3x6_3/bcat/keymap.c +++ b/layouts/community/split_3x6_3/bcat/keymap.c @@ -18,6 +18,10 @@ #include "bcat.h" +#if defined(OLED_ENABLE) +# include "bcat_oled.h" +#endif + const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // clang-format off /* Default layer: http://www.keyboard-layout-editor.com/#/gists/08d9827d916662a9414f48805aa895a5 */ @@ -50,3 +54,26 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ), // clang-format on }; + +#if defined(OLED_ENABLE) +oled_rotation_t oled_init_user(oled_rotation_t rotation) { return is_keyboard_master() ? OLED_ROTATION_270 : OLED_ROTATION_180; } + +void oled_task_user(void) { + if (is_keyboard_master()) { + uint8_t mods = get_mods(); + led_t leds = host_keyboard_led_state(); + uint8_t wpm = get_current_wpm(); + + render_oled_layers(); + oled_advance_page(/*clearPageRemainder=*/false); + render_oled_indicators(leds); + oled_advance_page(/*clearPageRemainder=*/false); + oled_advance_page(/*clearPageRemainder=*/false); + render_oled_wpm(wpm); + + render_oled_pet(/*col=*/0, /*line=*/12, mods, leds, wpm); + } else { + render_oled_logo(); + } +} +#endif diff --git a/layouts/community/split_3x6_3/bcat/rules.mk b/layouts/community/split_3x6_3/bcat/rules.mk index 5ee614b192ba..29e52b92db5a 100644 --- a/layouts/community/split_3x6_3/bcat/rules.mk +++ b/layouts/community/split_3x6_3/bcat/rules.mk @@ -1,5 +1,9 @@ +BCAT_OLED_PET = luna + ifeq ($(strip $(KEYBOARD)), crkbd/rev1) BOOTLOADER = atmel-dfu # Elite-C + OLED_ENABLE = yes # dual 128x32 OLED screens + OLED_DRIVER = SSD1306 RGB_MATRIX_ENABLE = yes # per-key RGB and underglow endif diff --git a/users/bcat/config.h b/users/bcat/config.h index 5bb93f3833e5..c0958272021a 100644 --- a/users/bcat/config.h +++ b/users/bcat/config.h @@ -14,6 +14,12 @@ * along with this program. If not, see . */ +/* Enable NKRO by default. All my devices support this, and it enables me to + * dispense with the NK_TOGG key, thus saving firmware space by not compiling + * magic keycode support. + */ +#define FORCE_NKRO + /* Wait between tap_code register and unregister to fix flaky media keys. */ #undef TAP_CODE_DELAY @@ -46,8 +52,9 @@ # define RGB_MATRIX_VAL_STEP 17 # define RGB_MATRIX_SPD_STEP 17 -/* Turn on additional RGB animations. */ -# define RGB_MATRIX_FRAMEBUFFER_EFFECTS +/* Turn on reactive RGB animations. (We don't enable + * RGB_MATRIX_FRAMEBUFFER_EFFECTS due to AVR size limits.) + */ # define RGB_MATRIX_KEYPRESSES #endif @@ -77,3 +84,9 @@ # define BACKLIGHT_LEVELS 7 #endif + +/* Turn off unused config options to reduce firmware size. */ +#define LAYER_STATE_8BIT +#define NO_ACTION_ONESHOT +#undef LOCKING_RESYNC_ENABLE +#undef LOCKING_SUPPORT_ENABLE diff --git a/users/bcat/rules.mk b/users/bcat/rules.mk index 29977d15a769..2659ed96f4bb 100644 --- a/users/bcat/rules.mk +++ b/users/bcat/rules.mk @@ -51,8 +51,11 @@ SLEEP_LED_ENABLE = no # Disable other unused options on all keyboards. AUTO_SHIFT_ENABLE = no COMBO_ENABLE = no +GRAVE_ESC_ENABLE = no KEY_LOCK_ENABLE = no LEADER_ENABLE = no +MAGIC_ENABLE = no +SPACE_CADET_ENABLE = no SWAP_HANDS_ENABLE = no TAP_DANCE_ENABLE = no UCIS_ENABLE = no From eed58f25b915bd7a0457c5d8e77d02773fdcc79e Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Sun, 20 Jun 2021 17:34:14 -0500 Subject: [PATCH 08/23] Remove vestigial NK_TOGG keybindings --- keyboards/eco/keymaps/bcat/keymap.c | 2 +- keyboards/eco/keymaps/bcat/readme.md | 2 +- keyboards/keebio/quefrency/keymaps/bcat/keymap.c | 2 +- keyboards/keebio/quefrency/keymaps/bcat/readme.md | 2 +- keyboards/lily58/keymaps/bcat/keymap.c | 2 +- keyboards/lily58/keymaps/bcat/readme.md | 2 +- layouts/community/60_ansi_split_bs_rshift/bcat/keymap.c | 2 +- layouts/community/60_ansi_split_bs_rshift/bcat/readme.md | 2 +- layouts/community/60_tsangan_hhkb/bcat/keymap.c | 2 +- layouts/community/60_tsangan_hhkb/bcat/readme.md | 2 +- layouts/community/65_ansi_blocker_split_bs/bcat/keymap.c | 2 +- layouts/community/65_ansi_blocker_split_bs/bcat/readme.md | 2 +- layouts/community/split_3x6_3/bcat/keymap.c | 2 +- layouts/community/split_3x6_3/bcat/readme.md | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/keyboards/eco/keymaps/bcat/keymap.c b/keyboards/eco/keymaps/bcat/keymap.c index cdc8859b3e76..8c50a9ed5583 100644 --- a/keyboards/eco/keymaps/bcat/keymap.c +++ b/keyboards/eco/keymaps/bcat/keymap.c @@ -43,7 +43,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ), /* Adjust layer: http://www.keyboard-layout-editor.com/#/gists/b18aafa0327d7e83eaf485546c067a21 */ [LAYER_ADJUST] = LAYOUT( - _______, NK_TOGG, KC_MPLY, KC_VOLU, KC_MSTP, _______, _______, _______, EEP_RST, RESET, _______, _______, _______, _______, + _______, _______, KC_MPLY, KC_VOLU, KC_MSTP, _______, _______, _______, EEP_RST, RESET, _______, _______, _______, _______, _______, _______, KC_MPRV, KC_VOLD, KC_MNXT, _______, _______, _______, RGB_RMOD, RGB_VAD, RGB_VAI, RGB_MOD, RGB_SPI, _______, _______, _______, _______, KC_MUTE, _______, _______, _______, _______, RGB_HUI, RGB_SAD, RGB_SAI, RGB_HUD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_TOG, _______, _______, _______, _______, _______ diff --git a/keyboards/eco/keymaps/bcat/readme.md b/keyboards/eco/keymaps/bcat/readme.md index 85e2615512fe..fd9e1bea7332 100644 --- a/keyboards/eco/keymaps/bcat/readme.md +++ b/keyboards/eco/keymaps/bcat/readme.md @@ -39,6 +39,6 @@ nothing really useful to bind them to anyway. ## Adjust layer -![Adjust layer layout](https://i.imgur.com/J2rOshm.png) +![Adjust layer layout](https://i.imgur.com/63vm0ke.png) ([KLE](http://www.keyboard-layout-editor.com/#/gists/b18aafa0327d7e83eaf485546c067a21)) diff --git a/keyboards/keebio/quefrency/keymaps/bcat/keymap.c b/keyboards/keebio/quefrency/keymaps/bcat/keymap.c index c57e4e79bd39..3dd48623fa85 100644 --- a/keyboards/keebio/quefrency/keymaps/bcat/keymap.c +++ b/keyboards/keebio/quefrency/keymaps/bcat/keymap.c @@ -31,7 +31,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* Function layer: http://www.keyboard-layout-editor.com/#/gists/59636898946da51f91fb290f8e078b4d */ [LAYER_FUNCTION_1] = LAYOUT_65( _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_DEL, RGB_HUI, - KC_CAPS, NK_TOGG, KC_MPLY, KC_VOLU, KC_MSTP, _______, EEP_RST, RESET, KC_PSCR, KC_SLCK, KC_PAUS, _______, _______, _______, RGB_SAI, + KC_CAPS, _______, KC_MPLY, KC_VOLU, KC_MSTP, _______, EEP_RST, RESET, KC_PSCR, KC_SLCK, KC_PAUS, _______, _______, _______, RGB_SAI, _______, _______, KC_MPRV, KC_VOLD, KC_MNXT, _______, _______, _______, _______, _______, _______, _______, RGB_TOG, RGB_SAD, _______, KC_APP, _______, KC_MUTE, _______, _______, _______, _______, _______, _______, _______, _______, RGB_VAI, RGB_HUD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_RMOD, RGB_VAD, RGB_MOD diff --git a/keyboards/keebio/quefrency/keymaps/bcat/readme.md b/keyboards/keebio/quefrency/keymaps/bcat/readme.md index 914aa84b6b10..59a691654d92 100644 --- a/keyboards/keebio/quefrency/keymaps/bcat/readme.md +++ b/keyboards/keebio/quefrency/keymaps/bcat/readme.md @@ -12,6 +12,6 @@ ESDF cluster), and RGB controls in the function layer (on the arrow/nav keys). ## Function layer -![Function layer layout](https://i.imgur.com/Fzshl0F.png) +![Function layer layout](https://i.imgur.com/7oCdN86.png) ([KLE](http://www.keyboard-layout-editor.com/#/gists/59636898946da51f91fb290f8e078b4d)) diff --git a/keyboards/lily58/keymaps/bcat/keymap.c b/keyboards/lily58/keymaps/bcat/keymap.c index e32e6cd30de5..f311dccb4bcc 100644 --- a/keyboards/lily58/keymaps/bcat/keymap.c +++ b/keyboards/lily58/keymaps/bcat/keymap.c @@ -51,7 +51,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* Adjust layer: http://www.keyboard-layout-editor.com/#/gists/8f6a3f08350a9bbe1d414b22bca4e6c7 */ [LAYER_ADJUST] = LAYOUT( _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, - _______, NK_TOGG, KC_MPLY, KC_VOLU, KC_MSTP, _______, EEP_RST, RESET, _______, _______, _______, _______, + _______, _______, KC_MPLY, KC_VOLU, KC_MSTP, _______, EEP_RST, RESET, _______, _______, _______, _______, _______, _______, KC_MPRV, KC_VOLD, KC_MNXT, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MUTE, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ diff --git a/keyboards/lily58/keymaps/bcat/readme.md b/keyboards/lily58/keymaps/bcat/readme.md index de03526a8bf9..8b0e77e1b7bf 100644 --- a/keyboards/lily58/keymaps/bcat/readme.md +++ b/keyboards/lily58/keymaps/bcat/readme.md @@ -37,6 +37,6 @@ back/forward navigation keys. ## Adjust layer -![Adjust layer layout](https://i.imgur.com/Q3PGsiK.png) +![Adjust layer layout](https://i.imgur.com/XC2eR2M.png) ([KLE](http://www.keyboard-layout-editor.com/#/gists/8f6a3f08350a9bbe1d414b22bca4e6c7)) diff --git a/layouts/community/60_ansi_split_bs_rshift/bcat/keymap.c b/layouts/community/60_ansi_split_bs_rshift/bcat/keymap.c index dd2576ea53dd..b40148e99534 100644 --- a/layouts/community/60_ansi_split_bs_rshift/bcat/keymap.c +++ b/layouts/community/60_ansi_split_bs_rshift/bcat/keymap.c @@ -41,7 +41,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* Function 2 layer: http://www.keyboard-layout-editor.com/#/gists/6e1068e4f91bbacccaf5ac0acbeec79c */ [LAYER_FUNCTION_2] = LAYOUT_60_ansi_split_bs_rshift( _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_DEL, - _______, NK_TOGG, KC_MPLY, KC_VOLU, KC_MSTP, BL_BRTG, EEP_RST, RESET, _______, _______, _______, RGB_VAI, _______, _______, + _______, _______, KC_MPLY, KC_VOLU, KC_MSTP, BL_BRTG, EEP_RST, RESET, _______, _______, _______, RGB_VAI, _______, _______, _______, _______, KC_MPRV, KC_VOLD, KC_MNXT, BL_INC, _______, RGB_SPI, RGB_HUI, RGB_SAI, RGB_RMOD, RGB_MOD, RGB_TOG, _______, _______, _______, KC_MUTE, _______, BL_DEC, _______, RGB_SPD, RGB_HUD, RGB_SAD, RGB_VAD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ diff --git a/layouts/community/60_ansi_split_bs_rshift/bcat/readme.md b/layouts/community/60_ansi_split_bs_rshift/bcat/readme.md index 2d578aa3d3ed..f6bcda91975b 100644 --- a/layouts/community/60_ansi_split_bs_rshift/bcat/readme.md +++ b/layouts/community/60_ansi_split_bs_rshift/bcat/readme.md @@ -19,6 +19,6 @@ layout](https://github.com/qmk/qmk_firmware/tree/master/layouts/community/60_tsa ## Function 2 layer -![Function 2 layer layout](https://i.imgur.com/vJaCzVo.png) +![Function 2 layer layout](https://i.imgur.com/DW03vvJ.png) ([KLE](http://www.keyboard-layout-editor.com/#/gists/6e1068e4f91bbacccaf5ac0acbeec79c)) diff --git a/layouts/community/60_tsangan_hhkb/bcat/keymap.c b/layouts/community/60_tsangan_hhkb/bcat/keymap.c index c1119661a50d..9ec75f3c4d46 100644 --- a/layouts/community/60_tsangan_hhkb/bcat/keymap.c +++ b/layouts/community/60_tsangan_hhkb/bcat/keymap.c @@ -39,7 +39,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* Function 2 layer: http://www.keyboard-layout-editor.com/#/gists/65ac939caec878401603bc36290852d4 */ [LAYER_FUNCTION_2] = LAYOUT_60_tsangan_hhkb( _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_DEL, - _______, NK_TOGG, KC_MPLY, KC_VOLU, KC_MSTP, BL_BRTG, EEP_RST, RESET, _______, _______, _______, RGB_VAI, _______, _______, + _______, _______, KC_MPLY, KC_VOLU, KC_MSTP, BL_BRTG, EEP_RST, RESET, _______, _______, _______, RGB_VAI, _______, _______, _______, _______, KC_MPRV, KC_VOLD, KC_MNXT, BL_INC, _______, RGB_SPI, RGB_HUI, RGB_SAI, RGB_RMOD, RGB_MOD, RGB_TOG, _______, _______, _______, KC_MUTE, _______, BL_DEC, _______, RGB_SPD, RGB_HUD, RGB_SAD, RGB_VAD, _______, _______, _______, _______, _______, _______, _______, _______, _______ diff --git a/layouts/community/60_tsangan_hhkb/bcat/readme.md b/layouts/community/60_tsangan_hhkb/bcat/readme.md index b7a3cde5d290..c8d0d72dd07e 100644 --- a/layouts/community/60_tsangan_hhkb/bcat/readme.md +++ b/layouts/community/60_tsangan_hhkb/bcat/readme.md @@ -39,6 +39,6 @@ and/or blockers, so there aren't switches installed in those positions. ## Function 2 layer -![Function 2 layer layout](https://i.imgur.com/vdNpFae.png) +![Function 2 layer layout](https://i.imgur.com/4Jdw9eL.png) ([KLE](http://www.keyboard-layout-editor.com/#/gists/65ac939caec878401603bc36290852d4)) diff --git a/layouts/community/65_ansi_blocker_split_bs/bcat/keymap.c b/layouts/community/65_ansi_blocker_split_bs/bcat/keymap.c index 31876770f6b8..c099d36e25fc 100644 --- a/layouts/community/65_ansi_blocker_split_bs/bcat/keymap.c +++ b/layouts/community/65_ansi_blocker_split_bs/bcat/keymap.c @@ -32,7 +32,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* Function layer: http://www.keyboard-layout-editor.com/#/gists/f29128427f674c43777f045e363d1b44 */ [LAYER_FUNCTION_1] = LAYOUT_65_ansi_blocker_split_bs( _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_DEL, _______, - KC_CAPS, NK_TOGG, KC_MPLY, KC_VOLU, KC_MSTP, _______, EEP_RST, RESET, KC_PSCR, KC_SLCK, KC_PAUS, _______, _______, _______, _______, + KC_CAPS, _______, KC_MPLY, KC_VOLU, KC_MSTP, _______, EEP_RST, RESET, KC_PSCR, KC_SLCK, KC_PAUS, _______, _______, _______, _______, _______, _______, KC_MPRV, KC_VOLD, KC_MNXT, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_APP, _______, KC_MUTE, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ diff --git a/layouts/community/65_ansi_blocker_split_bs/bcat/readme.md b/layouts/community/65_ansi_blocker_split_bs/bcat/readme.md index 0726cbecee26..5777c7c38ff0 100644 --- a/layouts/community/65_ansi_blocker_split_bs/bcat/readme.md +++ b/layouts/community/65_ansi_blocker_split_bs/bcat/readme.md @@ -12,6 +12,6 @@ keys, an HHKB-style (split) backspace, and media controls in the function layer ## Function layer -![Function layer layout](https://i.imgur.com/CsxfVfd.png) +![Function layer layout](https://i.imgur.com/s4hS9ZK.png) ([KLE](http://www.keyboard-layout-editor.com/#/gists/f29128427f674c43777f045e363d1b44)) diff --git a/layouts/community/split_3x6_3/bcat/keymap.c b/layouts/community/split_3x6_3/bcat/keymap.c index 58a5ae9bf88c..6df5e7578f46 100644 --- a/layouts/community/split_3x6_3/bcat/keymap.c +++ b/layouts/community/split_3x6_3/bcat/keymap.c @@ -47,7 +47,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ), /* Adjust layer: http://www.keyboard-layout-editor.com/#/gists/77e7572e077b36a23eb2086017e16fee */ [LAYER_ADJUST] = LAYOUT_split_3x6_3( - _______, NK_TOGG, KC_MPLY, KC_VOLU, KC_MSTP, _______, EEP_RST, RESET, _______, _______, _______, _______, + _______, _______, KC_MPLY, KC_VOLU, KC_MSTP, _______, EEP_RST, RESET, _______, _______, _______, _______, _______, _______, KC_MPRV, KC_VOLD, KC_MNXT, _______, RGB_RMOD, RGB_VAD, RGB_VAI, RGB_MOD, RGB_SPI, _______, _______, _______, _______, KC_MUTE, _______, _______, RGB_HUI, RGB_SAD, RGB_SAI, RGB_HUD, RGB_SPD, _______, _______, _______, _______, RGB_TOG, _______, _______ diff --git a/layouts/community/split_3x6_3/bcat/readme.md b/layouts/community/split_3x6_3/bcat/readme.md index c4bf891c40a5..b7b5d3de7d39 100644 --- a/layouts/community/split_3x6_3/bcat/readme.md +++ b/layouts/community/split_3x6_3/bcat/readme.md @@ -117,7 +117,7 @@ better location. ## Adjust layer -![Adjust layer layout](https://i.imgur.com/fZouko5.png) +![Adjust layer layout](https://i.imgur.com/Q4rN6cQ.png) ([KLE](http://www.keyboard-layout-editor.com/#/gists/77e7572e077b36a23eb2086017e16fee)) From 0f0f71ddb9e96df649f223426e099a8074333828 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Sun, 20 Jun 2021 19:08:53 -0500 Subject: [PATCH 09/23] Add post-render hook to OLED pet API This enables OLED pets to draw custom widgets (e.g., LED indicator status) on top of their animation frames. --- users/bcat/bcat_oled.c | 7 +++---- users/bcat/bcat_oled.h | 5 +---- users/bcat/bcat_oled_pet.h | 10 ++++++++++ users/bcat/bcat_oled_pet_luna.c | 2 ++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/users/bcat/bcat_oled.c b/users/bcat/bcat_oled.c index 373f9ca37633..664cdfa2cb6f 100644 --- a/users/bcat/bcat_oled.c +++ b/users/bcat/bcat_oled.c @@ -134,11 +134,10 @@ static void redraw_oled_pet(uint8_t col, uint8_t line, bool jumping, oled_pet_st } else { oled_advance_page(/*clearPageRemainder=*/true); oled_write_raw_P(oled_pet_frame(state, frame), oled_pet_frame_bytes()); - oled_set_cursor(col, line + oled_pet_frame_lines() + 1); } } -bool render_oled_pet(uint8_t col, uint8_t line, uint8_t mods, led_t leds, uint8_t wpm) { +void render_oled_pet(uint8_t col, uint8_t line, uint8_t mods, led_t leds, uint8_t wpm) { /* Whether or not the animation state or frame has changed since the pet * was last drawn. We track this to avoid redrawing the same frame * repeatedly during idle. This allows the caller to draw on top of the pet @@ -176,6 +175,8 @@ bool render_oled_pet(uint8_t col, uint8_t line, uint8_t mods, led_t leds, uint8_ if (redraw) { redraw_oled_pet(col, line, jumping, state, frame); } + oled_pet_post_render(col, line, jumping, mods, leds, wpm, redraw); + oled_set_cursor(col, line + oled_pet_frame_lines() + 1); /* If the update timer expired, recompute the pet's animation state and * possibly advance to the next frame. @@ -194,7 +195,5 @@ bool render_oled_pet(uint8_t col, uint8_t line, uint8_t mods, led_t leds, uint8_ animation_changed = true; } } - - return redraw; } #endif diff --git a/users/bcat/bcat_oled.h b/users/bcat/bcat_oled.h index d2962e37f312..9c3f289acc6f 100644 --- a/users/bcat/bcat_oled.h +++ b/users/bcat/bcat_oled.h @@ -47,9 +47,6 @@ void render_oled_wpm(uint8_t wpm); * * The rendered image will be one line taller than the OLED pet's animation * frame height to accommodate pets that "jump" when the spacebar is pressed. - * - * Returns whether or not a new frame of the animation was displayed, in case - * the caller wants to draw atop the pet animation (e.g., in empty space). */ -bool render_oled_pet(uint8_t col, uint8_t line, uint8_t mods, led_t leds, uint8_t wpm); +void render_oled_pet(uint8_t col, uint8_t line, uint8_t mods, led_t leds, uint8_t wpm); #endif diff --git a/users/bcat/bcat_oled_pet.h b/users/bcat/bcat_oled_pet.h index a67024e7a176..b0af1468a669 100644 --- a/users/bcat/bcat_oled_pet.h +++ b/users/bcat/bcat_oled_pet.h @@ -66,3 +66,13 @@ uint16_t oled_pet_update_millis(uint8_t wpm); * oled_pet_frame_bytes and is formatted as expected by oled_write_raw_P. */ const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame); + +/* Called after the OLED pet is rendered during each OLED task invocation. + * Receives the same keyboard state as render_oled_pet. The redraw param + * indicates whether or not an OLED frame was just redrawn, allowing a specific + * pet implementation to draw custom things atop its animation frames. + * + * When this function is called, the cursor will be in an unspecified location, + * not necessarily the top-left corner of the OLED pet. + */ +void oled_pet_post_render(uint8_t col, uint8_t line, bool jumping, uint8_t mods, led_t leds, uint8_t wpm, bool redraw); diff --git a/users/bcat/bcat_oled_pet_luna.c b/users/bcat/bcat_oled_pet_luna.c index e45793e5858c..636953f42162 100644 --- a/users/bcat/bcat_oled_pet_luna.c +++ b/users/bcat/bcat_oled_pet_luna.c @@ -154,3 +154,5 @@ const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame) { return IDLE_FRAMES[frame]; } } + +void oled_pet_post_render(uint8_t col, uint8_t line, bool jumping, uint8_t mods, led_t leds, uint8_t wpm, bool redraw) {} From a68cdacb6c63401b2a04448407c7ff7422b78173 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Sun, 20 Jun 2021 21:55:36 -0500 Subject: [PATCH 10/23] Add Isda keyboard pet For future use on my Unicorne keyboard. Unicorn artwork by sparrow666, licensed under GPL v2.0. See also: https://opengameart.org/content/unicorn-2 --- users/bcat/bcat_oled_pet_isda.c | 126 ++++++++++++++++++++++++++++++++ users/bcat/rules.mk | 4 + 2 files changed, 130 insertions(+) create mode 100644 users/bcat/bcat_oled_pet_isda.c diff --git a/users/bcat/bcat_oled_pet_isda.c b/users/bcat/bcat_oled_pet_isda.c new file mode 100644 index 000000000000..00dc60d7547c --- /dev/null +++ b/users/bcat/bcat_oled_pet_isda.c @@ -0,0 +1,126 @@ +/* Copyright 2018 sparrow666 + * Copyright 2021 Jonathan Rascher + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* OLED pet "Isda" (animated unicorn) featuring artwork by OpenGameArt user + * sparrow666, licensed under GPL v2.0. + * + * The animation is 32x72 pixels (9 lines tall). + * + * Runs faster the quicker you type. Shows LED indicator (Num/Caps/Scroll Lock) + * status in the bottom-right corner. + * + * Named after the goddess Ehlonna's personal unicorn in the first D&D campaign + * I ever played. :) + * + * Artwork source: https://opengameart.org/content/unicorn-2 + */ + +#include "bcat_oled_pet.h" + +#include +#include + +#include "led.h" +#include "oled_driver.h" +#include "progmem.h" + +#define NUM_FRAMES 4 +#define FRAME_BYTES 288 /* (32 pixel) * (72 pixel) / (8 pixel/byte) */ + +uint8_t oled_pet_num_frames(void) { return NUM_FRAMES; } +uint16_t oled_pet_frame_bytes(void) { return FRAME_BYTES; } +uint8_t oled_pet_frame_lines(void) { return 9 /* (72 pixel) / (8 pixel/line) */; } +bool oled_pet_can_jump(void) { return false; } + +oled_pet_state_t oled_pet_state(uint8_t mods, led_t led_state, uint8_t wpm) { return OLED_PET_IDLE; } + +uint16_t oled_pet_update_millis(uint8_t wpm) { + static const uint16_t MIN_MILLIS = 75; + static const uint16_t MAX_MILLIS = 300; + static const uint8_t MAX_WPM = 150; + return MAX_MILLIS - (MAX_MILLIS - MIN_MILLIS) * (wpm > MAX_WPM ? MAX_WPM : wpm) / MAX_WPM; +} + +const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame) { + static const char PROGMEM FRAMES[NUM_FRAMES][FRAME_BYTES] = { + // clang-format off + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0xa0, 0x60, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x88, 0xd0, 0x78, 0x04, 0x28, 0x70, 0x60, 0x90, 0x88, 0xc4, 0x22, 0x19, 0x04, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xfc, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x84, 0x8c, 0x08, 0x01, 0x01, 0x02, 0x02, 0x04, 0x88, 0xf0, 0x00, + 0xc0, 0xe0, 0xe0, 0x10, 0x10, 0x08, 0x04, 0x02, 0x01, 0xff, 0xff, 0xff, 0x7f, 0x0f, 0x1f, 0x00, 0x00, 0x00, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x0f, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xe0, 0x18, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfc, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0x3c, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x03, 0xc6, 0x3c, 0x00, 0x80, 0x70, 0x1c, 0x0f, 0x03, 0x0f, 0x3f, 0xff, 0xff, 0xfc, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x80, 0xe0, 0xf8, 0xfe, 0x7f, 0x1f, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x0e, 0x30, 0x40, 0x47, 0x4f, 0x77, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0xc0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x10, 0xa0, 0xf0, 0x08, 0x50, 0xe0, 0xc0, 0x20, 0x10, 0x88, 0x44, 0x32, 0x09, 0x06, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf8, 0xfe, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x19, 0x11, 0x03, 0x02, 0x04, 0x04, 0x08, 0x10, 0xe0, 0x00, + 0xc0, 0xe0, 0xe0, 0x10, 0x10, 0x08, 0x04, 0x02, 0x01, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x3f, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x00, + 0x00, 0x1f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x01, 0x03, 0x00, 0x00, 0x80, 0xc0, 0x20, 0x10, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0x3c, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x03, 0xc6, 0x3c, 0x00, 0x80, 0x70, 0x18, 0x0f, 0x03, 0x0f, 0x3f, 0xff, 0xff, 0xfc, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0x38, 0x07, 0xc0, 0x38, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0f, 0x7f, 0xff, 0xff, 0xe0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x21, 0x20, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x0f, 0x0f, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0xc0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x10, 0xa0, 0xf0, 0x08, 0x50, 0xe0, 0xc0, 0x20, 0x10, 0x88, 0x44, 0x32, 0x09, 0x06, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf8, 0xfe, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x19, 0x11, 0x03, 0x02, 0x04, 0x04, 0x08, 0x10, 0xe0, 0x00, + 0xc0, 0xc0, 0xc0, 0x20, 0x20, 0x10, 0x08, 0x04, 0x03, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x3f, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x00, + 0x00, 0x1f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x01, 0x03, 0x00, 0x00, 0x80, 0xc0, 0x20, 0x10, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x03, 0xc3, 0xfe, 0xfe, 0xfc, 0x7c, 0x1c, 0x0c, 0x0c, 0x08, 0x10, 0x60, 0x83, 0x07, 0x18, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x71, 0x0e, 0x80, 0x70, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x0f, 0x3f, 0x7f, 0x7f, 0x78, 0xe0, 0x90, 0x88, 0x66, 0x11, 0x08, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0xa0, 0x60, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x88, 0xd0, 0x78, 0x04, 0x28, 0x70, 0x60, 0x90, 0x88, 0xc4, 0x22, 0x19, 0x04, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xfc, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x84, 0x8c, 0x08, 0x01, 0x01, 0x02, 0x02, 0x04, 0x88, 0xf0, 0x00, + 0xc0, 0xe0, 0xe0, 0x10, 0x10, 0x08, 0x04, 0x02, 0x01, 0xff, 0xff, 0xff, 0x7f, 0x0f, 0x1f, 0x00, 0x00, 0x00, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x0f, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xe0, 0x18, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xfc, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x03, 0xc6, 0xfc, 0xfc, 0xfc, 0x7c, 0x18, 0x08, 0x08, 0x08, 0x30, 0xc0, 0x03, 0x0c, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xc0, 0xf8, 0xff, 0xff, 0x3f, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x70, 0x80, 0x1f, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x18, 0x3e, 0x3f, 0x3f, 0x1f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x0c, 0x09, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + // clang-format on + }; + return FRAMES[frame]; +} + +/* Draws LED indicator status in the bottom-right corner of the OLED pet, atop + * the animation frame. Redrawn only when necessary, e.g., when LED status + * changes or the animation itself updated (which overwrites any previously + * drawn indicators). + */ +void oled_pet_post_render(uint8_t col, uint8_t line, bool jumping, uint8_t mods, led_t leds, uint8_t wpm, bool redraw) { + static led_t prev_leds = {.raw = 0}; + if (redraw || leds.raw != prev_leds.raw) { + oled_set_cursor(col + 4, line + !jumping + 4); + oled_write_char(leds.num_lock ? 'N' : ' ', /*invert=*/false); + oled_set_cursor(col + 4, line + !jumping + 6); + oled_write_char(leds.caps_lock ? 'C' : ' ', /*invert=*/false); + oled_set_cursor(col + 4, line + !jumping + 8); + oled_write_char(leds.scroll_lock ? 'S' : ' ', /*invert=*/false); + prev_leds = leds; + } +} diff --git a/users/bcat/rules.mk b/users/bcat/rules.mk index 2659ed96f4bb..d745e23da5eb 100644 --- a/users/bcat/rules.mk +++ b/users/bcat/rules.mk @@ -25,6 +25,10 @@ ifeq ($(strip $(OLED_ENABLE)), yes) # OLED pets (animated critters that react to typing) take up a lot of # firmware space, so only compile one, and only if requested. + ifeq ($(strip $(BCAT_OLED_PET)), isda) + SRC += bcat_oled_pet_isda.c + OPT_DEFS += -DBCAT_OLED_PET + endif ifeq ($(strip $(BCAT_OLED_PET)), luna) SRC += bcat_oled_pet_luna.c OPT_DEFS += -DBCAT_OLED_PET From 45d690971bc71ee44c62962945e7d26fa40d562a Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Tue, 22 Jun 2021 22:38:30 -0500 Subject: [PATCH 11/23] Replace OLED timeout implementation with custom The default implementation never lets the OLED turn off if a continuous animation is in progress. The custom one does. --- keyboards/lily58/keymaps/bcat/keymap.c | 2 +- layouts/community/split_3x6_3/bcat/keymap.c | 2 +- users/bcat/bcat_oled.c | 21 +++++++++++++++++++++ users/bcat/config.h | 11 +++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/keyboards/lily58/keymaps/bcat/keymap.c b/keyboards/lily58/keymaps/bcat/keymap.c index f311dccb4bcc..c71bd5b4a110 100644 --- a/keyboards/lily58/keymaps/bcat/keymap.c +++ b/keyboards/lily58/keymaps/bcat/keymap.c @@ -62,7 +62,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { #if defined(OLED_ENABLE) oled_rotation_t oled_init_user(oled_rotation_t rotation) { return is_keyboard_master() ? OLED_ROTATION_270 : OLED_ROTATION_180; } -void oled_task_user(void) { +void oled_task_keymap(void) { if (is_keyboard_master()) { uint8_t mods = get_mods(); led_t leds = host_keyboard_led_state(); diff --git a/layouts/community/split_3x6_3/bcat/keymap.c b/layouts/community/split_3x6_3/bcat/keymap.c index 6df5e7578f46..973cbcbea9e4 100644 --- a/layouts/community/split_3x6_3/bcat/keymap.c +++ b/layouts/community/split_3x6_3/bcat/keymap.c @@ -58,7 +58,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { #if defined(OLED_ENABLE) oled_rotation_t oled_init_user(oled_rotation_t rotation) { return is_keyboard_master() ? OLED_ROTATION_270 : OLED_ROTATION_180; } -void oled_task_user(void) { +void oled_task_keymap(void) { if (is_keyboard_master()) { uint8_t mods = get_mods(); led_t leds = host_keyboard_led_state(); diff --git a/users/bcat/bcat_oled.c b/users/bcat/bcat_oled.c index 664cdfa2cb6f..3639421fe97a 100644 --- a/users/bcat/bcat_oled.c +++ b/users/bcat/bcat_oled.c @@ -38,6 +38,27 @@ static bool oled_pet_should_jump = false; #endif +__attribute__((weak)) void oled_task_keymap(void) {} + +bool oled_task_user(void) { + static const uint16_t TIMEOUT_MILLIS = 60000 /* 1 min */; + + /* Custom OLED timeout implementation that only considers user activity. + * Allows the OLED to turn off in the middle of a continuous animation. + */ + bool on = is_oled_on(); + if (last_input_activity_elapsed() < TIMEOUT_MILLIS) { + if (!on) { + oled_on(); + } + oled_task_keymap(); + } else if (on) { + oled_off(); + } + + return false; +} + void render_oled_logo(void) { static const char PROGMEM logo[] = { // clang-format off diff --git a/users/bcat/config.h b/users/bcat/config.h index c0958272021a..3f9054463f84 100644 --- a/users/bcat/config.h +++ b/users/bcat/config.h @@ -37,6 +37,17 @@ */ #define TAPPING_FORCE_HOLD +#if defined(OLED_ENABLE) +/* The built-in OLED timeout wakes the OLED screen every time the buffer is + * updated, even if no user activity has occurred recently. This prevents the + * OLED from ever turning off during a continuously running animation. To avoid + * this, we disable the default timeout and implement our own in + * oled_task_user. + */ +# undef OLED_TIMEOUT +# define OLED_DISABLE_TIMEOUT +#endif + #if defined(RGB_MATRIX_ENABLE) /* Turn off per-key RGB when the host goes to sleep. */ # define RGB_DISABLE_WHEN_USB_SUSPENDED From bc95ebb56a10c22f494bd977f2da3f7ec9e05454 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Wed, 23 Jun 2021 00:10:48 -0500 Subject: [PATCH 12/23] Move keyboard state for OLED functions into struct No change in firmware size, but makes keymaps read a little nicer and enables more functionality in OLED pets. --- keyboards/lily58/keymaps/bcat/keymap.c | 13 ++---- layouts/community/split_3x6_3/bcat/keymap.c | 13 ++---- users/bcat/bcat_oled.c | 22 +++++++--- users/bcat/bcat_oled.h | 11 ++++- users/bcat/bcat_oled_pet.h | 20 ++++----- users/bcat/bcat_oled_pet_isda.c | 48 ++++++++++++--------- users/bcat/bcat_oled_pet_luna.c | 18 ++++---- 7 files changed, 79 insertions(+), 66 deletions(-) diff --git a/keyboards/lily58/keymaps/bcat/keymap.c b/keyboards/lily58/keymaps/bcat/keymap.c index c71bd5b4a110..2095bbe7b569 100644 --- a/keyboards/lily58/keymaps/bcat/keymap.c +++ b/keyboards/lily58/keymaps/bcat/keymap.c @@ -62,20 +62,15 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { #if defined(OLED_ENABLE) oled_rotation_t oled_init_user(oled_rotation_t rotation) { return is_keyboard_master() ? OLED_ROTATION_270 : OLED_ROTATION_180; } -void oled_task_keymap(void) { +void oled_task_keymap(const oled_keyboard_state_t *keyboard_state) { if (is_keyboard_master()) { - uint8_t mods = get_mods(); - led_t leds = host_keyboard_led_state(); - uint8_t wpm = get_current_wpm(); - render_oled_layers(); oled_advance_page(/*clearPageRemainder=*/false); - render_oled_indicators(leds); + render_oled_indicators(keyboard_state->leds); oled_advance_page(/*clearPageRemainder=*/false); oled_advance_page(/*clearPageRemainder=*/false); - render_oled_wpm(wpm); - - render_oled_pet(/*col=*/0, /*line=*/12, mods, leds, wpm); + render_oled_wpm(keyboard_state->wpm); + render_oled_pet(/*col=*/0, /*line=*/12, keyboard_state); } else { render_oled_logo(); } diff --git a/layouts/community/split_3x6_3/bcat/keymap.c b/layouts/community/split_3x6_3/bcat/keymap.c index 973cbcbea9e4..66afdc130a49 100644 --- a/layouts/community/split_3x6_3/bcat/keymap.c +++ b/layouts/community/split_3x6_3/bcat/keymap.c @@ -58,20 +58,15 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { #if defined(OLED_ENABLE) oled_rotation_t oled_init_user(oled_rotation_t rotation) { return is_keyboard_master() ? OLED_ROTATION_270 : OLED_ROTATION_180; } -void oled_task_keymap(void) { +void oled_task_keymap(const oled_keyboard_state_t *keyboard_state) { if (is_keyboard_master()) { - uint8_t mods = get_mods(); - led_t leds = host_keyboard_led_state(); - uint8_t wpm = get_current_wpm(); - render_oled_layers(); oled_advance_page(/*clearPageRemainder=*/false); - render_oled_indicators(leds); + render_oled_indicators(keyboard_state->leds); oled_advance_page(/*clearPageRemainder=*/false); oled_advance_page(/*clearPageRemainder=*/false); - render_oled_wpm(wpm); - - render_oled_pet(/*col=*/0, /*line=*/12, mods, leds, wpm); + render_oled_wpm(keyboard_state->wpm); + render_oled_pet(/*col=*/0, /*line=*/12, keyboard_state); } else { render_oled_logo(); } diff --git a/users/bcat/bcat_oled.c b/users/bcat/bcat_oled.c index 3639421fe97a..4ae1f8f4970e 100644 --- a/users/bcat/bcat_oled.c +++ b/users/bcat/bcat_oled.c @@ -19,13 +19,16 @@ #include #include +#include "action_util.h" #include "bcat.h" +#include "host.h" #include "keycode.h" #include "led.h" #include "oled_driver.h" #include "progmem.h" #include "quantum.h" #include "timer.h" +#include "wpm.h" #if defined(BCAT_OLED_PET) # include "bcat_oled_pet.h" @@ -38,7 +41,7 @@ static bool oled_pet_should_jump = false; #endif -__attribute__((weak)) void oled_task_keymap(void) {} +__attribute__((weak)) void oled_task_keymap(const oled_keyboard_state_t *keyboard_state) {} bool oled_task_user(void) { static const uint16_t TIMEOUT_MILLIS = 60000 /* 1 min */; @@ -51,7 +54,12 @@ bool oled_task_user(void) { if (!on) { oled_on(); } - oled_task_keymap(); + oled_keyboard_state_t keyboard_state = { + .mods = get_mods(), + .leds = host_keyboard_led_state(), + .wpm = get_current_wpm(), + }; + oled_task_keymap(&keyboard_state); } else if (on) { oled_off(); } @@ -158,7 +166,7 @@ static void redraw_oled_pet(uint8_t col, uint8_t line, bool jumping, oled_pet_st } } -void render_oled_pet(uint8_t col, uint8_t line, uint8_t mods, led_t leds, uint8_t wpm) { +void render_oled_pet(uint8_t col, uint8_t line, const oled_keyboard_state_t *keyboard_state) { /* Whether or not the animation state or frame has changed since the pet * was last drawn. We track this to avoid redrawing the same frame * repeatedly during idle. This allows the caller to draw on top of the pet @@ -196,7 +204,7 @@ void render_oled_pet(uint8_t col, uint8_t line, uint8_t mods, led_t leds, uint8_ if (redraw) { redraw_oled_pet(col, line, jumping, state, frame); } - oled_pet_post_render(col, line, jumping, mods, leds, wpm, redraw); + oled_pet_post_render(col, line, keyboard_state, jumping, redraw); oled_set_cursor(col, line + oled_pet_frame_lines() + 1); /* If the update timer expired, recompute the pet's animation state and @@ -204,15 +212,15 @@ void render_oled_pet(uint8_t col, uint8_t line, uint8_t mods, led_t leds, uint8_ */ animation_changed = false; if (timer_expired32(timer_read32(), update_timeout)) { - oled_pet_state_t new_state = oled_pet_state(mods, leds, wpm); + oled_pet_state_t new_state = oled_pet_state(keyboard_state); if (state != new_state) { state = new_state; animation_changed = true; } /* If the user stopped typing, cycle around to the initial frame. */ - if (wpm > 0 || state != OLED_PET_IDLE || frame != 0) { + if (keyboard_state->wpm > 0 || state != OLED_PET_IDLE || frame != 0) { frame = (frame + 1) % oled_pet_num_frames(); - update_timeout = timer_read32() + oled_pet_update_millis(wpm); + update_timeout = timer_read32() + oled_pet_update_millis(keyboard_state); animation_changed = true; } } diff --git a/users/bcat/bcat_oled.h b/users/bcat/bcat_oled.h index 9c3f289acc6f..018284f9d112 100644 --- a/users/bcat/bcat_oled.h +++ b/users/bcat/bcat_oled.h @@ -21,6 +21,15 @@ #include "led.h" +/* Keyboard status passed to the oled_task_keymap function and used by the + * various keyboard pet implementations. + */ +typedef struct { + uint8_t mods; + led_t leds; + uint8_t wpm; +} oled_keyboard_state_t; + /* Renders the logo embedded at the "standard" location in the OLED font at the * cursor. By default, this is a "QMK Firmware" logo, but many keyboards put * their own logo here instead. Occupies 21x3 character cells. @@ -48,5 +57,5 @@ void render_oled_wpm(uint8_t wpm); * The rendered image will be one line taller than the OLED pet's animation * frame height to accommodate pets that "jump" when the spacebar is pressed. */ -void render_oled_pet(uint8_t col, uint8_t line, uint8_t mods, led_t leds, uint8_t wpm); +void render_oled_pet(uint8_t col, uint8_t line, const oled_keyboard_state_t *keyboard_state); #endif diff --git a/users/bcat/bcat_oled_pet.h b/users/bcat/bcat_oled_pet.h index b0af1468a669..26da874b0e40 100644 --- a/users/bcat/bcat_oled_pet.h +++ b/users/bcat/bcat_oled_pet.h @@ -23,7 +23,7 @@ #include #include -#include "led.h" +#include "bcat_oled.h" /* Opaque token identifying what animation state the pet is currently in. */ typedef uint8_t oled_pet_state_t; @@ -56,16 +56,10 @@ uint8_t oled_pet_frame_lines(void); bool oled_pet_can_jump(void); /* Returns the current state to be animated based on current keyboard state. */ -oled_pet_state_t oled_pet_state(uint8_t mods, led_t leds, uint8_t wpm); +oled_pet_state_t oled_pet_state(const oled_keyboard_state_t *keyboard_state); /* Returns the delay before the next animation frame should be displayed. */ -uint16_t oled_pet_update_millis(uint8_t wpm); - -/* Returns a PROGMEM pointer to the specified animation frame buffer for the - * specified state. The animation frame has length given by - * oled_pet_frame_bytes and is formatted as expected by oled_write_raw_P. - */ -const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame); +uint16_t oled_pet_update_millis(const oled_keyboard_state_t *keyboard_state); /* Called after the OLED pet is rendered during each OLED task invocation. * Receives the same keyboard state as render_oled_pet. The redraw param @@ -75,4 +69,10 @@ const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame); * When this function is called, the cursor will be in an unspecified location, * not necessarily the top-left corner of the OLED pet. */ -void oled_pet_post_render(uint8_t col, uint8_t line, bool jumping, uint8_t mods, led_t leds, uint8_t wpm, bool redraw); +void oled_pet_post_render(uint8_t col, uint8_t line, const oled_keyboard_state_t *keyboard_state, bool jumping, bool redraw); + +/* Returns a PROGMEM pointer to the specified animation frame buffer for the + * specified state. The animation frame has length given by + * oled_pet_frame_bytes and is formatted as expected by oled_write_raw_P. + */ +const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame); diff --git a/users/bcat/bcat_oled_pet_isda.c b/users/bcat/bcat_oled_pet_isda.c index 00dc60d7547c..581932ce54d4 100644 --- a/users/bcat/bcat_oled_pet_isda.c +++ b/users/bcat/bcat_oled_pet_isda.c @@ -34,6 +34,7 @@ #include #include +#include "bcat_oled.h" #include "led.h" #include "oled_driver.h" #include "progmem.h" @@ -46,13 +47,36 @@ uint16_t oled_pet_frame_bytes(void) { return FRAME_BYTES; } uint8_t oled_pet_frame_lines(void) { return 9 /* (72 pixel) / (8 pixel/line) */; } bool oled_pet_can_jump(void) { return false; } -oled_pet_state_t oled_pet_state(uint8_t mods, led_t led_state, uint8_t wpm) { return OLED_PET_IDLE; } +oled_pet_state_t oled_pet_state(const oled_keyboard_state_t *keyboard_state) { return OLED_PET_IDLE; } -uint16_t oled_pet_update_millis(uint8_t wpm) { +uint16_t oled_pet_update_millis(const oled_keyboard_state_t *keyboard_state) { static const uint16_t MIN_MILLIS = 75; static const uint16_t MAX_MILLIS = 300; static const uint8_t MAX_WPM = 150; - return MAX_MILLIS - (MAX_MILLIS - MIN_MILLIS) * (wpm > MAX_WPM ? MAX_WPM : wpm) / MAX_WPM; + uint8_t wpm = keyboard_state->wpm; + if (wpm > MAX_WPM) { + wpm = MAX_WPM; + } + return MAX_MILLIS - (MAX_MILLIS - MIN_MILLIS) * wpm / MAX_WPM; +} + +void oled_pet_post_render(uint8_t col, uint8_t line, const oled_keyboard_state_t *keyboard_state, bool jumping, bool redraw) { + /* Draws LED indicator status in the bottom-right corner of the OLED pet, + * atop the animation frame. Redrawn only when necessary, e.g., when LED + * status changes or the animation itself updated (which overwrites any + * previously drawn indicators). + */ + static led_t prev_leds = {.raw = 0}; + led_t leds = keyboard_state->leds; + if (redraw || leds.raw != prev_leds.raw) { + oled_set_cursor(col + 4, line + !jumping + 4); + oled_write_char(leds.num_lock ? 'N' : ' ', /*invert=*/false); + oled_set_cursor(col + 4, line + !jumping + 6); + oled_write_char(leds.caps_lock ? 'C' : ' ', /*invert=*/false); + oled_set_cursor(col + 4, line + !jumping + 8); + oled_write_char(leds.scroll_lock ? 'S' : ' ', /*invert=*/false); + prev_leds = leds; + } } const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame) { @@ -106,21 +130,3 @@ const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame) { }; return FRAMES[frame]; } - -/* Draws LED indicator status in the bottom-right corner of the OLED pet, atop - * the animation frame. Redrawn only when necessary, e.g., when LED status - * changes or the animation itself updated (which overwrites any previously - * drawn indicators). - */ -void oled_pet_post_render(uint8_t col, uint8_t line, bool jumping, uint8_t mods, led_t leds, uint8_t wpm, bool redraw) { - static led_t prev_leds = {.raw = 0}; - if (redraw || leds.raw != prev_leds.raw) { - oled_set_cursor(col + 4, line + !jumping + 4); - oled_write_char(leds.num_lock ? 'N' : ' ', /*invert=*/false); - oled_set_cursor(col + 4, line + !jumping + 6); - oled_write_char(leds.caps_lock ? 'C' : ' ', /*invert=*/false); - oled_set_cursor(col + 4, line + !jumping + 8); - oled_write_char(leds.scroll_lock ? 'S' : ' ', /*invert=*/false); - prev_leds = leds; - } -} diff --git a/users/bcat/bcat_oled_pet_luna.c b/users/bcat/bcat_oled_pet_luna.c index 636953f42162..0b7556d8416e 100644 --- a/users/bcat/bcat_oled_pet_luna.c +++ b/users/bcat/bcat_oled_pet_luna.c @@ -33,8 +33,8 @@ #include #include +#include "bcat_oled.h" #include "keycode.h" -#include "led.h" #include "progmem.h" enum state { @@ -52,23 +52,25 @@ uint16_t oled_pet_frame_bytes(void) { return FRAME_BYTES; } uint8_t oled_pet_frame_lines(void) { return 3 /* (24 pixel) / (8 pixel/line) */; } bool oled_pet_can_jump(void) { return true; } -oled_pet_state_t oled_pet_state(uint8_t mods, led_t led_state, uint8_t wpm) { - if (led_state.caps_lock) { +oled_pet_state_t oled_pet_state(const oled_keyboard_state_t *keyboard_state) { + if (keyboard_state->leds.caps_lock) { return OLED_PET_BARK; } - if (mods & MOD_MASK_CTRL) { + if (keyboard_state->mods & MOD_MASK_CTRL) { return OLED_PET_SNEAK; } - if (wpm >= 100) { + if (keyboard_state->wpm >= 100) { return OLED_PET_RUN; } - if (wpm >= 25) { + if (keyboard_state->wpm >= 25) { return OLED_PET_WALK; } return OLED_PET_IDLE; } -uint16_t oled_pet_update_millis(uint8_t wpm) { return 200; } +uint16_t oled_pet_update_millis(const oled_keyboard_state_t *keyboard_state) { return 200; } + +void oled_pet_post_render(uint8_t col, uint8_t line, const oled_keyboard_state_t *keyboard_state, bool jumping, bool redraw) {} const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame) { static const char PROGMEM IDLE_FRAMES[NUM_FRAMES][FRAME_BYTES] = { @@ -154,5 +156,3 @@ const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame) { return IDLE_FRAMES[frame]; } } - -void oled_pet_post_render(uint8_t col, uint8_t line, bool jumping, uint8_t mods, led_t leds, uint8_t wpm, bool redraw) {} From e07d9411e10693c025f958ce4225dcf1b9124594 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Sat, 26 Jun 2021 00:24:02 -0500 Subject: [PATCH 13/23] Enable continuously running OLED pet (for Luna) --- users/bcat/bcat_oled.c | 60 ++++++++++++-------------- users/bcat/bcat_oled_pet.h | 29 ++++++------- users/bcat/bcat_oled_pet_isda.c | 20 +++++---- users/bcat/bcat_oled_pet_luna.c | 74 +++++++++++++++++++-------------- 4 files changed, 91 insertions(+), 92 deletions(-) diff --git a/users/bcat/bcat_oled.c b/users/bcat/bcat_oled.c index 4ae1f8f4970e..e2f14944e38d 100644 --- a/users/bcat/bcat_oled.c +++ b/users/bcat/bcat_oled.c @@ -154,44 +154,40 @@ void process_record_oled(uint16_t keycode, const keyrecord_t *record) { } } -static void redraw_oled_pet(uint8_t col, uint8_t line, bool jumping, oled_pet_state_t state, uint8_t frame) { +static void redraw_oled_pet(uint8_t col, uint8_t line, bool jumping, oled_pet_state_t state) { oled_set_cursor(col, line); if (jumping) { - oled_write_raw_P(oled_pet_frame(state, frame), oled_pet_frame_bytes()); + oled_write_raw_P(oled_pet_frame(state), oled_pet_frame_bytes()); oled_set_cursor(col, line + oled_pet_frame_lines()); oled_advance_page(/*clearPageRemainder=*/true); } else { oled_advance_page(/*clearPageRemainder=*/true); - oled_write_raw_P(oled_pet_frame(state, frame), oled_pet_frame_bytes()); + oled_write_raw_P(oled_pet_frame(state), oled_pet_frame_bytes()); } } void render_oled_pet(uint8_t col, uint8_t line, const oled_keyboard_state_t *keyboard_state) { - /* Whether or not the animation state or frame has changed since the pet - * was last drawn. We track this to avoid redrawing the same frame - * repeatedly during idle. This allows the caller to draw on top of the pet - * without preventing the OLED from ever going to sleep. + /* Current animation to draw. We track changes to avoid redrawing the same + * frame repeatedly, allowing oled_pet_post_render to draw over the + * animation frame. */ - static bool animation_changed = true; - - /* Current animation state and frame to redraw. */ - static oled_pet_state_t state = OLED_PET_IDLE; - static uint8_t frame = 0; + static oled_pet_state_t state = 0; + static bool state_changed = true; /* Minimum time until the pet comes down after jumping. */ - static const uint16_t JUMP_MILLIS = 200; - static bool jumping = false; - static uint32_t jump_timeout = 0; + static const uint16_t JUMP_MILLIS = 200; + static bool jumping = false; - /* Time until next animation state/frame change. */ + /* Time until the next animation or jump state change. */ static uint32_t update_timeout = 0; + static uint32_t jump_timeout = 0; /* If the user pressed the jump key, immediately redraw instead of waiting * for the animation frame to update. That way, the pet appears to respond * to jump commands quickly rather than lagging. If the user released the * jump key, wait for the jump timeout to avoid overly brief jumps. */ - bool redraw = animation_changed; + bool redraw = state_changed; if (oled_pet_should_jump && !jumping) { redraw = true; jumping = true; @@ -201,28 +197,24 @@ void render_oled_pet(uint8_t col, uint8_t line, const oled_keyboard_state_t *key jumping = false; } + /* Draw the actual animation, then move the cursor to the end of the + * rendered area. (Note that we take up an extra line to account for + * jumping, which shifts the animation up or down a line.) + */ if (redraw) { - redraw_oled_pet(col, line, jumping, state, frame); + redraw_oled_pet(col, line, jumping, state); } - oled_pet_post_render(col, line, keyboard_state, jumping, redraw); + oled_pet_post_render(col, line + !jumping, keyboard_state, redraw); oled_set_cursor(col, line + oled_pet_frame_lines() + 1); - /* If the update timer expired, recompute the pet's animation state and - * possibly advance to the next frame. - */ - animation_changed = false; + /* If the update timer expired, recompute the pet's animation state. */ if (timer_expired32(timer_read32(), update_timeout)) { - oled_pet_state_t new_state = oled_pet_state(keyboard_state); - if (state != new_state) { - state = new_state; - animation_changed = true; - } - /* If the user stopped typing, cycle around to the initial frame. */ - if (keyboard_state->wpm > 0 || state != OLED_PET_IDLE || frame != 0) { - frame = (frame + 1) % oled_pet_num_frames(); - update_timeout = timer_read32() + oled_pet_update_millis(keyboard_state); - animation_changed = true; - } + oled_pet_state_t new_state = oled_pet_next_state(state, keyboard_state); + state_changed = new_state != state; + state = new_state; + update_timeout = timer_read32() + oled_pet_update_millis(keyboard_state); + } else { + state_changed = false; } } #endif diff --git a/users/bcat/bcat_oled_pet.h b/users/bcat/bcat_oled_pet.h index 26da874b0e40..ba8227ab6126 100644 --- a/users/bcat/bcat_oled_pet.h +++ b/users/bcat/bcat_oled_pet.h @@ -25,16 +25,11 @@ #include "bcat_oled.h" -/* Opaque token identifying what animation state the pet is currently in. */ -typedef uint8_t oled_pet_state_t; - -/* The default animation state that every OLED pet must support. */ -#define OLED_PET_IDLE 0 - -/* Returns the number of frames in the animation. Note that every state the pet - * supports is expected to have the same number of frames. +/* Opaque token representing a single frame of the OLED pet animation. + * Different pet implementations have different valid state values, but the + * zero value must always represent the default state of the pet at startup. */ -uint8_t oled_pet_num_frames(void); +typedef uint16_t oled_pet_state_t; /* Returns the number of bytes used to represent the animation frame (in * oled_write_raw_P format). Note that every state the pet supports is expected @@ -55,12 +50,12 @@ uint8_t oled_pet_frame_lines(void); */ bool oled_pet_can_jump(void); -/* Returns the current state to be animated based on current keyboard state. */ -oled_pet_state_t oled_pet_state(const oled_keyboard_state_t *keyboard_state); - /* Returns the delay before the next animation frame should be displayed. */ uint16_t oled_pet_update_millis(const oled_keyboard_state_t *keyboard_state); +/* Returns the state of the pet to be animated on the next animation tick. */ +oled_pet_state_t oled_pet_next_state(oled_pet_state_t state, const oled_keyboard_state_t *keyboard_state); + /* Called after the OLED pet is rendered during each OLED task invocation. * Receives the same keyboard state as render_oled_pet. The redraw param * indicates whether or not an OLED frame was just redrawn, allowing a specific @@ -69,10 +64,10 @@ uint16_t oled_pet_update_millis(const oled_keyboard_state_t *keyboard_state); * When this function is called, the cursor will be in an unspecified location, * not necessarily the top-left corner of the OLED pet. */ -void oled_pet_post_render(uint8_t col, uint8_t line, const oled_keyboard_state_t *keyboard_state, bool jumping, bool redraw); +void oled_pet_post_render(uint8_t col, uint8_t line, const oled_keyboard_state_t *keyboard_state, bool redraw); -/* Returns a PROGMEM pointer to the specified animation frame buffer for the - * specified state. The animation frame has length given by - * oled_pet_frame_bytes and is formatted as expected by oled_write_raw_P. +/* Returns a PROGMEM pointer to the specified frame buffer for the specified + * state. The animation frame has length given by oled_pet_frame_bytes and is + * formatted as expected by oled_write_raw_P. */ -const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame); +const char *oled_pet_frame(oled_pet_state_t state); diff --git a/users/bcat/bcat_oled_pet_isda.c b/users/bcat/bcat_oled_pet_isda.c index 581932ce54d4..98abddb13b05 100644 --- a/users/bcat/bcat_oled_pet_isda.c +++ b/users/bcat/bcat_oled_pet_isda.c @@ -42,13 +42,10 @@ #define NUM_FRAMES 4 #define FRAME_BYTES 288 /* (32 pixel) * (72 pixel) / (8 pixel/byte) */ -uint8_t oled_pet_num_frames(void) { return NUM_FRAMES; } uint16_t oled_pet_frame_bytes(void) { return FRAME_BYTES; } uint8_t oled_pet_frame_lines(void) { return 9 /* (72 pixel) / (8 pixel/line) */; } bool oled_pet_can_jump(void) { return false; } -oled_pet_state_t oled_pet_state(const oled_keyboard_state_t *keyboard_state) { return OLED_PET_IDLE; } - uint16_t oled_pet_update_millis(const oled_keyboard_state_t *keyboard_state) { static const uint16_t MIN_MILLIS = 75; static const uint16_t MAX_MILLIS = 300; @@ -60,7 +57,12 @@ uint16_t oled_pet_update_millis(const oled_keyboard_state_t *keyboard_state) { return MAX_MILLIS - (MAX_MILLIS - MIN_MILLIS) * wpm / MAX_WPM; } -void oled_pet_post_render(uint8_t col, uint8_t line, const oled_keyboard_state_t *keyboard_state, bool jumping, bool redraw) { +oled_pet_state_t oled_pet_next_state(oled_pet_state_t state, const oled_keyboard_state_t *keyboard_state) { + /* When the user stops typing, cycle the animation to frame 0 and stop. */ + return state != 0 || keyboard_state->wpm > 0 ? (state + 1) % NUM_FRAMES : 0; +} + +void oled_pet_post_render(uint8_t col, uint8_t line, const oled_keyboard_state_t *keyboard_state, bool redraw) { /* Draws LED indicator status in the bottom-right corner of the OLED pet, * atop the animation frame. Redrawn only when necessary, e.g., when LED * status changes or the animation itself updated (which overwrites any @@ -69,17 +71,17 @@ void oled_pet_post_render(uint8_t col, uint8_t line, const oled_keyboard_state_t static led_t prev_leds = {.raw = 0}; led_t leds = keyboard_state->leds; if (redraw || leds.raw != prev_leds.raw) { - oled_set_cursor(col + 4, line + !jumping + 4); + oled_set_cursor(col + 4, line + 4); oled_write_char(leds.num_lock ? 'N' : ' ', /*invert=*/false); - oled_set_cursor(col + 4, line + !jumping + 6); + oled_set_cursor(col + 4, line + 6); oled_write_char(leds.caps_lock ? 'C' : ' ', /*invert=*/false); - oled_set_cursor(col + 4, line + !jumping + 8); + oled_set_cursor(col + 4, line + 8); oled_write_char(leds.scroll_lock ? 'S' : ' ', /*invert=*/false); prev_leds = leds; } } -const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame) { +const char *oled_pet_frame(oled_pet_state_t state) { static const char PROGMEM FRAMES[NUM_FRAMES][FRAME_BYTES] = { // clang-format off { @@ -128,5 +130,5 @@ const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame) { }, // clang-format on }; - return FRAMES[frame]; + return FRAMES[state]; } diff --git a/users/bcat/bcat_oled_pet_luna.c b/users/bcat/bcat_oled_pet_luna.c index 0b7556d8416e..f0397c9c0594 100644 --- a/users/bcat/bcat_oled_pet_luna.c +++ b/users/bcat/bcat_oled_pet_luna.c @@ -37,42 +37,51 @@ #include "keycode.h" #include "progmem.h" -enum state { - OLED_PET_WALK = OLED_PET_IDLE + 1, - OLED_PET_RUN, - OLED_PET_SNEAK, - OLED_PET_BARK, +enum image { + IMAGE_IDLE, + IMAGE_WALK, + IMAGE_RUN, + IMAGE_SNEAK, + IMAGE_BARK, }; +typedef union { + oled_pet_state_t raw; + struct { + uint8_t image; + uint8_t frame; + }; +} luna_state_t; + #define NUM_FRAMES 2 #define FRAME_BYTES 96 /* (32 pixel) * (24 pixel) / (8 pixel/byte) */ -uint8_t oled_pet_num_frames(void) { return NUM_FRAMES; } uint16_t oled_pet_frame_bytes(void) { return FRAME_BYTES; } uint8_t oled_pet_frame_lines(void) { return 3 /* (24 pixel) / (8 pixel/line) */; } bool oled_pet_can_jump(void) { return true; } -oled_pet_state_t oled_pet_state(const oled_keyboard_state_t *keyboard_state) { +uint16_t oled_pet_update_millis(const oled_keyboard_state_t *keyboard_state) { return 200; } + +oled_pet_state_t oled_pet_next_state(oled_pet_state_t state, const oled_keyboard_state_t *keyboard_state) { + luna_state_t luna_state = {.raw = state}; if (keyboard_state->leds.caps_lock) { - return OLED_PET_BARK; - } - if (keyboard_state->mods & MOD_MASK_CTRL) { - return OLED_PET_SNEAK; + luna_state.image = IMAGE_BARK; + } else if (keyboard_state->mods & MOD_MASK_CTRL) { + luna_state.image = IMAGE_SNEAK; + } else if (keyboard_state->wpm >= 100) { + luna_state.image = IMAGE_RUN; + } else if (keyboard_state->wpm >= 25) { + luna_state.image = IMAGE_WALK; + } else { + luna_state.image = IMAGE_IDLE; } - if (keyboard_state->wpm >= 100) { - return OLED_PET_RUN; - } - if (keyboard_state->wpm >= 25) { - return OLED_PET_WALK; - } - return OLED_PET_IDLE; + luna_state.frame = (luna_state.frame + 1) % NUM_FRAMES; + return luna_state.raw; } -uint16_t oled_pet_update_millis(const oled_keyboard_state_t *keyboard_state) { return 200; } - -void oled_pet_post_render(uint8_t col, uint8_t line, const oled_keyboard_state_t *keyboard_state, bool jumping, bool redraw) {} +void oled_pet_post_render(uint8_t col, uint8_t line, const oled_keyboard_state_t *keyboard_state, bool redraw) {} -const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame) { +const char *oled_pet_frame(oled_pet_state_t state) { static const char PROGMEM IDLE_FRAMES[NUM_FRAMES][FRAME_BYTES] = { // clang-format off { @@ -143,16 +152,17 @@ const char *oled_pet_frame(oled_pet_state_t state, uint8_t frame) { }, // clang-format on }; - switch (state) { - case OLED_PET_WALK: - return WALK_FRAMES[frame]; - case OLED_PET_RUN: - return RUN_FRAMES[frame]; - case OLED_PET_SNEAK: - return SNEAK_FRAMES[frame]; - case OLED_PET_BARK: - return BARK_FRAMES[frame]; + luna_state_t luna_state = {.raw = state}; + switch (luna_state.image) { + case IMAGE_WALK: + return WALK_FRAMES[luna_state.frame]; + case IMAGE_RUN: + return RUN_FRAMES[luna_state.frame]; + case IMAGE_SNEAK: + return SNEAK_FRAMES[luna_state.frame]; + case IMAGE_BARK: + return BARK_FRAMES[luna_state.frame]; default: - return IDLE_FRAMES[frame]; + return IDLE_FRAMES[luna_state.frame]; } } From 23930f649a701a785b70460c1afef207236a8ef2 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Mon, 4 Oct 2021 17:22:18 -0500 Subject: [PATCH 14/23] Sync OLED state; enable Bootmagic only when needed The new extensible split transport for Split Common finally allows OLED on/off status to be synced between halves of the keyboard. :) Unfortunately, this required disabling Bootmagic Lite to keep my Crkbd under the firmware size limit. (I now after 28 bytes free on avr-gcc version 8.5.0.) So now I'll enable Bootmagic only on keyboards that actually require it, i.e., ones lacking an accessible reset button. --- keyboards/lily58/keymaps/bcat/keymap.c | 18 ++--- layouts/community/split_3x6_3/bcat/keymap.c | 18 ++--- users/bcat/bcat_oled.c | 73 +++++++++++++-------- users/bcat/bcat_oled.h | 6 -- users/bcat/config.h | 5 ++ users/bcat/rules.mk | 9 ++- 6 files changed, 70 insertions(+), 59 deletions(-) diff --git a/keyboards/lily58/keymaps/bcat/keymap.c b/keyboards/lily58/keymaps/bcat/keymap.c index 2095bbe7b569..a0856d0fdd5b 100644 --- a/keyboards/lily58/keymaps/bcat/keymap.c +++ b/keyboards/lily58/keymaps/bcat/keymap.c @@ -63,16 +63,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { oled_rotation_t oled_init_user(oled_rotation_t rotation) { return is_keyboard_master() ? OLED_ROTATION_270 : OLED_ROTATION_180; } void oled_task_keymap(const oled_keyboard_state_t *keyboard_state) { - if (is_keyboard_master()) { - render_oled_layers(); - oled_advance_page(/*clearPageRemainder=*/false); - render_oled_indicators(keyboard_state->leds); - oled_advance_page(/*clearPageRemainder=*/false); - oled_advance_page(/*clearPageRemainder=*/false); - render_oled_wpm(keyboard_state->wpm); - render_oled_pet(/*col=*/0, /*line=*/12, keyboard_state); - } else { - render_oled_logo(); - } + render_oled_layers(); + oled_advance_page(/*clearPageRemainder=*/false); + render_oled_indicators(keyboard_state->leds); + oled_advance_page(/*clearPageRemainder=*/false); + oled_advance_page(/*clearPageRemainder=*/false); + render_oled_wpm(keyboard_state->wpm); + render_oled_pet(/*col=*/0, /*line=*/12, keyboard_state); } #endif diff --git a/layouts/community/split_3x6_3/bcat/keymap.c b/layouts/community/split_3x6_3/bcat/keymap.c index 66afdc130a49..cfac93d1e350 100644 --- a/layouts/community/split_3x6_3/bcat/keymap.c +++ b/layouts/community/split_3x6_3/bcat/keymap.c @@ -59,16 +59,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { oled_rotation_t oled_init_user(oled_rotation_t rotation) { return is_keyboard_master() ? OLED_ROTATION_270 : OLED_ROTATION_180; } void oled_task_keymap(const oled_keyboard_state_t *keyboard_state) { - if (is_keyboard_master()) { - render_oled_layers(); - oled_advance_page(/*clearPageRemainder=*/false); - render_oled_indicators(keyboard_state->leds); - oled_advance_page(/*clearPageRemainder=*/false); - oled_advance_page(/*clearPageRemainder=*/false); - render_oled_wpm(keyboard_state->wpm); - render_oled_pet(/*col=*/0, /*line=*/12, keyboard_state); - } else { - render_oled_logo(); - } + render_oled_layers(); + oled_advance_page(/*clearPageRemainder=*/false); + render_oled_indicators(keyboard_state->leds); + oled_advance_page(/*clearPageRemainder=*/false); + oled_advance_page(/*clearPageRemainder=*/false); + render_oled_wpm(keyboard_state->wpm); + render_oled_pet(/*col=*/0, /*line=*/12, keyboard_state); } #endif diff --git a/users/bcat/bcat_oled.c b/users/bcat/bcat_oled.c index e2f14944e38d..c46e4dab7986 100644 --- a/users/bcat/bcat_oled.c +++ b/users/bcat/bcat_oled.c @@ -41,45 +41,60 @@ static bool oled_pet_should_jump = false; #endif +/* Should be overridden by the keymap to render the OLED contents. For split + * keyboards, this function is only called on the master side. + */ __attribute__((weak)) void oled_task_keymap(const oled_keyboard_state_t *keyboard_state) {} bool oled_task_user(void) { - static const uint16_t TIMEOUT_MILLIS = 60000 /* 1 min */; - - /* Custom OLED timeout implementation that only considers user activity. - * Allows the OLED to turn off in the middle of a continuous animation. - */ - bool on = is_oled_on(); - if (last_input_activity_elapsed() < TIMEOUT_MILLIS) { - if (!on) { - oled_on(); +#if defined(SPLIT_KEYBOARD) + if (is_keyboard_master()) { +#endif + /* Custom OLED timeout implementation that only considers user activity. + * Allows the OLED to turn off in the middle of a continuous animation. + */ + static const uint16_t TIMEOUT_MILLIS = 60000 /* 1 min */; + + bool on = is_oled_on(); + if (last_input_activity_elapsed() < TIMEOUT_MILLIS) { + if (!on) { + oled_on(); + } + oled_keyboard_state_t keyboard_state = { + .mods = get_mods(), + .leds = host_keyboard_led_state(), + .wpm = get_current_wpm(), + }; + oled_task_keymap(&keyboard_state); + } else if (on) { + oled_off(); } - oled_keyboard_state_t keyboard_state = { - .mods = get_mods(), - .leds = host_keyboard_led_state(), - .wpm = get_current_wpm(), +#if defined(SPLIT_KEYBOARD) + } else { + /* Display logo embedded at standard location in the OLED font on the + * slave side. By default, this is a "QMK firmware" logo, but many + * keyboards substitute their own logo. Occupies 21x3 character cells. + * + * Since the slave display buffer never changes, we don't need to worry + * about oled_render incorrectly turning the OLED on. Instead, we rely + * on SPLIT_OLED_ENABLE to propagate OLED on/off status from master. + */ + static const char PROGMEM logo[] = { + // clang-format off + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, + 0x00, + // clang-format on }; - oled_task_keymap(&keyboard_state); - } else if (on) { - oled_off(); + + oled_write_P(logo, /*invert=*/false); } +#endif return false; } -void render_oled_logo(void) { - static const char PROGMEM logo[] = { - // clang-format off - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, - 0x00, - // clang-format on - }; - - oled_write_P(logo, /*invert=*/false); -} - void render_oled_layers(void) { oled_advance_char(); oled_advance_char(); diff --git a/users/bcat/bcat_oled.h b/users/bcat/bcat_oled.h index 018284f9d112..f617e1f0640c 100644 --- a/users/bcat/bcat_oled.h +++ b/users/bcat/bcat_oled.h @@ -30,12 +30,6 @@ typedef struct { uint8_t wpm; } oled_keyboard_state_t; -/* Renders the logo embedded at the "standard" location in the OLED font at the - * cursor. By default, this is a "QMK Firmware" logo, but many keyboards put - * their own logo here instead. Occupies 21x3 character cells. - */ -void render_oled_logo(void); - /* Note: Functions below assume a vertical OLED that is 32px (5 chars) wide. */ /* Renders layer status at the cursor. Occupies 5x1 character cells. */ diff --git a/users/bcat/config.h b/users/bcat/config.h index 3f9054463f84..e67c033e5724 100644 --- a/users/bcat/config.h +++ b/users/bcat/config.h @@ -46,6 +46,11 @@ */ # undef OLED_TIMEOUT # define OLED_DISABLE_TIMEOUT + +# if defined(SPLIT_KEYBOARD) +/* Sync OLED on/off state between halves of split keyboards. */ +# define SPLIT_OLED_ENABLE +# endif #endif #if defined(RGB_MATRIX_ENABLE) diff --git a/users/bcat/rules.mk b/users/bcat/rules.mk index d745e23da5eb..a8e4c3c922c1 100644 --- a/users/bcat/rules.mk +++ b/users/bcat/rules.mk @@ -1,5 +1,10 @@ -# Enable Bootmagic Lite to consistently reset to bootloader and clear EEPROM. -BOOTMAGIC_ENABLE = yes # Enable Bootmagic Lite +# Enable Bootmagic Lite for keyboards that don't have an easily accessible +# reset button, but keep it disabled for all others to reduce firmware size. +ifneq ($(filter $(strip $(KEYBOARD)),ai03/polaris dz60 kbdfans/kbd67/hotswap),) + BOOTMAGIC_ENABLE = yes +else + BOOTMAGIC_ENABLE = no +endif # Enable media keys on all keyboards. EXTRAKEY_ENABLE = yes From bf46471d2c24872c839ee4288f4290969ae9838e Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Mon, 4 Oct 2021 13:38:44 -0500 Subject: [PATCH 15/23] Update 9-Key macropad keymap for working from home --- keyboards/9key/keymaps/bcat/keymap.c | 9 ++++++--- keyboards/9key/keymaps/bcat/readme.md | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/keyboards/9key/keymaps/bcat/keymap.c b/keyboards/9key/keymaps/bcat/keymap.c index 151d91719ba7..6768596b7b4c 100644 --- a/keyboards/9key/keymaps/bcat/keymap.c +++ b/keyboards/9key/keymaps/bcat/keymap.c @@ -18,13 +18,16 @@ #include "bcat.h" -#define KY_LOCK LCA(KC_L) /* Cinnamon lock screen */ +#define KY_LOCK LGUI(KC_L) /* Chrome OS: Lock screen */ +#define KY_MICM LSG(KC_1) /* Meet Shortcuts: Mute mic */ +#define KY_MICU LSG(KC_2) /* Meet Shortcuts: Unmute mic */ +#define KY_RHAND LSG(KC_3) /* Meet Shortcuts: Raise/lower hand */ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // clang-format off [LAYER_DEFAULT] = LAYOUT( - KC_MPLY, KC_VOLU, KC_MSTP, - KC_MPRV, KC_VOLD, KC_MNXT, + KC_MPLY, KC_VOLU, KY_RHAND, + KY_MICM, KC_VOLD, KY_MICU, KY_LOCK, KC_MUTE, LY_FN1 ), [LAYER_FUNCTION_1] = LAYOUT( diff --git a/keyboards/9key/keymaps/bcat/readme.md b/keyboards/9key/keymaps/bcat/readme.md index 2dee51de8b52..d38ae5463b9b 100644 --- a/keyboards/9key/keymaps/bcat/readme.md +++ b/keyboards/9key/keymaps/bcat/readme.md @@ -1,5 +1,5 @@ # bcat's 9-Key layout -This is a super simple PCB-mount macropad with nine keys, used at work for -media keys and quick access to screen lock on Linux (Cinnamon desktop -environment). +This is a super simple PCB-mount macropad with nine keys, used on my +work-from-home Chromebox for media/volume control and to activate some global +shortcuts for Google Meet. From e0f292e3f63f7f75874fb7cef0fd09d1c7fa7c30 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Mon, 4 Oct 2021 23:49:39 -0500 Subject: [PATCH 16/23] Remove includes redundant with quantum.h Co-authored-by: Drashna Jaelre --- users/bcat/bcat.c | 6 ------ users/bcat/bcat_oled.c | 13 +------------ 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/users/bcat/bcat.c b/users/bcat/bcat.c index 53a628154604..3a407cfac0a1 100644 --- a/users/bcat/bcat.c +++ b/users/bcat/bcat.c @@ -16,12 +16,6 @@ #include "bcat.h" -#include -#include - -#include "action.h" -#include "action_layer.h" -#include "keycode.h" #include "quantum.h" static int8_t alt_tab_layer = -1; diff --git a/users/bcat/bcat_oled.c b/users/bcat/bcat_oled.c index c46e4dab7986..0f5ef4cfa29f 100644 --- a/users/bcat/bcat_oled.c +++ b/users/bcat/bcat_oled.c @@ -16,19 +16,8 @@ #include "bcat_oled.h" -#include -#include - -#include "action_util.h" -#include "bcat.h" -#include "host.h" -#include "keycode.h" -#include "led.h" -#include "oled_driver.h" -#include "progmem.h" #include "quantum.h" -#include "timer.h" -#include "wpm.h" +#include "bcat.h" #if defined(BCAT_OLED_PET) # include "bcat_oled_pet.h" From 2ab419be25f601036fa57b5612155c301ea62d4a Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Tue, 5 Oct 2021 00:03:48 -0500 Subject: [PATCH 17/23] Simplify BCAT_OLED_PET makefile logic --- users/bcat/rules.mk | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/users/bcat/rules.mk b/users/bcat/rules.mk index a8e4c3c922c1..bb4bb11d8848 100644 --- a/users/bcat/rules.mk +++ b/users/bcat/rules.mk @@ -30,12 +30,9 @@ ifeq ($(strip $(OLED_ENABLE)), yes) # OLED pets (animated critters that react to typing) take up a lot of # firmware space, so only compile one, and only if requested. - ifeq ($(strip $(BCAT_OLED_PET)), isda) - SRC += bcat_oled_pet_isda.c - OPT_DEFS += -DBCAT_OLED_PET - endif - ifeq ($(strip $(BCAT_OLED_PET)), luna) - SRC += bcat_oled_pet_luna.c + BCAT_OLED_PET ?= no + ifneq ($(strip $(BCAT_OLED_PET)), no) + SRC += bcat_oled_pet_$(strip $(BCAT_OLED_PET)).c OPT_DEFS += -DBCAT_OLED_PET endif endif From aada1c1092658e1c9ab58324c53c8c0a63388a89 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Fri, 8 Oct 2021 13:59:44 -0500 Subject: [PATCH 18/23] Swap some keys on my 9-Key macropad around --- keyboards/9key/keymaps/bcat/keymap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keyboards/9key/keymaps/bcat/keymap.c b/keyboards/9key/keymaps/bcat/keymap.c index 6768596b7b4c..944a48c0d39a 100644 --- a/keyboards/9key/keymaps/bcat/keymap.c +++ b/keyboards/9key/keymaps/bcat/keymap.c @@ -27,8 +27,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // clang-format off [LAYER_DEFAULT] = LAYOUT( KC_MPLY, KC_VOLU, KY_RHAND, - KY_MICM, KC_VOLD, KY_MICU, - KY_LOCK, KC_MUTE, LY_FN1 + KY_LOCK, KC_VOLD, KY_MICU, + LY_FN1, KC_MUTE, KY_MICM ), [LAYER_FUNCTION_1] = LAYOUT( EEP_RST, _______, RESET, From d13f86909f1323fcbe9da6d2e036da9baef50f0d Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Tue, 23 Nov 2021 23:55:33 -0600 Subject: [PATCH 19/23] Inline spurious variable in OLED code --- users/bcat/bcat_oled.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/users/bcat/bcat_oled.c b/users/bcat/bcat_oled.c index 0f5ef4cfa29f..ec57ec8c89dc 100644 --- a/users/bcat/bcat_oled.c +++ b/users/bcat/bcat_oled.c @@ -44,9 +44,8 @@ bool oled_task_user(void) { */ static const uint16_t TIMEOUT_MILLIS = 60000 /* 1 min */; - bool on = is_oled_on(); if (last_input_activity_elapsed() < TIMEOUT_MILLIS) { - if (!on) { + if (!is_oled_on()) { oled_on(); } oled_keyboard_state_t keyboard_state = { @@ -55,7 +54,7 @@ bool oled_task_user(void) { .wpm = get_current_wpm(), }; oled_task_keymap(&keyboard_state); - } else if (on) { + } else if (is_oled_on()) { oled_off(); } #if defined(SPLIT_KEYBOARD) From 1d18c9d768f0bfa05c1a342b64618e3fee4ea178 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Tue, 23 Nov 2021 23:56:05 -0600 Subject: [PATCH 20/23] Remove max brightness that's now set by default The default max brightness is only 120 rather than 150, but that might actually fix some weirdness I've seen with bright white LED settings. --- layouts/community/split_3x6_3/bcat/config.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/layouts/community/split_3x6_3/bcat/config.h b/layouts/community/split_3x6_3/bcat/config.h index 81377ba16813..556fb90d5fe4 100644 --- a/layouts/community/split_3x6_3/bcat/config.h +++ b/layouts/community/split_3x6_3/bcat/config.h @@ -25,10 +25,4 @@ # undef OLED_FONT_H # define OLED_FONT_H "lib/glcdfont.c" # endif - -# if defined(RGB_MATRIX_ENABLE) -/* Limit max RGB LED current to avoid tripping controller fuse. */ -# undef RGB_MATRIX_MAXIMUM_BRIGHTNESS -# define RGB_MATRIX_MAXIMUM_BRIGHTNESS 150 -# endif #endif From cfcffdd2a59b331834ed1c2dfb86b203aa111b75 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Sun, 28 Nov 2021 15:20:19 -0600 Subject: [PATCH 21/23] Enable specific RGBLIGHT modes instead of default The general trend these days seems to be enabling only the modes you want, so I'm manually expanding the ones currently enabled by RGBLIGHT_ANIMATIONS. I'd like to try out the TWINKLE mode too, but it seems not to work at all on ARM right now, and all my usable RGBLIGHT keebs are ARM boards. --- users/bcat/config.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/users/bcat/config.h b/users/bcat/config.h index e67c033e5724..034f6934b7d4 100644 --- a/users/bcat/config.h +++ b/users/bcat/config.h @@ -87,8 +87,18 @@ # define RGBLIGHT_SAT_STEP 17 # define RGBLIGHT_VAL_STEP 17 -/* Turn on additional RGB animations. */ -# define RGBLIGHT_ANIMATIONS +/* Enable specific underglow animation modes. (Skip TWINKLE because it seems to + * be broken on ARM: https://github.com/qmk/qmk_firmware/issues/15345.) + */ +# define RGBLIGHT_EFFECT_ALTERNATING +# define RGBLIGHT_EFFECT_BREATHING +# define RGBLIGHT_EFFECT_CHRISTMAS +# define RGBLIGHT_EFFECT_KNIGHT +# define RGBLIGHT_EFFECT_RAINBOW_MOOD +# define RGBLIGHT_EFFECT_RAINBOW_SWIRL +# define RGBLIGHT_EFFECT_RGB_TEST +# define RGBLIGHT_EFFECT_SNAKE +# define RGBLIGHT_EFFECT_STATIC_GRADIENT #endif #if defined(BACKLIGHT_ENABLE) From 0b9ae7bd4c5fefb92821832584fa3667314ccf21 Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Sun, 28 Nov 2021 15:44:36 -0600 Subject: [PATCH 22/23] Reenable RGB_MATRIX animations after #15018 My Crkbd still has a reasonable amount of free space with these: 27974/28672 (97%, 698 bytes free). The RGB_MATRIX_KEYPRESSES effects would put it over the firmware size limit, but I really don't ever use those anyway. --- users/bcat/config.h | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/users/bcat/config.h b/users/bcat/config.h index 034f6934b7d4..7bb5d71baeb1 100644 --- a/users/bcat/config.h +++ b/users/bcat/config.h @@ -68,10 +68,42 @@ # define RGB_MATRIX_VAL_STEP 17 # define RGB_MATRIX_SPD_STEP 17 -/* Turn on reactive RGB animations. (We don't enable - * RGB_MATRIX_FRAMEBUFFER_EFFECTS due to AVR size limits.) +/* Enable specific per-key animation modes. */ +# define ENABLE_RGB_MATRIX_ALPHAS_MODS +# define ENABLE_RGB_MATRIX_BAND_PINWHEEL_SAT +# define ENABLE_RGB_MATRIX_BAND_PINWHEEL_VAL +# define ENABLE_RGB_MATRIX_BAND_SAT +# define ENABLE_RGB_MATRIX_BAND_SPIRAL_SAT +# define ENABLE_RGB_MATRIX_BAND_SPIRAL_VAL +# define ENABLE_RGB_MATRIX_BAND_VAL +# define ENABLE_RGB_MATRIX_BREATHING +# define ENABLE_RGB_MATRIX_CYCLE_ALL +# define ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT +# define ENABLE_RGB_MATRIX_CYCLE_OUT_IN +# define ENABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL +# define ENABLE_RGB_MATRIX_CYCLE_PINWHEEL +# define ENABLE_RGB_MATRIX_CYCLE_SPIRAL +# define ENABLE_RGB_MATRIX_CYCLE_UP_DOWN +# define ENABLE_RGB_MATRIX_DUAL_BEACON +# define ENABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT +# define ENABLE_RGB_MATRIX_GRADIENT_UP_DOWN +# define ENABLE_RGB_MATRIX_HUE_BREATHING +# define ENABLE_RGB_MATRIX_HUE_PENDULUM +# define ENABLE_RGB_MATRIX_HUE_WAVE +# define ENABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS +# define ENABLE_RGB_MATRIX_PIXEL_FRACTAL +# define ENABLE_RGB_MATRIX_PIXEL_RAIN +# define ENABLE_RGB_MATRIX_RAINBOW_BEACON +# define ENABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON +# define ENABLE_RGB_MATRIX_RAINBOW_PINWHEELS +# define ENABLE_RGB_MATRIX_RAINDROPS + +/* Enable additional per-key animation modes that require a copy of the + * framebuffer (with accompanying storage cost). */ -# define RGB_MATRIX_KEYPRESSES +# define RGB_MATRIX_FRAMEBUFFER_EFFECTS +# define ENABLE_RGB_MATRIX_DIGITAL_RAIN +# define ENABLE_RGB_MATRIX_TYPING_HEATMAP #endif #if defined(RGBLIGHT_ENABLE) From a3efc6b1bd3b59b2cc5cba39bc971f375205f33d Mon Sep 17 00:00:00 2001 From: Jonathan Rascher Date: Sun, 28 Nov 2021 14:18:52 -0600 Subject: [PATCH 23/23] Use new get_u8_str function for WPM display --- users/bcat/bcat_oled.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/users/bcat/bcat_oled.c b/users/bcat/bcat_oled.c index ec57ec8c89dc..390c9127b47a 100644 --- a/users/bcat/bcat_oled.c +++ b/users/bcat/bcat_oled.c @@ -122,23 +122,16 @@ void render_oled_wpm(uint8_t wpm) { static uint32_t update_timeout = 0; if (timer_expired32(timer_read32(), update_timeout)) { - char wpm_str[] = " "; - if (wpm > 0) { - wpm_str[2] = '0' + wpm % 10; - } - if (wpm >= 10) { - wpm_str[1] = '0' + wpm / 10 % 10; - } - if (wpm >= 100) { - wpm_str[0] = '0' + wpm / 100 % 10; - } - oled_advance_char(); oled_advance_char(); oled_write_P(wpm > 0 ? PSTR("WPM") : PSTR(" "), /*invert=*/false); - oled_advance_char(); - oled_advance_char(); - oled_write(wpm_str, /*invert=*/false); + if (wpm > 0) { + oled_advance_char(); + oled_advance_char(); + oled_write(get_u8_str(wpm, ' '), /*invert=*/false); + } else { + oled_advance_page(/*clearPageRemainder=*/true); + } update_timeout = timer_read32() + UPDATE_MILLIS; }