| 88 | |
| 89 | |
| 90 | int FastShiftIn::readMSBFIRST() |
| 91 | { |
| 92 | #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) |
| 93 | |
| 94 | uint8_t rv = 0; |
| 95 | uint8_t cbmask1 = _clockBit; |
| 96 | uint8_t cbmask2 = ~_clockBit; |
| 97 | uint8_t inmask1 = _dataInBit; |
| 98 | |
| 99 | for (uint8_t m = 0x80; m > 0; m >>= 1) |
| 100 | { |
| 101 | uint8_t oldSREG = SREG; |
| 102 | noInterrupts(); |
| 103 | // clock pulse HIGH |
| 104 | *_clockRegister |= cbmask1; |
| 105 | // read one bit |
| 106 | if ((*_dataInRegister & inmask1) > 0) rv |= m; |
| 107 | // clock pulse LOW |
| 108 | *_clockRegister &= cbmask2; |
| 109 | SREG = oldSREG; |
| 110 | } |
| 111 | _value = rv; |
| 112 | return rv; |
| 113 | |
| 114 | #else |
| 115 | |
| 116 | // reference implementation |
| 117 | _value = shiftIn(_dataPinIn, _clockPin, MSBFIRST); |
| 118 | return _value; |
| 119 | |
| 120 | #endif |
| 121 | |
| 122 | } |
| 123 | |
| 124 | |
| 125 | int FastShiftIn::lastRead(void) |