Skip to content

Add I2C target SCL high-spike filtering - #122

Draft
xross wants to merge 5 commits into
xmos:developfrom
xross:feature/spike_filter
Draft

Add I2C target SCL high-spike filtering#122
xross wants to merge 5 commits into
xmos:developfrom
xross:feature/spike_filter

Conversation

@xross

@xross xross commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a 50 ns SCL high-spike filter for mixed I3C/I2C bus compatibility.
  • Add I2C_SLAVE_CLOCK_STRETCH to optionally prevent the target from driving SCL low.
  • Add simulator coverage for SCL glitches and non-clock-stretch operation on XS2 and XS3.
  • Document both configuration macros.

Testing

  • Added dedicated spike-filter and no-clock-stretch tests.

@xross
xross requested review from Copilot and humphrey-xmos July 31, 2026 14:23
@xross xross changed the title Add I2C target SCL high-spiked filtering Add I2C target SCL high-spike filtering Jul 31, 2026

Copilot AI 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.

Pull request overview

This PR adds SCL high-spike filtering to the I2C target (slave) implementation to improve robustness in the presence of short SCL high glitches (e.g., I3C bus coexistence), and introduces simulator-based tests to validate the behavior.

Changes:

  • Add optional SCL high-spike filtering logic to i2c_slave.xc and apply it to clock-edge handling and START/STOP detection.
  • Add a new Pyxsim/pytest test suite to inject short SCL high glitches at specific bit positions and verify behavior matches the existing expected output.
  • Update test dependency wiring, build optimization flags, and the changelog.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/test_slave_scl_spike_filter.py New simulator test injecting SCL high glitches at various pulse indices.
tests/requirements.txt Changes how test_support is pulled in for tests (now via relative editable path).
tests/i2c_slave_test/CMakeLists.txt Changes test app optimization level (-O2-O3).
lib_i2c/src/i2c_slave.xc Implements SCL high-spike filtering and uses it in key state-machine decisions.
lib_i2c/lib_build_info.cmake Changes library optimization (-Os-O3) for the CMake-based build path.
CHANGELOG.rst Adds an UNRELEASED section describing the changes (currently includes an entry not reflected in this diff).
Suppressed comments (1)

lib_i2c/lib_build_info.cmake:13

  • This changes the library compiler optimization from -Os to -O3, but the legacy lib_i2c/module_build_info still uses -Os (line 6). That makes optimization level depend on which build system is used; consider keeping -Os here (or updating all build entrypoints consistently).
set(LIB_COMPILER_FLAGS  -O3
                        -Wall
                        -Wextra
                        -Wsign-compare
                        -Wconversion)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_slave_scl_spike_filter.py Outdated
Comment thread tests/requirements.txt Outdated
Comment thread tests/i2c_slave_test/CMakeLists.txt
Comment thread lib_i2c/src/i2c_slave.xc
Comment thread CHANGELOG.rst Outdated
@xross
xross force-pushed the feature/spike_filter branch 6 times, most recently from ced5614 to d112711 Compare July 31, 2026 15:05
@xross
xross removed the request for review from humphrey-xmos July 31, 2026 16:21
@xross
xross marked this pull request as draft July 31, 2026 16:21
@xross
xross force-pushed the feature/spike_filter branch from 1dff8c0 to a9daee9 Compare July 31, 2026 16:49
@xross

xross commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Exposed this: #123

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.

2 participants