Skip to content

Commit

Permalink
reverse the bits
Browse files Browse the repository at this point in the history
  • Loading branch information
jr1221 committed Jun 1, 2024
1 parent e5a8ff8 commit 93a2446
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion general/src/pca9539.c
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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);
}

0 comments on commit 93a2446

Please sign in to comment.