Skip to content

Commit

Permalink
Display & battery tweaks for Corneish Zen
Browse files Browse the repository at this point in the history
* Useful for EPD that ghost after several partial updates. Only a
  temporary fix, tracking number of partial updates and triggering
  full refreshes based on that would be better.
  • Loading branch information
petejohanson authored and urob committed Aug 1, 2024
1 parent 6a667a0 commit d295422
Show file tree
Hide file tree
Showing 19 changed files with 422 additions and 15 deletions.
3 changes: 3 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,9 @@ config ZMK_KEYMAP_SENSORS_DEFAULT_TRIGGERS_PER_ROTATION

endif # ZMK_KEYMAP_SENSORS

config ZMK_TRACK_MOMENTARY_LAYERS
bool "Track whether layer activations are momentary"

choice CBPRINTF_IMPLEMENTATION
default CBPRINTF_NANO

Expand Down
5 changes: 4 additions & 1 deletion app/boards/arm/corneish_zen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ if(CONFIG_ZMK_DISPLAY)
zephyr_library_sources(widgets/icons/layers2.c)
endif()
if(NOT CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
zephyr_library_sources(widgets/icons/zenlogo.c)
target_sources_ifdef(CONFIG_CUSTOM_WIDGET_LOGO_IMAGE_ZEN app PRIVATE widgets/icons/zenlogo.c)
target_sources_ifdef(CONFIG_CUSTOM_WIDGET_LOGO_IMAGE_LPKB app PRIVATE widgets/icons/lpkblogo.c)
target_sources_ifdef(CONFIG_CUSTOM_WIDGET_LOGO_IMAGE_ZMK app PRIVATE widgets/icons/zmklogo.c)
target_sources_ifdef(CONFIG_CUSTOM_WIDGET_LOGO_IMAGE_MIRYOKU app PRIVATE widgets/icons/miryokulogo.c)
endif()
endif()

Expand Down
20 changes: 20 additions & 0 deletions app/boards/arm/corneish_zen/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ menuconfig CUSTOM_WIDGET_LAYER_STATUS
menuconfig CUSTOM_WIDGET_PERIPHERAL_STATUS
bool "custom peripheral status widget"

config CUSTOM_WIDGET_LAYER_STATUS_HIDE_HEADING
bool "Hide heading strip for layer widget and center widgets on 1/3rds"

choice CUSTOM_WIDGET_LOGO_IMAGE
prompt "custom logo widget image"

config CUSTOM_WIDGET_LOGO_IMAGE_ZEN
bool "Corne-ish Zen"

config CUSTOM_WIDGET_LOGO_IMAGE_LPKB
bool "LPKB"

config CUSTOM_WIDGET_LOGO_IMAGE_ZMK
bool "ZMK"

config CUSTOM_WIDGET_LOGO_IMAGE_MIRYOKU
bool "Miryoku"

endchoice

endif # BOARD_CORNEISH_ZEN_LEFT || BOARD_CORNEISH_ZEN_RIGHT

if BOARD_CORNEISH_ZEN_V1_LEFT || BOARD_CORNEISH_ZEN_V1_RIGHT
Expand Down
1 change: 1 addition & 0 deletions app/boards/arm/corneish_zen/corneish_zen_v2_left_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ CONFIG_CUSTOM_WIDGET_OUTPUT_STATUS=y
CONFIG_ZMK_WIDGET_OUTPUT_STATUS=n
CONFIG_CUSTOM_WIDGET_LAYER_STATUS=y
CONFIG_ZMK_WIDGET_LAYER_STATUS=n
CONFIG_CUSTOM_WIDGET_LOGO_IMAGE_ZEN=y

# Turn on logging, and set ZMK logging to debug output
#CONFIG_LOG=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ CONFIG_CUSTOM_WIDGET_BATTERY_STATUS=y
CONFIG_ZMK_WIDGET_BATTERY_STATUS=n
CONFIG_CUSTOM_WIDGET_PERIPHERAL_STATUS=y
CONFIG_ZMK_WIDGET_PERIPHERAL_STATUS=n
CONFIG_CUSTOM_WIDGET_LOGO_IMAGE_ZEN=y

# Turn on logging, and set ZMK logging to debug output
#CONFIG_LOG=y
Expand Down
36 changes: 35 additions & 1 deletion app/boards/arm/corneish_zen/custom_status_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

LV_IMG_DECLARE(zenlogo);
LV_IMG_DECLARE(layers2);

#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_BATTERY_STATUS)
Expand All @@ -40,37 +39,72 @@ lv_obj_t *zmk_display_status_screen() {

#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_BATTERY_STATUS)
zmk_widget_battery_status_init(&battery_status_widget, screen);
#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_LAYER_STATUS_HIDE_HEADING)
lv_obj_align(zmk_widget_battery_status_obj(&battery_status_widget), LV_ALIGN_CENTER, 0, -43);
#else
lv_obj_align(zmk_widget_battery_status_obj(&battery_status_widget), LV_ALIGN_TOP_MID, 0, 2);
#endif
#endif

#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_OUTPUT_STATUS)
zmk_widget_output_status_init(&output_status_widget, screen);
#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_LAYER_STATUS_HIDE_HEADING)
lv_obj_align(zmk_widget_output_status_obj(&output_status_widget), LV_ALIGN_CENTER, 0, 0);
#else
lv_obj_align(zmk_widget_output_status_obj(&output_status_widget), LV_ALIGN_TOP_MID, 0, 41);
#endif
#endif

#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_PERIPHERAL_STATUS)
zmk_widget_peripheral_status_init(&peripheral_status_widget, screen);
#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_LAYER_STATUS_HIDE_HEADING)
lv_obj_align(zmk_widget_peripheral_status_obj(&peripheral_status_widget), LV_ALIGN_CENTER, 0,
0);
#else
lv_obj_align(zmk_widget_peripheral_status_obj(&peripheral_status_widget), LV_ALIGN_TOP_MID, 0,
41);
#endif
#endif

#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_LAYER_STATUS)
#if !IS_ENABLED(CONFIG_CUSTOM_WIDGET_LAYER_STATUS_HIDE_HEADING)
lv_obj_t *LayersHeading;
LayersHeading = lv_img_create(screen);
lv_obj_align(LayersHeading, LV_ALIGN_BOTTOM_MID, 0, -30);
lv_img_set_src(LayersHeading, &layers2);
#endif

zmk_widget_layer_status_init(&layer_status_widget, screen);
lv_obj_set_style_text_font(zmk_widget_layer_status_obj(&layer_status_widget),
&lv_font_montserrat_16, LV_PART_MAIN);
#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_LAYER_STATUS_HIDE_HEADING)
lv_obj_align(zmk_widget_layer_status_obj(&layer_status_widget), LV_ALIGN_CENTER, 0, 43);
#else
lv_obj_align(zmk_widget_layer_status_obj(&layer_status_widget), LV_ALIGN_BOTTOM_MID, 0, -5);
#endif
#endif

#if !IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
lv_obj_t *zenlogo_icon;
zenlogo_icon = lv_img_create(screen);
#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_LOGO_IMAGE_ZEN)
LV_IMG_DECLARE(zenlogo);
lv_img_set_src(zenlogo_icon, &zenlogo);
#elif IS_ENABLED(CONFIG_CUSTOM_WIDGET_LOGO_IMAGE_LPKB)
LV_IMG_DECLARE(lpkblogo);
lv_img_set_src(zenlogo_icon, &lpkblogo);
#elif IS_ENABLED(CONFIG_CUSTOM_WIDGET_LOGO_IMAGE_ZMK)
LV_IMG_DECLARE(zmklogo);
lv_img_set_src(zenlogo_icon, &zmklogo);
#elif IS_ENABLED(CONFIG_CUSTOM_WIDGET_LOGO_IMAGE_MIRYOKU)
LV_IMG_DECLARE(miryokulogo);
lv_img_set_src(zenlogo_icon, &miryokulogo);
#endif
#if IS_ENABLED(CONFIG_CUSTOM_WIDGET_LAYER_STATUS_HIDE_HEADING)
lv_obj_align(zenlogo_icon, LV_ALIGN_CENTER, 0, 43);
#else
lv_obj_align(zenlogo_icon, LV_ALIGN_BOTTOM_MID, 0, -5);
#endif
#endif

return screen;
Expand Down
55 changes: 43 additions & 12 deletions app/boards/arm/corneish_zen/widgets/battery_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,52 @@ LV_IMG_DECLARE(batt_0);
LV_IMG_DECLARE(batt_0_chg);

static void set_battery_symbol(lv_obj_t *icon, struct battery_status_state state) {
uint8_t level = state.level;

#if IS_ENABLED(CONFIG_USB_DEVICE_STACK)
if (level > 95) {
lv_img_set_src(icon, state.usb_present ? &batt_100_chg : &batt_100);
} else if (level > 74) {
lv_img_set_src(icon, state.usb_present ? &batt_75_chg : &batt_75);
} else if (level > 49) {
lv_img_set_src(icon, state.usb_present ? &batt_50_chg : &batt_50);
} else if (level > 24) {
lv_img_set_src(icon, state.usb_present ? &batt_25_chg : &batt_25);
static uint8_t stage_prev = 255;
static bool usb_prev = false;

uint8_t level = state.level;
bool usb_present = state.usb_present;
uint8_t stage;

if (level > 87) {
stage = 5;
} else if (level > 62) {
stage = 4;
} else if (level > 37) {
stage = 3;
} else if (level > 12) {
stage = 2;
} else if (level > 5) {
lv_img_set_src(icon, state.usb_present ? &batt_5_chg : &batt_5);
stage = 1;
} else {
lv_img_set_src(icon, state.usb_present ? &batt_0_chg : &batt_0);
stage = 0;
}

// check if there is a change requiring an update
if (usb_present != usb_prev || stage != stage_prev) {
switch (stage) {
case 5:
lv_img_set_src(icon, usb_present ? &batt_100_chg : &batt_100);
break;
case 4:
lv_img_set_src(icon, usb_present ? &batt_75_chg : &batt_75);
break;
case 3:
lv_img_set_src(icon, usb_present ? &batt_50_chg : &batt_50);
break;
case 2:
lv_img_set_src(icon, usb_present ? &batt_25_chg : &batt_25);
break;
case 1:
lv_img_set_src(icon, usb_present ? &batt_5_chg : &batt_5);
break;
default:
lv_img_set_src(icon, usb_present ? &batt_0_chg : &batt_0);
break;
}
usb_prev = usb_present;
stage_prev = stage;
}
#endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */
}
Expand Down
67 changes: 67 additions & 0 deletions app/boards/arm/corneish_zen/widgets/icons/lpkblogo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
*
* Copyright (c) 2021 Darryl deHaan
* SPDX-License-Identifier: MIT
*
*/

#include <lvgl.h>

#ifndef LV_ATTRIBUTE_MEM_ALIGN
#define LV_ATTRIBUTE_MEM_ALIGN
#endif

#ifndef LV_ATTRIBUTE_IMG_LPKBLOGO
#define LV_ATTRIBUTE_IMG_LPKBLOGO
#endif

const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_LPKBLOGO uint8_t lpkblogo_map[] = {
0xff, 0xff, 0xff, 0xff, /*Color of index 0*/
0x00, 0x00, 0x00, 0xff, /*Color of index 1*/

0x7f, 0xff, 0xff, 0xff, 0xc0,
0xff, 0xff, 0xff, 0xff, 0xe0,
0xe0, 0x00, 0x00, 0x00, 0xe0,
0xc0, 0x00, 0x00, 0x00, 0x60,
0xc7, 0x83, 0xff, 0xfc, 0x60,
0xcf, 0xc7, 0xff, 0xfc, 0x60,
0xcf, 0xc7, 0xff, 0xfc, 0x60,
0xcf, 0xc7, 0xff, 0xfc, 0x60,
0xcf, 0xc7, 0xff, 0xfc, 0x60,
0xcf, 0xc3, 0xff, 0xfc, 0x60,
0xcf, 0xc0, 0x00, 0xfc, 0x60,
0xcf, 0xc0, 0x00, 0xfc, 0x60,
0xcf, 0xc0, 0x00, 0xfc, 0x60,
0xcf, 0xc0, 0x00, 0xfc, 0x60,
0xcf, 0xc3, 0xff, 0xfc, 0x60,
0xcf, 0xc7, 0xff, 0xfc, 0x60,
0xcf, 0xc7, 0xff, 0xfc, 0x60,
0xcf, 0xc7, 0xff, 0xfc, 0x60,
0xcf, 0xc7, 0xff, 0xfc, 0x60,
0xcf, 0xc3, 0xff, 0xfc, 0x60,
0xcf, 0xc0, 0x00, 0x00, 0x60,
0xcf, 0xc0, 0x00, 0x00, 0x60,
0xcf, 0xc0, 0x00, 0x00, 0x60,
0xcf, 0xc0, 0x00, 0x00, 0x60,
0xcf, 0xc0, 0x00, 0x00, 0x60,
0xcf, 0xc3, 0xff, 0xf8, 0x60,
0xcf, 0xc7, 0xff, 0xfc, 0x60,
0xcf, 0xc7, 0xff, 0xfc, 0x60,
0xcf, 0xc7, 0xff, 0xfc, 0x60,
0xcf, 0xc7, 0xff, 0xfc, 0x60,
0xc7, 0x83, 0xff, 0xf8, 0x60,
0xc0, 0x00, 0x00, 0x00, 0x60,
0xe0, 0x00, 0x00, 0x00, 0xe0,
0xff, 0xff, 0xff, 0xff, 0xe0,
0x7f, 0xff, 0xff, 0xff, 0xc0,
};

const lv_img_dsc_t lpkblogo = {
.header.cf = LV_IMG_CF_INDEXED_1BIT,
.header.always_zero = 0,
.header.reserved = 0,
.header.w = 35,
.header.h = 35,
.data_size = 183,
.data = lpkblogo_map,
};
59 changes: 59 additions & 0 deletions app/boards/arm/corneish_zen/widgets/icons/miryokulogo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2022 Manna Harbour
// https://github.com/manna-harbour/miryoku

#include "lvgl.h"

#ifndef LV_ATTRIBUTE_MEM_ALIGN
#define LV_ATTRIBUTE_MEM_ALIGN
#endif

#ifndef LV_ATTRIBUTE_IMG_MIRYOKULOGO
#define LV_ATTRIBUTE_IMG_MIRYOKULOGO
#endif

const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_MIRYOKULOGO uint8_t miryokulogo_map[] = {
0x04, 0x02, 0x04, 0xff, /*Color of index 0*/
0xfc, 0xfe, 0xfc, 0xff, /*Color of index 1*/

0xff, 0xff, 0xff, 0xff,
0x80, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x01,
0x9f, 0xff, 0xff, 0xf9,
0x9f, 0xff, 0xff, 0xf9,
0x98, 0x01, 0x99, 0x99,
0x98, 0x01, 0x99, 0x99,
0x99, 0x99, 0x80, 0x19,
0x99, 0x99, 0x80, 0x19,
0x98, 0x01, 0xf9, 0xf9,
0x98, 0x01, 0xf9, 0xf9,
0x99, 0x99, 0x99, 0x99,
0x99, 0x99, 0x99, 0x99,
0x98, 0x01, 0x80, 0x19,
0x98, 0x01, 0x80, 0x19,
0x9f, 0x9f, 0xf9, 0xf9,
0x9f, 0x9f, 0xf9, 0xf9,
0x98, 0x01, 0x80, 0x19,
0x98, 0x01, 0x80, 0x19,
0x99, 0x99, 0x99, 0x99,
0x99, 0x99, 0x99, 0x99,
0x99, 0x81, 0x99, 0x99,
0x99, 0x81, 0x99, 0x99,
0x99, 0x9f, 0x99, 0x99,
0x99, 0x9f, 0x99, 0x99,
0x99, 0x80, 0x19, 0x99,
0x99, 0x80, 0x19, 0x99,
0x9f, 0xff, 0xff, 0xf9,
0x9f, 0xff, 0xff, 0xf9,
0x80, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x01,
0xff, 0xff, 0xff, 0xff,
};

const lv_img_dsc_t miryokulogo = {
.header.always_zero = 0,
.header.w = 32,
.header.h = 32,
.data_size = 136,
.header.cf = LV_IMG_CF_INDEXED_1BIT,
.data = miryokulogo_map,
};
Loading

0 comments on commit d295422

Please sign in to comment.