Teensy3 has some compatibility macros for macros like:
digitalPinToPort() etc. that map pins to ports and bit masks.
While the Teensy3 compatibility macros actually will work the same
as the AVR versions,
the macro definitions are a bit confusing at first glance.
This is because of the goofy way the Arduino team did their mappings.
In their AVR definition,
digitalPinToPort(pin) returns a port table index value that is then handed to the macros:
portOutputRegister()
portInputRegister()
portModeRegister()
to get the port address.
So to get the actual port address associated with a pin when using AVR Arduino you must do:
portOutputRegister(digitalPinToPort(pin))
In the Teensy3 macros, they show every macro taking a pin argument.
While given the way the io register mapping currently works on Teensy3, that will work,
as well as when used the AVR way,
it was a bit jarring to me to see it defined this way since the portXXXRegister() macros
in AVR don't take a pin as a parameter but rather the goofy port index returned by digitalPinToPort()
So technically the definitions of digitalPinToPortReg() and digitalPinToBit()
should be:
Not sure how many folks really use these low level i/o interface but
for those that do, maybe a small comment and redefining the dititalPinToXX() macros above
would help to keep people from scratching their heads for a while until they figure it that it really does work.
And to keep them by using the pin number directly as the argument to the portOutputRegister() macro.
--- bill
digitalPinToPort() etc. that map pins to ports and bit masks.
While the Teensy3 compatibility macros actually will work the same
as the AVR versions,
the macro definitions are a bit confusing at first glance.
This is because of the goofy way the Arduino team did their mappings.
In their AVR definition,
digitalPinToPort(pin) returns a port table index value that is then handed to the macros:
portOutputRegister()
portInputRegister()
portModeRegister()
to get the port address.
So to get the actual port address associated with a pin when using AVR Arduino you must do:
portOutputRegister(digitalPinToPort(pin))
In the Teensy3 macros, they show every macro taking a pin argument.
While given the way the io register mapping currently works on Teensy3, that will work,
as well as when used the AVR way,
it was a bit jarring to me to see it defined this way since the portXXXRegister() macros
in AVR don't take a pin as a parameter but rather the goofy port index returned by digitalPinToPort()
So technically the definitions of digitalPinToPortReg() and digitalPinToBit()
should be:
Code:
#define digitalPinToPortReg(pin) portOutputRegister(digitalPinToPort(pin))
#define digitalPinToBit(pin) digitalPinToBitMask(pin)
Not sure how many folks really use these low level i/o interface but
for those that do, maybe a small comment and redefining the dititalPinToXX() macros above
would help to keep people from scratching their heads for a while until they figure it that it really does work.
And to keep them by using the pin number directly as the argument to the portOutputRegister() macro.
--- bill