Skip to content

Conversation

Copy link

Copilot AI commented Nov 24, 2025

Renamed the I2C application from i2c_test to i2c_demo to better reflect its purpose as a demonstration rather than a test harness.

Changes

C++ Application

  • Directory: src/apps/i2c_test/src/apps/i2c_demo/
  • Files: i2c_test.{cpp,hpp}i2c_demo.{cpp,hpp}
  • Class: I2CTestI2CDemo
  • CMake targets updated in src/apps/CMakeLists.txt

Python Integration Tests

  • File: test_i2c_test.pytest_i2c_demo.py
  • Test functions: test_i2c_test_*()test_i2c_demo_*()
  • Fixture: i2c_testi2c_demo in conftest.py
  • CLI option: --i2c-test--i2c-demo

Example

# Before
pytest tests/test_i2c_test.py --i2c-test=/path/to/executable

# After
pytest tests/test_i2c_demo.py --i2c-demo=/path/to/executable

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
    • Triggering command: /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

The i2c_test app, source files, and identifiers need to be renamed to i2c_demo and I2CDemo for consistency.

Detailed task:

  1. Rename the application directory under src/apps from i2c_test to i2c_demo:
    • src/apps/i2c_test → src/apps/i2c_demo
  2. In src/apps/CMakeLists.txt, change any reference of i2c_test to i2c_demo (e.g., add_subdirectory(i2c_test) → add_subdirectory(i2c_demo)).
  3. Rename src/apps/i2c_test/CMakeLists.txt → src/apps/i2c_demo/CMakeLists.txt.
  4. Rename src/apps/i2c_test/i2c_test.cpp → src/apps/i2c_demo/i2c_demo.cpp and similarly i2c_test.hpp → i2c_demo.hpp.
  5. In the CMakeLists.txt and source files, update the executable name from i2c_test to i2c_demo, and update includes to reference i2c_demo.hpp.
  6. Update all code references from I2CTest to I2CDemo in .cpp and .hpp files.
  7. Update any references in comments and documentation as needed.
  8. Update the python test filename and identifier under py/host-emulator/tests/test_i2c_test.py to test_i2c_demo.py, and change test class/functions and message references from i2c_test to i2c_demo.

Apply ALL renamings and related updates.

This pull request was created as a result of the following prompt from Copilot chat.

The i2c_test app, source files, and identifiers need to be renamed to i2c_demo and I2CDemo for consistency.

Detailed task:

  1. Rename the application directory under src/apps from i2c_test to i2c_demo:
    • src/apps/i2c_test → src/apps/i2c_demo
  2. In src/apps/CMakeLists.txt, change any reference of i2c_test to i2c_demo (e.g., add_subdirectory(i2c_test) → add_subdirectory(i2c_demo)).
  3. Rename src/apps/i2c_test/CMakeLists.txt → src/apps/i2c_demo/CMakeLists.txt.
  4. Rename src/apps/i2c_test/i2c_test.cpp → src/apps/i2c_demo/i2c_demo.cpp and similarly i2c_test.hpp → i2c_demo.hpp.
  5. In the CMakeLists.txt and source files, update the executable name from i2c_test to i2c_demo, and update includes to reference i2c_demo.hpp.
  6. Update all code references from I2CTest to I2CDemo in .cpp and .hpp files.
  7. Update any references in comments and documentation as needed.
  8. Update the python test filename and identifier under py/host-emulator/tests/test_i2c_test.py to test_i2c_demo.py, and change test class/functions and message references from i2c_test to i2c_demo.

Apply ALL renamings and related updates.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

claude and others added 11 commits November 24, 2025 19:33
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.
Copilot AI and others added 2 commits November 24, 2025 22:48
- 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
Copilot AI requested a review from nehalkpatel November 24, 2025 23:00
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.

3 participants