Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
crc.h
Go to the documentation of this file.
1 #pragma once
3 #include <stdint.h>
4 
5 namespace modules {
6 
8 namespace crc {
9 
10 class CRC8 {
11 public:
14  static uint8_t CCITT_update(uint8_t crc, uint8_t b);
15 
16  static constexpr uint8_t CCITT_updateCX(uint8_t crc, uint8_t b) {
17  uint8_t data = crc ^ b;
18  for (uint8_t i = 0; i < 8; i++) {
19  if ((data & 0x80U) != 0) {
20  data <<= 1U;
21  data ^= 0x07U;
22  } else {
23  data <<= 1U;
24  }
25  }
26  return data;
27  }
28 
30  static constexpr uint8_t CCITT_updateW(uint8_t crc, uint16_t w) {
31  union U {
32  uint8_t b[2];
33  uint16_t w;
34  explicit constexpr inline U(uint16_t w)
35  : w(w) {}
36  } u(w);
37  return CCITT_updateCX(CCITT_updateCX(crc, u.b[0]), u.b[1]);
38  }
39 };
40 
41 } // namespace crc
42 
43 } // namespace modules
Definition: crc.h:10
static uint8_t CCITT_update(uint8_t crc, uint8_t b)
Definition: crc.cpp:16
static constexpr uint8_t CCITT_updateW(uint8_t crc, uint16_t w)
Compute/update CRC8 CCIIT from 16bits (convenience wrapper)
Definition: crc.h:30
The modules namespace contains models of MMU's components.
Definition: command_base.h:8