[max6956] Migrate to CachedGpioExpander to reduce I2C bus usage - #10589
[max6956] Migrate to CachedGpioExpander to reduce I2C bus usage#10589bdraco wants to merge 13 commits into
Conversation
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#10589
components: [max6956]
refresh: 1h(Added by the PR bot) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #10589 +/- ##
==========================================
+ Coverage 76.39% 76.46% +0.06%
==========================================
Files 56 57 +1
Lines 12580 12631 +51
Branches 1764 1773 +9
==========================================
+ Hits 9611 9658 +47
- Misses 2545 2546 +1
- Partials 424 427 +3 🚀 New features to boost your workflow:
|
|
👋 Hi there! This PR modifies 3 file(s) with codeowners. @looping40 - As codeowner(s) of the affected files, your review would be appreciated! 🙏 Note: Automatic review request may have failed, but you're still welcome to review. |
|
This is the last I/O expander not using the |
There was a problem hiding this comment.
Pull Request Overview
This PR migrates the MAX6956 I/O expander component to use the CachedGpioExpander base c
8000
lass to reduce I2C bus usage through intelligent caching of pin bank reads.
- Replaces individual pin reads with bank-based reads that cache 8-pin groups
- Implements the
CachedGpioExpanderinterface with hardware and cache read methods - Adds automatic cache invalidation at the start of each loop cycle
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
esphome/components/max6956/max6956.h |
Inherits from CachedGpioExpander, adds bank constants and cache storage |
esphome/components/max6956/max6956.cpp |
Replaces individual pin reads with bank-based caching implementation |
esphome/components/max6956/__init__.py |
Adds gpio_expander as auto-loaded dependency |
Memory Impact AnalysisComponents:
📊 Component Memory Breakdown
🔍 Symbol-Level Changes (click to expand)Changed Symbols
New Symbols (top 15)
Removed Symbols (top 15)
This analysis runs automatically when components change. Memory usage is measured from a representative test configuration. |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
What does this implement/fix?
This PR migrates the MAX6956 I/O expander component to use the
CachedGpioExpanderbase class to significantly reduce I2C bus usage through intelligent caching.The MAX6956 datasheet shows that pins 4-31 can be read in banks using registers 0x40, 0x48, 0x50, and 0x58. Previously, the component read each pin individually, resulting in one I2C transaction per
digital_read()call. With this migration, the component now:Performance improvement: Up to 8x reduction in I2C reads when accessing multiple pins from the same bank, significantly reducing bus congestion and improving responsiveness.
Types of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Component should work on:
Example entry for
config.yaml:Implementation Details
Bank Mapping (Aligned with Base Class View)
Key Changes
Now inherits from
CachedGpioExpander<uint8_t, 32>where:uint8_tis the bank type (8 bits per bank)32is the total pin address space (pins 0-31, with only 4-31 valid on the MAX6956)Implements three virtual methods:
digital_read_hw(): Reads the appropriate 8-pin bank based on requested pindigital_read_cache(): Returns cached pin value from the bankdigital_write_hw(): Writes individual pin (unchanged)Cache alignment strategy:
The base class views pins as a continuous 0-31 range, divided into 4 banks of 8.
Our implementation aligns the cache with this view:
Special handling for Bank 0: Data from register 0x40 arrives in bits D0-D3,
which we shift left by 4 to align with the base class's expectation that
pin N maps to bit (N % 8) within its bank.
Testing Considerations
The implementation has been verified through analysis of the datasheet and base class behavior:
Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: