From c73867ea4d12b723deef2b52fb02882928267d8b Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 30 May 2023 16:00:55 +0200 Subject: [PATCH] ngui: get rid of the ambiguous ui header file functions declared in ui.h were actually used by ui.c, the opposite of what such a header is expected to contain. these functions are defined in zig code and declarations are better off in the same ui.c file. this is just a quick clean up before porting some C code to zig. --- build.zig | 2 +- src/ui/c/lv_custom_tick.h | 16 ++++++++++++++++ src/ui/c/ui.c | 23 +++++++++++++++++++++-- src/ui/c/ui.h | 28 ---------------------------- 4 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 src/ui/c/lv_custom_tick.h delete mode 100644 src/ui/c/ui.h diff --git a/build.zig b/build.zig index cc283bc..ed397e8 100644 --- a/build.zig +++ b/build.zig @@ -54,7 +54,7 @@ pub fn build(b: *std.build.Builder) void { ngui.defineCMacroRaw(b.fmt("NM_DISP_VER={}", .{disp_vert})); ngui.defineCMacro("LV_CONF_INCLUDE_SIMPLE", null); ngui.defineCMacro("LV_TICK_CUSTOM", "1"); - ngui.defineCMacro("LV_TICK_CUSTOM_INCLUDE", "\"ui.h\""); + ngui.defineCMacro("LV_TICK_CUSTOM_INCLUDE", "\"lv_custom_tick.h\""); ngui.defineCMacro("LV_TICK_CUSTOM_SYS_TIME_EXPR", "(nm_get_curr_tick())"); switch (drv) { .sdl2 => { diff --git a/src/ui/c/lv_custom_tick.h b/src/ui/c/lv_custom_tick.h new file mode 100644 index 0000000..77ed9fb --- /dev/null +++ b/src/ui/c/lv_custom_tick.h @@ -0,0 +1,16 @@ +#ifndef NM_UI_H +#define NM_UI_H + +/** + * this file exists to satisfy LV_TICK_CUSTOM_INCLUDE. + */ + +#include + +/** + * returns elapsed time since program start, in ms. + * rolls over when overflow occurs. + */ +uint32_t nm_get_curr_tick(); + +#endif diff --git a/src/ui/c/ui.c b/src/ui/c/ui.c index e0d8599..e72724d 100644 --- a/src/ui/c/ui.c +++ b/src/ui/c/ui.c @@ -1,12 +1,31 @@ +/** + * function declarations with nm_ prefix are typically defined in zig, + * while extern'ed function definitions with nm_ prefix are typically called from zig. + */ + #define _DEFAULT_SOURCE /* needed for usleep() */ #include "lvgl/lvgl.h" -#include "ui.h" - #include #include +/** + * initiates system shutdown leading to poweroff. + */ +void nm_sys_shutdown(); + +/** + * invoken when the UI is switched to the network settings tab. + */ +void nm_tab_settings_active(); + +/** + * initiate connection to a wifi network with the given SSID and a password. + * connection, if successful, is persisted in wpa_supplicant config. + */ +int nm_wifi_start_connect(const char *ssid, const char *password); + static lv_style_t style_title; static lv_style_t style_text_muted; static lv_style_t style_btn_red; diff --git a/src/ui/c/ui.h b/src/ui/c/ui.h deleted file mode 100644 index 1029657..0000000 --- a/src/ui/c/ui.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef NM_UI_H -#define NM_UI_H - -#include - -/** - * returns elapsed time since program start, in ms. - * rolls over when overflow occurs. - */ -uint32_t nm_get_curr_tick(); - -/** - * initiates system shutdown leading to poweroff. - */ -void nm_sys_shutdown(); - -/** - * invoken when the UI is switched to the network settings tab. - */ -void nm_tab_settings_active(); - -/** - * initiate connection to a wifi network with the given SSID and a password. - * connection, if successful, is persisted in wpa_supplicant config. - */ -int nm_wifi_start_connect(const char *ssid, const char *password); - -#endif