-
Notifications
You must be signed in to change notification settings - Fork 180
/
pwm_input.rs
43 lines (32 loc) · 993 Bytes
/
pwm_input.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! Testing PWM input
#![deny(unsafe_code)]
#![no_main]
#![no_std]
use panic_halt as _;
use cortex_m_rt::entry;
use stm32f1xx_hal::{pac, prelude::*, timer::pwm_input::*};
#[entry]
fn main() -> ! {
let p = pac::Peripherals::take().unwrap();
let mut flash = p.FLASH.constrain();
let rcc = p.RCC.constrain();
let clocks = rcc.cfgr.freeze(&mut flash.acr);
let mut afio = p.AFIO.constrain();
let mut dbg = p.DBGMCU;
let gpioa = p.GPIOA.split();
let gpiob = p.GPIOB.split();
let (_pa15, _pb3, pb4) = afio.mapr.disable_jtag(gpioa.pa15, gpiob.pb3, gpiob.pb4);
let pb5 = gpiob.pb5;
let pwm_input = p.TIM3.remap(&mut afio.mapr).pwm_input(
(pb4, pb5),
&mut dbg,
Configuration::Frequency(10.kHz()),
&clocks,
);
loop {
let _freq = pwm_input
.read_frequency(ReadMode::Instant, &clocks)
.unwrap();
let _duty_cycle = pwm_input.read_duty(ReadMode::Instant).unwrap();
}
}