From 48305e2935ac02f93d21ac1cf8a3ba55670556b1 Mon Sep 17 00:00:00 2001 From: thorv Date: Sun, 12 Nov 2023 08:59:30 +0900 Subject: [PATCH] change digitalWrite() --- cores/arduino/wiring_digital.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 0d51d57d..9754e505 100644 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -145,22 +145,19 @@ void digitalWrite(uint8_t pin, PinStatus val) /* Get port */ PORT_t *port = digitalPinToPortStruct(pin); - /* Output direction */ - if(port->DIR & bit_mask){ - - /* Set output to value */ - if (val == LOW) { /* If LOW */ - port->OUTCLR = bit_mask; + /* Set output to value */ + if (val == LOW) { /* If LOW */ + port->OUTCLR = bit_mask; - } else if (val == CHANGE) { /* If TOGGLE */ - port->OUTTGL = bit_mask; - /* If HIGH OR > TOGGLE */ - } else { - port->OUTSET = bit_mask; - } + } else if (val == CHANGE) { /* If TOGGLE */ + port->OUTTGL = bit_mask; + /* If HIGH OR > TOGGLE */ + } else { + port->OUTSET = bit_mask; + } /* Input direction */ - } else { + if(port->DIR & bit_mask){ /* 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?