-
Notifications
You must be signed in to change notification settings - Fork 0
Rename i2c_test to i2c_demo for consistency #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
17
commits into
main
Choose a base branch
from
copilot/rename-i2c-test-to-i2c-demo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit adds a complete I2C driver implementation following the same patterns used for Pin and UART drivers. The implementation includes: C++ Changes: - Added I2C message types (I2CEmulatorRequest/Response) to support Send and Receive operations with I2C device addresses - Updated HostI2CController to use ZMQ transport instead of local buffers - Added JSON encoding/decoding support for I2C messages - Integrated I2C controller into HostBoard with proper transport wiring - I2C operations are synchronous and always initiated by the application Python Emulator Changes: - Added I2C class to emulate I2C peripherals at different addresses - Implemented device buffer storage per I2C address (address -> bytearray) - Added Send/Receive operation handlers in the emulator message loop - Provided helper methods for testing (write_to_device, read_from_device) Key Design Decisions: - I2C uses int error codes (as defined in i2c.hpp interface) instead of common::Error, with a helper function to convert between them - All I2C operations are blocking and synchronous - Data buffers are maintained per I2C address (up to 256 bytes each) - Interrupt and DMA variants delegate to blocking implementations for now The implementation enables I2C communication testing through the host emulation environment without requiring actual hardware.
Created comprehensive unit tests for HostI2CController following the same pattern as the existing UART tests. The tests cover: - Basic Send/Receive operations - Multiple I2C device addresses - Partial data reception - Receive from uninitialized devices - Interrupt-based operations (SendDataInterrupt, ReceiveDataInterrupt) - DMA-based operations (SendDataDma, ReceiveDataDma) The test fixture sets up a ZMQ-based emulator that simulates I2C device buffers, allowing thorough testing of the I2C driver without hardware. Test coverage includes: - HostI2CTest.SendData - HostI2CTest.SendReceiveData - HostI2CTest.MultipleAddresses - HostI2CTest.ReceiveWithoutSend - HostI2CTest.ReceivePartialData - HostI2CTest.SendDataInterrupt - HostI2CTest.ReceiveDataInterrupt - HostI2CTest.SendDataDma - HostI2CTest.ReceiveDataDma
Lambdas with captures cannot be converted to function pointers, which was causing compilation errors in the unit tests. Changed the I2C interface to use std::function instead, matching the pattern used in UART. This allows tests to use lambdas with captures for callback verification.
Created a complete I2C test application that demonstrates I2C driver usage and comprehensive Python integration tests. C++ Application (i2c_test): - Writes a test pattern (0xDE, 0xAD, 0xBE, 0xEF) to I2C device at 0x50 - Reads the data back and verifies it matches - Toggles LED1 when data verification succeeds - Toggles LED2 as a heartbeat indicator - Handles write/read errors gracefully Python Integration Tests (test_i2c_test.py): - test_i2c_test_starts: Verifies app starts successfully - test_i2c_test_write_read_cycle: Validates I2C write/read operations - test_i2c_test_toggles_leds: Checks LED toggling behavior - test_i2c_test_data_mismatch: Tests error handling with wrong data Updated conftest.py to add i2c_test fixture with --i2c-test CLI option. The tests use the Python emulator's I2C device buffer simulation to verify correct I2C communication without requiring hardware.
…https://github.com/nehalkpatel/embedded-cpp into copilot/rename-i2c-test-to-i2c-demo
- Rename directory: src/apps/i2c_test → src/apps/i2c_demo - Rename files: i2c_test.cpp/hpp → i2c_demo.cpp/hpp - Update class name: I2CTest → I2CDemo - Update all CMakeLists.txt references - Rename Python test: test_i2c_test.py → test_i2c_demo.py - Update Python fixtures and test functions - Update conftest.py: --i2c-test → --i2c-demo Co-authored-by: nehalkpatel <20796598+nehalkpatel@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Rename i2c_test app to i2c_demo for consistency
Rename i2c_test to i2c_demo for consistency
Nov 24, 2025
nehalkpatel
reviewed
Nov 24, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Renamed the I2C application from
i2c_testtoi2c_demoto better reflect its purpose as a demonstration rather than a test harness.Changes
C++ Application
src/apps/i2c_test/→src/apps/i2c_demo/i2c_test.{cpp,hpp}→i2c_demo.{cpp,hpp}I2CTest→I2CDemosrc/apps/CMakeLists.txtPython Integration Tests
test_i2c_test.py→test_i2c_demo.pytest_i2c_test_*()→test_i2c_demo_*()i2c_test→i2c_demoinconftest.py--i2c-test→--i2c-demoExample
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
esm.ubuntu.com/usr/lib/apt/methods/https /usr/lib/apt/methods/https(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This pull request was created as a result of the following prompt from Copilot chat.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.