-
-
Couldn't load subscription status.
- Fork 85
Description
Description
In order to support Bridge chips, such as an I2C to SPI converter, Onewire to I2C or SPI, or an I2C multiplexor (e.g. DS28E18, SC18IS606, or TCA9548A) the existing base classes should be abstract and the implementation details virtual.
This would allow using any iot driver (e.g. Ssd1306) via one of these devices.
It would also make the classes more closely align with the .NET IoT Libraries
https://learn.microsoft.com/en-us/dotnet/api/system.device.spi.spidevice
https://learn.microsoft.com/en-us/dotnet/api/system.device.spi.i2cdevice
How to solve the problem
Align the existing SpiDevice and I2cDevice with the https://github.com/dotnet/iot/ implementations
https://github.com/dotnet/iot/blob/main/src/System.Device.Gpio/System/Device/Spi/SpiDevice.cs
https://github.com/dotnet/iot/blob/main/src/System.Device.Gpio/System/Device/I2c/I2cDevice.cs
Moving the existing implementations to a 'NativeXXXDeviceclass similar to theUnixXXXDevice` classes.
The static Create methods would simply return the NativeXXXDevice implementation.
public static I2cDevice Create(I2cConnectionSettings settings)
{
return new NativeI2cDevice(settings);
} public static SpiDevice Create(SpiConnectionSettings settings)
{
return new NativeSpiDevice(settings);
}Example for using an Ssd1306 via a TCA9548A
// TCA9538A connected to I2C1
// https://www.ti.com/lit/ds/symlink/tca9548a.pdf
var tca9548a = new Tca9538A(I2cDevice.Create(
new I2cConnectionSettings(
1,
Tca9538A.DefaultI2cAddress,
I2cBusSpeed.FastMode)))
// SSD1306 connected to SC5/SC5 output of TCA9548A
var ssd1306 = new Ssd1306(
tca9548a.Create(
new I2cConnectionSettings(
5,
Ssd1306.DefaultI2cAddress,
I2cBusSpeed.FastMode)),
Ssd13xx.DisplayResolution.OLED128x64);Describe alternatives you've considered
It would be possible to manually copy the existing IoT drivers required and adjust them to work over whatever expander was in use, but this would end up duplicating code where it is not required.
Aditional context
https://discord.com/channels/478725473862549535/709495312401694735/1390131333317132419