u/silicagel777

How to structure a simple firmware with a GUI?

This is a question that's been bothering me for quite I while. I'm not talking about complex user interfaces that warrant a RTOS and a GUI framework, it's about something simple: like a clock with a few setup screens or a configurable thermostat.

Most projects I've seen use something like a big switch-case statement in a loop. However, this approach seems to descend into spaghetti madness really quickly, especially when something needs to run with a frequency not matching the GUI loop frequency.

I've currently settled on a more event-driven approach: I have a simple timer scheduler that runs function callbacks and I have a simple button handling thing that runs a callback whenever a button is pressed. This way, changing a GUI screen means removing older callbacks and registering a few new ones, and running something in the background means just registering another function in the scheduler. This approach works better for me, but I still feel like I'm halfway to an actually decent architecture.

So here the question: how do you structure embedded projects of this kind? Is there any publicly available code which you believe completely nailed it? Any input is welcome.

reddit.com
u/silicagel777 — 1 day ago