Ah, I remember Casey Muratori speaking having desktop OS where everything is memory mapped.
I remember reading a book that explains the low level Arduino schematic paired with C code that does exactly what you are describing. Is there any such book for modern microcontrollers?