2020-11-27 05:16:22 -05:00
|
|
|
#pragma once
|
2013-09-29 13:10:03 -04:00
|
|
|
//
|
|
|
|
// FILE: FastShiftIn.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2022-11-16 10:07:44 -05:00
|
|
|
// VERSION: 0.3.1
|
2020-11-27 05:16:22 -05:00
|
|
|
// PURPOSE: Fast ShiftIn for 74HC165 register, AVR optimized
|
2013-09-29 13:10:03 -04:00
|
|
|
// DATE: 2013-09-29
|
2020-11-27 05:16:22 -05:00
|
|
|
// URL: https://github.com/RobTillaart/FastShiftIn
|
2013-09-29 13:10:03 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2015-03-06 09:09:11 -05:00
|
|
|
#include "Arduino.h"
|
2013-09-29 13:10:03 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2022-11-16 10:07:44 -05:00
|
|
|
#define FASTSHIFTIN_LIB_VERSION (F("0.3.1"))
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2013-09-29 13:10:03 -04:00
|
|
|
|
|
|
|
class FastShiftIn
|
|
|
|
{
|
2015-03-06 09:09:11 -05:00
|
|
|
public:
|
2022-11-05 07:41:07 -04:00
|
|
|
// bitOrder = { LSBFIRST, MSBFIRST };
|
2022-11-05 13:50:25 -04:00
|
|
|
FastShiftIn(uint8_t dataIn, uint8_t clockPin, uint8_t bitOrder = LSBFIRST);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
int read(void);
|
2022-11-05 13:50:25 -04:00
|
|
|
int lastRead(void);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2022-11-05 13:50:25 -04:00
|
|
|
bool setBitOrder(uint8_t bitOrder);
|
|
|
|
uint8_t getBitOrder(void);
|
2020-11-27 05:16:22 -05:00
|
|
|
|
2022-11-05 07:41:07 -04:00
|
|
|
// overrule bitOrder (most optimized).
|
2021-01-29 06:31:58 -05:00
|
|
|
int readLSBFIRST(void);
|
|
|
|
int readMSBFIRST(void);
|
2013-09-29 13:10:03 -04:00
|
|
|
|
2015-03-06 09:09:11 -05:00
|
|
|
private:
|
2022-11-05 13:50:25 -04:00
|
|
|
uint8_t _bitOrder;
|
2021-01-29 06:31:58 -05:00
|
|
|
int _value;
|
2022-11-05 13:50:25 -04:00
|
|
|
|
|
|
|
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
|
2015-03-06 09:09:11 -05:00
|
|
|
|
2022-11-05 13:50:25 -04:00
|
|
|
volatile uint8_t *_dataInRegister;
|
|
|
|
uint8_t _dataInBit;
|
2015-03-06 09:09:11 -05:00
|
|
|
|
2022-11-05 13:50:25 -04:00
|
|
|
volatile uint8_t *_clockRegister;
|
|
|
|
uint8_t _clockBit;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
uint8_t _dataPinIn;
|
|
|
|
uint8_t _clockPin;
|
|
|
|
|
|
|
|
#endif
|
2013-09-29 13:10:03 -04:00
|
|
|
};
|
|
|
|
|
2021-12-17 09:14:55 -05:00
|
|
|
|
2020-11-27 05:16:22 -05:00
|
|
|
// -- END OF FILE --
|
2022-11-05 13:50:25 -04:00
|
|
|
|