Skip to content

Commit d044dad

Browse files
author
Jonathan Pallant (42 Technology)
committed
Allow PWM testing on the DWM1001C.
1 parent 037765b commit d044dad

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

examples/pwm-blinky-demo/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ features = ["rt"]
2121
path = "../../nrf9160-hal"
2222
optional = true
2323

24+
[dependencies.nrf52832-hal]
25+
features = ["rt"]
26+
path = "../../nrf52832-hal"
27+
optional = true
28+
2429
[dependencies.nrf52840-hal]
2530
features = ["rt"]
2631
path = "../../nrf52840-hal"
@@ -29,3 +34,4 @@ optional = true
2934
[features]
3035
9160 = ["nrf9160-hal"]
3136
52840 = ["nrf52840-hal"]
37+
52832 = ["nrf52832-hal"]

examples/pwm-blinky-demo/src/main.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use hal::{gpio, prelude::*, pwm, pwm::Pwm, timer, timer::Timer};
55
use nb::block;
66
#[cfg(feature = "52840")]
77
use nrf52840_hal as hal;
8+
#[cfg(feature = "52832")]
9+
use nrf52832_hal as hal;
810
#[cfg(feature = "9160")]
911
use nrf9160_hal as hal;
1012
use rtt_target::{rprintln, rtt_init_print};
@@ -27,11 +29,13 @@ fn main() -> ! {
2729
pwm.set_period(500u32.hz());
2830

2931
rprintln!("PWM Blinky demo starting");
32+
33+
let wait_time = 1_000_000u32 / pwm.get_max_duty() as u32;
3034
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+
}
3539
}
3640
}
3741

@@ -65,6 +69,22 @@ fn init_device(p: hal::pac::Peripherals) -> (Pwm<hal::pac::PWM0>, Timer<hal::pac
6569
(pwm, timer)
6670
}
6771

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+
6888
fn delay<T>(timer: &mut Timer<T>, cycles: u32)
6989
where
7090
T: timer::Instance,

0 commit comments

Comments
 (0)