eldruin / pcf857x-rs Goto Github PK
View Code? Open in Web Editor NEWPlatform agnostic driver for the PCF8574, PCF8574A and PCF8575 I/O expanders written in Rust using embedded-hal
License: Apache License 2.0
Platform agnostic driver for the PCF8574, PCF8574A and PCF8575 I/O expanders written in Rust using embedded-hal
License: Apache License 2.0
Looks like there is a lack of impl DerefMut for pins.
Example:
fn main() -> eyre::Result<()> {
// It is necessary to call this function once. Otherwise some patches to the runtime
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
esp_idf_svc::sys::link_patches();
let peripherals = Peripherals::take().unwrap();
let i2c = peripherals.i2c0;
let sda = peripherals.pins.gpio5;
let scl = peripherals.pins.gpio6;
let config = I2cConfig::new().baudrate(100.kHz().into());
let i2c = I2cDriver::new(i2c, sda, scl, &config)?;
let mut expander: Pcf8574<I2cDriver> = pcf857x::Pcf8574::new(i2c, SlaveAddr::Alternative(true, true, true));
let parts = expander.split();
fn test<'d>(p: impl Peripheral<P = impl OutputPin> + 'd) {
todo!()
}
test(parts.p0); // doesn't work
}
Error:
error[E0277]: the trait bound `P0<'_, Pcf8574<I2cDriver<'_>>, I2cError>: DerefMut` is not satisfied
--> examples/uln2003_via_pcf8574.rs:42:10
|
42 | test(parts.p0);
| ---- ^^^^^^^^ the trait `DerefMut` is not implemented for `P0<'_, Pcf8574<I2cDriver<'_>>, I2cError>`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `Peripheral`:
AnyIOPin
AnyInputPin
AnyOutputPin
Modem
ADC1
ADC2
CAN
Gpio0
and 46 others
= note: required for `P0<'_, Pcf8574<I2cDriver<'_>>, I2cError>` to implement `Peripheral`
note: required by a bound in `test`
--> examples/uln2003_via_pcf8574.rs:38:25
|
38 | fn test<'d>(p: impl Peripheral<P = impl OutputPin> + 'd) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `test`
PCF8575 has 18 output pins, so u16 doesn't have enough bits for that. A workaround is to set through an array, but it's just a workaround.
A split()
method should be added that returns the GPIO pins broken into individual generic embedded-hal
Pins.
Examples of this are:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.