Wed May 11 12:15:08 EDT 2016

Supporting multiple boards with optimized HW functions

I've found this hard to do in C.  Situation: a number of boards with
different hardware configurations (e.g pins, peripherals) but in need
of fast HW access.

For fast HW access, the solution is to use inline functions, possibly
parameterized by static const structures.  I.e. make sure the compiler
has access to the config for constant foldig, and optionally doesn't
need to include the config structs themselves in the image.

However, this still creates a problem of instantiation.  The idea is
then to instantiate functions in the main .c file, one for each board.
These main .c files provide an iterface to the library code that is
shared across the boards.  The HAL thus consists of plain C functions
defined in main .c, used by library code.

To further separate this I found it useful to define a set of
inline.*.c files that are not compiled to .o and gathered in in the
libary, but are inlined in the main file through #include preprocessor
directives.  These files expect symbols or macros defined outside of

It's possible to have it both ways:
- create .c files that reference a C object for config
  - either create this object as non-static, in which the config is dynamic 
  - or create it as a const static object and inline the .c in main .c to give static config

Depending on whether the code describes a singleton or a function that
is used multiple times it can reference a global symbol or a function
parameter for the configuration.