Home / Learn Embedded C / Arduino-Style Libraries vs Bare-Metal C
Arduino-Style Libraries vs Bare-Metal C
digitalWrite() vs writing directly to a hardware register — the trade-off explained.
Theory in plain words
The basic idea
Arduino-style functions like digitalWrite()/pinMode() are friendly wrapper functions; bare-metal code writes directly to the chip's hardware registers for full control and speed.
Why this comes up
Beginners usually start with the friendly wrappers to learn concepts fast; professional and performance-critical firmware often drops to bare-metal register access for speed, size or precise timing.
The mechanics
A wrapper function like digitalWrite(13, HIGH) internally does exactly the same register read-modify-write you would do by hand — it is just slower because of extra function-call and lookup overhead.
Where it is used
- Beginner vs advanced firmware style
- Code review discussions
Try it
Both lines end up doing the exact same bit-set operation on the same underlying register — the wrapper just hides the shift-and-OR.
This course teaches both styles
Early lessons use friendly simulated calls like GPIO_WRITE() so you can focus on concepts. Register-level lessons later (and the Chip Families group) show the exact bare-metal register writes those friendly calls stand in for.
Try it: a wrapper function for reading a pin
Just like digitalWrite(), a digitalRead()-style wrapper is only ever shifting and masking the same register you could read by hand.
Quick check
1. What does a function like digitalWrite() usually do internally?
Friendly wrapper functions are convenience layers over the same underlying register operations.