aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/ppi/ppi.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-10-28 03:07:06 +0200
committerDario Nieuwenhuis <[email protected]>2021-10-28 03:36:25 +0200
commit663141b4e456bbfacaaff8decdba6840c76a136b (patch)
tree8d151a795b008ab0791a6faa5dbd36e5b83522b5 /embassy-nrf/src/ppi/ppi.rs
parentc995a97f2032d329c2955c79054b7e466b0b423b (diff)
nrf: add initial nrf5340 support
Diffstat (limited to 'embassy-nrf/src/ppi/ppi.rs')
-rw-r--r--embassy-nrf/src/ppi/ppi.rs28
1 files changed, 24 insertions, 4 deletions
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) });