Skip to content

Conversation

@kfoltman
Copy link
Collaborator

@kfoltman kfoltman commented Oct 7, 2025

This adds support for the MCP23017 GPIO expander - I2C connected, 14 GPIO pins with optional pullup, 2 GPO pins (7 and 15, a silicon bug makes those pins unreliable as inputs).

The ports are polled while waiting for the packet and after updating the motion values. However, this normally shouldn't be the problem, because the polling code is guaranteed to finish quickly, except for the printf after a communication error.

int i2c = gpio_i2c_mcp_alloc(address);
if (i2c >= 0) {
i2c_gpio_set_pin_config(&i2c_gpio, i2c, index, gpio_type);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
} else {
printf("Error ...");
}

//uint32_t gpio_i2c_mcp_indexes[MAX_I2C_MCP] = {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff};
uint32_t gpio_i2c_mcp_indexes[MAX_I2C_MCP] = {0, 0, 0, 0};
uint8_t gpio_i2c_mcp_addresses[MAX_I2C_MCP] = {0xff, 0xff, 0xff, 0xff};
uint8_t gpio_last_type[32 * MAX_I2C_MCP];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see this being set but never used.



//uint32_t gpio_i2c_mcp_indexes[MAX_I2C_MCP] = {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff};
uint32_t gpio_i2c_mcp_indexes[MAX_I2C_MCP] = {0, 0, 0, 0};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gpio_i2c_mcp_indexes not used any more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used, by gpio_i2c_mcp_alloc.

Copy link
Owner

@mrdunk mrdunk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i left a couple of minor comments.
but LGTM.
you are more familiar with this code than me at the moment so feel free to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants