diff --git a/Dockerfile b/Dockerfile index c3f98f34..822cded5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,13 +9,13 @@ WORKDIR /build # musl-dev is required for the multi lang firmwares # clang is required for clang-format (for dev) ARG APK_COMPS="gcc-riscv-none-elf gcc-arm-none-eabi newlib-riscv-none-elf \ - newlib-arm-none-eabi" + newlib-arm-none-eabi" ARG APK_PYTHON="python3 py3-pip black" ARG APK_MISC="findutils make git" ARG APK_DEV="musl-dev clang bash clang-extra-tools" # PIP packages -ARG PIP_PKGS='bdflib' +ARG PIP_PKGS='bdflib pyyaml' RUN apk add --no-cache ${APK_COMPS} ${APK_PYTHON} ${APK_MISC} ${APK_DEV} diff --git a/source/Core/Drivers/OLED.hpp b/source/Core/Drivers/OLED.hpp index ded87efe..1954b8fa 100644 --- a/source/Core/Drivers/OLED.hpp +++ b/source/Core/Drivers/OLED.hpp @@ -103,7 +103,7 @@ public: static int16_t getCursorX() { return cursor_x; } static void printBounded(const char *str, const uint8_t x, const uint8_t y, const uint8_t w, const uint8_t h, FontStyle fontStyle = FontStyle::FROM_TEXT); - void printNumberBounded(const uint16_t num, bool noLeaderZeros, const uint8_t x, const uint8_t y, const uint8_t w, const uint8_t h); + static void printNumberBounded(const uint16_t num, bool noLeaderZeros, const uint8_t x, const uint8_t y, const uint8_t w, const uint8_t h); static void print(const char *string, FontStyle fontStyle, uint8_t length = 255); // Draw a string to the current location, with selected font; optionally - with MAX length only diff --git a/source/Makefile b/source/Makefile index ddbf4ed8..cacd4548 100644 --- a/source/Makefile +++ b/source/Makefile @@ -171,6 +171,7 @@ SOURCE_DRIVERS_DIR = ./Core/Drivers INC_PD_DRIVERS_DIR = ./Core/Drivers/usb-pd/include PD_DRIVER_TESTS_DIR = ./Core/Drivers/usb-pd/tests PD_DRIVER_DIR = ./Core/Drivers/usb-pd +UI_DIR = ./UI # Find-all's used for formatting; have to exclude external modules @@ -419,6 +420,7 @@ INCLUDES = -I$(APP_INC_DIR) \ -I$(FRTOS_INC_DIR) \ -I$(DRIVER_INC_DIR) \ -I$(BSP_INC_DIR) \ + -I$(UI_DIR) \ -I$(THREADS_INC_DIR) \ -I$(THREADS_OP_MODES_INC_DIR) \ -I$(THREADS_OP_MODES_TOOLS_INC_DIR) \ @@ -433,6 +435,7 @@ EXCLUDED_DIRS := -path $(PINECILV2_VENDOR_BSP_ES8388_DIR) \ -o -path $(PINECILV2_VENDOR_BSP_USB_DIR) \ SOURCE := $(shell find $(SOURCE_THREADS_DIR) -type f -name '*.c') \ +$(shell find $(UI_DIR) -type f -name '*.c') \ $(shell find $(SOURCE_CORE_DIR) -type f -name '*.c') \ $(shell find $(SOURCE_DRIVERS_DIR) -type f -name '*.c') \ $(shell find $(DEVICE_BSP_DIR) -type d \( $(EXCLUDED_DIRS) \) -prune -false -o -type f -name '*.c')\ @@ -441,6 +444,7 @@ $(SOURCE_BRIEFLZ_DIR)/depack.c # We exclude the USB-PD stack tests $(PD_DRIVER_TESTS_DIR) SOURCE_CPP := $(shell find $(SOURCE_THREADS_DIR) -type f -name '*.cpp') \ $(shell find $(SOURCE_CORE_DIR) -type f -name '*.cpp') \ +$(shell find $(UI_DIR) -type f -name '*.cpp') \ $(shell find $(SOURCE_DRIVERS_DIR) -path $(PD_DRIVER_TESTS_DIR) -prune -false -o -type f -name '*.cpp') \ $(shell find $(DEVICE_BSP_DIR) -type d \( $(EXCLUDED_DIRS) \) -prune -false -o -type f -name '*.cpp') \ $(shell find $(SOURCE_MIDDLEWARES_DIR) -type f -name '*.cpp') diff --git a/source/UI/UI.cpp b/source/UI/UI.cpp index 13b38293..33927e47 100644 --- a/source/UI/UI.cpp +++ b/source/UI/UI.cpp @@ -1,4 +1,8 @@ #include "UI.h" -void ui_render_screen(Screen_t *screen, ScreenContext_t *context) { - // Basically switch out the handlers +#include "OLED.hpp" +void ui_render_screen(screenLayout_t *screen, ScreenContext_t *context) { + // Walk the struct associated to the screen, calling render for each element of the screen + // Then start OLED refresh + + OLED::refresh(); } \ No newline at end of file diff --git a/source/UI/UI.h b/source/UI/UI.h index 3790bcc6..6f586c81 100644 --- a/source/UI/UI.h +++ b/source/UI/UI.h @@ -1,37 +1,7 @@ #pragma once +#include "UI_Layouts.h" #include -typedef enum { - SimplifiedHome, // Basic home - SimplifiedHomeWarning, // Home with temp warning - DetailedHome, // Detailed home view - DetailedHomeWarning, // Home with temp warning - DebugMenu, // Debugging metrics - settingsCategory, // Settings category with icon - SettingsEntryBool, // Tickbox setting - SettingsEntry3Number, // Settings adjust with 3 number digits - SettingsEntry2Number, // Settings adjust with 2 number digits - SettingsEntry1Number, // Settings adjust with 2 number digits - SettingsEntry1Text, // Setting with single text char for state - ScrollingText, // Scrolling large text (warnings, help text) - SolderingMode, // Basic soldering mode - DetailedSolderingMode, // Detailed soldering mode - NumberAdjust, // Number adjust of number with <> either side -} screenLayout_t; - -typedef void (*render_prep_fn)(); -typedef void (*tick_fn)(); -typedef void (*button_handler_fn)(); - -typedef struct { - // on_enter - // on_exit - tick_fn tick; - render_prep_fn render_prepare; - screenLayout_t layout; // Render layout used - button_handler_fn handle_button; -} Screen_t; - typedef union { int32_t i32; void *ptr; @@ -42,4 +12,5 @@ typedef struct { } ScreenContext_t; // -void ui_render_screen(Screen_t *screen, ScreenContext_t *context); +void ui_render_screen(screenLayout_t *screen, ScreenContext_t *context); +void ui_render_element(const ElementTypes_t element, const ElementSettings_t *settings, screen_arg_t *args); \ No newline at end of file diff --git a/source/UI/UI_Elements.cpp b/source/UI/UI_Elements.cpp index 7522ce69..bb7468ca 100644 --- a/source/UI/UI_Elements.cpp +++ b/source/UI/UI_Elements.cpp @@ -1,6 +1,7 @@ #include "UI_Elements.h" #include "FontUtils.h" #include "OLED.hpp" +#include "UI.h" void render_Text(const ElementSettings_t *settings, screen_arg_t *args); void render_Number(const ElementSettings_t *settings, screen_arg_t *args); void render_Image(const ElementSettings_t *settings, screen_arg_t *args); @@ -54,7 +55,7 @@ void render_Number(const ElementSettings_t *settings, screen_arg_t *args) { } void render_Image(const ElementSettings_t *settings, screen_arg_t *args) { // arg is a pointer to the raw image data to display - OLED::drawArea(settings->position.x, settings->position.y, settings->size.w, settings->size.h, (uint8_t *)args->ptr) + OLED::drawArea(settings->position.x, settings->position.y, settings->size.w, settings->size.h, (uint8_t *)args->ptr); } void render_PowerSource(const ElementSettings_t *settings, screen_arg_t *args) { // diff --git a/source/UI/UI_Elements.h b/source/UI/UI_Elements.h index 123dd008..0ce56b16 100644 --- a/source/UI/UI_Elements.h +++ b/source/UI/UI_Elements.h @@ -1,5 +1,6 @@ #pragma once -#include "UI.h" +#include + typedef enum { Text, // Basic text splat, using re-encoded strings Number, // Draws numbers using best size for the height (always one line) @@ -23,5 +24,3 @@ typedef struct { } size; } ElementSettings_t; - -void ui_render_element(const ElementTypes_t element,const ElementSettings_t * settings, screen_arg_t *args); \ No newline at end of file diff --git a/source/UI/UI_Layouts.h b/source/UI/UI_Layouts.h new file mode 100644 index 00000000..f78b6bcb --- /dev/null +++ b/source/UI/UI_Layouts.h @@ -0,0 +1,26 @@ +#pragma once +#include "UI_Elements.h" +typedef enum { + SimplifiedHome, // Basic home + SimplifiedHomeWarning, // Home with temp warning + DetailedHome, // Detailed home view + DetailedHomeWarning, // Home with temp warning + DebugView, // Debugging metrics + settingsCategory, // Settings category with icon + SettingsEntryBool, // Tickbox setting + SettingsEntry3Number, // Settings adjust with 3 number digits + SettingsEntry2Number, // Settings adjust with 2 number digits + SettingsEntry1Number, // Settings adjust with 2 number digits + SettingsEntry1Text, // Setting with single text char for state + ScrollingText, // Scrolling large text (warnings, help text) + SolderingMode, // Basic soldering mode + DetailedSolderingMode, // Detailed soldering mode + NumberAdjust, // Number adjust of number with <> either side +} screenLayout_t; + +typedef struct { + struct { + ElementTypes_t elementType; + ElementSettings_t elementSettings; + } elements[5]; +} ScreenLayoutRecord_t; \ No newline at end of file diff --git a/source/UI/UI_Screens.h b/source/UI/UI_Screens.h new file mode 100644 index 00000000..fbef6125 --- /dev/null +++ b/source/UI/UI_Screens.h @@ -0,0 +1,15 @@ +#pragma once +#include "UI_Layouts.h" + +typedef void (*render_prep_fn)(); +typedef void (*tick_fn)(); +typedef void (*button_handler_fn)(); + +typedef struct { + // on_enter + // on_exit + tick_fn tick; + render_prep_fn render_prepare; + screenLayout_t layout; // Render layout used + button_handler_fn handle_button; +} Screen_t; diff --git a/source/UI/layout_96x16.yaml b/source/UI/layout_96x16.yaml index 61d1fc5a..379eca55 100644 --- a/source/UI/layout_96x16.yaml +++ b/source/UI/layout_96x16.yaml @@ -1,5 +1,5 @@ layouts: - simplifiedHome: + SimplifiedHome: mirrorOnRotate: true elements: - type: image