fix(pa01): Optimize key matrix polling with split-cycle scanning#7405
fix(pa01): Optimize key matrix polling with split-cycle scanning#7405richardclli wants to merge 5 commits into
Conversation
…interrupt-driven caching Split the 4-column matrix scan across 4 poll cycles (1 I2C read + 1 write per cycle instead of 4 reads + 4 writes). The output for each column is set in one cycle and read in the next (10ms later), eliminating the 10us settling delay. Interrupt-driven caching: when no pin-change interrupt occurs between polls, the I2C read is skipped and per-column cached results are reused. A forced full rescan every 250ms catches key releases that may not trigger an interrupt.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughRefactors key matrix polling from a blocking full-matrix scan to an incremental, cached per-column scanner with idle-driven scheduling and ent_mask handling. Adds consecutive I2C error tracking that deinitializes/reinitializes the I2C bus after a configurable failure threshold; AW9523B device reinitialization/output-state restoration is not included here. ChangesKey Matrix Incremental Scan
I2C Error Recovery for AW9523B
🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
7ad0780 to
117c743
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@radio/src/targets/pa01/bsp_io.cpp`:
- Around line 81-84: The three post-init calls aw9523b_write(&i2c_exp,
BSP_OUT_MASK, BSP_KEY_OUT1 | BSP_KEY_OUT2 | BSP_KEY_OUT3 | BSP_KEY_OUT4),
aw9523b_set_direction(&i2c_exp, 0xFFFF, BSP_IN_MASK) and
bsp_output_clear(BSP_U6_SELECT) currently ignore return values; update this
block to check each return like the rest of bsp_io_init() (use BSP_CHECK or
equivalent error handling), and bail/log on failure before logging "I2C recovery
complete" so the device cannot reach an inconsistent state.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 123f361e-6ab9-4892-8b92-9dc800b0bb60
📒 Files selected for processing (2)
radio/src/targets/common/arm/stm32/stm32_i2c_driver.cppradio/src/targets/pa01/bsp_io.cpp
… to bus-only reset Add _track_i2c_error() helper used by both read and write paths. _Recover_i2c now only resets the I2C bus (deinit/init) — the AW9523B retains its register state, so chip re-config is unnecessary.
The bootloader calls pollKeys() only once (bl_keys.cpp:9) to detect held trims for entry condition. Split-scan approach needs 4 calls to populate all cached columns, so bootloader never sees the trims. Add #if defined(BOOT) guard: bootloader path does a synchronous 4-column scan in one call (same as original code). Firmware path keeps the split-scan optimization.
Developed by opencode + deepseek-v4
Split the 4-column matrix scan across 4 poll cycles (1 I2C read + 1 write per cycle instead of 4 reads + 4 writes). The output for each column is set in one cycle and read in the next (10ms later), eliminating the 10us settling delay.
Interrupt-driven caching: when no pin-change interrupt occurs between polls, the I2C read is skipped and per-column cached results are reused. A forced full rescan every 250ms catches key releases that may not trigger an interrupt.
Replaced #7394 and #7315
v2.11 version is at #7409
Summary by CodeRabbit