Description
Virtualization of pins, allowing the environment to be extended with external pin over SPI or I²C and making them transparent to user and libraries.
This can be implemented on multiple ways:
- Add an extra burden to the pinMode/digitalRead/digital by installing an
if (pin>nr_of_digital_pins) «call virtual pins handler here»
- Extend the pin tables with a predefined set of allowed extra virtual pins, then the actual
if (port == NOT_A_PIN)
already present on the pin functions could be used to call the virtual pins handler with no extra burden to pin functions.
About the virtual pins handler, I suggest it to be just a function address (x3) pointing to a dumb function (just return). This way virtual pins would have only the extra 3 function pointers and a simple return function allowing it to be implemented as a library
All this can be conditionally compiled if there's a way of introducing preprocessor defines to the compiler environment (-D
flag). However, there is not an easy way of doing that when using Arduino IDE.
Option 2 has the advantage of being compatible with code that checks the pin tables https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/Arduino.h#L177
I leave this to consideration and expect feedback of pros and cons before advancing.
I've done essays by extending the pin tables and they worked very well.