Skip to content
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

Add Tca955x device family #2374

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Add Tca955x device family #2374

wants to merge 10 commits into from

Conversation

tolobis
Copy link

@tolobis tolobis commented Jan 15, 2025

Add support for the device Tca9554 and Tca9555.

This PR introduces support for the TCA9554 and TCA9555 devices, which are simple I2C IO extensions (8-bit and 16-bit, respectively). The implementation in Tca955x.cs is based on the existing Mcp23xxx.cs class.

Datasheets:

Microsoft Reviewers: Open in CodeFlow

@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 Jan 15, 2025
@tolobis
Copy link
Author

tolobis commented Jan 15, 2025

@dotnet-policy-service agree

@Ellerbach
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@Ellerbach Ellerbach left a comment

Choose a reason for hiding this comment

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

Overall looks good. Couple of comments after a first quick review. Thanks!

The `Tca955x` has one interrupt pin. The corresponding pins need to be connected to a master GPIO controller for this feature to work. You can use a GPIO controller around the MCP device to handle everything for you:
```csharp
// Gpio controller from parent device (eg. Raspberry Pi)
_gpioController = new GpioController(PinNumberingScheme.Logical);
Copy link
Member

Choose a reason for hiding this comment

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

as a detail: we want to get rid of the PinNumberingSchemebecause no one use it and it's hard to maintain. So, better take it out of the parameters as it's anyway the default.

src/devices/Tca955x/README.md Show resolved Hide resolved
/// The device address for the connection on the I2C bus.
/// Start with 0x20 and ends with 0x27
/// </param>
public Tca9554(I2cDevice bus, int interrupt = -1, GpioController? gpioController = null, bool shouldDispose = true, byte adress = 0x20)
Copy link
Member

Choose a reason for hiding this comment

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

rather than a default 0x20 like this, can you add a public constant with DefaultI2cAddress and reuse that one? (see other I2C binding for the pattern)


private bool _shouldDispose;

private byte _adress = 0x20;
Copy link
Member

Choose a reason for hiding this comment

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

as mentioned before a public const would be better

if (adress < 0x20 ||
adress > 0x27)
{
new ArgumentOutOfRangeException(nameof(adress), "Adress should be in Range 0x20 to 0x28");
Copy link
Member

Choose a reason for hiding this comment

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

I guess 0x27 regarding the code

_interrupt = interrupt;
_adress = adress;

if (adress < 0x20 ||
Copy link
Member

Choose a reason for hiding this comment

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

you can then use the const and a +7 if that's the range. A few less magic numbers then.


<ItemGroup>
<Compile Include="*.cs" />
<Content Include="category.txt" />
Copy link
Member

Choose a reason for hiding this comment

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

you can put it as none as well I guess

@@ -0,0 +1,3 @@
# TODO: This needs to be determined
Copy link
Member

Choose a reason for hiding this comment

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

just make it simple :-) typically it's the usage you can add like for the main README.md

src/devices/Tca955x/samples/Tca955x.Sample.cs Show resolved Hide resolved
Copy link
Member

@Ellerbach Ellerbach left a comment

Choose a reason for hiding this comment

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

Thankd, looks really good now!

src/devices/Tca955x/samples/README.md Show resolved Hide resolved
src/devices/Tca955x/samples/README.md Show resolved Hide resolved
src/devices/Tca955x/samples/Tca955x.Sample.cs Show resolved Hide resolved
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.

2 participants