New fast digital I/O and Software SPI libraries

westfw,

Your right, the cost of making apps based on the Arduino core reliable is too high. That's one reason why using Arduino to build reliable critical systems is a bad idea.

There is a large literature of studies about the overhead required for reliability in well designed critical systems. The typical number is 5% performance and size.

I spent most of my career around large particle accelerators and space experiments. The above percentage matches my experience with real systems.

To achieve this low overhead means putting high priority on reliability in system architecture and design.

In your example, pin number is a variable and appears in every API function. This mean lots of range checks in libraries that present pin number as a variable in their API.

Often pin number is a constant and you could use a C++ template so no run-time checks are require. The code will be faster and smaller than the Arduino digital I/O implementation.

If pin number must be variable you can use a C++ object with pin number appearing in only one API function with only one check.

Ways to handle errors that occur deeply in embedded systems was solved in the 1970s for large embedded systems.