GY-63_MS5611/libraries/FastShiftIn/FastShiftIn.h

60 lines
1.1 KiB
C
Raw Normal View History

2020-11-27 05:16:22 -05:00
#pragma once
//
// FILE: FastShiftIn.h
// AUTHOR: Rob Tillaart
2023-02-20 11:23:35 -05:00
// VERSION: 0.3.2
2020-11-27 05:16:22 -05:00
// PURPOSE: Fast ShiftIn for 74HC165 register, AVR optimized
// DATE: 2013-09-29
2020-11-27 05:16:22 -05:00
// URL: https://github.com/RobTillaart/FastShiftIn
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
2021-01-29 06:31:58 -05:00
2023-02-20 11:23:35 -05:00
#define FASTSHIFTIN_LIB_VERSION (F("0.3.2"))
2021-01-29 06:31:58 -05:00
class FastShiftIn
{
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
2023-02-20 11:23:35 -05:00
uint16_t read(void);
uint16_t read16(void);
uint32_t read24(void);
uint32_t read32(void);
uint32_t lastRead(void);
2021-01-29 06:31:58 -05:00
2023-02-20 11:23:35 -05:00
// returns false if bitOrder out of range.
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).
2023-02-20 11:23:35 -05:00
uint8_t readLSBFIRST(void);
uint8_t readMSBFIRST(void);
private:
2023-02-20 11:23:35 -05:00
uint8_t _bitOrder;
uint32_t _lastValue;
2022-11-05 13:50:25 -04:00
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
2022-11-05 13:50:25 -04:00
volatile uint8_t *_dataInRegister;
2023-02-20 11:23:35 -05:00
uint8_t _dataInBit;
2022-11-05 13:50:25 -04:00
volatile uint8_t *_clockRegister;
2023-02-20 11:23:35 -05:00
uint8_t _clockBit;
2022-11-05 13:50:25 -04:00
#else
2023-02-20 11:23:35 -05:00
uint8_t _dataPinIn;
uint8_t _clockPin;
2022-11-05 13:50:25 -04:00
#endif
};
2021-12-17 09:14:55 -05:00
2023-02-20 11:23:35 -05:00
// -- END OF FILE --
2022-11-05 13:50:25 -04:00