【发布时间】:2021-06-23 08:40:21
【问题描述】:
我正在尝试为我的 STM32F303VC 使用 DHT11 库
我收到错误:
error[E0277]: trait bound `PE2 --> src/DHT11/auxiliary/src/lib.rs:51:32 | 51 | 让 mut dht11 = Dht11::new(pin); | ^^^ 特性 `_embedded_hal_digital_InputPin` 没有为 `PE2 | = 注:因为对 `PE2
我的代码在辅助模块是:
//! Initialization code
#![no_std]
#[allow(unused_extern_crates)] // bug rust-lang/rust#53964
extern crate panic_itm; // panic handler
pub use cortex_m::{asm::bkpt, iprint, iprintln};
pub use cortex_m_rt::entry;
pub use f3::hal::{delay::Delay, prelude, stm32f30x::i2c1};
pub use f3::led::{Direction, Leds};
pub use m::Float as _0;
pub use f3::hal::stm32f30x::{gpioc, rcc};
pub use dht11::{self,Measurement,Dht11};
pub use stm32f30x_hal::gpio;
use f3::hal::stm32f30x::{self, GPIOE, RCC};
pub use embedded_hal::digital::v2::OutputPin;
pub use embedded_hal::digital::v2::InputPin;
use cortex_m::peripheral::ITM;
use f3::{
hal::{
i2c::I2c,
prelude::*,
},
Lsm303dlhc,
};
pub fn init() -> (Delay, ITM, Leds, Dht11<GPIOE>) {
(stm32f30x::Peripherals::take().unwrap());
let cp = cortex_m::Peripherals::take().unwrap();
let dp = stm32f30x::Peripherals::take().unwrap();
let mut flash = dp.FLASH.constrain();
let mut rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.freeze(&mut flash.acr);
let gpioe = dp.GPIOE.split(&mut rcc.ahb);
let leds = Leds::new(gpioe);
let mut gpiob = dp.GPIOB.split(&mut rcc.ahb);
let scl = gpiob.pb6.into_af4(&mut gpiob.moder, &mut gpiob.afrl);
let sda = gpiob.pb7.into_af4(&mut gpiob.moder, &mut gpiob.afrl);
let i2c = I2c::i2c1(dp.I2C1, (scl, sda), 400.khz(), clocks, &mut rcc.apb1);
let pin = gpioe.pe2.into_open_drain_output(&mut gpioe.moder,&mut gpioe.otyper);
let delay = Delay::new(cp.SYST, clocks);
let mut dht11 = Dht11::new(pin);
(delay, cp.ITM, leds, dht11)
}
我的 main.rs 代码是:
#![deny(unsafe_code)]
#![no_main]
#![no_std]
#[allow(unused_imports)]
use aux19::{entry, iprint, iprintln, prelude::*, Direction};
use aux19::{prelude::_embedded_hal_blocking_delay_DelayMs};
use m::Float;
// Slave address
const MAGNETOMETER: u8 = 0b001_1110;
#[entry]
fn main() -> ! {
let (mut delay, mut itm,mut leds,mut dth11) = aux18::init();
loop {
match dht11.perform_measurement(&mut delay) {
Ok(meas) => iprintln!(&mut itm.stim[0],"Temp: {} Hum: {}", meas.temperature, meas.humidity).unwrap(),
Err(e) => iprintln!(&mut itm.stim[0],"Error: {:?}", e).unwrap(),
};
delay.delay_ms(2_000_u16);
}
}
【问题讨论】:
标签: rust compiler-errors embedded stm32