Skip to content

Commit 03c0a98

Browse files
committed
Cleanup, add docs
1 parent 56d155e commit 03c0a98

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

examples/pwm-demo/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const APP: () = {
4242
btn2: Pin<Input<PullUp>>,
4343
btn3: Pin<Input<PullUp>>,
4444
btn4: Pin<Input<PullUp>>,
45-
// pwm: Pwm<PWM0>,
4645
#[init(AppStatus::Idle)]
4746
status: AppStatus,
4847
pwm: Option<PwmSeq<PWM0, SeqBuffer, SeqBuffer>>,
@@ -98,7 +97,7 @@ const APP: () = {
9897
fn idle(_: idle::Context) -> ! {
9998
rprintln!("Press a button to start a demo");
10099
loop {
101-
cortex_m::asm::nop();
100+
cortex_m::asm::wfi();
102101
}
103102
}
104103

nrf-hal-common/src/pwm.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,7 @@ where
461461
self
462462
}
463463

464-
/// Loads a sequence buffer.
465-
/// NOTE: `buf` must live until the sequence is done playing, or it might play a corrupted sequence.
466-
pub fn load_seq<B>(&self, seq: Seq, buf: B) -> Result<(), Error>
464+
fn load_seq<B>(&self, seq: Seq, buf: B) -> Result<(), Error>
467465
where
468466
B: ReadBuffer<Word = u16> + 'static,
469467
{
@@ -1094,19 +1092,28 @@ pub enum Error {
10941092

10951093
pub trait Instance: private::Sealed + Deref<Target = crate::pac::pwm0::RegisterBlock> {
10961094
const INTERRUPT: Interrupt;
1095+
1096+
/// Provides access to the associated internal duty buffer for the instance.
10971097
fn buffer() -> &'static mut Cell<[u16; 4]>;
10981098
}
10991099

1100+
// Internal static duty buffers. One per instance.
11001101
static mut BUF0: Cell<[u16; 4]> = Cell::new([0; 4]);
1102+
#[cfg(not(any(feature = "52810", feature = "52811")))]
1103+
static mut BUF1: Cell<[u16; 4]> = Cell::new([0; 4]);
1104+
#[cfg(not(any(feature = "52810", feature = "52811")))]
1105+
static mut BUF2: Cell<[u16; 4]> = Cell::new([0; 4]);
1106+
#[cfg(not(any(feature = "52810", feature = "52811", feature = "52832")))]
1107+
static mut BUF3: Cell<[u16; 4]> = Cell::new([0; 4]);
1108+
11011109
impl Instance for PWM0 {
11021110
const INTERRUPT: Interrupt = Interrupt::PWM0;
1111+
#[inline(always)]
11031112
fn buffer() -> &'static mut Cell<[u16; 4]> {
11041113
unsafe { &mut BUF0 }
11051114
}
11061115
}
11071116

1108-
#[cfg(not(any(feature = "52810", feature = "52811")))]
1109-
static mut BUF1: Cell<[u16; 4]> = Cell::new([0; 4]);
11101117
#[cfg(not(any(feature = "52810", feature = "52811")))]
11111118
impl Instance for PWM1 {
11121119
const INTERRUPT: Interrupt = Interrupt::PWM1;
@@ -1115,8 +1122,6 @@ impl Instance for PWM1 {
11151122
}
11161123
}
11171124

1118-
#[cfg(not(any(feature = "52810", feature = "52811")))]
1119-
static mut BUF2: Cell<[u16; 4]> = Cell::new([0; 4]);
11201125
#[cfg(not(any(feature = "52810", feature = "52811")))]
11211126
impl Instance for PWM2 {
11221127
const INTERRUPT: Interrupt = Interrupt::PWM2;
@@ -1125,8 +1130,6 @@ impl Instance for PWM2 {
11251130
}
11261131
}
11271132

1128-
#[cfg(not(any(feature = "52810", feature = "52811", feature = "52832")))]
1129-
static mut BUF3: Cell<[u16; 4]> = Cell::new([0; 4]);
11301133
#[cfg(not(any(feature = "52810", feature = "52811", feature = "52832")))]
11311134
impl Instance for PWM3 {
11321135
const INTERRUPT: Interrupt = Interrupt::PWM3;

0 commit comments

Comments
 (0)