-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFastShiftIn.h
64 lines (44 loc) · 1.27 KB
/
FastShiftIn.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
//
// FILE: FastShiftIn.h
// AUTHOR: Rob Tillaart
// VERSION: 0.4.0
// PURPOSE: Fast ShiftIn for 74HC165 register, AVR optimized
// DATE: 2013-09-29
// URL: https://github.com/RobTillaart/FastShiftIn
#include "Arduino.h"
#define FASTSHIFTIN_LIB_VERSION (F("0.4.0"))
// uncomment next line to get SPEED OPTIMIZED CODE
// #define FASTSHIFTIN_AVR_LOOP_UNROLLED 1
class FastShiftIn
{
public:
// bitOrder = { LSBFIRST, MSBFIRST };
FastShiftIn(uint8_t dataIn, uint8_t clockPin, uint8_t bitOrder = LSBFIRST);
uint16_t read(void);
uint16_t read16(void);
uint32_t read24(void);
uint32_t read32(void);
uint32_t lastRead(void);
// Experimental 0.3.4
void read(uint8_t * array, uint8_t size);
// returns false if bitOrder out of range.
bool setBitOrder(uint8_t bitOrder);
uint8_t getBitOrder(void);
// overrule bitOrder (most optimized).
uint8_t readLSBFIRST(void);
uint8_t readMSBFIRST(void);
private:
uint8_t _bitOrder;
uint32_t _lastValue;
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
volatile uint8_t *_dataInRegister;
uint8_t _dataInBit;
volatile uint8_t *_clockRegister;
uint8_t _clockBit;
#else
uint8_t _dataPinIn;
uint8_t _clockPin;
#endif
};
// -- END OF FILE --