Skip to content

Make FT4222 I2C master clock frequency configurable#2558

Merged
pgrawehr merged 7 commits into
mainfrom
copilot/ft4222-fix-i2c-clock-frequency
Jun 14, 2026
Merged

Make FT4222 I2C master clock frequency configurable#2558
pgrawehr merged 7 commits into
mainfrom
copilot/ft4222-fix-i2c-clock-frequency

Conversation

Copilot AI commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

The FT4222 I2C master clock frequency was hard-coded to 400 kbps in Ft4222I2cBus, with no public way to change it (e.g. to 100 kbps). Per the LibFT4222 user guide, FT4222_I2CMaster_Init supports speeds from 60 to 3400 kbps.

Changes

  • Ft4222I2cBus: Replaced the private 400 constant with public Default/Minimum/Maximum (400/60/3400) constants. Made Ft4222I2cBus public so those constants are part of the public API. Added constructor overloads for the default and explicit frequency cases, validating the range and surfacing the selected value via a read-only I2cMasterFrequencyKbps property.
  • Ft4222Device: Added a public I2cBusFrequencyKbps property (default 400 kbps), forwarded to Ft4222I2cBus in CreateI2cBusCore.
  • README: Documented configuring the frequency.

Usage

Ft4222Device device = new Ft4222Device(FtCommon.GetDevices()[0]);
device.I2cBusFrequencyKbps = 100;
using I2cBus ftI2c = device.CreateI2cBus();

Values outside 60–3400 kbps throw ArgumentOutOfRangeException. Existing callers are unaffected since the default preserves the prior 400 kbps behavior, and the constructor overload pair avoids relying on a default argument for compatibility.

@dotnet-policy-service dotnet-policy-service Bot added the area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio label Jun 2, 2026
Copilot AI changed the title [WIP] Add public method to set I2C clock frequency to 100Kbps Make FT4222 I2C master clock frequency configurable Jun 2, 2026
Copilot AI requested a review from raffaeler June 2, 2026 16:01
@raffaeler

Copy link
Copy Markdown
Contributor

@copilot address the errors that caused the tests to fail

Copilot AI commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

@copilot address the errors that caused the tests to fail

Fixed in af the latest commit — there was a stray duplicate closing brace in Ft4222I2cBus.cs that broke compilation and caused the build/test failures. Brace balance is now correct.

@raffaeler raffaeler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This implementation looks reasonable to me

@raffaeler raffaeler marked this pull request as ready for review June 4, 2026 15:57
Copilot AI review requested due to automatic review settings June 4, 2026 15:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 makes the FT4222 I2C master clock frequency configurable instead of being hard-coded to 400, enabling scenarios like running the bus at 100 (within the LibFT4222-supported range of 60–3400).

Changes:

  • Added frequency range constants plus an optional i2cMasterFrequencyKbps constructor parameter to Ft4222I2cBus, surfaced via I2cMasterFrequencyKbps.
  • Added Ft4222Device.I2cBusFrequencyKbps (defaulting to 400) and forwarded it when creating the Ft4222I2cBus.
  • Documented how to configure the frequency in the FT4222 README.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/devices/Ft4222/Ft4222I2cBus.cs Adds configurable I2C master init frequency with validation and a readable property.
src/devices/Ft4222/Ft4222Device.cs Exposes bus-frequency configuration on the public device wrapper and forwards it into bus creation.
src/devices/Ft4222/README.md Documents how to set the I2C bus frequency before creating the bus.

Comment thread src/devices/Ft4222/Ft4222I2cBus.cs
Comment thread src/devices/Ft4222/Ft4222I2cBus.cs Outdated
Comment thread src/devices/Ft4222/Ft4222Device.cs
Comment thread src/devices/Ft4222/README.md Outdated
Comment thread src/devices/Ft4222/Ft4222I2cBus.cs
Comment thread src/devices/Ft4222/Ft4222I2cBus.cs Outdated
Comment thread src/devices/Ft4222/Ft4222I2cBus.cs Outdated
Comment thread src/devices/Ft4222/README.md Outdated
Copilot AI requested a review from pgrawehr June 6, 2026 15:38
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@raffaeler

Copy link
Copy Markdown
Contributor

@copilot fix the compilation errors

Copilot AI commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix the compilation errors

Fixed in 8288ae5. The newly public Ft4222I2cBus was missing XML documentation on QueryComponentInformation(), which breaks this repo's build because public API docs are enforced.

Copilot AI requested a review from raffaeler June 14, 2026 12:35
@pgrawehr pgrawehr merged commit c57edaf into main Jun 14, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FT4222 - Cannot set I2C Clock frequency to 100Kbps

4 participants