2.2 C for hardware
Talking to peripherals through registers, what volatile and const promise, the preprocessor, callbacks and dispatch tables, data structures on static memory,…
Lessons
- Registers, volatile and const · How C talks to hardware: memory-mapped registers, what volatile and const promise, register structs and read-modify-write.
- Inline functions and macros · The preprocessor, macro pitfalls, inline functions and X-macros.
- Function pointers and callbacks · Callbacks, dispatch tables and the context pointer that makes them reusable.
- Buffers and data structures · Ring buffers, pools, lists and bitmaps on static memory.
- Fixed-point and signal processing · Scaling, rounding, saturation and filters without floating point.
Project: Smart LED lamp
A Wi-Fi lamp, written the way firmware for hardware is written: pins configured through register fields, helper macros that cannot bite, effects in a table of function pointers, an event log in a ring buffer, and fades in fixed-point arithmetic.