From 61b48599acab82a37e9bf88cb1d77b3724da4095 Mon Sep 17 00:00:00 2001 From: Andrey Gusakov Date: Fri, 21 Jun 2024 00:42:57 +0300 Subject: [PATCH] gpio: tle9104: use __builtin_popcount() for parity calculation --- firmware/hw_layer/drivers/gpio/tle9104.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/firmware/hw_layer/drivers/gpio/tle9104.cpp b/firmware/hw_layer/drivers/gpio/tle9104.cpp index f5d4ee7240..807384b09e 100644 --- a/firmware/hw_layer/drivers/gpio/tle9104.cpp +++ b/firmware/hw_layer/drivers/gpio/tle9104.cpp @@ -88,9 +88,11 @@ static Tle9104 chips[BOARD_TLE9104_COUNT]; static bool parityBit(uint16_t val) { // (1 + number of bits set) mod 2 = parity bit - int count = 1; + int count = 1 + __builtin_popcount(val); - /* TODO: use __builtin_popcount() */ + return count % 2; + +#if 0 while (val != 0) { if (val & 0x01) { count++; @@ -100,6 +102,7 @@ static bool parityBit(uint16_t val) { } return (count % 2) == 1; +#endif } int Tle9104::spi_rw(uint16_t tx, uint16_t *rx) {