question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

1reaction
pgrawehrcommented, Dec 7, 2020

@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.

1reaction
pgrawehrcommented, Dec 3, 2020

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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found