diff options
| author | Dion Dokter <[email protected]> | 2021-10-19 10:13:08 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-10-26 14:47:31 +0200 |
| commit | a6c84cb91552fc0442a28126d3fae60031aa6622 (patch) | |
| tree | 260555ec0c58eb5e2053f4031889b4260bb9ebea /embassy-nrf/src/ppi/ppi.rs | |
| parent | 531dfcffb3c203dff15dcb53fe25577c121c7784 (diff) | |
- Interconnect is now PPI again
- Scary pointer math is now contained in the tasks and events
- ppi now sets the tasks and events immediately and the struct is now zero-sized
- StaticToOne is renamed to ZeroToOne
- Used DPPI tasks and events now panic when enabled twice
Diffstat (limited to 'embassy-nrf/src/ppi/ppi.rs')
| -rw-r--r-- | embassy-nrf/src/ppi/ppi.rs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/embassy-nrf/src/ppi/ppi.rs b/embassy-nrf/src/ppi/ppi.rs new file mode 100644 index 000000000..67d2086c3 --- /dev/null +++ b/embassy-nrf/src/ppi/ppi.rs | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | use super::{Channel, Event, Ppi, Task}; | ||
| 2 | use crate::pac; | ||
| 3 | |||
| 4 | impl<'d, C: Channel + 'd, const EVENT_COUNT: usize, const TASK_COUNT: usize> | ||
| 5 | Ppi<'d, C, EVENT_COUNT, TASK_COUNT> | ||
| 6 | { | ||
| 7 | fn set_main_task(task: Option<&Task>, channel: usize) { | ||
| 8 | let r = unsafe { &*pac::PPI::ptr() }; | ||
| 9 | if let Some(task) = task { | ||
| 10 | r.ch[channel] | ||
| 11 | .tep | ||
| 12 | .write(|w| unsafe { w.bits(task.0.as_ptr() as u32) }) | ||
| 13 | } else { | ||
| 14 | r.ch[channel].tep.write(|w| unsafe { w.bits(0) }) | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | fn set_fork_task(task: Option<&Task>, channel: usize) { | ||
| 19 | let r = unsafe { &*pac::PPI::ptr() }; | ||
| 20 | if let Some(task) = task { | ||
| 21 | r.fork[channel] | ||
| 22 | .tep | ||
| 23 | .write(|w| unsafe { w.bits(task.0.as_ptr() as u32) }) | ||
| 24 | } else { | ||
| 25 | r.fork[channel].tep.write(|w| unsafe { w.bits(0) }) | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | fn set_event(event: Option<&Event>, channel: usize) { | ||
| 30 | let r = unsafe { &*pac::PPI::ptr() }; | ||
| 31 | if let Some(event) = event { | ||
| 32 | r.ch[channel] | ||
| 33 | .eep | ||
| 34 | .write(|w| unsafe { w.bits(event.0.as_ptr() as u32) }) | ||
| 35 | } else { | ||
| 36 | r.ch[channel].eep.write(|w| unsafe { w.bits(0) }) | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | /// Enables all tasks and events | ||
| 41 | pub(super) fn enable_all(tasks: &[Task], events: &[Event], channel: &C) { | ||
| 42 | // One configurable task, no fork | ||
| 43 | if channel.is_task_configurable() && TASK_COUNT == 1 { | ||
| 44 | Self::set_main_task(Some(&tasks[0]), channel.number()); | ||
| 45 | } | ||
| 46 | |||
| 47 | // One configurable task, as fork | ||
| 48 | if !channel.is_task_configurable() && TASK_COUNT == 1 { | ||
| 49 | Self::set_fork_task(Some(&tasks[0]), channel.number()); | ||
| 50 | } | ||
| 51 | |||
| 52 | // Two configurable tasks (main + fork) | ||
| 53 | if TASK_COUNT == 2 { | ||
| 54 | Self::set_main_task(Some(&tasks[0]), channel.number()); | ||
| 55 | Self::set_fork_task(Some(&tasks[1]), channel.number()); | ||
| 56 | } | ||
| 57 | |||
| 58 | if EVENT_COUNT == 1 { | ||
| 59 | Self::set_event(Some(&events[0]), channel.number()); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | /// Disable all tasks and events | ||
| 64 | pub(super) fn disable_all(&self) { | ||
| 65 | if self.ch.is_task_configurable() { | ||
| 66 | Self::set_main_task(None, self.ch.number()); | ||
| 67 | } | ||
| 68 | |||
| 69 | if TASK_COUNT == 1 && !self.ch.is_task_configurable() || TASK_COUNT == 2 { | ||
| 70 | Self::set_fork_task(None, self.ch.number()); | ||
| 71 | } | ||
| 72 | |||
| 73 | if EVENT_COUNT == 1 { | ||
| 74 | Self::set_event(None, self.ch.number()); | ||
| 75 | } | ||
| 76 | } | ||
| 77 | } | ||
