Skip to content
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

mcp23018: add return status to init #18178

Merged
merged 1 commit into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions drivers/gpio/mcp23018.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ enum {
CMD_GPIOB = 0x13,
};

void mcp23018_init(uint8_t addr) {
bool mcp23018_init(uint8_t slave_addr) {
static uint8_t s_init = 0;
if (!s_init) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
if (0 == s_init) {
i2c_init();
wait_ms(1000);
wait_ms(100);

s_init = 1;
// probe that the expander is actually connected by reading from it
uint8_t data = 0;
if (I2C_STATUS_SUCCESS == i2c_readReg(addr, 0, &data, sizeof(data), 150)) {
s_init = 1;
}
}
return (s_init > 0);
}

bool mcp23018_set_config(uint8_t slave_addr, mcp23018_port_t port, uint8_t conf) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/mcp23018.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ enum {
/**
* Init expander and any other dependent drivers
*/
void mcp23018_init(uint8_t slave_addr);
bool mcp23018_init(uint8_t slave_addr);

/**
* Configure input/output to a given port
Expand Down