mirror of
https://github.com/PaulStoffregen/OneWire.git
synced 2026-07-27 19:57:07 +00:00
Merge pull request #12 from tico-tico/master
Use avr-libc implementation of crc8
This commit is contained in:
+5
-1
@@ -519,8 +519,11 @@ uint8_t OneWire::crc8(const uint8_t *addr, uint8_t len)
|
||||
uint8_t OneWire::crc8(const uint8_t *addr, uint8_t len)
|
||||
{
|
||||
uint8_t crc = 0;
|
||||
|
||||
|
||||
while (len--) {
|
||||
#if defined(__AVR__)
|
||||
crc = _crc_ibutton_update(crc, *addr++);
|
||||
#else
|
||||
uint8_t inbyte = *addr++;
|
||||
for (uint8_t i = 8; i; i--) {
|
||||
uint8_t mix = (crc ^ inbyte) & 0x01;
|
||||
@@ -528,6 +531,7 @@ uint8_t OneWire::crc8(const uint8_t *addr, uint8_t len)
|
||||
if (mix) crc ^= 0x8C;
|
||||
inbyte >>= 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user