makes GPIO_PIN_RST optional for the sx1276
[ExpressLRS.git] / src / lib / CRC / crc.cpp
blob475e30db42cf3d8a1df855a3914d2756273031e7
1 #include "crc.h"
3 GENERIC_CRC8::GENERIC_CRC8(uint8_t poly)
5 uint8_t crc;
7 for (uint16_t i = 0; i < crclen; i++)
9 crc = i;
10 for (uint8_t j = 0; j < 8; j++)
12 crc = (crc << 1) ^ ((crc & 0x80) ? poly : 0);
14 crc8tab[i] = crc & 0xFF;
18 uint8_t ICACHE_RAM_ATTR GENERIC_CRC8::calc(const uint8_t data)
20 return crc8tab[data];
23 uint8_t ICACHE_RAM_ATTR GENERIC_CRC8::calc(const uint8_t *data, uint8_t len, uint8_t crc)
25 while (len--)
27 crc = crc8tab[crc ^ *data++];
29 return crc;
32 GENERIC_CRC14::GENERIC_CRC14(uint16_t poly)
34 uint16_t crc;
35 for (uint16_t i = 0; i < crclen; i++)
37 crc = i << (14 - 8);
38 for (uint8_t j = 0; j < 8; j++)
40 crc = (crc << 1) ^ ((crc & 0x2000) ? poly : 0);
42 crc14tab[i] = crc;
46 uint16_t ICACHE_RAM_ATTR GENERIC_CRC14::calc(uint8_t *data, uint8_t len, uint16_t crc)
48 while (len--)
50 crc = (crc << 8) ^ crc14tab[((crc >> 6) ^ (uint16_t) *data++) & 0x00FF];
52 return crc & 0x3FFF;
55 uint16_t ICACHE_RAM_ATTR GENERIC_CRC14::calc(volatile uint8_t *data, uint8_t len, uint16_t crc)
57 while (len--)
59 crc = (crc << 8) ^ crc14tab[((crc >> 6) ^ (uint16_t) *data++) & 0x00FF];
61 return crc & 0x3FFF;