Skip to content

digitalWrite() backwards compatibility problem #86

Open
@benwillcocks

Description

@benwillcocks

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions