Skip to content

fix: include 0x77 in CircuitPython I2C scans - #310

Open
YashAnand69 wants to merge 1 commit into
fossasia:mainfrom
YashAnand69:fix/busio-i2c-scan-endpoint
Open

YashAnand69 wants to merge 1 commit into
fossasia:mainfrom
YashAnand69:fix/busio-i2c-scan-endpoint

Conversation

@YashAnand69

@YashAnand69 YashAnand69 commented Oct 9, 2026 •

Copy link
Copy Markdown

The CircuitPython-compatible I2C.scan() documents addresses 0x08 through 0x77, but passes 0x77 as the primitive's exclusive end. Devices responding only at 0x77 are never probed.

Pass 0x78 as the exclusive endpoint. The scan still excludes reserved addresses and emits a STOP for each probed address.

Validation:

  • Five public scan cases fail on unchanged main. Command-level ACK responses cover a device only at 0x77, the lower endpoint, multiple devices, no responders and reserved addresses; each checks the full probe range and matching STOPs.
  • Available hardware-independent suite: 33 passed (baseline 28); changed line covered and same-subset coverage increases. Configured Black, Flake8, Bandit and pydocstyle checks pass.
  • Wheel/source distribution and documentation builds pass. Documentation diagnostics match baseline: five distinct messages, Sphinx counter seven.
  • No physical PSLab/sensor or full hardware record/playback validation was performed.

No matching scan-endpoint issue or overlapping open PR found. Developed and tested with OpenAI Codex assistance.

Summary by Sourcery

Correct the CircuitPython-compatible I2C scan range so devices at the highest permitted address are detected.

Bug Fixes:

  • Include address 0x77 in CircuitPython-compatible I2C scans by correcting the scan range endpoint.

Tests:

  • Add hardware-independent coverage for scan endpoints, reserved addresses, device responses, and matching STOP operations.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected the I2C scan range so the highest address, 0x77, is included.
  • Tests
    • Added coverage for detected addresses, probe cleanup, and transaction state after scanning.

@sourcery-ai

sourcery-ai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Fixes CircuitPython-compatible I2C scans by making 0x78 the exclusive endpoint, ensuring devices at 0x77 are detected. Adds hardware-independent command-level tests covering the full range, ACK behavior, reserved addresses, and cleanup semantics.

Sequence diagram for the corrected I2C scan range

sequenceDiagram
    participant Caller
    participant I2C
    participant Primitive
    participant Device

    Caller->>I2C: scan()
    I2C->>Primitive: _scan(0x08, 0x78)
    loop Addresses 0x08 through 0x77
        Primitive->>Device: Probe address
        Device-->>Primitive: ACK or no response
        Primitive->>Device: STOP
    end
    Primitive-->>I2C: Responding addresses
    I2C-->>Caller: List of detected addresses
Loading

File-Level Changes

Change Details Files
Extend the CircuitPython-compatible I2C scan’s exclusive upper bound so address 0x77 is probed while preserving reserved-address filtering and per-address STOP handling.
  • Change the scan endpoint from 0x77 to exclusive endpoint 0x78.
  • Add a command-level connection test double that tracks probed and stopped addresses and simulates address-specific ACKs.
  • Cover endpoint-only, lower-endpoint, multiple-device, empty, and reserved-address responder scenarios.
  • Verify the complete 0x08–0x77 probe range, matching STOPs, and cleared bus state.
pslab/bus/busio.py
tests/test_busio_i2c_scan.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8637287c-42b7-40b1-aa5c-de09612d1b16

📥 Commits

Reviewing files that changed from the base of the PR and between 08de0d0 and ec1a66b.


📒 Files selected for processing (2)
  • pslab/bus/busio.py
  • tests/test_busio_i2c_scan.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.



📝 Walkthrough

Walkthrough

I2C.scan() now probes addresses from 0x08 through 0x77. New parameterized tests check which addresses are returned and verify that each address is probed and stopped.

Changes

I2C scanning

Layer / File(s) Summary
Scan range and test coverage
pslab/bus/busio.py, tests/test_busio_i2c_scan.py
I2C.scan() changes its exclusive upper bound to 0x78. Parameterized tests check returned addresses, probe and stop calls, and the final connection state.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix


Merge Risk: ⚪ Minimal · up to ec1a6

The scan now includes address 0x77. No actionable merge-blocking risk remains after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: including address 0x77 in CircuitPython I2C scans.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.


  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
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.

1 participant