Skip to content

Commit

Permalink
Fixes PCA driver (#224)
Browse files Browse the repository at this point in the history
* removed references to HAL

* fixed structure
  • Loading branch information
caiodasilva2005 authored Jan 14, 2025
1 parent fb29004 commit e02f66b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
16 changes: 7 additions & 9 deletions general/include/pca9539.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,19 @@ PCA 9539 16 bit GPIO expander. Datasheet: https://www.ti.com/lit/ds/symlink/pca
* @brief Pointer to write function
*
*/
typedef int (*WritePtr)(uint16_t dev_addr, uint16_t mem_address,
uint16_t mem_add_size, uint8_t *data, uint16_t size,
int delay);
typedef uint8_t (*PCA_Write)(uint16_t dev_addr, uint8_t reg, uint8_t *data,
uint8_t size);

/**
* @brief Pointer to read function
*
*/
typedef int (*ReadPtr)(uint16_t dev_addr, uint16_t mem_address,
uint16_t mem_add_size, uint8_t *data, uint16_t size,
int delay);
typedef uint8_t (*PCA_Read)(uint16_t dev_addr, uint8_t reg, uint8_t *data,
uint8_t size);

typedef struct {
WritePtr write;
ReadPtr read;
PCA_Write write;
PCA_Read read;

uint16_t dev_addr;
} pca9539_t;
Expand All @@ -66,7 +64,7 @@ typedef struct {
* @param readFunc function pointer to HAL specific read func
* @param dev_addr i2c device address
*/
void pca9539_init(pca9539_t *pca, WritePtr writeFunc, ReadPtr readFunc,
void pca9539_init(pca9539_t *pca, PCA_Write writeFunc, PCA_Read readFunc,
uint8_t dev_addr);

/**
Expand Down
21 changes: 5 additions & 16 deletions general/src/pca9539.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,17 @@

#define REG_SIZE_BITS 8

int pca_write_reg(pca9539_t *pca, uint16_t address, uint8_t *data)
static int pca_write_reg(pca9539_t *pca, uint8_t address, uint8_t *data)
{
//Parameters in the HAL Function
uint16_t mem_add_size = 8;
uint16_t data_size = 1;
int delay = 0xFFFFFFFFU;

return pca->write(pca->dev_addr, address, mem_add_size, data, data_size,
delay);
return pca->write(pca->dev_addr, address, data, 1);
}

int pca_read_reg(pca9539_t *pca, uint16_t address, uint8_t *data)
static int pca_read_reg(pca9539_t *pca, uint8_t address, uint8_t *data)
{
uint16_t mem_add_size = 8;
uint16_t data_size = 1;
int delay = 0xFFFFFFFFU;

return pca->read(pca->dev_addr, address, mem_add_size, data, data_size,
delay);
return pca->read(pca->dev_addr, address, data, 1);
}

void pca9539_init(pca9539_t *pca, WritePtr writeFunc, ReadPtr readFunc,
void pca9539_init(pca9539_t *pca, PCA_Write writeFunc, PCA_Read readFunc,
uint8_t dev_addr)
{
pca->dev_addr = dev_addr << 1u;
Expand Down

0 comments on commit e02f66b

Please sign in to comment.