Skip to content

Commit 4a87d05

Browse files
committed
Add support for 52810, add Interrupt const to Instance
1 parent 90ec787 commit 4a87d05

File tree

2 files changed

+39
-38
lines changed

2 files changed

+39
-38
lines changed

nrf-hal-common/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub mod i2s;
4444
pub mod lpcomp;
4545
#[cfg(not(feature = "9160"))]
4646
pub mod ppi;
47-
#[cfg(any(feature = "52833", feature = "52840"))]
47+
#[cfg(not(any(feature = "51", feature = "52832", feature = "9160")))]
4848
pub mod pwm;
4949
#[cfg(not(any(feature = "51", feature = "9160")))]
5050
pub mod qdec;

nrf-hal-common/src/pwm.rs

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
//!
33
//! The pulse with modulation (PWM) module enables the generation of pulse width modulated signals on GPIO.
44
5-
use core::cell::RefCell;
6-
use core::sync::atomic::{compiler_fence, Ordering};
7-
8-
#[cfg(any(feature = "52833", feature = "52840"))]
5+
#[cfg(not(feature = "52810"))]
6+
use crate::{
7+
gpio::Port,
8+
pac::PWM3,
9+
pac::{PWM1, PWM2},
10+
};
911
use crate::{
10-
gpio::{Output, Pin, Port, PushPull},
11-
pac::{
12-
generic::Reg,
13-
pwm0::{
14-
_EVENTS_LOOPSDONE, _EVENTS_PWMPERIODEND, _EVENTS_SEQEND, _EVENTS_SEQSTARTED,
15-
_EVENTS_STOPPED, _TASKS_NEXTSTEP, _TASKS_SEQSTART, _TASKS_STOP,
16-
},
17-
PWM0, PWM1, PWM2, PWM3,
18-
},
12+
gpio::{Output, Pin, PushPull},
13+
pac::{generic::Reg, pwm0::*, Interrupt, PWM0},
1914
target_constants::{SRAM_LOWER, SRAM_UPPER},
2015
time::*,
2116
};
17+
use core::{
18+
cell::RefCell,
19+
ops::Deref,
20+
sync::atomic::{compiler_fence, Ordering},
21+
};
2222
use embedded_dma::*;
2323

2424
/// A safe wrapper around the raw peripheral.
@@ -474,16 +474,16 @@ where
474474

475475
/// Loads a sequence buffer.
476476
/// NOTE: `buf` must live until the sequence is done playing, or it might play a corrupted sequence.
477-
pub fn load_seq<W, B>(&self, seq: Seq, buf: B) -> Result<(), Error>
477+
pub fn load_seq<B>(&self, seq: Seq, buf: B) -> Result<(), Error>
478478
where
479-
B: ReadBuffer<Word = W>,
479+
B: ReadBuffer<Word = u16>,
480480
{
481481
let (ptr, len) = unsafe { buf.read_buffer() };
482482
if (ptr as usize) < SRAM_LOWER || (ptr as usize) > SRAM_UPPER {
483483
return Err(Error::DMABufferNotInDataMemory);
484484
}
485485

486-
if len > (1 << 15) / core::mem::size_of::<W>() {
486+
if len > (1 << 15) / core::mem::size_of::<u16>() {
487487
return Err(Error::BufferTooLong);
488488
}
489489

@@ -637,14 +637,12 @@ where
637637
}
638638

639639
/// Returns reference to `Seq0 Start` task endpoint for PPI.
640-
#[cfg(any(feature = "52833", feature = "52840"))]
641640
#[inline(always)]
642641
pub fn task_start_seq0(&self) -> &Reg<u32, _TASKS_SEQSTART> {
643642
&self.pwm.tasks_seqstart[0]
644643
}
645644

646645
/// Returns reference to `Seq1 Started` task endpoint for PPI.
647-
#[cfg(any(feature = "52833", feature = "52840"))]
648646
#[inline(always)]
649647
pub fn task_start_seq1(&self) -> &Reg<u32, _TASKS_SEQSTART> {
650648
&self.pwm.tasks_seqstart[1]
@@ -966,30 +964,33 @@ pub enum Error {
966964
BufferTooLong,
967965
}
968966

969-
pub trait Instance: private::Sealed {}
970-
971-
impl Instance for PWM0 {}
972-
973-
#[cfg(not(any(feature = "52810")))]
974-
impl Instance for PWM1 {}
975-
976-
#[cfg(not(any(feature = "52810")))]
977-
impl Instance for PWM2 {}
967+
pub trait Instance: private::Sealed + Deref<Target = crate::pac::pwm0::RegisterBlock> {
968+
const INTERRUPT: Interrupt;
969+
}
978970

979-
#[cfg(not(any(feature = "52810", feature = "52832")))]
980-
impl Instance for PWM3 {}
971+
impl Instance for PWM0 {
972+
const INTERRUPT: Interrupt = Interrupt::PWM0;
973+
}
974+
#[cfg(not(feature = "52810"))]
975+
impl Instance for PWM1 {
976+
const INTERRUPT: Interrupt = Interrupt::PWM1;
977+
}
978+
#[cfg(not(feature = "52810"))]
979+
impl Instance for PWM2 {
980+
const INTERRUPT: Interrupt = Interrupt::PWM2;
981+
}
982+
#[cfg(not(feature = "52810"))]
983+
impl Instance for PWM3 {
984+
const INTERRUPT: Interrupt = Interrupt::PWM3;
985+
}
981986

982987
mod private {
983-
pub trait Sealed: core::ops::Deref<Target = crate::pac::pwm0::RegisterBlock> {}
984-
988+
pub trait Sealed {}
985989
impl Sealed for crate::pwm::PWM0 {}
986-
987-
#[cfg(not(any(feature = "52810")))]
990+
#[cfg(not(feature = "52810"))]
988991
impl Sealed for crate::pwm::PWM1 {}
989-
990-
#[cfg(not(any(feature = "52810")))]
992+
#[cfg(not(feature = "52810"))]
991993
impl Sealed for crate::pwm::PWM2 {}
992-
993-
#[cfg(not(any(feature = "52810", feature = "52832")))]
994+
#[cfg(not(feature = "52810"))]
994995
impl Sealed for crate::pwm::PWM3 {}
995996
}

0 commit comments

Comments
 (0)