| 54 | |
| 55 | |
| 56 | int FastShiftIn::readLSBFIRST() |
| 57 | { |
| 58 | #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) |
| 59 | |
| 60 | uint8_t rv = 0; |
| 61 | uint8_t cbmask1 = _clockBit; |
| 62 | uint8_t cbmask2 = ~_clockBit; |
| 63 | uint8_t inmask1 = _dataInBit; |
| 64 | |
| 65 | for (uint8_t m = 1; m > 0; m <<= 1) |
| 66 | { |
| 67 | uint8_t oldSREG = SREG; |
| 68 | noInterrupts(); |
| 69 | // clock pulse HIGH |
| 70 | *_clockRegister |= cbmask1; |
| 71 | // read one bit |
| 72 | if ((*_dataInRegister & inmask1) > 0) rv |= m; |
| 73 | // clock pulse LOW |
| 74 | *_clockRegister &= cbmask2; |
| 75 | SREG = oldSREG; |
| 76 | } |
| 77 | _value = rv; |
| 78 | return rv; |
| 79 | |
| 80 | #else |
| 81 | |
| 82 | // reference implementation |
| 83 | _value = shiftIn(_dataPinIn, _clockPin, LSBFIRST); |
| 84 | return _value; |
| 85 | |
| 86 | #endif |
| 87 | } |
| 88 | |
| 89 | |
| 90 | int FastShiftIn::readMSBFIRST() |