From 649f978224d79947d679612e4bcb326280f4f963 Mon Sep 17 00:00:00 2001 From: luca Date: Fri, 26 Apr 2019 14:32:43 +0200 Subject: Minor optimization in shiftOut function --- cores/arduino/wiring_shift.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'cores/arduino') diff --git a/cores/arduino/wiring_shift.c b/cores/arduino/wiring_shift.c index 2b6f7a8..042a95a 100644 --- a/cores/arduino/wiring_shift.c +++ b/cores/arduino/wiring_shift.c @@ -42,10 +42,13 @@ void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) uint8_t i; for (i = 0; i < 8; i++) { - if (bitOrder == LSBFIRST) - digitalWrite(dataPin, !!(val & (1 << i))); - else - digitalWrite(dataPin, !!(val & (1 << (7 - i)))); + if (bitOrder == LSBFIRST) { + digitalWrite(dataPin, val & 1); + val >>= 1; + } else { + digitalWrite(dataPin, val & 128); + val <<= 1; + } digitalWrite(clockPin, HIGH); digitalWrite(clockPin, LOW); -- cgit v1.2.3-18-g5258 From 4d074e8a54d5395cafbb2c860f55304b329d83ab Mon Sep 17 00:00:00 2001 From: luca Date: Fri, 26 Apr 2019 20:21:27 +0200 Subject: Fixed shiftOut in MSBFIRST mode HIGH/LOW --- cores/arduino/wiring_shift.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cores/arduino') diff --git a/cores/arduino/wiring_shift.c b/cores/arduino/wiring_shift.c index 042a95a..a9b3be5 100644 --- a/cores/arduino/wiring_shift.c +++ b/cores/arduino/wiring_shift.c @@ -46,7 +46,7 @@ void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) digitalWrite(dataPin, val & 1); val >>= 1; } else { - digitalWrite(dataPin, val & 128); + digitalWrite(dataPin, (val & 128) != 0); val <<= 1; } -- cgit v1.2.3-18-g5258