GY-63_MS5611/libraries/CRC/CRC8.h

66 lines
1.7 KiB
C
Raw Normal View History

2021-01-29 06:31:58 -05:00
#pragma once
//
// FILE: CRC8.h
// AUTHOR: Rob Tillaart
// PURPOSE: Arduino class for CRC8
// URL: https://github.com/RobTillaart/CRC
#include "Arduino.h"
2022-02-07 08:10:53 -05:00
#include "CRC_polynomes.h"
2021-01-29 06:31:58 -05:00
class CRC8
{
public:
CRC8();
2022-05-20 03:04:29 -04:00
CRC8(uint8_t polynome, uint8_t XORstart, uint8_t XORend, bool reverseIn, bool reverseOut);
2021-01-29 06:31:58 -05:00
// set parameters to default
void reset(); // set all to constructor defaults
void restart(); // reset crc with same parameters.
// set parameters
void setPolynome(uint8_t polynome) { _polynome = polynome; };
void setStartXOR(uint8_t start) { _startMask = start; };
void setEndXOR(uint8_t end) { _endMask = end; };
void setReverseIn(bool reverseIn) { _reverseIn = reverseIn; };
void setReverseOut(bool reverseOut) { _reverseOut = reverseOut; };
2022-01-28 08:56:11 -05:00
// get parameters
uint8_t getPolynome() { return _polynome; };
uint8_t getStartXOR() { return _startMask; };
uint8_t getEndXOR() { return _endMask; };
bool getReverseIn() { return _reverseIn; };
bool getReverseOut() { return _reverseOut; };
2021-01-29 06:31:58 -05:00
void add(uint8_t value);
2022-02-07 08:10:53 -05:00
void add(const uint8_t * array, uint16_t length);
2021-01-29 06:31:58 -05:00
2022-05-20 03:04:29 -04:00
uint8_t getCRC(); // returns CRC
uint32_t count() { return _count; };
2021-01-29 06:31:58 -05:00
2022-02-08 04:10:54 -05:00
// POWER USER ONLY
2022-05-20 03:04:29 -04:00
void enableYield() { _canYield = true; };
void disableYield() { _canYield = false; };
2022-02-08 04:10:54 -05:00
2021-01-29 06:31:58 -05:00
private:
uint8_t _reverse(uint8_t value);
void _update(uint8_t value);
uint8_t _polynome;
uint8_t _startMask;
uint8_t _endMask;
uint8_t _crc;
bool _reverseIn;
bool _reverseOut;
bool _started;
2022-02-08 04:10:54 -05:00
bool _canYield;
2021-01-29 06:31:58 -05:00
uint32_t _count;
};
2021-12-14 14:22:40 -05:00
// -- END OF FILE --
2022-05-20 03:04:29 -04:00