mirror of
https://xff.cz/git/pinephone-keyboard
synced 2024-12-22 04:48:49 -05:00
common: Improve crc8 generation
Start with 0xff instead of 0x00, so the CRC will be nonzero (and length dependent) for data that is all zeroes. Remove unnecessary masking, since `crc` is already an 8-bit integer.
This commit is contained in:
parent
206b96c1e2
commit
bd69a00f7a
6
common.c
6
common.c
@ -291,11 +291,11 @@ static const uint8_t crc8_0x7_table[] = {
|
||||
static uint8_t crc8(const uint8_t *pdata, size_t nbytes)
|
||||
{
|
||||
unsigned int idx;
|
||||
uint8_t crc = 0;
|
||||
uint8_t crc = 0xff;
|
||||
|
||||
while (nbytes--) {
|
||||
idx = (crc ^ *pdata);
|
||||
crc = (crc8_0x7_table[idx]) & 0xff;
|
||||
idx = crc ^ *pdata;
|
||||
crc = crc8_0x7_table[idx];
|
||||
pdata++;
|
||||
}
|
||||
|
||||
|
@ -557,11 +557,11 @@ static const uint8_t crc8_0x7_table[] = {
|
||||
static uint8_t crc8(const uint8_t *pdata, size_t nbytes)
|
||||
{
|
||||
unsigned int idx;
|
||||
uint8_t crc = 0;
|
||||
uint8_t crc = 0xff;
|
||||
|
||||
while (nbytes--) {
|
||||
idx = (crc ^ *pdata);
|
||||
crc = (crc8_0x7_table[idx]) & 0xff;
|
||||
idx = crc ^ *pdata;
|
||||
crc = crc8_0x7_table[idx];
|
||||
pdata++;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user