aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/ppi
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-nrf/src/ppi')
-rw-r--r--embassy-nrf/src/ppi/dppi.rs22
-rw-r--r--embassy-nrf/src/ppi/mod.rs20
-rw-r--r--embassy-nrf/src/ppi/ppi.rs28
3 files changed, 47 insertions, 23 deletions
diff --git a/embassy-nrf/src/ppi/dppi.rs b/embassy-nrf/src/ppi/dppi.rs
index b3676fca4..1842590b4 100644
--- a/embassy-nrf/src/ppi/dppi.rs
+++ b/embassy-nrf/src/ppi/dppi.rs
@@ -3,11 +3,17 @@ use core::marker::PhantomData;
3use embassy::util::Unborrow; 3use embassy::util::Unborrow;
4use embassy_hal_common::unborrow; 4use embassy_hal_common::unborrow;
5 5
6use crate::pac;
7
6use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; 8use super::{Channel, ConfigurableChannel, Event, Ppi, Task};
7 9
8const DPPI_ENABLE_BIT: u32 = 0x8000_0000; 10const DPPI_ENABLE_BIT: u32 = 0x8000_0000;
9const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF; 11const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF;
10 12
13fn regs() -> &'static pac::dppic::RegisterBlock {
14 unsafe { &*pac::DPPIC::ptr() }
15}
16
11impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { 17impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> {
12 pub fn new_one_to_one(ch: impl Unborrow<Target = C> + 'd, event: Event, task: Task) -> Self { 18 pub fn new_one_to_one(ch: impl Unborrow<Target = C> + 'd, event: Event, task: Task) -> Self {
13 Ppi::new_many_to_many(ch, [event], [task]) 19 Ppi::new_many_to_many(ch, [event], [task])
@@ -58,6 +64,22 @@ impl<'d, C: ConfigurableChannel, const EVENT_COUNT: usize, const TASK_COUNT: usi
58 } 64 }
59} 65}
60 66
67impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize>
68 Ppi<'d, C, EVENT_COUNT, TASK_COUNT>
69{
70 /// Enables the channel.
71 pub fn enable(&mut self) {
72 let n = self.ch.number();
73 regs().chenset.write(|w| unsafe { w.bits(1 << n) });
74 }
75
76 /// Disables the channel.
77 pub fn disable(&mut self) {
78 let n = self.ch.number();
79 regs().chenclr.write(|w| unsafe { w.bits(1 << n) });
80 }
81}
82
61impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop 83impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop
62 for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> 84 for Ppi<'d, C, EVENT_COUNT, TASK_COUNT>
63{ 85{
diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs
index 96f867d18..aeccb154b 100644
--- a/embassy-nrf/src/ppi/mod.rs
+++ b/embassy-nrf/src/ppi/mod.rs
@@ -15,7 +15,7 @@
15//! many tasks and events, but any single task or event can only be coupled with one channel. 15//! many tasks and events, but any single task or event can only be coupled with one channel.
16//! 16//!
17 17
18use crate::{pac, peripherals}; 18use crate::peripherals;
19use core::marker::PhantomData; 19use core::marker::PhantomData;
20use core::ptr::NonNull; 20use core::ptr::NonNull;
21use embassy::util::Unborrow; 21use embassy::util::Unborrow;
@@ -35,24 +35,6 @@ pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize
35 phantom: PhantomData<&'d mut C>, 35 phantom: PhantomData<&'d mut C>,
36} 36}
37 37
38impl<'d, C: Channel + 'd, const EVENT_COUNT: usize, const TASK_COUNT: usize>
39 Ppi<'d, C, EVENT_COUNT, TASK_COUNT>
40{
41 /// Enables the channel.
42 pub fn enable(&mut self) {
43 let r = unsafe { &*pac::PPI::ptr() };
44 r.chenset
45 .write(|w| unsafe { w.bits(1 << self.ch.number()) });
46 }
47
48 /// Disables the channel.
49 pub fn disable(&mut self) {
50 let r = unsafe { &*pac::PPI::ptr() };
51 r.chenclr
52 .write(|w| unsafe { w.bits(1 << self.ch.number()) });
53 }
54}
55
56const REGISTER_DPPI_CONFIG_OFFSET: usize = 0x80 / core::mem::size_of::<u32>(); 38const REGISTER_DPPI_CONFIG_OFFSET: usize = 0x80 / core::mem::size_of::<u32>();
57 39
58/// Represents a task that a peripheral can do. 40/// Represents a task that a peripheral can do.
diff --git a/embassy-nrf/src/ppi/ppi.rs b/embassy-nrf/src/ppi/ppi.rs
index c1d9794c9..cdbe046f8 100644
--- a/embassy-nrf/src/ppi/ppi.rs
+++ b/embassy-nrf/src/ppi/ppi.rs
@@ -17,12 +17,16 @@ impl Event {
17 } 17 }
18} 18}
19 19
20fn regs() -> &'static pac::ppi::RegisterBlock {
21 unsafe { &*pac::PPI::ptr() }
22}
23
20#[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task 24#[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task
21impl<'d, C: StaticChannel> Ppi<'d, C, 0, 1> { 25impl<'d, C: StaticChannel> Ppi<'d, C, 0, 1> {
22 pub fn new_zero_to_one(ch: impl Unborrow<Target = C> + 'd, task: Task) -> Self { 26 pub fn new_zero_to_one(ch: impl Unborrow<Target = C> + 'd, task: Task) -> Self {
23 unborrow!(ch); 27 unborrow!(ch);
24 28
25 let r = unsafe { &*pac::PPI::ptr() }; 29 let r = regs();
26 let n = ch.number(); 30 let n = ch.number();
27 r.fork[n].tep.write(|w| unsafe { w.bits(task.reg_val()) }); 31 r.fork[n].tep.write(|w| unsafe { w.bits(task.reg_val()) });
28 32
@@ -37,7 +41,7 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> {
37 pub fn new_one_to_one(ch: impl Unborrow<Target = C> + 'd, event: Event, task: Task) -> Self { 41 pub fn new_one_to_one(ch: impl Unborrow<Target = C> + 'd, event: Event, task: Task) -> Self {
38 unborrow!(ch); 42 unborrow!(ch);
39 43
40 let r = unsafe { &*pac::PPI::ptr() }; 44 let r = regs();
41 let n = ch.number(); 45 let n = ch.number();
42 r.ch[n].eep.write(|w| unsafe { w.bits(event.reg_val()) }); 46 r.ch[n].eep.write(|w| unsafe { w.bits(event.reg_val()) });
43 r.ch[n].tep.write(|w| unsafe { w.bits(task.reg_val()) }); 47 r.ch[n].tep.write(|w| unsafe { w.bits(task.reg_val()) });
@@ -59,7 +63,7 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> {
59 ) -> Self { 63 ) -> Self {
60 unborrow!(ch); 64 unborrow!(ch);
61 65
62 let r = unsafe { &*pac::PPI::ptr() }; 66 let r = regs();
63 let n = ch.number(); 67 let n = ch.number();
64 r.ch[n].eep.write(|w| unsafe { w.bits(event.reg_val()) }); 68 r.ch[n].eep.write(|w| unsafe { w.bits(event.reg_val()) });
65 r.ch[n].tep.write(|w| unsafe { w.bits(task1.reg_val()) }); 69 r.ch[n].tep.write(|w| unsafe { w.bits(task1.reg_val()) });
@@ -72,13 +76,29 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> {
72 } 76 }
73} 77}
74 78
79impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize>
80 Ppi<'d, C, EVENT_COUNT, TASK_COUNT>
81{
82 /// Enables the channel.
83 pub fn enable(&mut self) {
84 let n = self.ch.number();
85 regs().chenset.write(|w| unsafe { w.bits(1 << n) });
86 }
87
88 /// Disables the channel.
89 pub fn disable(&mut self) {
90 let n = self.ch.number();
91 regs().chenclr.write(|w| unsafe { w.bits(1 << n) });
92 }
93}
94
75impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop 95impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop
76 for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> 96 for Ppi<'d, C, EVENT_COUNT, TASK_COUNT>
77{ 97{
78 fn drop(&mut self) { 98 fn drop(&mut self) {
79 self.disable(); 99 self.disable();
80 100
81 let r = unsafe { &*pac::PPI::ptr() }; 101 let r = regs();
82 let n = self.ch.number(); 102 let n = self.ch.number();
83 r.ch[n].eep.write(|w| unsafe { w.bits(0) }); 103 r.ch[n].eep.write(|w| unsafe { w.bits(0) });
84 r.ch[n].tep.write(|w| unsafe { w.bits(0) }); 104 r.ch[n].tep.write(|w| unsafe { w.bits(0) });