Merge pull request #10558 from iNavFlight/MrD_Correct-comments-on-OSD-symbols
[inav.git] / src / main / drivers / 1-wire / ds_crc.c
blob8332ab0a5fa7353275daa91eb5c30088d82e957e
2 #include <stdint.h>
4 uint8_t ds_crc8_bit_update(uint8_t crc8, uint8_t bit)
6 uint8_t crc8_base = (crc8 >> 1) & 0x73;
7 uint8_t xor1 = (crc8 & 1) ^ bit;
8 return crc8_base | ((((crc8 >> 3) & 1) ^ xor1) << 2) | ((((crc8 >> 4) & 1) ^ xor1) << 3) | (xor1 << 7);
11 uint8_t ds_crc8_byte_update(uint8_t crc8, uint8_t byte)
13 for (uint8_t i = 0; i < 8; ++i) {
14 uint8_t mix = (crc8 ^ byte) & 0x01;
15 crc8 >>= 1;
16 if (mix) crc8 ^= 0x8C;
17 byte >>= 1;
19 return crc8;
22 uint8_t ds_crc8(const uint8_t *addr, uint8_t len)
24 uint8_t crc8 = 0;
25 for (uint8_t i=0; i < len; ++i) crc8 = ds_crc8_byte_update(crc8, addr[i]);
26 return crc8;