Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/devices/Ft4222/Ft4222Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ namespace Iot.Device.Ft4222
/// </summary>
public class Ft4222Device : FtDevice
{
/// <summary>
/// Gets or sets the I2C master clock frequency in kbps used when creating an I2C bus.
/// Supported range is 60 to 3400 kbps. Defaults to 400 kbps.
/// </summary>
Comment thread
pgrawehr marked this conversation as resolved.
public uint I2cBusFrequencyKbps { get; set; } = Ft4222I2cBus.DefaultI2cMasterFrequencyKbps;

/// <summary>
/// Gets all the FT4222 connected
/// </summary>
Expand Down Expand Up @@ -69,7 +75,7 @@ protected override I2cBusManager CreateI2cBusCore(int busNumber, int[]? pins)
throw new ArgumentOutOfRangeException(nameof(busNumber));
}

return new I2cBusManager(this, busNumber, pins, new Ft4222I2cBus(this));
return new I2cBusManager(this, busNumber, pins, new Ft4222I2cBus(this, I2cBusFrequencyKbps));
}

/// <inheritdoc />
Expand Down
41 changes: 38 additions & 3 deletions src/devices/Ft4222/Ft4222I2cBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,59 @@
/// <summary>
/// FT4222 I2C Device
/// </summary>
internal class Ft4222I2cBus : I2cBus
public class Ft4222I2cBus : I2cBus
{
private const uint I2cMasterFrequencyKbps = 400;
/// <summary>
/// The default I2C master clock frequency in kbps used when none is specified.
/// </summary>
public const uint DefaultI2cMasterFrequencyKbps = 400;

/// <summary>
/// The minimum I2C master clock frequency in kbps supported by the FT4222.
/// </summary>
public const uint MinimumI2cMasterFrequencyKbps = 60;

/// <summary>
/// The maximum I2C master clock frequency in kbps supported by the FT4222.
/// </summary>
public const uint MaximumI2cMasterFrequencyKbps = 3400;
Comment on lines +24 to +34

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.

@copilot Make the containing class public instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 84a1806: Ft4222I2cBus is now public, so the public frequency constants are part of the public API.


private readonly Dictionary<int, I2cDevice> _usedAddresses = new Dictionary<int, I2cDevice>();
private SafeFtHandle _ftHandle;

/// <summary>
/// Gets the I2C master clock frequency in kbps used by this bus.
/// </summary>
public uint I2cMasterFrequencyKbps { get; }

/// <summary>
/// Store the FTDI Device Information
/// </summary>
public Ft4222Device DeviceInformation { get; private set; }

/// <summary>
/// Create a FT4222 I2C Device
/// Create a FT4222 I2C device using the default I2C master clock frequency.
/// </summary>
/// <param name="deviceInformation">Device information. Use FtCommon.GetDevices to get it.</param>
public Ft4222I2cBus(Ft4222Device deviceInformation)
: this(deviceInformation, DefaultI2cMasterFrequencyKbps)
{
}

/// <summary>
/// Create a FT4222 I2C device using the specified I2C master clock frequency.
/// </summary>
/// <param name="deviceInformation">Device information. Use FtCommon.GetDevices to get it.</param>
/// <param name="i2cMasterFrequencyKbps">The I2C master clock frequency in kbps. Supported range is 60 to 3400 kbps.</param>
public Ft4222I2cBus(Ft4222Device deviceInformation, uint i2cMasterFrequencyKbps)
{
if (i2cMasterFrequencyKbps < MinimumI2cMasterFrequencyKbps || i2cMasterFrequencyKbps > MaximumI2cMasterFrequencyKbps)
{
throw new ArgumentOutOfRangeException(nameof(i2cMasterFrequencyKbps), $"I2C master clock frequency must be between {MinimumI2cMasterFrequencyKbps} and {MaximumI2cMasterFrequencyKbps} kbps.");

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.

Include this in the next change.

}

I2cMasterFrequencyKbps = i2cMasterFrequencyKbps;

switch (deviceInformation.Type)
{
case FtDeviceType.Ft4222HMode0or2With2Interfaces:
Expand Down Expand Up @@ -143,7 +178,7 @@
_ftHandle = null!;
}

public override ComponentInformation QueryComponentInformation()

Check failure on line 181 in src/devices/Ft4222/Ft4222I2cBus.cs

View check run for this annotation

Azure Pipelines / dotnet.iot (Build MacOS Build Build_Debug)

src/devices/Ft4222/Ft4222I2cBus.cs#L181

src/devices/Ft4222/Ft4222I2cBus.cs(181,46): error CS1591: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing XML comment for publicly visible type or member 'Ft4222I2cBus.QueryComponentInformation()'

Check failure on line 181 in src/devices/Ft4222/Ft4222I2cBus.cs

View check run for this annotation

Azure Pipelines / dotnet.iot (Build Linux Build Build_Release)

src/devices/Ft4222/Ft4222I2cBus.cs#L181

src/devices/Ft4222/Ft4222I2cBus.cs(181,46): error CS1591: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing XML comment for publicly visible type or member 'Ft4222I2cBus.QueryComponentInformation()'

Check failure on line 181 in src/devices/Ft4222/Ft4222I2cBus.cs

View check run for this annotation

Azure Pipelines / dotnet.iot (Build Linux Build Build_Release)

src/devices/Ft4222/Ft4222I2cBus.cs#L181

src/devices/Ft4222/Ft4222I2cBus.cs(181,46): error CS1591: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing XML comment for publicly visible type or member 'Ft4222I2cBus.QueryComponentInformation()'

Check failure on line 181 in src/devices/Ft4222/Ft4222I2cBus.cs

View check run for this annotation

Azure Pipelines / dotnet.iot (Build Linux Build Build_Debug)

src/devices/Ft4222/Ft4222I2cBus.cs#L181

src/devices/Ft4222/Ft4222I2cBus.cs(181,46): error CS1591: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing XML comment for publicly visible type or member 'Ft4222I2cBus.QueryComponentInformation()'

Check failure on line 181 in src/devices/Ft4222/Ft4222I2cBus.cs

View check run for this annotation

Azure Pipelines / dotnet.iot (Build Linux Build Build_Debug)

src/devices/Ft4222/Ft4222I2cBus.cs#L181

src/devices/Ft4222/Ft4222I2cBus.cs(181,46): error CS1591: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing XML comment for publicly visible type or member 'Ft4222I2cBus.QueryComponentInformation()'

Check failure on line 181 in src/devices/Ft4222/Ft4222I2cBus.cs

View check run for this annotation

Azure Pipelines / dotnet.iot (Build MacOS Build Build_Release)

src/devices/Ft4222/Ft4222I2cBus.cs#L181

src/devices/Ft4222/Ft4222I2cBus.cs(181,46): error CS1591: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing XML comment for publicly visible type or member 'Ft4222I2cBus.QueryComponentInformation()'

Check failure on line 181 in src/devices/Ft4222/Ft4222I2cBus.cs

View check run for this annotation

Azure Pipelines / dotnet.iot

src/devices/Ft4222/Ft4222I2cBus.cs#L181

src/devices/Ft4222/Ft4222I2cBus.cs(181,46): error CS1591: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing XML comment for publicly visible type or member 'Ft4222I2cBus.QueryComponentInformation()'

Check failure on line 181 in src/devices/Ft4222/Ft4222I2cBus.cs

View check run for this annotation

Azure Pipelines / dotnet.iot

src/devices/Ft4222/Ft4222I2cBus.cs#L181

src/devices/Ft4222/Ft4222I2cBus.cs(181,46): error CS1591: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing XML comment for publicly visible type or member 'Ft4222I2cBus.QueryComponentInformation()'

Check failure on line 181 in src/devices/Ft4222/Ft4222I2cBus.cs

View check run for this annotation

Azure Pipelines / dotnet.iot

src/devices/Ft4222/Ft4222I2cBus.cs#L181

src/devices/Ft4222/Ft4222I2cBus.cs(181,46): error CS1591: (NETCORE_ENGINEERING_TELEMETRY=Build) Missing XML comment for publicly visible type or member 'Ft4222I2cBus.QueryComponentInformation()'
{
var self = new ComponentInformation(this, "FT4222 I2C Bus driver");
self.Properties["BusNo"] = "0";
Expand Down
8 changes: 8 additions & 0 deletions src/devices/Ft4222/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ if (bme280.TryReadTemperature(out Temperature temperature))
}
```

By default, the I2C bus is initialized at 400 kbps. You can change the I2C master clock frequency (supported range is 60 to 3400 kbps) by setting `I2cBusFrequencyKbps` on the `Ft4222Device` before creating the bus:

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.

Ok, apply this.


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

### SPI

```Ft4222Spi``` is the SPI driver which you can pass later to any device requiring SPI or directly use it to send SPI commands. The SPI implementation is fully compatible with ```System.Device.Spi.SpiDevice```.
Expand Down
Loading