diff --git a/config/boards/arm/hw75_dynamic/app/screen/CMakeLists.txt b/config/boards/arm/hw75_dynamic/app/screen/CMakeLists.txt index 883bb8f9..31f6f627 100644 --- a/config/boards/arm/hw75_dynamic/app/screen/CMakeLists.txt +++ b/config/boards/arm/hw75_dynamic/app/screen/CMakeLists.txt @@ -9,12 +9,18 @@ zephyr_library_include_directories(${APPLICATION_SOURCE_DIR}/include) include(${ZMK_CONFIG}/cmake/ui_strings.cmake) +generate_ui_strings(icons.csv + OUTPUT_DEFS ICONS_SRC + OUTPUT_TEXT ICONS_TXT + UNICODE_HEX +) + generate_ui_strings(strings.csv OUTPUT_DEFS STRINGS_SRC OUTPUT_TEXT STRINGS_TXT ) -zephyr_library_sources(${STRINGS_SRC}) +zephyr_library_sources(${ICONS_SRC} ${STRINGS_SRC}) zephyr_library_include_directories(${CMAKE_CURRENT_BINARY_DIR}) zephyr_library_sources(layer_status.c) diff --git a/config/boards/arm/hw75_dynamic/app/screen/fonts/CMakeLists.txt b/config/boards/arm/hw75_dynamic/app/screen/fonts/CMakeLists.txt index 29ec1eea..2246ac61 100644 --- a/config/boards/arm/hw75_dynamic/app/screen/fonts/CMakeLists.txt +++ b/config/boards/arm/hw75_dynamic/app/screen/fonts/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (c) 2022-2023 XiNGRZ # SPDX-License-Identifier: MIT +add_subdirectory(mono_19) add_subdirectory(zfull_9) -zephyr_library_sources(icons_19.c) zephyr_compile_options(-DLV_LVGL_H_INCLUDE_SIMPLE) diff --git a/config/boards/arm/hw75_dynamic/app/screen/fonts/icons_19.c b/config/boards/arm/hw75_dynamic/app/screen/fonts/icons_19.c deleted file mode 100644 index 7973d1f3..00000000 --- a/config/boards/arm/hw75_dynamic/app/screen/fonts/icons_19.c +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Size: 19 px - * Bpp: 1 - * Opts: - ******************************************************************************/ - -#include "lvgl.h" - -#ifndef ICONS_19 -#define ICONS_19 1 -#endif - -#if ICONS_19 - -/*----------------- - * BITMAPS - *----------------*/ - -/*Store the image of the glyphs*/ -static LV_ATTRIBUTE_LARGE_CONST const uint8_t glyph_bitmap[] = { - /* U+F028 "" */ - 0x0, 0x0, 0xc0, 0x0, 0x3, 0x80, 0xc, 0x7, - 0x0, 0xf1, 0x8c, 0x7, 0xc3, 0x1b, 0xff, 0x6, - 0x6f, 0xfc, 0xdc, 0xff, 0xf3, 0xb3, 0xff, 0xc6, - 0xcf, 0xff, 0x1b, 0x3f, 0xfc, 0xec, 0xff, 0xf3, - 0x63, 0x7, 0xc3, 0x98, 0xf, 0x1c, 0x60, 0xc, - 0x63, 0x0, 0x0, 0x1c, 0x0, 0x0, 0xe0, 0x0, - 0x2, 0x0, - - /* U+F0DC "" */ - 0x6, 0x1, 0xe0, 0x7e, 0x1f, 0xe7, 0xfe, 0xff, - 0xc0, 0x0, 0x0, 0x7f, 0xef, 0xfc, 0xff, 0xf, - 0xc0, 0xf0, 0xc, 0x0, - - /* U+F185 "" */ - 0x0, 0x40, 0x0, 0x1c, 0x0, 0x3, 0x80, 0xe, - 0xfb, 0x81, 0xff, 0xf0, 0x3c, 0x1e, 0x3, 0x39, - 0x80, 0xef, 0xb8, 0x7b, 0xfb, 0xdf, 0x7f, 0x7d, - 0xef, 0xef, 0xc, 0xf9, 0x80, 0xce, 0x60, 0x18, - 0xc, 0x7, 0xc7, 0xc0, 0xff, 0xf8, 0x1c, 0xe7, - 0x0, 0x1c, 0x0, 0x3, 0x80, 0x0, 0x20, 0x0 -}; - - -/*--------------------- - * GLYPH DESCRIPTION - *--------------------*/ - -static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = { - {.bitmap_index = 0, .adv_w = 0, .box_w = 0, .box_h = 0, .ofs_x = 0, .ofs_y = 0} /* id = 0 reserved */, - {.bitmap_index = 0, .adv_w = 342, .box_w = 22, .box_h = 18, .ofs_x = 0, .ofs_y = -2}, - {.bitmap_index = 50, .adv_w = 190, .box_w = 11, .box_h = 14, .ofs_x = 0, .ofs_y = 0}, - {.bitmap_index = 70, .adv_w = 304, .box_w = 19, .box_h = 20, .ofs_x = 0, .ofs_y = -3} -}; - -/*--------------------- - * CHARACTER MAPPING - *--------------------*/ - -static const uint16_t unicode_list_0[] = { - 0x0, 0xb4, 0x15d -}; - -/*Collect the unicode lists and glyph_id offsets*/ -static const lv_font_fmt_txt_cmap_t cmaps[] = -{ - { - .range_start = 61480, .range_length = 350, .glyph_id_start = 1, - .unicode_list = unicode_list_0, .glyph_id_ofs_list = NULL, .list_length = 3, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_TINY - } -}; - - - -/*-------------------- - * ALL CUSTOM DATA - *--------------------*/ - -#if LV_VERSION_CHECK(8, 0, 0) -/*Store all the custom data of the font*/ -static lv_font_fmt_txt_glyph_cache_t cache; -static const lv_font_fmt_txt_dsc_t font_dsc = { -#else -static lv_font_fmt_txt_dsc_t font_dsc = { -#endif - .glyph_bitmap = glyph_bitmap, - .glyph_dsc = glyph_dsc, - .cmaps = cmaps, - .kern_dsc = NULL, - .kern_scale = 0, - .cmap_num = 1, - .bpp = 1, - .kern_classes = 0, - .bitmap_format = 0, -#if LV_VERSION_CHECK(8, 0, 0) - .cache = &cache -#endif -}; - - -/*----------------- - * PUBLIC FONT - *----------------*/ - -/*Initialize a public general font descriptor*/ -#if LV_VERSION_CHECK(8, 0, 0) -const lv_font_t icons_19 = { -#else -lv_font_t icons_19 = { -#endif - .get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt, /*Function pointer to get glyph's data*/ - .get_glyph_bitmap = lv_font_get_bitmap_fmt_txt, /*Function pointer to get glyph's bitmap*/ - .line_height = 20, /*The maximum line height required by the font*/ - .base_line = 3, /*Baseline measured from the bottom of the line*/ -#if !(LVGL_VERSION_MAJOR == 6 && LVGL_VERSION_MINOR == 0) - .subpx = LV_FONT_SUBPX_NONE, -#endif -#if LV_VERSION_CHECK(7, 4, 0) || LVGL_VERSION_MAJOR >= 8 - .underline_position = -7, - .underline_thickness = 1, -#endif - .dsc = &font_dsc /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */ -}; - - - -#endif /*#if ICONS_19*/ - diff --git a/config/boards/arm/hw75_dynamic/app/screen/fonts/mono_19/CMakeLists.txt b/config/boards/arm/hw75_dynamic/app/screen/fonts/mono_19/CMakeLists.txt new file mode 100644 index 00000000..dc289e10 --- /dev/null +++ b/config/boards/arm/hw75_dynamic/app/screen/fonts/mono_19/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright (c) 2022-2023 XiNGRZ +# SPDX-License-Identifier: MIT + +zephyr_library() + +set(FONT_SRC icons.ttf) + +set(FONT_NAME mono) +set(FONT_SIZE 19) + +include(${ZMK_CONFIG}/cmake/font_subset.cmake) +font_subset(FONT_SUBSET_TTF ${FONT_SRC} ${ICONS_TXT}) + +include(${ZMK_CONFIG}/cmake/lv_font_conv.cmake) +lv_font_conv(FONT_C_SRCS ${FONT_SUBSET_TTF} + NAME ${FONT_NAME} + SIZE ${FONT_SIZE} + BPP 1 + NO_PREFILTER + NO_KERNING +) + +zephyr_library_sources(${FONT_C_SRCS}) +zephyr_library_include_directories(${ZEPHYR_LVGL_MODULE_DIR}) +zephyr_library_include_directories(${ZEPHYR_BASE}/lib/gui/lvgl) diff --git a/config/boards/arm/hw75_dynamic/app/screen/fonts/mono_19/icons.ttf b/config/boards/arm/hw75_dynamic/app/screen/fonts/mono_19/icons.ttf new file mode 100644 index 00000000..62f6f980 Binary files /dev/null and b/config/boards/arm/hw75_dynamic/app/screen/fonts/mono_19/icons.ttf differ diff --git a/config/boards/arm/hw75_dynamic/app/screen/icons.csv b/config/boards/arm/hw75_dynamic/app/screen/icons.csv new file mode 100644 index 00000000..84492998 --- /dev/null +++ b/config/boards/arm/hw75_dynamic/app/screen/icons.csv @@ -0,0 +1,3 @@ +ICON_VOL,f1ae +ICON_BRI,f198 +ICON_SCR,f193 diff --git a/config/boards/arm/hw75_dynamic/app/screen/layer_status.c b/config/boards/arm/hw75_dynamic/app/screen/layer_status.c index 7bd3d272..af3d2dd1 100644 --- a/config/boards/arm/hw75_dynamic/app/screen/layer_status.c +++ b/config/boards/arm/hw75_dynamic/app/screen/layer_status.c @@ -16,6 +16,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include +#include "icons.h" + #define DISPLAY_NODE DT_CHOSEN(zephyr_display) #define SCREEN_W DT_PROP(DISPLAY_NODE, width) @@ -29,17 +31,13 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #define LAYER_LABEL(node) COND_CODE_0(DT_NODE_HAS_PROP(node, label), (NULL), (DT_LABEL(node))), -LV_FONT_DECLARE(icons_19); +LV_FONT_DECLARE(mono_19); LV_FONT_DECLARE(zfull_9); -#define UI_SYMBOL_VOLUME "\xEF\x80\xA8" -#define UI_SYMBOL_BRIGHTNESS "\xEF\x86\x85" -#define UI_SYMBOL_SCROLL "\xEF\x83\x9C" - static const char *layer_icons[KEYMAP_LAYERS_NUM] = { - UI_SYMBOL_VOLUME, - UI_SYMBOL_BRIGHTNESS, - UI_SYMBOL_SCROLL, + ICON_VOL, + ICON_BRI, + ICON_SCR, }; static const char *layer_names[KEYMAP_LAYERS_NUM] = { DT_FOREACH_CHILD(KEYMAP_NODE, LAYER_LABEL) }; @@ -111,7 +109,7 @@ int layer_status_init(lv_obj_t *parent, lv_group_t *group) lv_style_set_text_color(&st_item, LV_STATE_DEFAULT, LV_COLOR_BLACK); lv_style_set_bg_color(&st_item, LV_STATE_FOCUSED, LV_COLOR_BLACK); lv_style_set_text_color(&st_item, LV_STATE_FOCUSED, LV_COLOR_WHITE); - lv_style_set_text_font(&st_item, LV_STATE_DEFAULT, &icons_19); + lv_style_set_text_font(&st_item, LV_STATE_DEFAULT, &mono_19); lv_obj_t *cont = lv_cont_create(parent, NULL); lv_cont_set_layout(cont, LV_LAYOUT_COLUMN_MID); diff --git a/config/cmake/ui_strings.cmake b/config/cmake/ui_strings.cmake index 128be9e3..fd2a8eed 100644 --- a/config/cmake/ui_strings.cmake +++ b/config/cmake/ui_strings.cmake @@ -2,7 +2,7 @@ # SPDX-License-Identifier: MIT function(GENERATE_UI_STRINGS INPUT) - set(options) + set(options UNICODE_HEX) set(one_value_keywords OUTPUT_DEFS OUTPUT_TEXT) set(multi_value_keywords) cmake_parse_arguments(UI_STRINGS @@ -19,12 +19,19 @@ function(GENERATE_UI_STRINGS INPUT) set(DEFS_FILE ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.h) set(TEXT_FILE ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.txt) + set(OPTS) + + if(UI_STRINGS_UNICODE_HEX) + list(APPEND OPTS "--unicode-hex") + endif() + add_custom_command( OUTPUT ${DEFS_FILE} ${TEXT_FILE} COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ui_strings.py ARGS --input ${INPUT} --output-defs ${DEFS_FILE} --output-text ${TEXT_FILE} + ${OPTS} DEPENDS ${INPUT} COMMENT "Generating UI strings: ${NAME}.h, ${NAME}.txt" ) diff --git a/config/cmake/ui_strings.py b/config/cmake/ui_strings.py index 54130fc3..ce5ed7db 100644 --- a/config/cmake/ui_strings.py +++ b/config/cmake/ui_strings.py @@ -6,15 +6,21 @@ def main(): parser.add_argument('--input', type=str, required=True) parser.add_argument('--output-defs', type=str, required=True) parser.add_argument('--output-text', type=str, required=True) + parser.add_argument('--unicode-hex', action='store_true', required=False) args = parser.parse_args() with open(args.input, 'r') as f_in, open(args.output_defs, 'w') as f_od, open(args.output_text, 'w') as f_ot: reader = csv.reader(f_in) for row in reader: key, value = row - text = value.strip().replace('\\n', '') - f_od.write(f'#define {key} "{value}"\n') - f_ot.write(f'{text}\n') + if args.unicode_hex: + text = chr(int(value, 16)) + f_od.write(f'#define {key} "\\u{value}"\n') + f_ot.write(f'{text}\n') + else: + text = value.strip().replace('\\n', '') + f_od.write(f'#define {key} "{value}"\n') + f_ot.write(f'{text}\n') if __name__ == '__main__': main()