arduino / arduino/ArduinoCore-avr
shiftin() bad code size and speed
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
shiftin() seems inefficient especially for small machines because of the use of "dynamic shifts" like (1<>1) | (digitalRead(dataPin)<<7);
else
val = (val<<1) | digitalRead(dataPin);
digitalWrite(clockPin, LOW);
}
return val;
}
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) {
for (uint8_t i = 0; i != 8; i++) {
if (bitOrder == LSBFIRST)
digitalWrite(dataPin, val & 0x01), val >>= 1;
else
digitalWrite(dataPin, !!(val & 0x80)), val <<= 1;
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Locate the existing C implementations of shiftIn()/shiftOut() and compare their behavior with the proposed replacements, including both LSBFIRST and MSBFIRST paths. Done means the cleanup preserves the existing pin and bit-order behavior while addressing the reported code-size and speed concerns on small AVR machines.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100