@@ -18,7 +18,7 @@ fn main() -> ! {
1818 use stm32g4xx_hal as hal;
1919
2020 use hal:: {
21- gpio:: { gpioa :: PA8 , Alternate , GpioExt , AF13 } ,
21+ gpio:: GpioExt ,
2222 hrtim:: {
2323 capture:: HrCapture , compare_register:: HrCompareRegister , control:: HrControltExt ,
2424 external_event, external_event:: ToExternalEventSource , output:: HrOutput ,
@@ -40,7 +40,7 @@ fn main() -> ! {
4040 let pwr = dp. PWR . constrain ( ) . freeze ( ) ;
4141 let mut rcc = dp. RCC . freeze (
4242 rcc:: Config :: pll ( ) . pll_cfg ( rcc:: PllConfig {
43- mux : rcc:: PLLSrc :: HSI ,
43+ mux : rcc:: PllSrc :: HSI ,
4444 n : rcc:: PllNMul :: MUL_15 ,
4545 m : rcc:: PllMDiv :: DIV_1 ,
4646 r : Some ( rcc:: PllRDiv :: DIV_2 ) ,
@@ -55,7 +55,7 @@ fn main() -> ! {
5555 let gpiob = dp. GPIOB . split ( & mut rcc) ;
5656
5757 // PA8 (D7 on Nucleo G474RE)
58- let pin_a: PA8 < Alternate < AF13 > > = gpioa. pa8 . into_alternate ( ) ;
58+ let pin_a = gpioa. pa8 ;
5959
6060 // PB5 (D4 on Nucleo G474RE)
6161 let input = gpiob. pb5 . into_pull_down_input ( ) ;
@@ -94,7 +94,7 @@ fn main() -> ! {
9494 out1. enable_set_event ( & timer) ; // Set high at new period
9595
9696 cr1. set_duty ( period / 2 ) ;
97- timer. start ( & mut hr_control) ;
97+ timer. start ( & mut hr_control. control ) ;
9898 out1. enable ( ) ;
9999
100100 let capture = timer. capture_ch1 ( ) ;
@@ -104,19 +104,16 @@ fn main() -> ! {
104104 let mut old_duty = 0 ;
105105 loop {
106106 for duty in ( u32:: from ( period) / 10 ) ..( 9 * u32:: from ( period) / 10 ) {
107- if !capture. is_pending ( ) {
108- continue ;
107+ if let Some ( value) = capture. get_signed ( period) {
108+ info ! (
109+ "Capture: {:?}, duty: {}, diff: {}" ,
110+ value,
111+ old_duty,
112+ value - old_duty as i32
113+ ) ;
114+ cr1. set_duty ( duty as u16 ) ;
115+ old_duty = duty;
109116 }
110- let value = capture. get_signed ( ) ;
111- cr1. set_duty ( duty as u16 ) ;
112- capture. clear_interrupt ( ) ;
113- info ! (
114- "Capture: {:?}, duty: {}, diff: {}" ,
115- value,
116- old_duty,
117- value - old_duty as i32
118- ) ;
119- old_duty = duty;
120117 }
121118 }
122119}
0 commit comments