From cb3d81535b54c57bc619bc7e1d3b468ea0be5039 Mon Sep 17 00:00:00 2001 From: liquidraver <504870+liquidraver@users.noreply.github.com> Date: Fri, 3 Jul 2026 20:14:18 +0200 Subject: [PATCH] gate color code to tft only --- zephcore/helpers/ui/display.c | 37 ++++++++++++++++++++++++++++++----- zephcore/helpers/ui/display.h | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/zephcore/helpers/ui/display.c b/zephcore/helpers/ui/display.c index 4fbe34e..c06f453 100644 --- a/zephcore/helpers/ui/display.c +++ b/zephcore/helpers/ui/display.c @@ -55,6 +55,8 @@ static uint16_t disp_height; static uint8_t font_w; static uint8_t font_h; static bool is_epd; /* true for e-paper displays */ + +#if MC_DISPLAY_COLOR_PANEL static bool has_color; /* true when a raw RGB565 TFT is available */ const uint8_t *zephcore_font_6x8_glyph(uint8_t c); @@ -82,12 +84,9 @@ static struct color_op color_ops[COLOR_MAX_OPS]; static uint8_t color_op_count; static uint16_t color_line[COLOR_MAX_WIDTH]; -#if DT_NODE_EXISTS(DT_NODELABEL(tft)) static const struct device *color_dev = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(tft)); -#else -static const struct device *color_dev; -#endif +#endif /* MC_DISPLAY_COLOR_PANEL */ /* Optional symmetric inset (pixels). Shrinks reported width/height and * offsets all draw primitives so panels with edge artefacts can hide them @@ -165,6 +164,7 @@ static inline void panel_vdd_enable(void) } } +#if MC_DISPLAY_COLOR_PANEL static void color_overlay_probe(void) { has_color = false; @@ -299,6 +299,11 @@ static void color_write_text_now(int x, int y, const char *text, uint16_t color) } } +static void color_ops_reset(void) +{ + color_op_count = 0; +} + static void color_flush_ops(void) { if (!has_color) { @@ -318,6 +323,22 @@ static void color_flush_ops(void) color_op_count = 0; } +#else /* !MC_DISPLAY_COLOR_PANEL */ + +static void color_overlay_probe(void) +{ +} + +static void color_ops_reset(void) +{ +} + +static void color_flush_ops(void) +{ +} + +#endif /* MC_DISPLAY_COLOR_PANEL */ + /* Auto-off work */ static struct k_work_delayable auto_off_work; @@ -583,10 +604,12 @@ bool mc_display_is_epd(void) return is_epd; } +#if MC_DISPLAY_COLOR_PANEL bool mc_display_has_color(void) { return has_color; } +#endif void mc_display_clear(void) { @@ -594,7 +617,7 @@ void mc_display_clear(void) return; } - color_op_count = 0; + color_ops_reset(); if (is_epd) { epd_frame_hash = 2166136261u; } @@ -624,6 +647,7 @@ void mc_display_text(int x, int y, const char *text, bool invert) } } +#if MC_DISPLAY_COLOR_PANEL void mc_display_color_text(int x, int y, const char *text, uint16_t color) { if (!disp_initialized || !text) { @@ -634,6 +658,7 @@ void mc_display_color_text(int x, int y, const char *text, uint16_t color) mc_display_text(x, y, text, false); } } +#endif void mc_display_fill_rect(int x, int y, int w, int h) { @@ -657,6 +682,7 @@ void mc_display_fill_rect(int x, int y, int w, int h) } } +#if MC_DISPLAY_COLOR_PANEL void mc_display_color_fill_rect(int x, int y, int w, int h, uint16_t color) { if (!disp_initialized) { @@ -667,6 +693,7 @@ void mc_display_color_fill_rect(int x, int y, int w, int h, uint16_t color) mc_display_fill_rect(x, y, w, h); } } +#endif void mc_display_hline(int x, int y, int w) { diff --git a/zephcore/helpers/ui/display.h b/zephcore/helpers/ui/display.h index c6b1810..1e5cb67 100644 --- a/zephcore/helpers/ui/display.h +++ b/zephcore/helpers/ui/display.h @@ -20,6 +20,8 @@ #include #include +#include + #ifdef __cplusplus extern "C" { #endif @@ -83,11 +85,25 @@ bool mc_display_is_on(void); */ bool mc_display_is_epd(void); +/* Color overlay support is compiled only when the devicetree has a raw + * RGB565 TFT under the `tft` nodelabel (the runtime probe still verifies + * pixel format and readiness). Boards without one get constant-false / + * mono-fallback inlines so every color code path — including the ~3.8 KB + * overlay op queue in display.c — is dropped at compile time. */ +#define MC_DISPLAY_COLOR_PANEL DT_NODE_EXISTS(DT_NODELABEL(tft)) + /** * @return true when a raw RGB565-capable color panel is available for * optional color overlays. Monochrome displays return false. */ +#if MC_DISPLAY_COLOR_PANEL bool mc_display_has_color(void); +#else +static inline bool mc_display_has_color(void) +{ + return false; +} +#endif /** * Clear the framebuffer (fill with black). @@ -122,7 +138,16 @@ void mc_display_text(int x, int y, const char *text, bool invert); * * Color overlays are flushed after the normal CFB frame in mc_display_finalize(). */ +#if MC_DISPLAY_COLOR_PANEL void mc_display_color_text(int x, int y, const char *text, uint16_t color); +#else +static inline void mc_display_color_text(int x, int y, const char *text, + uint16_t color) +{ + (void)color; + mc_display_text(x, y, text, false); +} +#endif /** * Draw a filled rectangle. @@ -138,7 +163,16 @@ void mc_display_fill_rect(int x, int y, int w, int h); * Draw a filled rectangle using RGB565 color when supported. On non-color * displays this falls back to mc_display_fill_rect(). */ +#if MC_DISPLAY_COLOR_PANEL void mc_display_color_fill_rect(int x, int y, int w, int h, uint16_t color); +#else +static inline void mc_display_color_fill_rect(int x, int y, int w, int h, + uint16_t color) +{ + (void)color; + mc_display_fill_rect(x, y, w, h); +} +#endif /** * Draw a horizontal line.