diff options
| author | Jacob Rosenthal <[email protected]> | 2021-11-13 15:03:10 -0700 |
|---|---|---|
| committer | Jacob Rosenthal <[email protected]> | 2021-11-13 16:24:41 -0700 |
| commit | 2bcacd4f16276fccb88c7dc3b5e541581e60039b (patch) | |
| tree | 4d5bc2384e3f8d5bda16acc0957e94d6cc43cf7b /embassy-nrf/src | |
| parent | 0f322c1d4ef341c3468ff291fca740bcdae3fa48 (diff) | |
nrf: sequencepwm add events
Diffstat (limited to 'embassy-nrf/src')
| -rw-r--r-- | embassy-nrf/src/pwm.rs | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index 90cdf69c6..87a2d5b65 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs | |||
| @@ -9,6 +9,7 @@ use crate::gpio::sealed::Pin as _; | |||
| 9 | use crate::gpio::{AnyPin, OptionalPin as GpioOptionalPin}; | 9 | use crate::gpio::{AnyPin, OptionalPin as GpioOptionalPin}; |
| 10 | use crate::interrupt::Interrupt; | 10 | use crate::interrupt::Interrupt; |
| 11 | use crate::pac; | 11 | use crate::pac; |
| 12 | use crate::ppi::{Event, Task}; | ||
| 12 | use crate::util::slice_in_ram_or; | 13 | use crate::util::slice_in_ram_or; |
| 13 | 14 | ||
| 14 | /// SimplePwm is the traditional pwm interface you're probably used to, allowing | 15 | /// SimplePwm is the traditional pwm interface you're probably used to, allowing |
| @@ -101,6 +102,13 @@ impl<'d, T: Instance> SequencePwm<'d, T> { | |||
| 101 | // Disable all interrupts | 102 | // Disable all interrupts |
| 102 | r.intenclr.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); | 103 | r.intenclr.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); |
| 103 | r.shorts.reset(); | 104 | r.shorts.reset(); |
| 105 | r.events_stopped.reset(); | ||
| 106 | r.events_loopsdone.reset(); | ||
| 107 | r.events_seqend[0].reset(); | ||
| 108 | r.events_seqend[1].reset(); | ||
| 109 | r.events_pwmperiodend.reset(); | ||
| 110 | r.events_seqstarted[0].reset(); | ||
| 111 | r.events_seqstarted[1].reset(); | ||
| 104 | 112 | ||
| 105 | r.seq0 | 113 | r.seq0 |
| 106 | .ptr | 114 | .ptr |
| @@ -200,6 +208,106 @@ impl<'d, T: Instance> SequencePwm<'d, T> { | |||
| 200 | Ok(()) | 208 | Ok(()) |
| 201 | } | 209 | } |
| 202 | 210 | ||
| 211 | /// Returns reference to `Stopped` event endpoint for PPI. | ||
| 212 | #[inline(always)] | ||
| 213 | pub fn event_stopped(&self) -> Event { | ||
| 214 | let r = T::regs(); | ||
| 215 | |||
| 216 | Event::from_reg(&r.events_stopped) | ||
| 217 | } | ||
| 218 | |||
| 219 | /// Returns reference to `LoopsDone` event endpoint for PPI. | ||
| 220 | #[inline(always)] | ||
| 221 | pub fn event_loops_done(&self) -> Event { | ||
| 222 | let r = T::regs(); | ||
| 223 | |||
| 224 | Event::from_reg(&r.events_loopsdone) | ||
| 225 | } | ||
| 226 | |||
| 227 | /// Returns reference to `PwmPeriodEnd` event endpoint for PPI. | ||
| 228 | #[inline(always)] | ||
| 229 | pub fn event_pwm_period_end(&self) -> Event { | ||
| 230 | let r = T::regs(); | ||
| 231 | |||
| 232 | Event::from_reg(&r.events_pwmperiodend) | ||
| 233 | } | ||
| 234 | |||
| 235 | /// Returns reference to `Seq0 End` event endpoint for PPI. | ||
| 236 | #[inline(always)] | ||
| 237 | pub fn event_seq_end(&self) -> Event { | ||
| 238 | let r = T::regs(); | ||
| 239 | |||
| 240 | Event::from_reg(&r.events_seqend[0]) | ||
| 241 | } | ||
| 242 | |||
| 243 | /// Returns reference to `Seq1 End` event endpoint for PPI. | ||
| 244 | #[inline(always)] | ||
| 245 | pub fn event_seq1_end(&self) -> Event { | ||
| 246 | let r = T::regs(); | ||
| 247 | |||
| 248 | Event::from_reg(&r.events_seqend[1]) | ||
| 249 | } | ||
| 250 | |||
| 251 | /// Returns reference to `Seq0 Started` event endpoint for PPI. | ||
| 252 | #[inline(always)] | ||
| 253 | pub fn event_seq0_started(&self) -> Event { | ||
| 254 | let r = T::regs(); | ||
| 255 | |||
| 256 | Event::from_reg(&r.events_seqstarted[0]) | ||
| 257 | } | ||
| 258 | |||
| 259 | /// Returns reference to `Seq1 Started` event endpoint for PPI. | ||
| 260 | #[inline(always)] | ||
| 261 | pub fn event_seq1_started(&self) -> Event { | ||
| 262 | let r = T::regs(); | ||
| 263 | |||
| 264 | Event::from_reg(&r.events_seqstarted[1]) | ||
| 265 | } | ||
| 266 | |||
| 267 | /// Returns reference to `Seq0 Start` task endpoint for PPI. | ||
| 268 | /// # Safety | ||
| 269 | /// | ||
| 270 | /// Interacting with the sequence while it runs puts it in an unknown state | ||
| 271 | #[inline(always)] | ||
| 272 | pub unsafe fn task_start_seq0(&self) -> Task { | ||
| 273 | let r = T::regs(); | ||
| 274 | |||
| 275 | Task::from_reg(&r.tasks_seqstart[0]) | ||
| 276 | } | ||
| 277 | |||
| 278 | /// Returns reference to `Seq1 Started` task endpoint for PPI. | ||
| 279 | /// # Safety | ||
| 280 | /// | ||
| 281 | /// Interacting with the sequence while it runs puts it in an unknown state | ||
| 282 | #[inline(always)] | ||
| 283 | pub unsafe fn task_start_seq1(&self) -> Task { | ||
| 284 | let r = T::regs(); | ||
| 285 | |||
| 286 | Task::from_reg(&r.tasks_seqstart[1]) | ||
| 287 | } | ||
| 288 | |||
| 289 | /// Returns reference to `NextStep` task endpoint for PPI. | ||
| 290 | /// # Safety | ||
| 291 | /// | ||
| 292 | /// Interacting with the sequence while it runs puts it in an unknown state | ||
| 293 | #[inline(always)] | ||
| 294 | pub unsafe fn task_next_step(&self) -> Task { | ||
| 295 | let r = T::regs(); | ||
| 296 | |||
| 297 | Task::from_reg(&r.tasks_nextstep) | ||
| 298 | } | ||
| 299 | |||
| 300 | /// Returns reference to `Stop` task endpoint for PPI. | ||
| 301 | /// # Safety | ||
| 302 | /// | ||
| 303 | /// Interacting with the sequence while it runs puts it in an unknown state | ||
| 304 | #[inline(always)] | ||
| 305 | pub unsafe fn task_stop(&self) -> Task { | ||
| 306 | let r = T::regs(); | ||
| 307 | |||
| 308 | Task::from_reg(&r.tasks_stop) | ||
| 309 | } | ||
| 310 | |||
| 203 | /// Stop playback. | 311 | /// Stop playback. |
| 204 | #[inline(always)] | 312 | #[inline(always)] |
| 205 | pub fn stop(&self) { | 313 | pub fn stop(&self) { |
