mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/sht3x: use crc8 function from common code
This makes the sht3x driver use the crc-8 routine from sys/hashes. It's the same code, was just moved to a common place.
This commit is contained in:
parent
e4a33ca413
commit
22c2dbbbe5
@ -529,6 +529,7 @@ endif
|
||||
|
||||
ifneq (,$(filter sht3x,$(USEMODULE)))
|
||||
USEMODULE += xtimer
|
||||
USEMODULE += checksum
|
||||
FEATURES_REQUIRED += periph_i2c
|
||||
endif
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "checksum/crc8.h"
|
||||
#include "sht3x.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
@ -99,8 +100,10 @@ static int _status (sht3x_dev_t* dev, uint16_t* status);
|
||||
static int _send_command(sht3x_dev_t* dev, uint16_t cmd);
|
||||
static int _read_data(sht3x_dev_t* dev, uint8_t *data, uint8_t len);
|
||||
|
||||
/* helper functions */
|
||||
static uint8_t _crc8 (uint8_t data[], int len);
|
||||
static inline uint8_t _crc8(const void* buf, size_t len)
|
||||
{
|
||||
return crc8(buf, len, 0x31, 0xff);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------ */
|
||||
|
||||
@ -416,27 +419,3 @@ static int _status (sht3x_dev_t* dev, uint16_t* status)
|
||||
DEBUG_DEV("status=%02x", dev, *status);
|
||||
return SHT3X_OK;
|
||||
}
|
||||
|
||||
|
||||
static const uint8_t g_polynom = 0x31;
|
||||
|
||||
static uint8_t _crc8 (uint8_t data[], int len)
|
||||
{
|
||||
/* initialization value */
|
||||
uint8_t crc = 0xff;
|
||||
|
||||
/* iterate over all bytes */
|
||||
for (int i=0; i < len; i++)
|
||||
{
|
||||
crc ^= data[i];
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
bool xor = crc & 0x80;
|
||||
crc = crc << 1;
|
||||
crc = xor ? crc ^ g_polynom : crc;
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user