我开始做了一个Rust 的节目,我想要能够得到一些瞬间过go 的时间.下面是STD图书馆如何做到这一点.
use std::time::{Duration, Instant};
use std::thread::sleep;
fn main() {
let now = Instant::now();
// we sleep for 2 seconds
sleep(Duration::new(2, 0));
// it prints '2'
println!("{}", now.elapsed().as_secs());
}
我没有带 rust 的性传播疾病,我怎么才能避开这个问题呢?我正在使用stm32f1xx HAL和stm32f103c8t6.我试着看了一下HAL中与定时器相关的各种模块,以及embedded time crate.但我没办法让任何东西发挥作用.任何帮助都将不胜感激.
我从其他人做过的松散相关的事情中拼凑了一些随机的代码行.
let mut counter = Timer::new(dp.TIM2, &clocks).counter_us();
counter.start(1_000_000_u32.micros()).unwrap();
let mut timer = Timer::syst(cp.SYST, &clocks);
let mut counter = Timer::counter_us(timer);
但是我甚至不能没有错误地初始化计数器,即使相关的函数、 struct 等都应该导入.
error[E0599]: no function or associated item named `new` found for struct `Timer` in the current scope
--> src/main.rs:87:30
|
87 | let mut counter = Timer::new(dp.TIM2, &clocks).counter_us();
| ^^^ function or associated item not found in `Timer<_>`
use panic_halt as _;
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use stm32f1xx_hal as hal;
use hal::{pac, TIM2, timer::Timer, delay::Delay, prelude::*};
use rtt_target::{rprintln, rtt_init_print};