arduino / arduino/ArduinoCore-megaavr
digitalWrite() backwards compatibility problem
- Dominant language
- C++
- Stars
- 111
- Forks
- 65
- PR merge metrics
- No merged PRs in 30d
Description
Line 164 of wiring_digital.c has the comment "old implementation has side effect when pin set as input - pull up is enabled if this function is called. Should we purposely implement this side effect?". Actually, a more important feature of the old implementation of digitalWrite(), which is missing from the new implementation, is that it can be used to set the output register whilst the pin is configured as an input. Here are two situations where this is useful:
1] if a pin is used for bidirectional communication, it can be necessary to change direction from input to output without changing the state of the pin. To achieve this one needs to read the input, set the output register accordingly, and then make the pin an output.
2] if multiple pins (not necessarily on the same port) are commoned for extra drive strength, then one must be careful to avoid the outputs fighting one another. When changing the state it is necessary to make all the pins inputs, then change the output registers, then make all the pins outputs.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at line 164 of wiring_digital.c and inspect the current digitalWrite() behavior against the old implementation referenced in the issue. Done means preserving the output-register state when a pin is configured as an input, including the bidirectional and commoned-pin use cases described; the payload names no test file to run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100