I really appreciate all of your helpful comments.
I am trying to finish a digital I/O library for advanced users. Maybe I should go back to my original thought.
void mode(bool) - writes the DDR bit for the Arduino pin.
bool read() - reads the PIN bit for the Arduino pin.
void write(bool) - writes the PORT bit for the Arduino pin.
This would be easy to explain to an advanced user. I won't worry about beginners.
Here is a test program that makes 125 ns wide pulses for scope tests:
// scope test for write timing
#include <DigitalPin.h>
// class with compile time pin number
DigitalPin<13> pin13;
void setup() {
// set mode to OUTPUT
pin13.mode(OUTPUT);
}
void loop() {
pin13.high();
pin13.low();
pin13.write(1);
pin13.write(0);
delay(1);
}
high() and low() are the same as write(1) and write(0). If the argument of write is not a constant, write takes longer than two cycles. A high address port on a Mega takes much longer for atomic writes.
I also provide a class with run-time pin numbers which takes 13 cycles for atomic writes. This is still about four times faster than digitalWrite(). 13 cycles is for a constant write argument.
This library also has a software SPI class for all SPI modes that runs at about 2 MHz. Currently I only provide MSB first but it would be easy to support LSB first also.
I currently use SoftSPI in SdFat for software SPI access to SD cards. This allows 328 SD shields to be used on Mega and Leonardo without jumpers.
I can't imagine making a reasonable Arduino port for Cortex ARM processors. I use STM32, LPC, and SAM3. I would hate being locked into one Atmel processor that the Arduino team picked.