KurtE
Senior Member+
I was trying out a sketch where I did not specify an optional pin number to the constructor.
The library code later did a
The addr2line pointed to core_pins.h to the digitalWriteFast function
Which make sense, as:
As portSetRegister just blindly indexes into an array and grabs stuff from random location:
And likewise for getting the mask and then writing that mask value into the random location
returned from the portSetRegister...
Note: This does not happen if you pass in a constant pin number like 0xff
as none of the tests like:
will match so it does not do anything...
Two obvious options here:
a) Punt and say - as expected... And change library to check for this.
b) change digitalWriteFast (and probably others to be like:
Back to playing
The library code later did a
Code:
digitalWriteFast(_rd, HIGH);
The addr2line pointed to core_pins.h to the digitalWriteFast function
Which make sense, as:
C++:
static inline void digitalWriteFast(uint8_t pin, uint8_t val)
{
if (__builtin_constant_p(pin)) {
if (val) {
if (pin == 0) {
CORE_PIN0_PORTSET = CORE_PIN0_BITMASK;
} else if (pin == 1) {
CORE_PIN1_PORTSET = CORE_PIN1_BITMASK;
} else if (pin == 2) {
CORE_PIN2_PORTSET = CORE_PIN2_BITMASK;
...
}
} else {
if(val) *portSetRegister(pin) = digitalPinToBitMask(pin);
else *portClearRegister(pin) = digitalPinToBitMask(pin);
}
}
Code:
#define portSetRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 33))
And likewise for getting the mask and then writing that mask value into the random location
returned from the portSetRegister...
Note: This does not happen if you pass in a constant pin number like 0xff
as none of the tests like:
Code:
if (pin == 0) {
CORE_PIN0_PORTSET = CORE_PIN0_BITMASK;
} else if (pin == 1) {
CORE_PIN1_PORTSET = CORE_PIN1_BITMASK;
} else if (pin == 2) {
CORE_PIN2_PORTSET = CORE_PIN2_BITMASK;
} else if (pin == 3) {
will match so it does not do anything...
Two obvious options here:
a) Punt and say - as expected... And change library to check for this.
b) change digitalWriteFast (and probably others to be like:
Code:
} else if (pin < CORE_NUM_DIGITAL {
if(val) *portSetRegister(pin) = digitalPinToBitMask(pin);
else *portClearRegister(pin) = digitalPinToBitMask(pin);
}
Back to playing