Skip to content

Fast functions not single-statement safe... #7

@WestfW

Description

@WestfW

the digitalWriteFast() and etc macros will not compile properly as "single statements", causing constructs like the following to fail with an "'else' without a previous 'if' error"

void setup() {
  if (digitalRead(1) == HIGH)
    digitalWriteFast(2, HIGH);
  else
    digitalWriteFast(3, HIGH);
}

This can be fixed (in a standard way) by wrapping them in a 1-time loop:

#define digitalWriteFast(P, V) \
 do { \
  if (__builtin_constant_p(P)) { \
    BIT_WRITE(*__digitalPinToPortReg(P), __digitalPinToBit(P), (V)); \
  } else { \
    digitalWrite((P), (V)); \
  } \
 } while (0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions