5.3 Designing firmware
Layering drivers so they are portable and testable, and the error-handling, encapsulation and table-driven patterns that recur in every codebase.
Lessons
- Driver design: HAL versus bare metal · Layering a driver so it is testable, portable and still fast.
- Embedded C code patterns · Error handling, opaque handles, ring buffers, tables and other everyday shapes.
- Firmware architectures · Superloop, interrupts, event-driven or an RTOS: how to structure firmware and when to choose each.
- Error handling and fault strategy · Error codes, assertions, safe states and keeping evidence of what went wrong.
Project: Smart thermostat
A thermostat that runs for years without a reboot: drivers that can be tested without a board, modules that do not depend on each other, a main loop that never blocks, and a safe answer when the sensor fails.