rust-embedded / linux-embedded-hal

Implementation of the `embedded-hal` traits for Linux devices
Apache License 2.0
232 stars 40 forks source link

Enable i2c as a feature? #80

Closed zuckschwerdt closed 2 years ago

zuckschwerdt commented 2 years ago

The dependency on i2cdev for i2c is currently the only thing tying this to linux. I confirmed this crate to compile and work on unix with i2c removed. Would it be an option to offer i2c as a (default enabled) feature?

ryankurte commented 2 years ago

seems reasonable to me! though it may be a breaking change for folks selecting gpio implementations at the moment, maybe both spi and i2c so we're consistent?

zuckschwerdt commented 2 years ago

True, adding an i2c feature would break default-features = false (for gpio selection) setups. Alternative could be conditional compilation on target_os, it would just-work and not expose settings. But there might be users wondering where i2c is (on host != target).

eldruin commented 2 years ago

I would be fine with adding spi and i2c features. We can do so in the upcoming 0.4.0 release, since it is breaking anyway and this does not seem time-critical to me. Have you tested SPI to work on non-linux platforms? also, which platform are you working with?

zuckschwerdt commented 2 years ago

Not time-critical at all, just ergonomics to me. I use modular hardware, missing components are expected. Building with inaccessible or missing hardware interfaces is fine for me. In my application it turns out to be less involved to just recognize a missing /dev/spidev, GPIO or serial at runtime then to stub out all the code.

zuckschwerdt commented 2 years ago

For anyone wanting to test this, there are branches for 0.3 and 0.4 to show the changes:

eldruin commented 2 years ago

Nice, would you create a PR with your feat-i2cspi04 branch?