Skip to content

Commit 4c008ed

Browse files
committed
Enable PWM for nrf52832
1 parent ed5d87d commit 4c008ed

File tree

2 files changed

+52
-46
lines changed

2 files changed

+52
-46
lines changed

nrf-hal-common/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub mod ieee802154;
4949
pub mod lpcomp;
5050
#[cfg(not(feature = "9160"))]
5151
pub mod ppi;
52-
#[cfg(not(any(feature = "51", feature = "52832")))]
52+
#[cfg(not(feature = "51"))]
5353
pub mod pwm;
5454
#[cfg(not(any(feature = "51", feature = "9160")))]
5555
pub mod qdec;

nrf-hal-common/src/pwm.rs

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@
33
//! The pulse with modulation (PWM) module enables the generation of pulse width modulated signals on GPIO.
44
55
#[cfg(not(any(feature = "9160")))]
6-
use crate::pac::{
7-
pwm0::*, PWM0,
8-
};
6+
use crate::pac::pwm0::*;
97
#[cfg(any(feature = "9160"))]
10-
use crate::pac::{
11-
pwm0_ns::*, PWM0_NS, PWM1_NS, PWM2_NS, PWM3_NS,
12-
};
13-
#[cfg(not(any(feature = "52810", feature = "52811", feature = "9160")))]
14-
use crate::pac::{
15-
PWM1, PWM2, PWM3,
16-
};
8+
use crate::pac::pwm0_ns::*;
179
use crate::{
1810
gpio::{Output, Pin, PushPull},
1911
pac::{generic::Reg, Interrupt},
@@ -379,9 +371,12 @@ where
379371
T::buffer().set(buffer);
380372
self.one_shot();
381373
self.set_load_mode(LoadMode::Individual);
382-
self.pwm.seq0.ptr.write(|w| unsafe { w.bits(T::buffer().as_ptr() as u32) });
374+
self.pwm
375+
.seq0
376+
.ptr
377+
.write(|w| unsafe { w.bits(T::buffer().as_ptr() as u32) });
383378
self.pwm.seq0.cnt.write(|w| unsafe { w.bits(4) });
384-
self.start_seq(Seq::Seq0);
379+
self.start_seq(Seq::Seq0);
385380
}
386381

387382
/// Sets inverted duty cycle (15 bit) for a PWM channel.
@@ -392,9 +387,12 @@ where
392387
T::buffer().set(buffer);
393388
self.one_shot();
394389
self.set_load_mode(LoadMode::Individual);
395-
self.pwm.seq0.ptr.write(|w| unsafe { w.bits(T::buffer().as_ptr() as u32) });
390+
self.pwm
391+
.seq0
392+
.ptr
393+
.write(|w| unsafe { w.bits(T::buffer().as_ptr() as u32) });
396394
self.pwm.seq0.cnt.write(|w| unsafe { w.bits(4) });
397-
self.start_seq(Seq::Seq0);
395+
self.start_seq(Seq::Seq0);
398396
}
399397

400398
/// Returns the duty cycle value for a PWM channel.
@@ -470,7 +468,7 @@ where
470468
pub fn start_seq(&self, seq: Seq) {
471469
compiler_fence(Ordering::SeqCst);
472470
self.pwm.enable.write(|w| w.enable().enabled());
473-
self.pwm.tasks_seqstart[usize::from(seq)].write(|w| w.tasks_seqstart().set_bit());
471+
self.pwm.tasks_seqstart[usize::from(seq)].write(|w| unsafe { w.bits(1) });
474472
while self.pwm.events_seqstarted[usize::from(seq)].read().bits() == 0 {}
475473
self.pwm.events_seqend[0].write(|w| w);
476474
self.pwm.events_seqend[1].write(|w| w);
@@ -480,16 +478,14 @@ where
480478
/// Does not cause PWM generation to start if not running.
481479
#[inline(always)]
482480
pub fn next_step(&self) {
483-
self.pwm
484-
.tasks_nextstep
485-
.write(|w| w.tasks_nextstep().set_bit());
481+
self.pwm.tasks_nextstep.write(|w| unsafe { w.bits(1) });
486482
}
487483

488484
/// Stops PWM pulse generation on all channels at the end of current PWM period, and stops sequence playback.
489485
#[inline(always)]
490486
pub fn stop(&self) {
491487
compiler_fence(Ordering::SeqCst);
492-
self.pwm.tasks_stop.write(|w| w.tasks_stop().set_bit());
488+
self.pwm.tasks_stop.write(|w| unsafe { w.bits(1) });
493489
while self.pwm.events_stopped.read().bits() == 0 {}
494490
}
495491

@@ -1082,94 +1078,104 @@ static mut BUF2: Cell<[u16; 4]> = Cell::new([0; 4]);
10821078
static mut BUF3: Cell<[u16; 4]> = Cell::new([0; 4]);
10831079

10841080
#[cfg(not(any(feature = "9160")))]
1085-
impl Instance for PWM0 {
1081+
impl Instance for crate::pac::PWM0 {
10861082
const INTERRUPT: Interrupt = Interrupt::PWM0;
10871083
#[inline(always)]
10881084
fn buffer() -> &'static Cell<[u16; 4]> {
1089-
unsafe { &BUF0 }
1085+
unsafe { &BUF0 }
10901086
}
10911087
}
10921088

10931089
#[cfg(not(any(feature = "52810", feature = "52811", feature = "9160")))]
1094-
impl Instance for PWM1 {
1090+
impl Instance for crate::pac::PWM1 {
10951091
const INTERRUPT: Interrupt = Interrupt::PWM1;
10961092
fn buffer() -> &'static Cell<[u16; 4]> {
1097-
unsafe { &BUF1 }
1093+
unsafe { &BUF1 }
10981094
}
10991095
}
11001096

11011097
#[cfg(not(any(feature = "52810", feature = "52811", feature = "9160")))]
1102-
impl Instance for PWM2 {
1098+
impl Instance for crate::pac::PWM2 {
11031099
const INTERRUPT: Interrupt = Interrupt::PWM2;
11041100
fn buffer() -> &'static Cell<[u16; 4]> {
1105-
unsafe { &BUF2 }
1101+
unsafe { &BUF2 }
11061102
}
11071103
}
11081104

1109-
#[cfg(not(any(feature = "52810", feature = "52811", feature = "52832", feature = "9160")))]
1110-
impl Instance for PWM3 {
1105+
#[cfg(not(any(
1106+
feature = "52810",
1107+
feature = "52811",
1108+
feature = "52832",
1109+
feature = "9160"
1110+
)))]
1111+
impl Instance for crate::pac::PWM3 {
11111112
const INTERRUPT: Interrupt = Interrupt::PWM3;
11121113
fn buffer() -> &'static Cell<[u16; 4]> {
1113-
unsafe { &BUF3 }
1114+
unsafe { &BUF3 }
11141115
}
11151116
}
11161117

11171118
#[cfg(any(feature = "9160"))]
1118-
impl Instance for PWM0_NS {
1119+
impl Instance for crate::pac::PWM0_NS {
11191120
const INTERRUPT: Interrupt = Interrupt::PWM0;
11201121
#[inline(always)]
11211122
fn buffer() -> &'static Cell<[u16; 4]> {
1122-
unsafe { &BUF0 }
1123+
unsafe { &BUF0 }
11231124
}
11241125
}
11251126

11261127
#[cfg(any(feature = "9160"))]
1127-
impl Instance for PWM1_NS {
1128+
impl Instance for crate::pac::PWM1_NS {
11281129
const INTERRUPT: Interrupt = Interrupt::PWM1;
11291130
fn buffer() -> &'static Cell<[u16; 4]> {
1130-
unsafe { &BUF1 }
1131+
unsafe { &BUF1 }
11311132
}
11321133
}
11331134

11341135
#[cfg(any(feature = "9160"))]
1135-
impl Instance for PWM2_NS {
1136+
impl Instance for crate::pac::PWM2_NS {
11361137
const INTERRUPT: Interrupt = Interrupt::PWM2;
11371138
fn buffer() -> &'static Cell<[u16; 4]> {
1138-
unsafe { &BUF2 }
1139+
unsafe { &BUF2 }
11391140
}
11401141
}
11411142

11421143
#[cfg(any(feature = "9160"))]
1143-
impl Instance for PWM3_NS {
1144+
impl Instance for crate::pac::PWM3_NS {
11441145
const INTERRUPT: Interrupt = Interrupt::PWM3;
11451146
fn buffer() -> &'static Cell<[u16; 4]> {
1146-
unsafe { &BUF3 }
1147+
unsafe { &BUF3 }
11471148
}
11481149
}
11491150
mod sealed {
11501151
pub trait Sealed {}
11511152

11521153
#[cfg(not(any(feature = "9160")))]
1153-
impl Sealed for crate::pwm::PWM0 {}
1154+
impl Sealed for crate::pac::PWM0 {}
11541155

11551156
#[cfg(not(any(feature = "52810", feature = "52811", feature = "9160")))]
1156-
impl Sealed for crate::pwm::PWM1 {}
1157+
impl Sealed for crate::pac::PWM1 {}
11571158

11581159
#[cfg(not(any(feature = "52810", feature = "52811", feature = "9160")))]
1159-
impl Sealed for crate::pwm::PWM2 {}
1160+
impl Sealed for crate::pac::PWM2 {}
11601161

1161-
#[cfg(not(any(feature = "52810", feature = "52811", feature = "52832", feature = "9160")))]
1162-
impl Sealed for crate::pwm::PWM3 {}
1162+
#[cfg(not(any(
1163+
feature = "52810",
1164+
feature = "52811",
1165+
feature = "52832",
1166+
feature = "9160"
1167+
)))]
1168+
impl Sealed for crate::pac::PWM3 {}
11631169

11641170
#[cfg(any(feature = "9160"))]
1165-
impl Sealed for crate::pwm::PWM0_NS {}
1171+
impl Sealed for crate::pac::PWM0_NS {}
11661172

11671173
#[cfg(any(feature = "9160"))]
1168-
impl Sealed for crate::pwm::PWM1_NS {}
1174+
impl Sealed for crate::pac::PWM1_NS {}
11691175

11701176
#[cfg(any(feature = "9160"))]
1171-
impl Sealed for crate::pwm::PWM2_NS {}
1177+
impl Sealed for crate::pac::PWM2_NS {}
11721178

11731179
#[cfg(any(feature = "9160"))]
1174-
impl Sealed for crate::pwm::PWM3_NS {}
1180+
impl Sealed for crate::pac::PWM3_NS {}
11751181
}

0 commit comments

Comments
 (0)