@@ -9,12 +9,7 @@ use panic_halt as _;
99
1010use cortex_m:: asm;
1111use cortex_m_rt:: entry;
12- use stm32f1xx_hal:: {
13- pac,
14- prelude:: * ,
15- time:: ms,
16- timer:: { Channel , Tim2NoRemap } ,
17- } ;
12+ use stm32f1xx_hal:: { pac, prelude:: * , time:: ms} ;
1813
1914#[ entry]
2015fn main ( ) -> ! {
@@ -25,90 +20,70 @@ fn main() -> ! {
2520
2621 let clocks = rcc. cfgr . freeze ( & mut flash. acr ) ;
2722
28- let mut afio = p. AFIO . constrain ( ) ;
29-
30- let mut gpioa = p. GPIOA . split ( ) ;
31- // let mut gpiob = p.GPIOB.split();
23+ let gpioa = p. GPIOA . split ( ) ;
24+ // let gpiob = p.GPIOB.split();
3225
3326 // TIM2
34- let c1 = gpioa. pa0 . into_alternate_push_pull ( & mut gpioa . crl ) ;
35- let c2 = gpioa. pa1 . into_alternate_push_pull ( & mut gpioa . crl ) ;
36- let c3 = gpioa. pa2 . into_alternate_push_pull ( & mut gpioa . crl ) ;
27+ let c1 = gpioa. pa0 ;
28+ let c2 = gpioa. pa1 ;
29+ let c3 = gpioa. pa2 ;
3730 // If you don't want to use all channels, just leave some out
38- // let c4 = gpioa.pa3.into_alternate_push_pull(&mut gpioa.crl);
39- let pins = ( c1, c2, c3) ;
31+ // let c4 = gpioa.pa3;
4032
4133 // TIM3
42- // let c1 = gpioa.pa6.into_alternate_push_pull(&mut gpioa.crl) ;
43- // let c2 = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl) ;
44- // let c3 = gpiob.pb0.into_alternate_push_pull(&mut gpiob.crl) ;
45- // let c4 = gpiob.pb1.into_alternate_push_pull(&mut gpiob.crl) ;
34+ // let c1 = gpioa.pa6;
35+ // let c2 = gpioa.pa7;
36+ // let c3 = gpiob.pb0;
37+ // let c4 = gpiob.pb1;
4638
4739 // TIM4 (Only available with the "medium" density feature)
48- // let c1 = gpiob.pb6.into_alternate_push_pull(&mut gpiob.crl) ;
49- // let c2 = gpiob.pb7.into_alternate_push_pull(&mut gpiob.crl) ;
50- // let c3 = gpiob.pb8.into_alternate_push_pull(&mut gpiob.crh) ;
51- // let c4 = gpiob.pb9.into_alternate_push_pull(&mut gpiob.crh) ;
40+ // let c1 = gpiob.pb6;
41+ // let c2 = gpiob.pb7;
42+ // let c3 = gpiob.pb8;
43+ // let c4 = gpiob.pb9;
5244
5345 //let mut pwm =
54- // Timer::new(p.TIM2, &clocks).pwm_hz::<Tim2NoRemap, _, _> (pins, &mut afio.mapr , 1.kHz());
46+ // Timer::new(p.TIM2, &clocks).pwm_hz(pins, 1.kHz());
5547 // or
56- let mut pwm = p
57- . TIM2
58- . pwm_hz :: < Tim2NoRemap , _ , _ > ( pins, & mut afio. mapr , 1 . kHz ( ) , & clocks) ;
48+ let ( mut pwm_mgr, ( pwm_c1, pwm_c2, pwm_c3, ..) ) = p. TIM2 . pwm_hz ( 1 . kHz ( ) , & clocks) ;
5949
6050 // Enable clock on each of the channels
61- pwm. enable ( Channel :: C1 ) ;
62- pwm. enable ( Channel :: C2 ) ;
63- pwm. enable ( Channel :: C3 ) ;
51+ let mut c1 = pwm_c1. with ( c1) ;
52+ c1. enable ( ) ;
53+ let mut c2 = pwm_c2. with ( c2) ;
54+ c2. enable ( ) ;
55+ let mut c3 = pwm_c3. with ( c3) ;
56+ c3. enable ( ) ;
6457
6558 //// Operations affecting all defined channels on the Timer
6659
6760 // Adjust period to 0.5 seconds
68- pwm . set_period ( ms ( 500 ) . into_rate ( ) ) ;
61+ pwm_mgr . set_period ( ms ( 500 ) . into_rate ( ) ) ;
6962
7063 asm:: bkpt ( ) ;
7164
7265 // Return to the original frequency
73- pwm . set_period ( 1 . kHz ( ) ) ;
66+ pwm_mgr . set_period ( 1 . kHz ( ) ) ;
7467
7568 asm:: bkpt ( ) ;
7669
77- let max = pwm . get_max_duty ( ) ;
70+ let max = pwm_mgr . get_max_duty ( ) ;
7871
7972 //// Operations affecting single channels can be accessed through
8073 //// the Pwm object or via dereferencing to the pin.
8174
8275 // Use the Pwm object to set C3 to full strength
83- pwm . set_duty ( Channel :: C3 , max) ;
76+ c3 . set_duty ( max) ;
8477
8578 asm:: bkpt ( ) ;
8679
8780 // Use the Pwm object to set C3 to be dim
88- pwm . set_duty ( Channel :: C3 , max / 4 ) ;
81+ c3 . set_duty ( max / 4 ) ;
8982
9083 asm:: bkpt ( ) ;
9184
9285 // Use the Pwm object to set C3 to be zero
93- pwm. set_duty ( Channel :: C3 , 0 ) ;
94-
95- asm:: bkpt ( ) ;
96-
97- // Extract the PwmChannel for C3
98- let mut pwm_channel = pwm. split ( ) . 2 ;
99-
100- // Use the PwmChannel object to set C3 to be full strength
101- pwm_channel. set_duty ( max) ;
102-
103- asm:: bkpt ( ) ;
104-
105- // Use the PwmChannel object to set C3 to be dim
106- pwm_channel. set_duty ( max / 4 ) ;
107-
108- asm:: bkpt ( ) ;
109-
110- // Use the PwmChannel object to set C3 to be zero
111- pwm_channel. set_duty ( 0 ) ;
86+ c3. set_duty ( 0 ) ;
11287
11388 asm:: bkpt ( ) ;
11489
0 commit comments