-
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
Newnewfeat/pca #198
Merged
Merged
Newnewfeat/pca #198
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4e9db2f
changes finalized
e5441af
finalized 2
824f3ef
struct fix
dbf5358
final final
c526b7c
removing the i2c_handler, preping for cerb changes
57ef881
Better Documentation
d6679ec
added doxygen comments, removed unnecessary comments
72c7b4c
added param & ret comments
3bb4e77
Merge branch 'main' of https://github.com/Northeastern-Electric-Racin…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,7 @@ | |
#include <stdint.h> | ||
|
||
/* | ||
PCA 9539 16 bit GPIO expander. Datasheet: | ||
https://www.ti.com/lit/ds/symlink/pca9539.pdf?ts=1716785085909 | ||
PCA 9539 16 bit GPIO expander. Datasheet: https://www.ti.com/lit/ds/symlink/pca9539.pdf?ts=1716785085909 | ||
*/ | ||
|
||
/// Possible I2C addresses, see comment below | ||
|
@@ -36,31 +35,83 @@ PCA 9539 16 bit GPIO expander. Datasheet: | |
#define PCA_DIRECTION_0_REG 0x06 | ||
#define PCA_DIRECTION_1_REG 0x07 | ||
|
||
/** | ||
* @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); | ||
|
||
/** | ||
* @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 struct { | ||
I2C_HandleTypeDef *i2c_handle; | ||
WritePtr write; | ||
ReadPtr read; | ||
|
||
uint16_t dev_addr; | ||
} pca9539_t; | ||
|
||
/// Init PCA9539, a 16 bit I2C GPIO expander | ||
void pca9539_init(pca9539_t *pca, I2C_HandleTypeDef *i2c_handle, | ||
/** | ||
* @brief Initialize the PCA9539 Driver | ||
* | ||
* @param pca pointer to a new driver struct | ||
* @param writeFunc function pointer to HAL specific write func | ||
* @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, | ||
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. Doc comments are missing. Use doxygen, javadoc style comments seen in other repos. |
||
uint8_t dev_addr); | ||
|
||
/// @brief Read all pins on a bus, for example using reg_type input to get | ||
/// incoming logic level | ||
HAL_StatusTypeDef pca9539_read_reg(pca9539_t *pca, uint8_t reg_type, | ||
uint8_t *buf); | ||
/// @brief Read a specific pin on a bus, do not iterate over this, use read_pins | ||
/// instead | ||
HAL_StatusTypeDef pca9539_read_pin(pca9539_t *pca, uint8_t reg_type, | ||
uint8_t pin, uint8_t *buf); | ||
|
||
/// @brief Write all pins on a bus, for example using reg_type OUTPUT to set | ||
/// logic level or DIRECTION to set as output | ||
HAL_StatusTypeDef pca9539_write_reg(pca9539_t *pca, uint8_t reg_type, | ||
uint8_t buf); | ||
/// @brief Write a specific pin on a bus, do not iterate over this, use | ||
/// write_pins instead | ||
HAL_StatusTypeDef pca9539_write_pin(pca9539_t *pca, uint8_t reg_type, | ||
uint8_t pin, uint8_t buf); | ||
/** | ||
* @brief Read the register of the PCA9539 | ||
* | ||
* @param pca pointer to driver struct with read & write funcs | ||
* @param reg_type type of register being read | ||
* @param buf pointer to buffer storing reg data | ||
* @return int Error code return | ||
*/ | ||
int pca9539_read_reg(pca9539_t *pca, uint8_t reg_type, uint8_t *buf); | ||
|
||
/** | ||
* @brief Read the pin state of the PCA9539 | ||
* | ||
* @param pca pointer to driver struct with read & write funcs | ||
* @param reg_type type of register being read | ||
* @param pin pin num to read | ||
* @param buf pointer storing buffer state | ||
* @return int Error code return | ||
*/ | ||
int pca9539_read_pin(pca9539_t *pca, uint8_t reg_type, uint8_t pin, | ||
uint8_t *buf); | ||
|
||
/** | ||
|
||
* @brief Write the register of the PCA9539 | ||
* | ||
* @param pca pointer to driver struct with read & write funcs | ||
* @param reg_type type of register being written to | ||
* @param buf pointer with value to write to reg | ||
* @return int Error code return | ||
*/ | ||
int pca9539_write_reg(pca9539_t *pca, uint8_t reg_type, uint8_t buf); | ||
|
||
/** | ||
* @brief Write the pin of the PCA9539 | ||
* | ||
* @param pca pointer to driver struct with read & write funcs | ||
* @param reg_type type of register being written to | ||
* @param pin pin to modify | ||
* @param buf pointer with value to write to reg | ||
* @return int Error code return | ||
*/ | ||
int pca9539_write_pin(pca9539_t *pca, uint8_t reg_type, uint8_t pin, | ||
uint8_t buf); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These also need to include definitions for parameters and return types. If you use VScode, you should get the doxygen extension. It autofills all that stuff for you.