@@ -5,6 +5,8 @@ use hal::{gpio, prelude::*, pwm, pwm::Pwm, timer, timer::Timer};
5
5
use nb:: block;
6
6
#[ cfg( feature = "52840" ) ]
7
7
use nrf52840_hal as hal;
8
+ #[ cfg( feature = "52832" ) ]
9
+ use nrf52832_hal as hal;
8
10
#[ cfg( feature = "9160" ) ]
9
11
use nrf9160_hal as hal;
10
12
use rtt_target:: { rprintln, rtt_init_print} ;
@@ -27,11 +29,13 @@ fn main() -> ! {
27
29
pwm. set_period ( 500u32 . hz ( ) ) ;
28
30
29
31
rprintln ! ( "PWM Blinky demo starting" ) ;
32
+
33
+ let wait_time = 1_000_000u32 / pwm. get_max_duty ( ) as u32 ;
30
34
loop {
31
- pwm . set_duty_on_common ( pwm. get_max_duty ( ) ) ;
32
- delay ( & mut timer , 250_000 ) ; // 250ms
33
- pwm . set_duty_on_common ( 0 ) ;
34
- delay ( & mut timer , 1_000_000 ) ; // 1s
35
+ for duty in 0 .. pwm. get_max_duty ( ) {
36
+ pwm . set_duty_on_common ( duty ) ;
37
+ delay ( & mut timer , wait_time ) ;
38
+ }
35
39
}
36
40
}
37
41
@@ -65,6 +69,22 @@ fn init_device(p: hal::pac::Peripherals) -> (Pwm<hal::pac::PWM0>, Timer<hal::pac
65
69
( pwm, timer)
66
70
}
67
71
72
+ #[ cfg( feature = "52832" ) ]
73
+ fn init_device ( p : hal:: pac:: Peripherals ) -> ( Pwm < hal:: pac:: PWM0 > , Timer < hal:: pac:: TIMER0 > ) {
74
+ let p0 = gpio:: p0:: Parts :: new ( p. P0 ) ;
75
+
76
+ let pwm = Pwm :: new ( p. PWM0 ) ;
77
+ pwm. set_output_pin (
78
+ pwm:: Channel :: C0 ,
79
+ & p0. p0_30 . into_push_pull_output ( gpio:: Level :: High ) . degrade ( ) ,
80
+ ) ;
81
+
82
+ let timer = Timer :: new ( p. TIMER0 ) ;
83
+
84
+ ( pwm, timer)
85
+ }
86
+
87
+
68
88
fn delay < T > ( timer : & mut Timer < T > , cycles : u32 )
69
89
where
70
90
T : timer:: Instance ,
0 commit comments