From 11884715b8d7d2fc0b4c16ad71013dd79a7cbe05 Mon Sep 17 00:00:00 2001 From: Felix Collins Date: Tue, 16 Sep 2025 13:58:23 +1200 Subject: [PATCH] making address check optional so this driver can be used with other compatible chips with different address range. --- src/devices/Tca955x/Tca9554.cs | 5 +++-- src/devices/Tca955x/Tca9555.cs | 5 +++-- src/devices/Tca955x/Tca955x.cs | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/devices/Tca955x/Tca9554.cs b/src/devices/Tca955x/Tca9554.cs index 6368c8314d..adf28d2be4 100644 --- a/src/devices/Tca955x/Tca9554.cs +++ b/src/devices/Tca955x/Tca9554.cs @@ -18,8 +18,9 @@ public class Tca9554 : Tca955x /// The input pin number that is connected to the interrupt. /// The controller for the reset and interrupt pins. If not specified, the default controller will be used. /// True to dispose the when this object is disposed - public Tca9554(I2cDevice device, int interrupt = -1, GpioController? gpioController = null, bool shouldDispose = true) - : base(device, interrupt, gpioController, shouldDispose) + /// True to skip checking the I2C address is in the valid range for the device. Only set this to true if you are using a compatible device with a different addresss scheme. + public Tca9554(I2cDevice device, int interrupt = -1, GpioController? gpioController = null, bool shouldDispose = true, bool skipAddressCheck = false) + : base(device, interrupt, gpioController, shouldDispose, skipAddressCheck) { } diff --git a/src/devices/Tca955x/Tca9555.cs b/src/devices/Tca955x/Tca9555.cs index ecad645913..abfd41c36c 100644 --- a/src/devices/Tca955x/Tca9555.cs +++ b/src/devices/Tca955x/Tca9555.cs @@ -19,8 +19,9 @@ public class Tca9555 : Tca955x /// The input pin number that is connected to the interrupt. /// The controller for the reset and interrupt pins. If not specified, the default controller will be used. /// True to dispose the when this object is disposed - public Tca9555(I2cDevice device, int interrupt = -1, GpioController? gpioController = null, bool shouldDispose = true) - : base(device, interrupt, gpioController, shouldDispose) + /// True to skip checking the I2C address is in the valid range for the device. Only set this to true if you are using a compatible device with a different addresss scheme. + public Tca9555(I2cDevice device, int interrupt = -1, GpioController? gpioController = null, bool shouldDispose = true, bool skipAddressCheck = false) + : base(device, interrupt, gpioController, shouldDispose, skipAddressCheck) { } diff --git a/src/devices/Tca955x/Tca955x.cs b/src/devices/Tca955x/Tca955x.cs index f839b456a0..907185a9d1 100644 --- a/src/devices/Tca955x/Tca955x.cs +++ b/src/devices/Tca955x/Tca955x.cs @@ -69,13 +69,15 @@ public abstract class Tca955x : GpioDriver /// The input pin number that is connected to the interrupt.Must be set together with the /// The controller for the interrupt pin. Must be set together with the /// True to dispose the when this object is disposed - protected Tca955x(I2cDevice device, int interrupt = -1, GpioController? gpioController = null, bool shouldDispose = true) + /// True to skip checking the I2C address is in the valid range for the device. Only set this to true if you are using a compatible device with a different addresss scheme. + protected Tca955x(I2cDevice device, int interrupt = -1, GpioController? gpioController = null, bool shouldDispose = true, bool skipAddressCheck = false) { _busDevice = device; _interrupt = interrupt; - if (_busDevice.ConnectionSettings.DeviceAddress < DefaultI2cAddress || - _busDevice.ConnectionSettings.DeviceAddress > DefaultI2cAddress + AddressRange) + if (!skipAddressCheck && + (_busDevice.ConnectionSettings.DeviceAddress < DefaultI2cAddress || + _busDevice.ConnectionSettings.DeviceAddress > DefaultI2cAddress + AddressRange)) { throw new ArgumentOutOfRangeException(nameof(device), $"Address should be in Range {DefaultI2cAddress} to {DefaultI2cAddress + AddressRange} inclusive"); }