From 93a244621dc1efba16efc26e802aab77c75056d5 Mon Sep 17 00:00:00 2001 From: Jack Rubacha Date: Fri, 31 May 2024 21:06:26 -0400 Subject: [PATCH] reverse the bits --- general/src/pca9539.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/general/src/pca9539.c b/general/src/pca9539.c index cad250d..1316b54 100644 --- a/general/src/pca9539.c +++ b/general/src/pca9539.c @@ -1,5 +1,7 @@ #include "pca9539.h" +#include "../../middleware/include/c_utils.h" + #define REG_SIZE_BITS 8 HAL_StatusTypeDef pca_write_reg(pca9539_t* pca, uint16_t address, uint8_t* data) @@ -56,13 +58,14 @@ HAL_StatusTypeDef pca9539_write_pin(pca9539_t* pca, uint8_t reg_type, uint8_t pi { uint8_t data; + uint8_t data_new; HAL_StatusTypeDef status = pca_read_reg(pca, reg_type, &data); if (status) { return status; } - uint8_t data_new = (data & ~(1 << pin)) | (buf << pin); + data_new = reverse_bits(data & ~(1u << pin)) | (buf << pin); return pca_write_reg(pca, reg_type, &data_new); }