-
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 all 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,68 +4,55 @@ | |
|
||
#define REG_SIZE_BITS 8 | ||
|
||
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) { | ||
|
||
return HAL_I2C_Mem_Read(pca->i2c_handle, pca->dev_addr, address, | ||
I2C_MEMADD_SIZE_8BIT, data, 1, HAL_MAX_DELAY); | ||
} | ||
|
||
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 */ | ||
void pca9539_init(pca9539_t *pca, WritePtr writeFunc, | ||
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. i2c Handle is STM HAL, so that should be removed here 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. the i2c_handle member of the pca type can be removed too |
||
ReadPtr readFunc, uint8_t dev_addr) | ||
{ | ||
pca->dev_addr = dev_addr << 1u; | ||
} | ||
|
||
HAL_StatusTypeDef pca9539_read_reg(pca9539_t *pca, uint8_t reg_type, | ||
uint8_t *buf) { | ||
|
||
HAL_StatusTypeDef status = pca_read_reg(pca, reg_type, buf); | ||
if (status) { | ||
return status; | ||
} | ||
|
||
return status; | ||
int pca9539_read_reg(pca9539_t *pca, uint16_t reg_type, uint8_t *buf) | ||
{ | ||
return pca->read(pca->dev_addr, reg_type, *buf); | ||
} | ||
|
||
HAL_StatusTypeDef pca9539_read_pin(pca9539_t *pca, uint8_t reg_type, | ||
uint8_t pin, uint8_t *buf) { | ||
uint8_t data; | ||
HAL_StatusTypeDef status = pca_read_reg(pca, reg_type, &data); | ||
if (status) { | ||
return status; | ||
} | ||
|
||
*buf = (data & (1 << pin)) > 0; | ||
|
||
return status; | ||
int pca9539_write_reg(pca9539_t *pca, uint16_t reg_type, uint8_t buf) | ||
{ | ||
return pca->write(pca->dev_addr, reg_type, buf); | ||
} | ||
|
||
HAL_StatusTypeDef pca9539_write_reg(pca9539_t *pca, uint8_t reg_type, | ||
uint8_t buf) { | ||
//Errors in write_pin and read_pin functions if the commented code left in | ||
//Variables within function are unused | ||
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. the logic of this function has been changed, hence the errors. Take a look at the diff - the old code first read the state of the pin with a read call, then set data_new to the opposite state, and then wrote that back to the device. If you undo changes to that logic and keep it the same as it was u shoudlnt get any errors |
||
int pca9539_write_pin(pca9539_t *pca, uint16_t reg_type, uint8_t pin, | ||
uint8_t buf) | ||
{ | ||
//uint8_t data; | ||
//uint8_t data_new; | ||
|
||
|
||
return pca_write_reg(pca, reg_type, &buf); | ||
} | ||
int status = pca->write(pca->dev_addr, reg_type, buf); | ||
if (status) { | ||
return status; | ||
} | ||
|
||
HAL_StatusTypeDef pca9539_write_pin(pca9539_t *pca, uint8_t reg_type, | ||
uint8_t pin, uint8_t buf) { | ||
//data_new = (data & ~(1u << pin)) | (buf << pin); | ||
|
||
uint8_t data; | ||
uint8_t data_new; | ||
return pca->write(pca->dev_addr, reg_type, buf); | ||
} | ||
|
||
HAL_StatusTypeDef status = pca_read_reg(pca, reg_type, &data); | ||
if (status) { | ||
return status; | ||
} | ||
|
||
data_new = (data & ~(1u << pin)) | (buf << pin); | ||
int pca9539_read_pin(pca9539_t *pca, uint16_t reg_type, uint8_t pin, | ||
uint8_t *buf) | ||
{ | ||
//uint8_t data; | ||
|
||
return pca_write_reg(pca, reg_type, &data_new); | ||
int status = pca->read(pca->dev_addr, reg_type, *buf); | ||
if (status) { | ||
return status; | ||
} | ||
//*buf = (data & (1 << pin)) > 0; | ||
|
||
return pca->read(pca->dev_addr, reg_type, *buf); | ||
} |
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"