I also tried borrowing peripherals
in the sub-initialization functions but I get errors:
the trait
esp_idf_hal::gpio::OutputPinis not implemented for
&Gpio4`
Function with peripherals
borrow attempt:
pub fn i2c_peripheral(
peripherals: &Peripherals,
) -> i2c::Master<
i2c::I2C0,
esp_idf_hal::gpio::Gpio4<gpio::InputOutput>,
esp_idf_hal::gpio::Gpio5<gpio::Output>,
> {
let sda = &peripherals.pins.gpio4.into_input_output().unwrap();
let scl = &peripherals.pins.gpio5.into_output().unwrap();
let i2c = &peripherals.i2c0;
let config = <i2c::config::MasterConfig as Default>::default().baudrate(400.kHz().into());
let i2c =
i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
i2c
}
Errors:
error[E0277]: the trait bound `&Gpio4<InputOutput>: esp_idf_hal::gpio::OutputPin` is not satisfied
--> src/init.rs:21:68
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ^^^ the trait `esp_idf_hal::gpio::OutputPin` is not implemented for `&Gpio4<InputOutput>`
|
= help: the trait `esp_idf_hal::gpio::OutputPin` is implemented for `Gpio4<MODE>`
note: required by a bound in `MasterPins`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:13:28
|
13 | pub struct MasterPins<SDA: OutputPin + InputPin, SCL: OutputPin + InputPin> {
| ^^^^^^^^^ required by this bound in `MasterPins`
error[E0277]: the trait bound `&Gpio4<InputOutput>: esp_idf_hal::gpio::InputPin` is not satisfied
--> src/init.rs:21:68
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ^^^ the trait `esp_idf_hal::gpio::InputPin` is not implemented for `&Gpio4<InputOutput>`
|
= help: the trait `esp_idf_hal::gpio::InputPin` is implemented for `Gpio4<MODE>`
note: required by a bound in `MasterPins`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:13:40
|
13 | pub struct MasterPins<SDA: OutputPin + InputPin, SCL: OutputPin + InputPin> {
| ^^^^^^^^ required by this bound in `MasterPins`
error[E0277]: the trait bound `&Gpio5<esp_idf_hal::gpio::Output>: esp_idf_hal::gpio::OutputPin` is not satisfied
--> src/init.rs:21:73
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ^^^ the trait `esp_idf_hal::gpio::OutputPin` is not implemented for `&Gpio5<esp_idf_hal::gpio::Output>`
|
= help: the trait `esp_idf_hal::gpio::OutputPin` is implemented for `Gpio5<MODE>`
note: required by a bound in `MasterPins`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:13:55
|
13 | pub struct MasterPins<SDA: OutputPin + InputPin, SCL: OutputPin + InputPin> {
| ^^^^^^^^^ required by this bound in `MasterPins`
error[E0277]: the trait bound `&Gpio5<esp_idf_hal::gpio::Output>: esp_idf_hal::gpio::InputPin` is not satisfied
--> src/init.rs:21:73
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ^^^ the trait `esp_idf_hal::gpio::InputPin` is not implemented for `&Gpio5<esp_idf_hal::gpio::Output>`
|
= help: the trait `esp_idf_hal::gpio::InputPin` is implemented for `Gpio5<MODE>`
note: required by a bound in `MasterPins`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:13:67
|
13 | pub struct MasterPins<SDA: OutputPin + InputPin, SCL: OutputPin + InputPin> {
| ^^^^^^^^ required by this bound in `MasterPins`
error[E0277]: the trait bound `&Gpio4<InputOutput>: esp_idf_hal::gpio::OutputPin` is not satisfied
--> src/init.rs:21:50
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `esp_idf_hal::gpio::OutputPin` is not implemented for `&Gpio4<InputOutput>`
| |
| required by a bound introduced by this call
|
= help: the trait `esp_idf_hal::gpio::OutputPin` is implemented for `Gpio4<MODE>`
note: required by a bound in `esp_idf_hal::i2c::Master::<I2C, SDA, SCL>::new`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:176:10
|
176 | SDA: OutputPin + InputPin,
| ^^^^^^^^^ required by this bound in `esp_idf_hal::i2c::Master::<I2C, SDA, SCL>::new`
error[E0277]: the trait bound `&Gpio4<InputOutput>: esp_idf_hal::gpio::InputPin` is not satisfied
--> src/init.rs:21:50
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `esp_idf_hal::gpio::InputPin` is not implemented for `&Gpio4<InputOutput>`
| |
| required by a bound introduced by this call
|
= help: the trait `esp_idf_hal::gpio::InputPin` is implemented for `Gpio4<MODE>`
note: required by a bound in `esp_idf_hal::i2c::Master::<I2C, SDA, SCL>::new`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:176:22
|
176 | SDA: OutputPin + InputPin,
| ^^^^^^^^ required by this bound in `esp_idf_hal::i2c::Master::<I2C, SDA, SCL>::new`
error[E0277]: the trait bound `&Gpio5<esp_idf_hal::gpio::Output>: esp_idf_hal::gpio::OutputPin` is not satisfied
--> src/init.rs:21:50
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `esp_idf_hal::gpio::OutputPin` is not implemented for `&Gpio5<esp_idf_hal::gpio::Output>`
| |
| required by a bound introduced by this call
|
= help: the trait `esp_idf_hal::gpio::OutputPin` is implemented for `Gpio5<MODE>`
note: required by a bound in `esp_idf_hal::i2c::Master::<I2C, SDA, SCL>::new`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:177:10
|
177 | SCL: OutputPin + InputPin,
| ^^^^^^^^^ required by this bound in `esp_idf_hal::i2c::Master::<I2C, SDA, SCL>::new`
error[E0277]: the trait bound `&Gpio5<esp_idf_hal::gpio::Output>: esp_idf_hal::gpio::InputPin` is not satisfied
--> src/init.rs:21:50
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ----------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `esp_idf_hal::gpio::InputPin` is not implemented for `&Gpio5<esp_idf_hal::gpio::Output>`
| |
| required by a bound introduced by this call
|
= help: the trait `esp_idf_hal::gpio::InputPin` is implemented for `Gpio5<MODE>`
note: required by a bound in `esp_idf_hal::i2c::Master::<I2C, SDA, SCL>::new`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:177:22
|
177 | SCL: OutputPin + InputPin,
| ^^^^^^^^ required by this bound in `esp_idf_hal::i2c::Master::<I2C, SDA, SCL>::new`
error[E0308]: mismatched types
--> src/init.rs:21:45
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ----------------------------------- ^^^ expected struct `I2C0`, found `&I2C0`
| |
| arguments to this function are incorrect
|
note: associated function defined here
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:179:12
|
179 | pub fn new(
| ^^^
error[E0277]: the trait bound `&Gpio4<InputOutput>: esp_idf_hal::gpio::OutputPin` is not satisfied
--> src/init.rs:21:9
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `esp_idf_hal::gpio::OutputPin` is not implemented for `&Gpio4<InputOutput>`
|
= help: the trait `esp_idf_hal::gpio::OutputPin` is implemented for `Gpio4<MODE>`
note: required by a bound in `esp_idf_hal::i2c::Master`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:149:10
|
149 | SDA: OutputPin + InputPin,
| ^^^^^^^^^ required by this bound in `esp_idf_hal::i2c::Master`
error[E0277]: the trait bound `&Gpio4<InputOutput>: esp_idf_hal::gpio::InputPin` is not satisfied
--> src/init.rs:21:9
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `esp_idf_hal::gpio::InputPin` is not implemented for `&Gpio4<InputOutput>`
|
= help: the trait `esp_idf_hal::gpio::InputPin` is implemented for `Gpio4<MODE>`
note: required by a bound in `esp_idf_hal::i2c::Master`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:149:22
|
149 | SDA: OutputPin + InputPin,
| ^^^^^^^^ required by this bound in `esp_idf_hal::i2c::Master`
error[E0277]: the trait bound `&Gpio5<esp_idf_hal::gpio::Output>: esp_idf_hal::gpio::OutputPin` is not satisfied
--> src/init.rs:21:9
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `esp_idf_hal::gpio::OutputPin` is not implemented for `&Gpio5<esp_idf_hal::gpio::Output>`
|
= help: the trait `esp_idf_hal::gpio::OutputPin` is implemented for `Gpio5<MODE>`
note: required by a bound in `esp_idf_hal::i2c::Master`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:150:10
|
150 | SCL: OutputPin + InputPin,
| ^^^^^^^^^ required by this bound in `esp_idf_hal::i2c::Master`
error[E0277]: the trait bound `&Gpio5<esp_idf_hal::gpio::Output>: esp_idf_hal::gpio::InputPin` is not satisfied
--> src/init.rs:21:9
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `esp_idf_hal::gpio::InputPin` is not implemented for `&Gpio5<esp_idf_hal::gpio::Output>`
|
= help: the trait `esp_idf_hal::gpio::InputPin` is implemented for `Gpio5<MODE>`
note: required by a bound in `esp_idf_hal::i2c::Master`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:150:22
|
150 | SCL: OutputPin + InputPin,
| ^^^^^^^^ required by this bound in `esp_idf_hal::i2c::Master`
error[E0277]: the trait bound `&Gpio4<InputOutput>: esp_idf_hal::gpio::OutputPin` is not satisfied
--> src/init.rs:21:9
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `esp_idf_hal::gpio::OutputPin` is not implemented for `&Gpio4<InputOutput>`
|
= help: the trait `esp_idf_hal::gpio::OutputPin` is implemented for `Gpio4<MODE>`
note: required by a bound in `esp_idf_hal::i2c::Master`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:149:10
|
149 | SDA: OutputPin + InputPin,
| ^^^^^^^^^ required by this bound in `esp_idf_hal::i2c::Master`
error[E0277]: the trait bound `&Gpio4<InputOutput>: esp_idf_hal::gpio::InputPin` is not satisfied
--> src/init.rs:21:9
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `esp_idf_hal::gpio::InputPin` is not implemented for `&Gpio4<InputOutput>`
|
= help: the trait `esp_idf_hal::gpio::InputPin` is implemented for `Gpio4<MODE>`
note: required by a bound in `esp_idf_hal::i2c::Master`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:149:22
|
149 | SDA: OutputPin + InputPin,
| ^^^^^^^^ required by this bound in `esp_idf_hal::i2c::Master`
error[E0277]: the trait bound `&Gpio5<esp_idf_hal::gpio::Output>: esp_idf_hal::gpio::OutputPin` is not satisfied
--> src/init.rs:21:9
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `esp_idf_hal::gpio::OutputPin` is not implemented for `&Gpio5<esp_idf_hal::gpio::Output>`
|
= help: the trait `esp_idf_hal::gpio::OutputPin` is implemented for `Gpio5<MODE>`
note: required by a bound in `esp_idf_hal::i2c::Master`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:150:10
|
150 | SCL: OutputPin + InputPin,
| ^^^^^^^^^ required by this bound in `esp_idf_hal::i2c::Master`
error[E0277]: the trait bound `&Gpio5<esp_idf_hal::gpio::Output>: esp_idf_hal::gpio::InputPin` is not satisfied
--> src/init.rs:21:9
|
21 | i2c::Master::<i2c::I2C0, _, _>::new(i2c, i2c::MasterPins { sda, scl }, config).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `esp_idf_hal::gpio::InputPin` is not implemented for `&Gpio5<esp_idf_hal::gpio::Output>`
|
= help: the trait `esp_idf_hal::gpio::InputPin` is implemented for `Gpio5<MODE>`
note: required by a bound in `esp_idf_hal::i2c::Master`
--> /home/shane/.cargo/registry/src/github.com-1ecc6299db9ec823/esp-idf-hal-0.38.1/src/i2c.rs:150:22
|
150 | SCL: OutputPin + InputPin,
| ^^^^^^^^ required by this bound in `esp_idf_hal::i2c::Master`
error[E0308]: mismatched types
--> src/init.rs:22:5
|
10 | ) -> i2c::Master<
| ______-
11 | | i2c::I2C0,
12 | | esp_idf_hal::gpio::Gpio4<gpio::InputOutput>,
13 | | esp_idf_hal::gpio::Gpio5<gpio::Output>,
14 | | > {
| |_- expected `esp_idf_hal::i2c::Master<I2C0, Gpio4<InputOutput>, Gpio5<esp_idf_hal::gpio::Output>>` because of return type
...
22 | i2c
| ^^^ expected struct `Gpio4`, found reference
|
= note: expected struct `esp_idf_hal::i2c::Master<_, Gpio4<InputOutput>, Gpio5<esp_idf_hal::gpio::Output>>`
found struct `esp_idf_hal::i2c::Master<_, &Gpio4<InputOutput>, &Gpio5<esp_idf_hal::gpio::Output>>`