@@ -9,103 +9,78 @@ 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 ( ) -> ! {
2116 let p = pac:: Peripherals :: take ( ) . unwrap ( ) ;
2217
2318 let mut rcc = p. RCC . constrain ( ) ;
2419
25- let mut afio = p. AFIO . constrain ( & mut rcc) ;
26-
27- let mut gpioa = p. GPIOA . split ( & mut rcc) ;
20+ let gpioa = p. GPIOA . split ( & mut rcc) ;
2821 // let mut gpiob = p.GPIOB.split(&mut rcc);
2922
3023 // TIM2
31- let c1 = gpioa. pa0 . into_alternate_push_pull ( & mut gpioa . crl ) ;
32- let c2 = gpioa. pa1 . into_alternate_push_pull ( & mut gpioa . crl ) ;
33- let c3 = gpioa. pa2 . into_alternate_push_pull ( & mut gpioa . crl ) ;
24+ let c1 = gpioa. pa0 ;
25+ let c2 = gpioa. pa1 ;
26+ let c3 = gpioa. pa2 ;
3427 // If you don't want to use all channels, just leave some out
35- // let c4 = gpioa.pa3.into_alternate_push_pull(&mut gpioa.crl);
36- let pins = ( c1, c2, c3) ;
28+ // let c4 = gpioa.pa3;
3729
3830 // TIM3
39- // let c1 = gpioa.pa6.into_alternate_push_pull(&mut gpioa.crl) ;
40- // let c2 = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl) ;
41- // let c3 = gpiob.pb0.into_alternate_push_pull(&mut gpiob.crl) ;
42- // let c4 = gpiob.pb1.into_alternate_push_pull(&mut gpiob.crl) ;
31+ // let c1 = gpioa.pa6;
32+ // let c2 = gpioa.pa7;
33+ // let c3 = gpiob.pb0;
34+ // let c4 = gpiob.pb1;
4335
4436 // TIM4 (Only available with the "medium" density feature)
45- // let c1 = gpiob.pb6.into_alternate_push_pull(&mut gpiob.crl) ;
46- // let c2 = gpiob.pb7.into_alternate_push_pull(&mut gpiob.crl) ;
47- // let c3 = gpiob.pb8.into_alternate_push_pull(&mut gpiob.crh) ;
48- // let c4 = gpiob.pb9.into_alternate_push_pull(&mut gpiob.crh) ;
37+ // let c1 = gpiob.pb6;
38+ // let c2 = gpiob.pb7;
39+ // let c3 = gpiob.pb8;
40+ // let c4 = gpiob.pb9;
4941
5042 //let mut pwm =
51- // Timer::new(p.TIM2, &mut rcc).pwm_hz::<Tim2NoRemap, _, _> (pins, &mut afio.mapr , 1.kHz());
43+ // Timer::new(p.TIM2, &mut rcc).pwm_hz(pins, 1.kHz());
5244 // or
53- let mut pwm = p
54- . TIM2
55- . pwm_hz :: < Tim2NoRemap , _ , _ > ( pins, & mut afio. mapr , 1 . kHz ( ) , & mut rcc) ;
45+ let ( mut pwm_mgr, ( pwm_c1, pwm_c2, pwm_c3, ..) ) = p. TIM2 . pwm_hz ( 1 . kHz ( ) , & mut rcc) ;
5646
5747 // Enable clock on each of the channels
58- pwm. enable ( Channel :: C1 ) ;
59- pwm. enable ( Channel :: C2 ) ;
60- pwm. enable ( Channel :: C3 ) ;
48+ let mut c1 = pwm_c1. with ( c1) ;
49+ c1. enable ( ) ;
50+ let mut c2 = pwm_c2. with ( c2) ;
51+ c2. enable ( ) ;
52+ let mut c3 = pwm_c3. with ( c3) ;
53+ c3. enable ( ) ;
6154
6255 //// Operations affecting all defined channels on the Timer
6356
6457 // Adjust period to 0.5 seconds
65- pwm . set_period ( ms ( 500 ) . into_rate ( ) ) ;
58+ pwm_mgr . set_period ( ms ( 500 ) . into_rate ( ) ) ;
6659
6760 asm:: bkpt ( ) ;
6861
6962 // Return to the original frequency
70- pwm . set_period ( 1 . kHz ( ) ) ;
63+ pwm_mgr . set_period ( 1 . kHz ( ) ) ;
7164
7265 asm:: bkpt ( ) ;
7366
74- let max = pwm . get_max_duty ( ) ;
67+ let max = pwm_mgr . get_max_duty ( ) ;
7568
7669 //// Operations affecting single channels can be accessed through
7770 //// the Pwm object or via dereferencing to the pin.
7871
7972 // Use the Pwm object to set C3 to full strength
80- pwm . set_duty ( Channel :: C3 , max) ;
73+ c3 . set_duty ( max) ;
8174
8275 asm:: bkpt ( ) ;
8376
8477 // Use the Pwm object to set C3 to be dim
85- pwm . set_duty ( Channel :: C3 , max / 4 ) ;
78+ c3 . set_duty ( max / 4 ) ;
8679
8780 asm:: bkpt ( ) ;
8881
8982 // Use the Pwm object to set C3 to be zero
90- pwm. set_duty ( Channel :: C3 , 0 ) ;
91-
92- asm:: bkpt ( ) ;
93-
94- // Extract the PwmChannel for C3
95- let mut pwm_channel = pwm. split ( ) . 2 ;
96-
97- // Use the PwmChannel object to set C3 to be full strength
98- pwm_channel. set_duty ( max) ;
99-
100- asm:: bkpt ( ) ;
101-
102- // Use the PwmChannel object to set C3 to be dim
103- pwm_channel. set_duty ( max / 4 ) ;
104-
105- asm:: bkpt ( ) ;
106-
107- // Use the PwmChannel object to set C3 to be zero
108- pwm_channel. set_duty ( 0 ) ;
83+ c3. set_duty ( 0 ) ;
10984
11085 asm:: bkpt ( ) ;
11186
0 commit comments