|
2 | 2 | //!
|
3 | 3 | //! The pulse with modulation (PWM) module enables the generation of pulse width modulated signals on GPIO.
|
4 | 4 |
|
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 | +}; |
9 | 11 | 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}, |
19 | 14 | target_constants::{SRAM_LOWER, SRAM_UPPER},
|
20 | 15 | time::*,
|
21 | 16 | };
|
| 17 | +use core::{ |
| 18 | + cell::RefCell, |
| 19 | + ops::Deref, |
| 20 | + sync::atomic::{compiler_fence, Ordering}, |
| 21 | +}; |
22 | 22 | use embedded_dma::*;
|
23 | 23 |
|
24 | 24 | /// A safe wrapper around the raw peripheral.
|
@@ -474,16 +474,16 @@ where
|
474 | 474 |
|
475 | 475 | /// Loads a sequence buffer.
|
476 | 476 | /// 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> |
478 | 478 | where
|
479 |
| - B: ReadBuffer<Word = W>, |
| 479 | + B: ReadBuffer<Word = u16>, |
480 | 480 | {
|
481 | 481 | let (ptr, len) = unsafe { buf.read_buffer() };
|
482 | 482 | if (ptr as usize) < SRAM_LOWER || (ptr as usize) > SRAM_UPPER {
|
483 | 483 | return Err(Error::DMABufferNotInDataMemory);
|
484 | 484 | }
|
485 | 485 |
|
486 |
| - if len > (1 << 15) / core::mem::size_of::<W>() { |
| 486 | + if len > (1 << 15) / core::mem::size_of::<u16>() { |
487 | 487 | return Err(Error::BufferTooLong);
|
488 | 488 | }
|
489 | 489 |
|
@@ -637,14 +637,12 @@ where
|
637 | 637 | }
|
638 | 638 |
|
639 | 639 | /// Returns reference to `Seq0 Start` task endpoint for PPI.
|
640 |
| - #[cfg(any(feature = "52833", feature = "52840"))] |
641 | 640 | #[inline(always)]
|
642 | 641 | pub fn task_start_seq0(&self) -> &Reg<u32, _TASKS_SEQSTART> {
|
643 | 642 | &self.pwm.tasks_seqstart[0]
|
644 | 643 | }
|
645 | 644 |
|
646 | 645 | /// Returns reference to `Seq1 Started` task endpoint for PPI.
|
647 |
| - #[cfg(any(feature = "52833", feature = "52840"))] |
648 | 646 | #[inline(always)]
|
649 | 647 | pub fn task_start_seq1(&self) -> &Reg<u32, _TASKS_SEQSTART> {
|
650 | 648 | &self.pwm.tasks_seqstart[1]
|
@@ -966,30 +964,33 @@ pub enum Error {
|
966 | 964 | BufferTooLong,
|
967 | 965 | }
|
968 | 966 |
|
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 | +} |
978 | 970 |
|
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 | +} |
981 | 986 |
|
982 | 987 | mod private {
|
983 |
| - pub trait Sealed: core::ops::Deref<Target = crate::pac::pwm0::RegisterBlock> {} |
984 |
| - |
| 988 | + pub trait Sealed {} |
985 | 989 | impl Sealed for crate::pwm::PWM0 {}
|
986 |
| - |
987 |
| - #[cfg(not(any(feature = "52810")))] |
| 990 | + #[cfg(not(feature = "52810"))] |
988 | 991 | impl Sealed for crate::pwm::PWM1 {}
|
989 |
| - |
990 |
| - #[cfg(not(any(feature = "52810")))] |
| 992 | + #[cfg(not(feature = "52810"))] |
991 | 993 | impl Sealed for crate::pwm::PWM2 {}
|
992 |
| - |
993 |
| - #[cfg(not(any(feature = "52810", feature = "52832")))] |
| 994 | + #[cfg(not(feature = "52810"))] |
994 | 995 | impl Sealed for crate::pwm::PWM3 {}
|
995 | 996 | }
|
0 commit comments