Some sensors use multiple I2C devices. Example of that is SenseHat. Currently in order to swap I2C implementation with different one (i.e. Ft4222) it’s a bit of a hassle: device need to take 6 I2C Devices as inputs and construct all of them. If we had I2cBus this could be solved much simpler:
public abstract class I2cBus
{
public abstract I2cDevice CreateDevice(int deviceAddress);
public static I2cBus Create(int bus)
{
return new DefaultI2cBus(bus);
}
}
internal class DefaultI2cBus : I2cBus
{
private int _bus;
public DefaultI2cBus(int bus)
{
_bus = bus;
}
public override I2cDevice CreateDevice(int deviceAddress)
{
return I2cDevice.Create(new I2cConnectionSettings(bus, deviceAddress));
}
}
in that case sense hat could take bus as an input (and null as default which would use the correct bus). The Ft4222 could implement a bus and could be provided directly to SenseHat.
- open question: should bus manage lifetime of devices or just be a factory (factory would be fine for most of the cases)
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (18 by maintainers)
Top Results From Across the Web
I2C Bus
The I2C bus was designed by Philips in the early '80s to allow easy communication between components which reside on the same circuit...
Read more >Understanding the I2C Bus
The I2C bus is a very popular and powerful bus used for communication between a master (or multiple masters) and a single or...
Read more >I²C - Wikipedia
I 2 C alternatively known as I2C or IIC, is a synchronous, multi-master/multi-slave (controller/target), packet switched, single-ended, serial communication ...
Read more >I2C tutorial
The devices on the I2C bus are either masters or slaves. The master is always the device that drives the SCL clock line....
Read more >I2C - SparkFun Learn
Build a long-range, noise-isolated I2C bus with the SparkFun QwiicBus Kit featuring the QwiicBus EndPoint and MidPoint following this Hookup Guide.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@krwq I’ve implemented basically that design, except not (yet) in System.Device. Ideally, your FT4222 showcase would, in the end, simply be changed to inherit from my base class with almost no further impact. We can hopefully talk this over directly in the triage call later this week.
I’ve also thought of this before, but IIRC it was considered to much overhead. But I agree that an i2cbus instance would be helpful. It could provide functions such as bus scanning or also bus reset (send a 0x6 to addres 0x0 I think that was).