Skip to content

Commit

Permalink
Zen display & battery tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
urob committed Apr 9, 2024
1 parent 9094140 commit 5796aa0
Show file tree
Hide file tree
Showing 18 changed files with 314 additions and 27 deletions.
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
45 changes: 45 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,45 @@
/*
*
* 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,
};
37 changes: 37 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,37 @@
// 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,
};
40 changes: 40 additions & 0 deletions app/boards/arm/corneish_zen/widgets/icons/zmklogo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "lvgl.h"

#ifndef LV_ATTRIBUTE_MEM_ALIGN
#define LV_ATTRIBUTE_MEM_ALIGN
#endif

#ifndef LV_ATTRIBUTE_IMG_ZMKLOGO
#define LV_ATTRIBUTE_IMG_ZMKLOGO
#endif

const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_ZMKLOGO uint8_t
zmklogo_map[] = {
0xff, 0xff, 0xff, 0xff, /*Color of index 0*/
0x00, 0x00, 0x00, 0xfe, /*Color of index 1*/

0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x0e, 0x7e, 0x73, 0xc7, 0xe0, 0x04, 0x3c, 0x31, 0x87,
0xf0, 0x0c, 0x18, 0x31, 0x0f, 0xff, 0x0c, 0x18, 0x30, 0x1f, 0xff, 0x1c, 0x00, 0x30, 0x3f,
0xfe, 0x3c, 0x00, 0x30, 0x7f, 0xfe, 0x3c, 0x42, 0x30, 0xff, 0xfc, 0x7c, 0x66, 0x30, 0xff,
0xf8, 0x7c, 0x7e, 0x30, 0x7f, 0xf8, 0xfc, 0x7e, 0x30, 0x3f, 0xf0, 0xfc, 0x7e, 0x30, 0x1f,
0xf0, 0x0c, 0x7e, 0x31, 0x0f, 0xe0, 0x04, 0x7e, 0x31, 0x87, 0xf0, 0x0e, 0xff, 0x73, 0xc7,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff,
};

const lv_img_dsc_t zmklogo = {
.header.cf = LV_IMG_CF_INDEXED_1BIT,
.header.always_zero = 0,
.header.reserved = 0,
.header.w = 40,
.header.h = 40,
.data_size = 208,
.data = zmklogo_map,
};
10 changes: 10 additions & 0 deletions app/boards/arm/corneish_zen/widgets/layer_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ static void set_layer_symbol(lv_obj_t *label, struct layer_status_state state) {
const char *layer_label = state.label;
uint8_t active_layer_index = state.index;

#if IS_ENABLED(CONFIG_ZMK_DISPLAY_HIDE_MOMENTARY_LAYERS)
static uint8_t last_perm_index = 255;
if (!zmk_keymap_layer_momentary(active_layer_index) && last_perm_index != active_layer_index) {
last_perm_index = active_layer_index;
LOG_DBG("Last perm layer index updated to %i", active_layer_index);
} else {
return;
}
#endif

if (layer_label == NULL) {
char text[6] = {};

Expand Down
4 changes: 3 additions & 1 deletion app/include/zmk/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ typedef uint32_t zmk_keymap_layers_state_t;
uint8_t zmk_keymap_layer_default(void);
zmk_keymap_layers_state_t zmk_keymap_layer_state(void);
bool zmk_keymap_layer_active(uint8_t layer);
bool zmk_keymap_layer_momentary(uint8_t layer);
bool zmk_keymap_layers_any_momentary(zmk_keymap_layers_state_t layers_mask);
uint8_t zmk_keymap_highest_layer_active(void);
int zmk_keymap_layer_activate(uint8_t layer);
int zmk_keymap_layer_activate(uint8_t layer, bool momentary);
int zmk_keymap_layer_deactivate(uint8_t layer);
int zmk_keymap_layer_toggle(uint8_t layer);
int zmk_keymap_layer_to(uint8_t layer);
Expand Down
10 changes: 9 additions & 1 deletion app/module/drivers/display/Kconfig.il0323
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ config IL0323
depends on SPI
depends on HEAP_MEM_POOL_SIZE != 0
help
Enable driver for IL0323 compatible controller.
Enable driver for IL0323 compatible controller.

config IL0323_INVERT
bool "Invert display"
default n

config IL0323_ALTERNATIVE_REFRESH
bool "Use an alternative approach for partial refreshes"
default n

0 comments on commit 5796aa0

Please sign in to comment.