-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/pca #179
base: main
Are you sure you want to change the base?
Feature/pca #179
Changes from 4 commits
4f05562
a99ed85
d1e770a
2cd92d4
60186eb
c3d041e
aada812
f81659a
f86e6b5
1459dd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,37 @@ | |
|
||
#define REG_SIZE_BITS 8 | ||
|
||
|
||
void pca9539_init(pca9539_t *pca, I2C_WriteFuncPtr writeFunc, | ||
I2C_ReadFuncPtr readFunc, I2C_HandleTypeDef *i2c_handle, | ||
uint8_t dev_addr) | ||
{ | ||
pca->i2c_handle = i2c_handle; | ||
pca->dev_addr = dev_addr << 1u; | ||
} | ||
/*General PCA Functions | ||
int pca_read_reg(pca9539_t* pca, uint8_t reg_type, uint8_t *buf){ | ||
return HAL_I2C_Mem_Read(pca->i2c_handle, pca->dev_addr, address, I2C_MEMADD_SIZE_8BIT, data, 1, | ||
HAL_MAX_DELAY); | ||
}*/ | ||
/* | ||
int pca_write_reg(pca9539_t pca, uint8_t reg_type, uint8_t buf){ | ||
return HAL_I2C_Mem_Write(pca->i2c_handle, pca->dev_addr, address, I2C_MEMADD_SIZE_8BIT, data, 1, | ||
HAL_MAX_DELAY); | ||
}*/ | ||
//Original PCA Functions | ||
/* | ||
HAL_StatusTypeDef pca_write_reg(pca9539_t* pca, uint16_t address, uint8_t* data) | ||
{ | ||
// ensure shifting left one, HAL adds the write bit | ||
return HAL_I2C_Mem_Write(pca->i2c_handle, pca->dev_addr, address, I2C_MEMADD_SIZE_8BIT, data, 1, | ||
HAL_MAX_DELAY); | ||
}*/ | ||
|
||
/* | ||
HAL_StatusTypeDef pca_read_reg(pca9539_t* pca, uint16_t address, uint8_t* data) | ||
{ | ||
|
||
HAL_StatusTypeDef pca_write_reg(pca9539_t *pca, uint16_t address, | ||
uint8_t *data) { | ||
// ensure shifting left one, HAL adds the write bit | ||
|
@@ -14,25 +45,83 @@ HAL_StatusTypeDef pca_write_reg(pca9539_t *pca, uint16_t address, | |
HAL_StatusTypeDef pca_read_reg(pca9539_t *pca, uint16_t address, | ||
uint8_t *data) { | ||
|
||
|
||
return HAL_I2C_Mem_Read(pca->i2c_handle, pca->dev_addr, address, | ||
I2C_MEMADD_SIZE_8BIT, data, 1, HAL_MAX_DELAY); | ||
} | ||
*/ | ||
|
||
|
||
/* | ||
Original PCA Constructor | ||
void pca9539_init(pca9539_t* pca, I2C_HandleTypeDef* i2c_handle, uint8_t dev_addr) | ||
{ | ||
pca->i2c_handle = i2c_handle; | ||
pca->dev_addr = dev_addr << 1u; shifted one to the left cuz STM says so | ||
//} | ||
*/ | ||
//FILL IN THESE | ||
int pca9539_read_reg(pca9539_t *pca, uint16_t reg_type, uint8_t *buf) | ||
{ | ||
return pca->local_I2C_Read(pca->dev_addr, reg_type, *buf); | ||
} | ||
|
||
int pca9539_write_reg(pca9539_t *pca, uint16_t reg_type, uint8_t buf) | ||
{ | ||
return pca->local_I2C_Write(pca->dev_addr, reg_type, buf); | ||
} | ||
|
||
int pca9539_write_pin(pca9539_t *pca, uint16_t reg_type, uint8_t pin, | ||
uint8_t buf) | ||
{ | ||
//uint8_t data; -> where is this used? | ||
|
||
|
||
int status = pca->local_I2C_Write(pca->dev_addr, reg_type, buf); | ||
if (status) { | ||
return status; | ||
} | ||
//uint8_t data_new; | ||
//uint8_t data; | ||
//data_new = (data & ~(1u << pin)) | (buf << pin); | ||
|
||
return pca->local_I2C_Write(pca->dev_addr, reg_type, buf); | ||
} | ||
int pca9539_read_pin(pca9539_t *pca, uint16_t reg_type, uint8_t pin, | ||
uint8_t *buf) | ||
{ | ||
//uint8_t data; | ||
|
||
int status = pca->local_I2C_Read(pca->dev_addr, reg_type, *buf); | ||
if (status) { | ||
return status; | ||
} | ||
//*buf = (data & (1 << pin)) > 0; What to do with this? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i dont know without looking much what this does, but changing exisint stuff outside of HAL related info is not needed, so you can keep this logic the same as it was initially |
||
|
||
return pca->local_I2C_Read(pca->dev_addr, reg_type, *buf); | ||
} | ||
|
||
//END OF NEW CODE | ||
/* | ||
HAL_StatusTypeDef pca9539_read_reg(pca9539_t* pca, uint8_t reg_type, uint8_t* buf) | ||
{ | ||
|
||
void pca9539_init(pca9539_t *pca, I2C_HandleTypeDef *i2c_handle, | ||
uint8_t dev_addr) { | ||
pca->i2c_handle = i2c_handle; | ||
pca->dev_addr = dev_addr << 1u; /* shifted one to the left cuz STM says so */ | ||
} | ||
pca->dev_addr = dev_addr << 1u; shifted one to the left cuz STM says so */ | ||
|
||
HAL_StatusTypeDef pca9539_read_reg(pca9539_t *pca, uint8_t reg_type, | ||
uint8_t *buf) { | ||
/* | ||
HAL_StatusTypeDef pca9539_read_reg(pca9539_t *pca, uint8_t reg_type, uint8_t *buf) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to remove HAL_Status_TypeDef to make this agnostic - those are just enums to ints so can replace with int |
||
|
||
HAL_StatusTypeDef status = pca_read_reg(pca, reg_type, buf); | ||
if (status) { | ||
return status; | ||
} | ||
|
||
return status; | ||
|
||
return status; | ||
//AKA return pca_read_reg(pca, reg_type, buf); | ||
} | ||
|
||
HAL_StatusTypeDef pca9539_read_pin(pca9539_t *pca, uint8_t reg_type, | ||
|
@@ -67,5 +156,6 @@ HAL_StatusTypeDef pca9539_write_pin(pca9539_t *pca, uint8_t reg_type, | |
|
||
data_new = (data & ~(1u << pin)) | (buf << pin); | ||
|
||
return pca_write_reg(pca, reg_type, &data_new); | ||
} | ||
|
||
return pca_write_reg(pca, reg_type, &data_new); | ||
}*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick but can we change names:
I2c write function ptr --> Write_Ptr
read func ptr ----> Read_Ptr
then the local versions from "local..." to just "read" and "write"