-
Notifications
You must be signed in to change notification settings - Fork 585
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
Unify platform specific implementations of I2cDevice/SpiDevice into one class #534
Comments
How would we implement a GpioI2cDevice? Is this where GenericI2cDevice comes into play? |
GpioI2cDevice/SoftI2cDevice assuming we don't pick the interface would derive from I2cDevice. The only thing is that without GenericI2cDevice the abstraction for I2cDevice will be kinda weird (software implementation would not use anything from that class - it would just reuse the public surface). On the other hand GenericI2cDevice is just awkward from naming and discoverability point of view (which feels we should have I2cDevice.Create which creates internal GenericI2cDevice). |
I might be overlooking this new direction, but I'm thinking we keep the Then the We could pass
Again, not completely sure. |
Thinking a little more on this... why not consolidate to the following files... I2c
Devices (can possibly get rid of this directory and place I2cDevice files back at I2c folder?)
I2cDevice.Linux.cs // Implements II2cDevice. Move all code from UnixI2cDevice to this file.
I2cDevice.Windows.cs // Implements II2cDevice. Move all code from Windows10I2cDevice to this file.
II2cDevice.cs // Includes same method signatures as original I2cDevice.cs
I2cConnectionSettings.cs (not changed; same location)
Delete the following files.
UnixI2cDevice.Linux.cs
UnixI2cDevice.Windows.cs
Windows10I2cDevice.Linux.cs
Windows10I2cDevice.Windows.cs public class I2cDevice : II2cDevice // Both flavors of I2cDevice.*.cs has static Create method, so it should still return II2cDevice for OS.
public static II2cDevice Create(I2cConnectionSettings settings) => new I2cDevice(settings);
var i2cDevice = I2cDevice.Create(settings);
// Can pass along to binding.
I see your point on this. Not sure if the C# 8 default interface feature helps in this case. |
I've talked with @bartonjs offline about the design and I believe we should go with more or less following direction (we are currently very close to that): public abstract class I2cDevice
{
public static I2cDevice Create(I2cSettings settings);
// ideally we should move all non-generic settings like BusId outside and take as args
// but considering this particular function should cover 99% use case it is acceptable if we leave it as is
// we can re-iterate on that separately
// software implementation can be added in the future i.e. like following:
// public static I2cDevice Create(IGpioController controller, int sda, int scl, I2cSettings settings);
// note that implementation does not have to be public
}
Assuming we went with proposed design *.I2c namespace would effectively have 2 types which does not justify making another sub-namespace for it (or in other words we should get rid of I2c.Devices namespace or at least it should not have anything public) as an implementation detail layout can be similar to as proposed above (perhaps we can move I2cDevice outside of Devices but I don't have strong opinion either way). |
This is how I interpret the direction...
So basically the final structure would be... I2c
Devices
I2cDevice.cs // All classes have namespace of 'namespace System.Device.I2c'
I2cDevice.Linux.cs
I2cDevice.Windows.cs
SoftI2cDevice.cs // Future internal
UnixI2cDevice.Linux.cs // Internal
Windows10I2cDevice.Windows.cs // Internal
I2cConnectionSettings.cs |
One area this breaks is the DevicApiTester utility. I was able to update and compiles locally.
This shouldn't be a biggie though as the commands could be simplified by removing Device parameter and update // Example command...
./DeviceApiTester i2c-detect -d Unix -b 1
// Would become...
./DeviceApiTester i2c-detect -b 1 |
Side question... since we are changing file names, would it be appropriate to go ahead and rename the following since it is based on WinRT? Just curious. // From...
Windows10I2cDevice.Windows.cs
// To...
WinRtI2cDevice.Windows.cs |
@shaggygi corefx convention would be (GenericI2cDevice is internal): |
Wouldn't making GenericI2cDevice internal and not providing an interface cripple future extensibility? |
@kmate95 No, the plan is to continue having var i2cDevice = I2cDevice.Create(settings);
var i2cDevice = I2cCreate.Create(controller, sda, scl, settings); // or similar |
@shaggygi Thanks for clarifying. |
@shaggygi planning to pick it up or shall I go ahead with this? |
@krwq I have a PR about ready to go. Gimme a couple of hours. |
@shaggygi thanks! PR makes stuff simpler and is inline with what I'm thinking |
I2cDevice.Create
=>new I2cDevice()
open questions:
cc: @joperezr @shaggygi @ZhangGaoxing
The text was updated successfully, but these errors were encountered: