diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-03-26 16:01:37 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2025-03-27 15:18:06 +0100 |
| commit | d41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch) | |
| tree | 678b6fc732216e529dc38e6f65b72a309917ac32 /embassy-nrf/src | |
| parent | 9edf5b7f049f95742b60b041e4443967d8a6b708 (diff) | |
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-nrf/src')
29 files changed, 509 insertions, 696 deletions
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index c3fcfd06e..f939be004 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs | |||
| @@ -16,7 +16,7 @@ use core::sync::atomic::{compiler_fence, AtomicBool, AtomicU8, AtomicUsize, Orde | |||
| 16 | use core::task::Poll; | 16 | use core::task::Poll; |
| 17 | 17 | ||
| 18 | use embassy_hal_internal::atomic_ring_buffer::RingBuffer; | 18 | use embassy_hal_internal::atomic_ring_buffer::RingBuffer; |
| 19 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 19 | use embassy_hal_internal::Peri; |
| 20 | use pac::uarte::vals; | 20 | use pac::uarte::vals; |
| 21 | // Re-export SVD variants to allow user to directly set values | 21 | // Re-export SVD variants to allow user to directly set values |
| 22 | pub use pac::uarte::vals::{Baudrate, ConfigParity as Parity}; | 22 | pub use pac::uarte::vals::{Baudrate, ConfigParity as Parity}; |
| @@ -28,7 +28,7 @@ use crate::ppi::{ | |||
| 28 | }; | 28 | }; |
| 29 | use crate::timer::{Instance as TimerInstance, Timer}; | 29 | use crate::timer::{Instance as TimerInstance, Timer}; |
| 30 | use crate::uarte::{configure, configure_rx_pins, configure_tx_pins, drop_tx_rx, Config, Instance as UarteInstance}; | 30 | use crate::uarte::{configure, configure_rx_pins, configure_tx_pins, drop_tx_rx, Config, Instance as UarteInstance}; |
| 31 | use crate::{interrupt, pac, Peripheral, EASY_DMA_SIZE}; | 31 | use crate::{interrupt, pac, EASY_DMA_SIZE}; |
| 32 | 32 | ||
| 33 | pub(crate) struct State { | 33 | pub(crate) struct State { |
| 34 | tx_buf: RingBuffer, | 34 | tx_buf: RingBuffer, |
| @@ -222,27 +222,26 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { | |||
| 222 | /// Panics if `rx_buffer.len()` is odd. | 222 | /// Panics if `rx_buffer.len()` is odd. |
| 223 | #[allow(clippy::too_many_arguments)] | 223 | #[allow(clippy::too_many_arguments)] |
| 224 | pub fn new( | 224 | pub fn new( |
| 225 | uarte: impl Peripheral<P = U> + 'd, | 225 | uarte: Peri<'d, U>, |
| 226 | timer: impl Peripheral<P = T> + 'd, | 226 | timer: Peri<'d, T>, |
| 227 | ppi_ch1: impl Peripheral<P = impl ConfigurableChannel> + 'd, | 227 | ppi_ch1: Peri<'d, impl ConfigurableChannel>, |
| 228 | ppi_ch2: impl Peripheral<P = impl ConfigurableChannel> + 'd, | 228 | ppi_ch2: Peri<'d, impl ConfigurableChannel>, |
| 229 | ppi_group: impl Peripheral<P = impl Group> + 'd, | 229 | ppi_group: Peri<'d, impl Group>, |
| 230 | _irq: impl interrupt::typelevel::Binding<U::Interrupt, InterruptHandler<U>> + 'd, | 230 | _irq: impl interrupt::typelevel::Binding<U::Interrupt, InterruptHandler<U>> + 'd, |
| 231 | rxd: impl Peripheral<P = impl GpioPin> + 'd, | 231 | rxd: Peri<'d, impl GpioPin>, |
| 232 | txd: impl Peripheral<P = impl GpioPin> + 'd, | 232 | txd: Peri<'d, impl GpioPin>, |
| 233 | config: Config, | 233 | config: Config, |
| 234 | rx_buffer: &'d mut [u8], | 234 | rx_buffer: &'d mut [u8], |
| 235 | tx_buffer: &'d mut [u8], | 235 | tx_buffer: &'d mut [u8], |
| 236 | ) -> Self { | 236 | ) -> Self { |
| 237 | into_ref!(uarte, timer, rxd, txd, ppi_ch1, ppi_ch2, ppi_group); | ||
| 238 | Self::new_inner( | 237 | Self::new_inner( |
| 239 | uarte, | 238 | uarte, |
| 240 | timer, | 239 | timer, |
| 241 | ppi_ch1.map_into(), | 240 | ppi_ch1.into(), |
| 242 | ppi_ch2.map_into(), | 241 | ppi_ch2.into(), |
| 243 | ppi_group.map_into(), | 242 | ppi_group.into(), |
| 244 | rxd.map_into(), | 243 | rxd.into(), |
| 245 | txd.map_into(), | 244 | txd.into(), |
| 246 | None, | 245 | None, |
| 247 | None, | 246 | None, |
| 248 | config, | 247 | config, |
| @@ -258,31 +257,30 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { | |||
| 258 | /// Panics if `rx_buffer.len()` is odd. | 257 | /// Panics if `rx_buffer.len()` is odd. |
| 259 | #[allow(clippy::too_many_arguments)] | 258 | #[allow(clippy::too_many_arguments)] |
| 260 | pub fn new_with_rtscts( | 259 | pub fn new_with_rtscts( |
| 261 | uarte: impl Peripheral<P = U> + 'd, | 260 | uarte: Peri<'d, U>, |
| 262 | timer: impl Peripheral<P = T> + 'd, | 261 | timer: Peri<'d, T>, |
| 263 | ppi_ch1: impl Peripheral<P = impl ConfigurableChannel> + 'd, | 262 | ppi_ch1: Peri<'d, impl ConfigurableChannel>, |
| 264 | ppi_ch2: impl Peripheral<P = impl ConfigurableChannel> + 'd, | 263 | ppi_ch2: Peri<'d, impl ConfigurableChannel>, |
| 265 | ppi_group: impl Peripheral<P = impl Group> + 'd, | 264 | ppi_group: Peri<'d, impl Group>, |
| 266 | _irq: impl interrupt::typelevel::Binding<U::Interrupt, InterruptHandler<U>> + 'd, | 265 | _irq: impl interrupt::typelevel::Binding<U::Interrupt, InterruptHandler<U>> + 'd, |
| 267 | rxd: impl Peripheral<P = impl GpioPin> + 'd, | 266 | rxd: Peri<'d, impl GpioPin>, |
| 268 | txd: impl Peripheral<P = impl GpioPin> + 'd, | 267 | txd: Peri<'d, impl GpioPin>, |
| 269 | cts: impl Peripheral<P = impl GpioPin> + 'd, | 268 | cts: Peri<'d, impl GpioPin>, |
| 270 | rts: impl Peripheral<P = impl GpioPin> + 'd, | 269 | rts: Peri<'d, impl GpioPin>, |
| 271 | config: Config, | 270 | config: Config, |
| 272 | rx_buffer: &'d mut [u8], | 271 | rx_buffer: &'d mut [u8], |
| 273 | tx_buffer: &'d mut [u8], | 272 | tx_buffer: &'d mut [u8], |
| 274 | ) -> Self { | 273 | ) -> Self { |
| 275 | into_ref!(uarte, timer, rxd, txd, cts, rts, ppi_ch1, ppi_ch2, ppi_group); | ||
| 276 | Self::new_inner( | 274 | Self::new_inner( |
| 277 | uarte, | 275 | uarte, |
| 278 | timer, | 276 | timer, |
| 279 | ppi_ch1.map_into(), | 277 | ppi_ch1.into(), |
| 280 | ppi_ch2.map_into(), | 278 | ppi_ch2.into(), |
| 281 | ppi_group.map_into(), | 279 | ppi_group.into(), |
| 282 | rxd.map_into(), | 280 | rxd.into(), |
| 283 | txd.map_into(), | 281 | txd.into(), |
| 284 | Some(cts.map_into()), | 282 | Some(cts.into()), |
| 285 | Some(rts.map_into()), | 283 | Some(rts.into()), |
| 286 | config, | 284 | config, |
| 287 | rx_buffer, | 285 | rx_buffer, |
| 288 | tx_buffer, | 286 | tx_buffer, |
| @@ -291,15 +289,15 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { | |||
| 291 | 289 | ||
| 292 | #[allow(clippy::too_many_arguments)] | 290 | #[allow(clippy::too_many_arguments)] |
| 293 | fn new_inner( | 291 | fn new_inner( |
| 294 | peri: PeripheralRef<'d, U>, | 292 | peri: Peri<'d, U>, |
| 295 | timer: PeripheralRef<'d, T>, | 293 | timer: Peri<'d, T>, |
| 296 | ppi_ch1: PeripheralRef<'d, AnyConfigurableChannel>, | 294 | ppi_ch1: Peri<'d, AnyConfigurableChannel>, |
| 297 | ppi_ch2: PeripheralRef<'d, AnyConfigurableChannel>, | 295 | ppi_ch2: Peri<'d, AnyConfigurableChannel>, |
| 298 | ppi_group: PeripheralRef<'d, AnyGroup>, | 296 | ppi_group: Peri<'d, AnyGroup>, |
| 299 | rxd: PeripheralRef<'d, AnyPin>, | 297 | rxd: Peri<'d, AnyPin>, |
| 300 | txd: PeripheralRef<'d, AnyPin>, | 298 | txd: Peri<'d, AnyPin>, |
| 301 | cts: Option<PeripheralRef<'d, AnyPin>>, | 299 | cts: Option<Peri<'d, AnyPin>>, |
| 302 | rts: Option<PeripheralRef<'d, AnyPin>>, | 300 | rts: Option<Peri<'d, AnyPin>>, |
| 303 | config: Config, | 301 | config: Config, |
| 304 | rx_buffer: &'d mut [u8], | 302 | rx_buffer: &'d mut [u8], |
| 305 | tx_buffer: &'d mut [u8], | 303 | tx_buffer: &'d mut [u8], |
| @@ -372,20 +370,19 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { | |||
| 372 | 370 | ||
| 373 | /// Reader part of the buffered UARTE driver. | 371 | /// Reader part of the buffered UARTE driver. |
| 374 | pub struct BufferedUarteTx<'d, U: UarteInstance> { | 372 | pub struct BufferedUarteTx<'d, U: UarteInstance> { |
| 375 | _peri: PeripheralRef<'d, U>, | 373 | _peri: Peri<'d, U>, |
| 376 | } | 374 | } |
| 377 | 375 | ||
| 378 | impl<'d, U: UarteInstance> BufferedUarteTx<'d, U> { | 376 | impl<'d, U: UarteInstance> BufferedUarteTx<'d, U> { |
| 379 | /// Create a new BufferedUarteTx without hardware flow control. | 377 | /// Create a new BufferedUarteTx without hardware flow control. |
| 380 | pub fn new( | 378 | pub fn new( |
| 381 | uarte: impl Peripheral<P = U> + 'd, | 379 | uarte: Peri<'d, U>, |
| 382 | _irq: impl interrupt::typelevel::Binding<U::Interrupt, InterruptHandler<U>> + 'd, | 380 | _irq: impl interrupt::typelevel::Binding<U::Interrupt, InterruptHandler<U>> + 'd, |
| 383 | txd: impl Peripheral<P = impl GpioPin> + 'd, | 381 | txd: Peri<'d, impl GpioPin>, |
| 384 | config: Config, | 382 | config: Config, |
| 385 | tx_buffer: &'d mut [u8], | 383 | tx_buffer: &'d mut [u8], |
| 386 | ) -> Self { | 384 | ) -> Self { |
| 387 | into_ref!(uarte, txd); | 385 | Self::new_inner(uarte, txd.into(), None, config, tx_buffer) |
| 388 | Self::new_inner(uarte, txd.map_into(), None, config, tx_buffer) | ||
| 389 | } | 386 | } |
| 390 | 387 | ||
| 391 | /// Create a new BufferedUarte with hardware flow control (RTS/CTS) | 388 | /// Create a new BufferedUarte with hardware flow control (RTS/CTS) |
| @@ -394,21 +391,20 @@ impl<'d, U: UarteInstance> BufferedUarteTx<'d, U> { | |||
| 394 | /// | 391 | /// |
| 395 | /// Panics if `rx_buffer.len()` is odd. | 392 | /// Panics if `rx_buffer.len()` is odd. |
| 396 | pub fn new_with_cts( | 393 | pub fn new_with_cts( |
| 397 | uarte: impl Peripheral<P = U> + 'd, | 394 | uarte: Peri<'d, U>, |
| 398 | _irq: impl interrupt::typelevel::Binding<U::Interrupt, InterruptHandler<U>> + 'd, | 395 | _irq: impl interrupt::typelevel::Binding<U::Interrupt, InterruptHandler<U>> + 'd, |
| 399 | txd: impl Peripheral<P = impl GpioPin> + 'd, | 396 | txd: Peri<'d, impl GpioPin>, |
| 400 | cts: impl Peripheral<P = impl GpioPin> + 'd, | 397 | cts: Peri<'d, impl GpioPin>, |
| 401 | config: Config, | 398 | config: Config, |
| 402 | tx_buffer: &'d mut [u8], | 399 | tx_buffer: &'d mut [u8], |
| 403 | ) -> Self { | 400 | ) -> Self { |
| 404 | into_ref!(uarte, txd, cts); | 401 | Self::new_inner(uarte, txd.into(), Some(cts.into()), config, tx_buffer) |
| 405 | Self::new_inner(uarte, txd.map_into(), Some(cts.map_into()), config, tx_buffer) | ||
| 406 | } | 402 | } |
| 407 | 403 | ||
| 408 | fn new_inner( | 404 | fn new_inner( |
| 409 | peri: PeripheralRef<'d, U>, | 405 | peri: Peri<'d, U>, |
| 410 | txd: PeripheralRef<'d, AnyPin>, | 406 | txd: Peri<'d, AnyPin>, |
| 411 | cts: Option<PeripheralRef<'d, AnyPin>>, | 407 | cts: Option<Peri<'d, AnyPin>>, |
| 412 | config: Config, | 408 | config: Config, |
| 413 | tx_buffer: &'d mut [u8], | 409 | tx_buffer: &'d mut [u8], |
| 414 | ) -> Self { | 410 | ) -> Self { |
| @@ -426,9 +422,9 @@ impl<'d, U: UarteInstance> BufferedUarteTx<'d, U> { | |||
| 426 | } | 422 | } |
| 427 | 423 | ||
| 428 | fn new_innerer( | 424 | fn new_innerer( |
| 429 | peri: PeripheralRef<'d, U>, | 425 | peri: Peri<'d, U>, |
| 430 | txd: PeripheralRef<'d, AnyPin>, | 426 | txd: Peri<'d, AnyPin>, |
| 431 | cts: Option<PeripheralRef<'d, AnyPin>>, | 427 | cts: Option<Peri<'d, AnyPin>>, |
| 432 | tx_buffer: &'d mut [u8], | 428 | tx_buffer: &'d mut [u8], |
| 433 | ) -> Self { | 429 | ) -> Self { |
| 434 | let r = U::regs(); | 430 | let r = U::regs(); |
| @@ -542,7 +538,7 @@ impl<'a, U: UarteInstance> Drop for BufferedUarteTx<'a, U> { | |||
| 542 | 538 | ||
| 543 | /// Reader part of the buffered UARTE driver. | 539 | /// Reader part of the buffered UARTE driver. |
| 544 | pub struct BufferedUarteRx<'d, U: UarteInstance, T: TimerInstance> { | 540 | pub struct BufferedUarteRx<'d, U: UarteInstance, T: TimerInstance> { |
| 545 | _peri: PeripheralRef<'d, U>, | 541 | _peri: Peri<'d, U>, |
| 546 | timer: Timer<'d, T>, | 542 | timer: Timer<'d, T>, |
| 547 | _ppi_ch1: Ppi<'d, AnyConfigurableChannel, 1, 1>, | 543 | _ppi_ch1: Ppi<'d, AnyConfigurableChannel, 1, 1>, |
| 548 | _ppi_ch2: Ppi<'d, AnyConfigurableChannel, 1, 2>, | 544 | _ppi_ch2: Ppi<'d, AnyConfigurableChannel, 1, 2>, |
| @@ -557,24 +553,23 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarteRx<'d, U, T> { | |||
| 557 | /// Panics if `rx_buffer.len()` is odd. | 553 | /// Panics if `rx_buffer.len()` is odd. |
| 558 | #[allow(clippy::too_many_arguments)] | 554 | #[allow(clippy::too_many_arguments)] |
| 559 | pub fn new( | 555 | pub fn new( |
| 560 | uarte: impl Peripheral<P = U> + 'd, | 556 | uarte: Peri<'d, U>, |
| 561 | timer: impl Peripheral<P = T> + 'd, | 557 | timer: Peri<'d, T>, |
| 562 | ppi_ch1: impl Peripheral<P = impl ConfigurableChannel> + 'd, | 558 | ppi_ch1: Peri<'d, impl ConfigurableChannel>, |
| 563 | ppi_ch2: impl Peripheral<P = impl ConfigurableChannel> + 'd, | 559 | ppi_ch2: Peri<'d, impl ConfigurableChannel>, |
| 564 | ppi_group: impl Peripheral<P = impl Group> + 'd, | 560 | ppi_group: Peri<'d, impl Group>, |
| 565 | _irq: impl interrupt::typelevel::Binding<U::Interrupt, InterruptHandler<U>> + 'd, | 561 | _irq: impl interrupt::typelevel::Binding<U::Interrupt, InterruptHandler<U>> + 'd, |
| 566 | rxd: impl Peripheral<P = impl GpioPin> + 'd, | 562 | rxd: Peri<'d, impl GpioPin>, |
| 567 | config: Config, | 563 | config: Config, |
| 568 | rx_buffer: &'d mut [u8], | 564 | rx_buffer: &'d mut [u8], |
| 569 | ) -> Self { | 565 | ) -> Self { |
| 570 | into_ref!(uarte, timer, rxd, ppi_ch1, ppi_ch2, ppi_group); | ||
| 571 | Self::new_inner( | 566 | Self::new_inner( |
| 572 | uarte, | 567 | uarte, |
| 573 | timer, | 568 | timer, |
| 574 | ppi_ch1.map_into(), | 569 | ppi_ch1.into(), |
| 575 | ppi_ch2.map_into(), | 570 | ppi_ch2.into(), |
| 576 | ppi_group.map_into(), | 571 | ppi_group.into(), |
| 577 | rxd.map_into(), | 572 | rxd.into(), |
| 578 | None, | 573 | None, |
| 579 | config, | 574 | config, |
| 580 | rx_buffer, | 575 | rx_buffer, |
| @@ -588,26 +583,25 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarteRx<'d, U, T> { | |||
| 588 | /// Panics if `rx_buffer.len()` is odd. | 583 | /// Panics if `rx_buffer.len()` is odd. |
| 589 | #[allow(clippy::too_many_arguments)] | 584 | #[allow(clippy::too_many_arguments)] |
| 590 | pub fn new_with_rts( | 585 | pub fn new_with_rts( |
| 591 | uarte: impl Peripheral<P = U> + 'd, | 586 | uarte: Peri<'d, U>, |
| 592 | timer: impl Peripheral<P = T> + 'd, | 587 | timer: Peri<'d, T>, |
| 593 | ppi_ch1: impl Peripheral<P = impl ConfigurableChannel> + 'd, | 588 | ppi_ch1: Peri<'d, impl ConfigurableChannel>, |
| 594 | ppi_ch2: impl Peripheral<P = impl ConfigurableChannel> + 'd, | 589 | ppi_ch2: Peri<'d, impl ConfigurableChannel>, |
| 595 | ppi_group: impl Peripheral<P = impl Group> + 'd, | 590 | ppi_group: Peri<'d, impl Group>, |
| 596 | _irq: impl interrupt::typelevel::Binding<U::Interrupt, InterruptHandler<U>> + 'd, | 591 | _irq: impl interrupt::typelevel::Binding<U::Interrupt, InterruptHandler<U>> + 'd, |
| 597 | rxd: impl Peripheral<P = impl GpioPin> + 'd, | 592 | rxd: Peri<'d, impl GpioPin>, |
| 598 | rts: impl Peripheral<P = impl GpioPin> + 'd, | 593 | rts: Peri<'d, impl GpioPin>, |
| 599 | config: Config, | 594 | config: Config, |
| 600 | rx_buffer: &'d mut [u8], | 595 | rx_buffer: &'d mut [u8], |
| 601 | ) -> Self { | 596 | ) -> Self { |
| 602 | into_ref!(uarte, timer, rxd, rts, ppi_ch1, ppi_ch2, ppi_group); | ||
| 603 | Self::new_inner( | 597 | Self::new_inner( |
| 604 | uarte, | 598 | uarte, |
| 605 | timer, | 599 | timer, |
| 606 | ppi_ch1.map_into(), | 600 | ppi_ch1.into(), |
| 607 | ppi_ch2.map_into(), | 601 | ppi_ch2.into(), |
| 608 | ppi_group.map_into(), | 602 | ppi_group.into(), |
| 609 | rxd.map_into(), | 603 | rxd.into(), |
| 610 | Some(rts.map_into()), | 604 | Some(rts.into()), |
| 611 | config, | 605 | config, |
| 612 | rx_buffer, | 606 | rx_buffer, |
| 613 | ) | 607 | ) |
| @@ -615,13 +609,13 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarteRx<'d, U, T> { | |||
| 615 | 609 | ||
| 616 | #[allow(clippy::too_many_arguments)] | 610 | #[allow(clippy::too_many_arguments)] |
| 617 | fn new_inner( | 611 | fn new_inner( |
| 618 | peri: PeripheralRef<'d, U>, | 612 | peri: Peri<'d, U>, |
| 619 | timer: PeripheralRef<'d, T>, | 613 | timer: Peri<'d, T>, |
| 620 | ppi_ch1: PeripheralRef<'d, AnyConfigurableChannel>, | 614 | ppi_ch1: Peri<'d, AnyConfigurableChannel>, |
| 621 | ppi_ch2: PeripheralRef<'d, AnyConfigurableChannel>, | 615 | ppi_ch2: Peri<'d, AnyConfigurableChannel>, |
| 622 | ppi_group: PeripheralRef<'d, AnyGroup>, | 616 | ppi_group: Peri<'d, AnyGroup>, |
| 623 | rxd: PeripheralRef<'d, AnyPin>, | 617 | rxd: Peri<'d, AnyPin>, |
| 624 | rts: Option<PeripheralRef<'d, AnyPin>>, | 618 | rts: Option<Peri<'d, AnyPin>>, |
| 625 | config: Config, | 619 | config: Config, |
| 626 | rx_buffer: &'d mut [u8], | 620 | rx_buffer: &'d mut [u8], |
| 627 | ) -> Self { | 621 | ) -> Self { |
| @@ -640,13 +634,13 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarteRx<'d, U, T> { | |||
| 640 | 634 | ||
| 641 | #[allow(clippy::too_many_arguments)] | 635 | #[allow(clippy::too_many_arguments)] |
| 642 | fn new_innerer( | 636 | fn new_innerer( |
| 643 | peri: PeripheralRef<'d, U>, | 637 | peri: Peri<'d, U>, |
| 644 | timer: PeripheralRef<'d, T>, | 638 | timer: Peri<'d, T>, |
| 645 | ppi_ch1: PeripheralRef<'d, AnyConfigurableChannel>, | 639 | ppi_ch1: Peri<'d, AnyConfigurableChannel>, |
| 646 | ppi_ch2: PeripheralRef<'d, AnyConfigurableChannel>, | 640 | ppi_ch2: Peri<'d, AnyConfigurableChannel>, |
| 647 | ppi_group: PeripheralRef<'d, AnyGroup>, | 641 | ppi_group: Peri<'d, AnyGroup>, |
| 648 | rxd: PeripheralRef<'d, AnyPin>, | 642 | rxd: Peri<'d, AnyPin>, |
| 649 | rts: Option<PeripheralRef<'d, AnyPin>>, | 643 | rts: Option<Peri<'d, AnyPin>>, |
| 650 | rx_buffer: &'d mut [u8], | 644 | rx_buffer: &'d mut [u8], |
| 651 | ) -> Self { | 645 | ) -> Self { |
| 652 | assert!(rx_buffer.len() % 2 == 0); | 646 | assert!(rx_buffer.len() % 2 == 0); |
diff --git a/embassy-nrf/src/egu.rs b/embassy-nrf/src/egu.rs index 7f9abdac4..028396c7c 100644 --- a/embassy-nrf/src/egu.rs +++ b/embassy-nrf/src/egu.rs | |||
| @@ -7,20 +7,19 @@ | |||
| 7 | 7 | ||
| 8 | use core::marker::PhantomData; | 8 | use core::marker::PhantomData; |
| 9 | 9 | ||
| 10 | use embassy_hal_internal::into_ref; | 10 | use embassy_hal_internal::PeripheralType; |
| 11 | 11 | ||
| 12 | use crate::ppi::{Event, Task}; | 12 | use crate::ppi::{Event, Task}; |
| 13 | use crate::{interrupt, pac, Peripheral, PeripheralRef}; | 13 | use crate::{interrupt, pac, Peri}; |
| 14 | 14 | ||
| 15 | /// An instance of the EGU. | 15 | /// An instance of the EGU. |
| 16 | pub struct Egu<'d, T: Instance> { | 16 | pub struct Egu<'d, T: Instance> { |
| 17 | _p: PeripheralRef<'d, T>, | 17 | _p: Peri<'d, T>, |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | impl<'d, T: Instance> Egu<'d, T> { | 20 | impl<'d, T: Instance> Egu<'d, T> { |
| 21 | /// Create a new EGU instance. | 21 | /// Create a new EGU instance. |
| 22 | pub fn new(_p: impl Peripheral<P = T> + 'd) -> Self { | 22 | pub fn new(_p: Peri<'d, T>) -> Self { |
| 23 | into_ref!(_p); | ||
| 24 | Self { _p } | 23 | Self { _p } |
| 25 | } | 24 | } |
| 26 | 25 | ||
| @@ -39,7 +38,7 @@ pub(crate) trait SealedInstance { | |||
| 39 | 38 | ||
| 40 | /// Basic Egu instance. | 39 | /// Basic Egu instance. |
| 41 | #[allow(private_bounds)] | 40 | #[allow(private_bounds)] |
| 42 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | 41 | pub trait Instance: SealedInstance + PeripheralType + 'static + Send { |
| 43 | /// Interrupt for this peripheral. | 42 | /// Interrupt for this peripheral. |
| 44 | type Interrupt: interrupt::typelevel::Interrupt; | 43 | type Interrupt: interrupt::typelevel::Interrupt; |
| 45 | } | 44 | } |
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index c78fa4df5..d02da9ac5 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs | |||
| @@ -5,14 +5,14 @@ use core::convert::Infallible; | |||
| 5 | use core::hint::unreachable_unchecked; | 5 | use core::hint::unreachable_unchecked; |
| 6 | 6 | ||
| 7 | use cfg_if::cfg_if; | 7 | use cfg_if::cfg_if; |
| 8 | use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; | 8 | use embassy_hal_internal::{impl_peripheral, Peri, PeripheralType}; |
| 9 | 9 | ||
| 10 | use crate::pac; | ||
| 10 | use crate::pac::common::{Reg, RW}; | 11 | use crate::pac::common::{Reg, RW}; |
| 11 | use crate::pac::gpio; | 12 | use crate::pac::gpio; |
| 12 | use crate::pac::gpio::vals; | 13 | use crate::pac::gpio::vals; |
| 13 | #[cfg(not(feature = "_nrf51"))] | 14 | #[cfg(not(feature = "_nrf51"))] |
| 14 | use crate::pac::shared::{regs::Psel, vals::Connect}; | 15 | use crate::pac::shared::{regs::Psel, vals::Connect}; |
| 15 | use crate::{pac, Peripheral}; | ||
| 16 | 16 | ||
| 17 | /// A GPIO port with up to 32 pins. | 17 | /// A GPIO port with up to 32 pins. |
| 18 | #[derive(Debug, Eq, PartialEq)] | 18 | #[derive(Debug, Eq, PartialEq)] |
| @@ -49,7 +49,7 @@ pub struct Input<'d> { | |||
| 49 | impl<'d> Input<'d> { | 49 | impl<'d> Input<'d> { |
| 50 | /// Create GPIO input driver for a [Pin] with the provided [Pull] configuration. | 50 | /// Create GPIO input driver for a [Pin] with the provided [Pull] configuration. |
| 51 | #[inline] | 51 | #[inline] |
| 52 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, pull: Pull) -> Self { | 52 | pub fn new(pin: Peri<'d, impl Pin>, pull: Pull) -> Self { |
| 53 | let mut pin = Flex::new(pin); | 53 | let mut pin = Flex::new(pin); |
| 54 | pin.set_as_input(pull); | 54 | pin.set_as_input(pull); |
| 55 | 55 | ||
| @@ -210,7 +210,7 @@ pub struct Output<'d> { | |||
| 210 | impl<'d> Output<'d> { | 210 | impl<'d> Output<'d> { |
| 211 | /// Create GPIO output driver for a [Pin] with the provided [Level] and [OutputDriver] configuration. | 211 | /// Create GPIO output driver for a [Pin] with the provided [Level] and [OutputDriver] configuration. |
| 212 | #[inline] | 212 | #[inline] |
| 213 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, initial_output: Level, drive: OutputDrive) -> Self { | 213 | pub fn new(pin: Peri<'d, impl Pin>, initial_output: Level, drive: OutputDrive) -> Self { |
| 214 | let mut pin = Flex::new(pin); | 214 | let mut pin = Flex::new(pin); |
| 215 | match initial_output { | 215 | match initial_output { |
| 216 | Level::High => pin.set_high(), | 216 | Level::High => pin.set_high(), |
| @@ -310,7 +310,7 @@ fn convert_pull(pull: Pull) -> vals::Pull { | |||
| 310 | /// set while not in output mode, so the pin's level will be 'remembered' when it is not in output | 310 | /// set while not in output mode, so the pin's level will be 'remembered' when it is not in output |
| 311 | /// mode. | 311 | /// mode. |
| 312 | pub struct Flex<'d> { | 312 | pub struct Flex<'d> { |
| 313 | pub(crate) pin: PeripheralRef<'d, AnyPin>, | 313 | pub(crate) pin: Peri<'d, AnyPin>, |
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | impl<'d> Flex<'d> { | 316 | impl<'d> Flex<'d> { |
| @@ -319,10 +319,9 @@ impl<'d> Flex<'d> { | |||
| 319 | /// The pin remains disconnected. The initial output level is unspecified, but can be changed | 319 | /// The pin remains disconnected. The initial output level is unspecified, but can be changed |
| 320 | /// before the pin is put into output mode. | 320 | /// before the pin is put into output mode. |
| 321 | #[inline] | 321 | #[inline] |
| 322 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd) -> Self { | 322 | pub fn new(pin: Peri<'d, impl Pin>) -> Self { |
| 323 | into_ref!(pin); | ||
| 324 | // Pin will be in disconnected state. | 323 | // Pin will be in disconnected state. |
| 325 | Self { pin: pin.map_into() } | 324 | Self { pin: pin.into() } |
| 326 | } | 325 | } |
| 327 | 326 | ||
| 328 | /// Put the pin into input mode. | 327 | /// Put the pin into input mode. |
| @@ -503,7 +502,7 @@ pub(crate) trait SealedPin { | |||
| 503 | 502 | ||
| 504 | /// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. | 503 | /// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. |
| 505 | #[allow(private_bounds)] | 504 | #[allow(private_bounds)] |
| 506 | pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static { | 505 | pub trait Pin: PeripheralType + Into<AnyPin> + SealedPin + Sized + 'static { |
| 507 | /// Number of the pin within the port (0..31) | 506 | /// Number of the pin within the port (0..31) |
| 508 | #[inline] | 507 | #[inline] |
| 509 | fn pin(&self) -> u8 { | 508 | fn pin(&self) -> u8 { |
| @@ -529,19 +528,11 @@ pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static | |||
| 529 | fn psel_bits(&self) -> pac::shared::regs::Psel { | 528 | fn psel_bits(&self) -> pac::shared::regs::Psel { |
| 530 | pac::shared::regs::Psel(self.pin_port() as u32) | 529 | pac::shared::regs::Psel(self.pin_port() as u32) |
| 531 | } | 530 | } |
| 532 | |||
| 533 | /// Convert from concrete pin type PX_XX to type erased `AnyPin`. | ||
| 534 | #[inline] | ||
| 535 | fn degrade(self) -> AnyPin { | ||
| 536 | AnyPin { | ||
| 537 | pin_port: self.pin_port(), | ||
| 538 | } | ||
| 539 | } | ||
| 540 | } | 531 | } |
| 541 | 532 | ||
| 542 | /// Type-erased GPIO pin | 533 | /// Type-erased GPIO pin |
| 543 | pub struct AnyPin { | 534 | pub struct AnyPin { |
| 544 | pin_port: u8, | 535 | pub(crate) pin_port: u8, |
| 545 | } | 536 | } |
| 546 | 537 | ||
| 547 | impl AnyPin { | 538 | impl AnyPin { |
| @@ -550,8 +541,8 @@ impl AnyPin { | |||
| 550 | /// # Safety | 541 | /// # Safety |
| 551 | /// - `pin_port` should not in use by another driver. | 542 | /// - `pin_port` should not in use by another driver. |
| 552 | #[inline] | 543 | #[inline] |
| 553 | pub unsafe fn steal(pin_port: u8) -> Self { | 544 | pub unsafe fn steal(pin_port: u8) -> Peri<'static, Self> { |
| 554 | Self { pin_port } | 545 | Peri::new_unchecked(Self { pin_port }) |
| 555 | } | 546 | } |
| 556 | } | 547 | } |
| 557 | 548 | ||
| @@ -573,7 +564,7 @@ pub(crate) trait PselBits { | |||
| 573 | } | 564 | } |
| 574 | 565 | ||
| 575 | #[cfg(not(feature = "_nrf51"))] | 566 | #[cfg(not(feature = "_nrf51"))] |
| 576 | impl<'a, P: Pin> PselBits for Option<PeripheralRef<'a, P>> { | 567 | impl<'a, P: Pin> PselBits for Option<Peri<'a, P>> { |
| 577 | #[inline] | 568 | #[inline] |
| 578 | fn psel_bits(&self) -> pac::shared::regs::Psel { | 569 | fn psel_bits(&self) -> pac::shared::regs::Psel { |
| 579 | match self { | 570 | match self { |
| @@ -611,8 +602,10 @@ macro_rules! impl_pin { | |||
| 611 | } | 602 | } |
| 612 | 603 | ||
| 613 | impl From<peripherals::$type> for crate::gpio::AnyPin { | 604 | impl From<peripherals::$type> for crate::gpio::AnyPin { |
| 614 | fn from(val: peripherals::$type) -> Self { | 605 | fn from(_val: peripherals::$type) -> Self { |
| 615 | crate::gpio::Pin::degrade(val) | 606 | Self { |
| 607 | pin_port: $port_num * 32 + $pin_num, | ||
| 608 | } | ||
| 616 | } | 609 | } |
| 617 | } | 610 | } |
| 618 | }; | 611 | }; |
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index 8771f9f08..d169b49f9 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs | |||
| @@ -4,7 +4,7 @@ use core::convert::Infallible; | |||
| 4 | use core::future::{poll_fn, Future}; | 4 | use core::future::{poll_fn, Future}; |
| 5 | use core::task::{Context, Poll}; | 5 | use core::task::{Context, Poll}; |
| 6 | 6 | ||
| 7 | use embassy_hal_internal::{impl_peripheral, into_ref, Peripheral, PeripheralRef}; | 7 | use embassy_hal_internal::{impl_peripheral, Peri, PeripheralType}; |
| 8 | use embassy_sync::waitqueue::AtomicWaker; | 8 | use embassy_sync::waitqueue::AtomicWaker; |
| 9 | 9 | ||
| 10 | use crate::gpio::{AnyPin, Flex, Input, Output, Pin as GpioPin, SealedPin as _}; | 10 | use crate::gpio::{AnyPin, Flex, Input, Output, Pin as GpioPin, SealedPin as _}; |
| @@ -189,7 +189,7 @@ impl Iterator for BitIter { | |||
| 189 | 189 | ||
| 190 | /// GPIOTE channel driver in input mode | 190 | /// GPIOTE channel driver in input mode |
| 191 | pub struct InputChannel<'d> { | 191 | pub struct InputChannel<'d> { |
| 192 | ch: PeripheralRef<'d, AnyChannel>, | 192 | ch: Peri<'d, AnyChannel>, |
| 193 | pin: Input<'d>, | 193 | pin: Input<'d>, |
| 194 | } | 194 | } |
| 195 | 195 | ||
| @@ -204,9 +204,7 @@ impl<'d> Drop for InputChannel<'d> { | |||
| 204 | 204 | ||
| 205 | impl<'d> InputChannel<'d> { | 205 | impl<'d> InputChannel<'d> { |
| 206 | /// Create a new GPIOTE input channel driver. | 206 | /// Create a new GPIOTE input channel driver. |
| 207 | pub fn new(ch: impl Peripheral<P = impl Channel> + 'd, pin: Input<'d>, polarity: InputChannelPolarity) -> Self { | 207 | pub fn new(ch: Peri<'d, impl Channel>, pin: Input<'d>, polarity: InputChannelPolarity) -> Self { |
| 208 | into_ref!(ch); | ||
| 209 | |||
| 210 | let g = regs(); | 208 | let g = regs(); |
| 211 | let num = ch.number(); | 209 | let num = ch.number(); |
| 212 | 210 | ||
| @@ -228,7 +226,7 @@ impl<'d> InputChannel<'d> { | |||
| 228 | 226 | ||
| 229 | g.events_in(num).write_value(0); | 227 | g.events_in(num).write_value(0); |
| 230 | 228 | ||
| 231 | InputChannel { ch: ch.map_into(), pin } | 229 | InputChannel { ch: ch.into(), pin } |
| 232 | } | 230 | } |
| 233 | 231 | ||
| 234 | /// Asynchronously wait for an event in this channel. | 232 | /// Asynchronously wait for an event in this channel. |
| @@ -261,7 +259,7 @@ impl<'d> InputChannel<'d> { | |||
| 261 | 259 | ||
| 262 | /// GPIOTE channel driver in output mode | 260 | /// GPIOTE channel driver in output mode |
| 263 | pub struct OutputChannel<'d> { | 261 | pub struct OutputChannel<'d> { |
| 264 | ch: PeripheralRef<'d, AnyChannel>, | 262 | ch: Peri<'d, AnyChannel>, |
| 265 | _pin: Output<'d>, | 263 | _pin: Output<'d>, |
| 266 | } | 264 | } |
| 267 | 265 | ||
| @@ -276,8 +274,7 @@ impl<'d> Drop for OutputChannel<'d> { | |||
| 276 | 274 | ||
| 277 | impl<'d> OutputChannel<'d> { | 275 | impl<'d> OutputChannel<'d> { |
| 278 | /// Create a new GPIOTE output channel driver. | 276 | /// Create a new GPIOTE output channel driver. |
| 279 | pub fn new(ch: impl Peripheral<P = impl Channel> + 'd, pin: Output<'d>, polarity: OutputChannelPolarity) -> Self { | 277 | pub fn new(ch: Peri<'d, impl Channel>, pin: Output<'d>, polarity: OutputChannelPolarity) -> Self { |
| 280 | into_ref!(ch); | ||
| 281 | let g = regs(); | 278 | let g = regs(); |
| 282 | let num = ch.number(); | 279 | let num = ch.number(); |
| 283 | 280 | ||
| @@ -301,7 +298,7 @@ impl<'d> OutputChannel<'d> { | |||
| 301 | }); | 298 | }); |
| 302 | 299 | ||
| 303 | OutputChannel { | 300 | OutputChannel { |
| 304 | ch: ch.map_into(), | 301 | ch: ch.into(), |
| 305 | _pin: pin, | 302 | _pin: pin, |
| 306 | } | 303 | } |
| 307 | } | 304 | } |
| @@ -351,14 +348,12 @@ impl<'d> OutputChannel<'d> { | |||
| 351 | 348 | ||
| 352 | #[must_use = "futures do nothing unless you `.await` or poll them"] | 349 | #[must_use = "futures do nothing unless you `.await` or poll them"] |
| 353 | pub(crate) struct PortInputFuture<'a> { | 350 | pub(crate) struct PortInputFuture<'a> { |
| 354 | pin: PeripheralRef<'a, AnyPin>, | 351 | pin: Peri<'a, AnyPin>, |
| 355 | } | 352 | } |
| 356 | 353 | ||
| 357 | impl<'a> PortInputFuture<'a> { | 354 | impl<'a> PortInputFuture<'a> { |
| 358 | fn new(pin: impl Peripheral<P = impl GpioPin> + 'a) -> Self { | 355 | fn new(pin: Peri<'a, impl GpioPin>) -> Self { |
| 359 | Self { | 356 | Self { pin: pin.into() } |
| 360 | pin: pin.into_ref().map_into(), | ||
| 361 | } | ||
| 362 | } | 357 | } |
| 363 | } | 358 | } |
| 364 | 359 | ||
| @@ -415,13 +410,13 @@ impl<'d> Flex<'d> { | |||
| 415 | /// Wait until the pin is high. If it is already high, return immediately. | 410 | /// Wait until the pin is high. If it is already high, return immediately. |
| 416 | pub async fn wait_for_high(&mut self) { | 411 | pub async fn wait_for_high(&mut self) { |
| 417 | self.pin.conf().modify(|w| w.set_sense(Sense::HIGH)); | 412 | self.pin.conf().modify(|w| w.set_sense(Sense::HIGH)); |
| 418 | PortInputFuture::new(&mut self.pin).await | 413 | PortInputFuture::new(self.pin.reborrow()).await |
| 419 | } | 414 | } |
| 420 | 415 | ||
| 421 | /// Wait until the pin is low. If it is already low, return immediately. | 416 | /// Wait until the pin is low. If it is already low, return immediately. |
| 422 | pub async fn wait_for_low(&mut self) { | 417 | pub async fn wait_for_low(&mut self) { |
| 423 | self.pin.conf().modify(|w| w.set_sense(Sense::LOW)); | 418 | self.pin.conf().modify(|w| w.set_sense(Sense::LOW)); |
| 424 | PortInputFuture::new(&mut self.pin).await | 419 | PortInputFuture::new(self.pin.reborrow()).await |
| 425 | } | 420 | } |
| 426 | 421 | ||
| 427 | /// Wait for the pin to undergo a transition from low to high. | 422 | /// Wait for the pin to undergo a transition from low to high. |
| @@ -443,7 +438,7 @@ impl<'d> Flex<'d> { | |||
| 443 | } else { | 438 | } else { |
| 444 | self.pin.conf().modify(|w| w.set_sense(Sense::HIGH)); | 439 | self.pin.conf().modify(|w| w.set_sense(Sense::HIGH)); |
| 445 | } | 440 | } |
| 446 | PortInputFuture::new(&mut self.pin).await | 441 | PortInputFuture::new(self.pin.reborrow()).await |
| 447 | } | 442 | } |
| 448 | } | 443 | } |
| 449 | 444 | ||
| @@ -455,24 +450,14 @@ trait SealedChannel {} | |||
| 455 | /// | 450 | /// |
| 456 | /// Implemented by all GPIOTE channels. | 451 | /// Implemented by all GPIOTE channels. |
| 457 | #[allow(private_bounds)] | 452 | #[allow(private_bounds)] |
| 458 | pub trait Channel: SealedChannel + Into<AnyChannel> + Sized + 'static { | 453 | pub trait Channel: PeripheralType + SealedChannel + Into<AnyChannel> + Sized + 'static { |
| 459 | /// Get the channel number. | 454 | /// Get the channel number. |
| 460 | fn number(&self) -> usize; | 455 | fn number(&self) -> usize; |
| 461 | |||
| 462 | /// Convert this channel to a type-erased `AnyChannel`. | ||
| 463 | /// | ||
| 464 | /// This allows using several channels in situations that might require | ||
| 465 | /// them to be the same type, like putting them in an array. | ||
| 466 | fn degrade(self) -> AnyChannel { | ||
| 467 | AnyChannel { | ||
| 468 | number: self.number() as u8, | ||
| 469 | } | ||
| 470 | } | ||
| 471 | } | 456 | } |
| 472 | 457 | ||
| 473 | /// Type-erased channel. | 458 | /// Type-erased channel. |
| 474 | /// | 459 | /// |
| 475 | /// Obtained by calling `Channel::degrade`. | 460 | /// Obtained by calling `Channel::into()`. |
| 476 | /// | 461 | /// |
| 477 | /// This allows using several channels in situations that might require | 462 | /// This allows using several channels in situations that might require |
| 478 | /// them to be the same type, like putting them in an array. | 463 | /// them to be the same type, like putting them in an array. |
| @@ -498,7 +483,9 @@ macro_rules! impl_channel { | |||
| 498 | 483 | ||
| 499 | impl From<peripherals::$type> for AnyChannel { | 484 | impl From<peripherals::$type> for AnyChannel { |
| 500 | fn from(val: peripherals::$type) -> Self { | 485 | fn from(val: peripherals::$type) -> Self { |
| 501 | Channel::degrade(val) | 486 | Self { |
| 487 | number: val.number() as u8, | ||
| 488 | } | ||
| 502 | } | 489 | } |
| 503 | } | 490 | } |
| 504 | }; | 491 | }; |
diff --git a/embassy-nrf/src/i2s.rs b/embassy-nrf/src/i2s.rs index 384a1637b..a7dde8cd7 100644 --- a/embassy-nrf/src/i2s.rs +++ b/embassy-nrf/src/i2s.rs | |||
| @@ -10,14 +10,14 @@ use core::sync::atomic::{compiler_fence, AtomicBool, Ordering}; | |||
| 10 | use core::task::Poll; | 10 | use core::task::Poll; |
| 11 | 11 | ||
| 12 | use embassy_hal_internal::drop::OnDrop; | 12 | use embassy_hal_internal::drop::OnDrop; |
| 13 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 13 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 14 | use embassy_sync::waitqueue::AtomicWaker; | 14 | use embassy_sync::waitqueue::AtomicWaker; |
| 15 | 15 | ||
| 16 | use crate::gpio::{AnyPin, Pin as GpioPin, PselBits}; | 16 | use crate::gpio::{AnyPin, Pin as GpioPin, PselBits}; |
| 17 | use crate::interrupt::typelevel::Interrupt; | 17 | use crate::interrupt::typelevel::Interrupt; |
| 18 | use crate::pac::i2s::vals; | 18 | use crate::pac::i2s::vals; |
| 19 | use crate::util::slice_in_ram_or; | 19 | use crate::util::slice_in_ram_or; |
| 20 | use crate::{interrupt, pac, Peripheral, EASY_DMA_SIZE}; | 20 | use crate::{interrupt, pac, EASY_DMA_SIZE}; |
| 21 | 21 | ||
| 22 | /// Type alias for `MultiBuffering` with 2 buffers. | 22 | /// Type alias for `MultiBuffering` with 2 buffers. |
| 23 | pub type DoubleBuffering<S, const NS: usize> = MultiBuffering<S, 2, NS>; | 23 | pub type DoubleBuffering<S, const NS: usize> = MultiBuffering<S, 2, NS>; |
| @@ -406,12 +406,12 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 406 | 406 | ||
| 407 | /// I2S driver. | 407 | /// I2S driver. |
| 408 | pub struct I2S<'d, T: Instance> { | 408 | pub struct I2S<'d, T: Instance> { |
| 409 | i2s: PeripheralRef<'d, T>, | 409 | i2s: Peri<'d, T>, |
| 410 | mck: Option<PeripheralRef<'d, AnyPin>>, | 410 | mck: Option<Peri<'d, AnyPin>>, |
| 411 | sck: PeripheralRef<'d, AnyPin>, | 411 | sck: Peri<'d, AnyPin>, |
| 412 | lrck: PeripheralRef<'d, AnyPin>, | 412 | lrck: Peri<'d, AnyPin>, |
| 413 | sdin: Option<PeripheralRef<'d, AnyPin>>, | 413 | sdin: Option<Peri<'d, AnyPin>>, |
| 414 | sdout: Option<PeripheralRef<'d, AnyPin>>, | 414 | sdout: Option<Peri<'d, AnyPin>>, |
| 415 | master_clock: Option<MasterClock>, | 415 | master_clock: Option<MasterClock>, |
| 416 | config: Config, | 416 | config: Config, |
| 417 | } | 417 | } |
| @@ -419,20 +419,19 @@ pub struct I2S<'d, T: Instance> { | |||
| 419 | impl<'d, T: Instance> I2S<'d, T> { | 419 | impl<'d, T: Instance> I2S<'d, T> { |
| 420 | /// Create a new I2S in master mode | 420 | /// Create a new I2S in master mode |
| 421 | pub fn new_master( | 421 | pub fn new_master( |
| 422 | i2s: impl Peripheral<P = T> + 'd, | 422 | i2s: Peri<'d, T>, |
| 423 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 423 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 424 | mck: impl Peripheral<P = impl GpioPin> + 'd, | 424 | mck: Peri<'d, impl GpioPin>, |
| 425 | sck: impl Peripheral<P = impl GpioPin> + 'd, | 425 | sck: Peri<'d, impl GpioPin>, |
| 426 | lrck: impl Peripheral<P = impl GpioPin> + 'd, | 426 | lrck: Peri<'d, impl GpioPin>, |
| 427 | master_clock: MasterClock, | 427 | master_clock: MasterClock, |
| 428 | config: Config, | 428 | config: Config, |
| 429 | ) -> Self { | 429 | ) -> Self { |
| 430 | into_ref!(i2s, mck, sck, lrck); | ||
| 431 | Self { | 430 | Self { |
| 432 | i2s, | 431 | i2s, |
| 433 | mck: Some(mck.map_into()), | 432 | mck: Some(mck.into()), |
| 434 | sck: sck.map_into(), | 433 | sck: sck.into(), |
| 435 | lrck: lrck.map_into(), | 434 | lrck: lrck.into(), |
| 436 | sdin: None, | 435 | sdin: None, |
| 437 | sdout: None, | 436 | sdout: None, |
| 438 | master_clock: Some(master_clock), | 437 | master_clock: Some(master_clock), |
| @@ -442,18 +441,17 @@ impl<'d, T: Instance> I2S<'d, T> { | |||
| 442 | 441 | ||
| 443 | /// Create a new I2S in slave mode | 442 | /// Create a new I2S in slave mode |
| 444 | pub fn new_slave( | 443 | pub fn new_slave( |
| 445 | i2s: impl Peripheral<P = T> + 'd, | 444 | i2s: Peri<'d, T>, |
| 446 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 445 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 447 | sck: impl Peripheral<P = impl GpioPin> + 'd, | 446 | sck: Peri<'d, impl GpioPin>, |
| 448 | lrck: impl Peripheral<P = impl GpioPin> + 'd, | 447 | lrck: Peri<'d, impl GpioPin>, |
| 449 | config: Config, | 448 | config: Config, |
| 450 | ) -> Self { | 449 | ) -> Self { |
| 451 | into_ref!(i2s, sck, lrck); | ||
| 452 | Self { | 450 | Self { |
| 453 | i2s, | 451 | i2s, |
| 454 | mck: None, | 452 | mck: None, |
| 455 | sck: sck.map_into(), | 453 | sck: sck.into(), |
| 456 | lrck: lrck.map_into(), | 454 | lrck: lrck.into(), |
| 457 | sdin: None, | 455 | sdin: None, |
| 458 | sdout: None, | 456 | sdout: None, |
| 459 | master_clock: None, | 457 | master_clock: None, |
| @@ -464,10 +462,10 @@ impl<'d, T: Instance> I2S<'d, T> { | |||
| 464 | /// I2S output only | 462 | /// I2S output only |
| 465 | pub fn output<S: Sample, const NB: usize, const NS: usize>( | 463 | pub fn output<S: Sample, const NB: usize, const NS: usize>( |
| 466 | mut self, | 464 | mut self, |
| 467 | sdout: impl Peripheral<P = impl GpioPin> + 'd, | 465 | sdout: Peri<'d, impl GpioPin>, |
| 468 | buffers: MultiBuffering<S, NB, NS>, | 466 | buffers: MultiBuffering<S, NB, NS>, |
| 469 | ) -> OutputStream<'d, T, S, NB, NS> { | 467 | ) -> OutputStream<'d, T, S, NB, NS> { |
| 470 | self.sdout = Some(sdout.into_ref().map_into()); | 468 | self.sdout = Some(sdout.into()); |
| 471 | OutputStream { | 469 | OutputStream { |
| 472 | _p: self.build(), | 470 | _p: self.build(), |
| 473 | buffers, | 471 | buffers, |
| @@ -477,10 +475,10 @@ impl<'d, T: Instance> I2S<'d, T> { | |||
| 477 | /// I2S input only | 475 | /// I2S input only |
| 478 | pub fn input<S: Sample, const NB: usize, const NS: usize>( | 476 | pub fn input<S: Sample, const NB: usize, const NS: usize>( |
| 479 | mut self, | 477 | mut self, |
| 480 | sdin: impl Peripheral<P = impl GpioPin> + 'd, | 478 | sdin: Peri<'d, impl GpioPin>, |
| 481 | buffers: MultiBuffering<S, NB, NS>, | 479 | buffers: MultiBuffering<S, NB, NS>, |
| 482 | ) -> InputStream<'d, T, S, NB, NS> { | 480 | ) -> InputStream<'d, T, S, NB, NS> { |
| 483 | self.sdin = Some(sdin.into_ref().map_into()); | 481 | self.sdin = Some(sdin.into()); |
| 484 | InputStream { | 482 | InputStream { |
| 485 | _p: self.build(), | 483 | _p: self.build(), |
| 486 | buffers, | 484 | buffers, |
| @@ -490,13 +488,13 @@ impl<'d, T: Instance> I2S<'d, T> { | |||
| 490 | /// I2S full duplex (input and output) | 488 | /// I2S full duplex (input and output) |
| 491 | pub fn full_duplex<S: Sample, const NB: usize, const NS: usize>( | 489 | pub fn full_duplex<S: Sample, const NB: usize, const NS: usize>( |
| 492 | mut self, | 490 | mut self, |
| 493 | sdin: impl Peripheral<P = impl GpioPin> + 'd, | 491 | sdin: Peri<'d, impl GpioPin>, |
| 494 | sdout: impl Peripheral<P = impl GpioPin> + 'd, | 492 | sdout: Peri<'d, impl GpioPin>, |
| 495 | buffers_out: MultiBuffering<S, NB, NS>, | 493 | buffers_out: MultiBuffering<S, NB, NS>, |
| 496 | buffers_in: MultiBuffering<S, NB, NS>, | 494 | buffers_in: MultiBuffering<S, NB, NS>, |
| 497 | ) -> FullDuplexStream<'d, T, S, NB, NS> { | 495 | ) -> FullDuplexStream<'d, T, S, NB, NS> { |
| 498 | self.sdout = Some(sdout.into_ref().map_into()); | 496 | self.sdout = Some(sdout.into()); |
| 499 | self.sdin = Some(sdin.into_ref().map_into()); | 497 | self.sdin = Some(sdin.into()); |
| 500 | 498 | ||
| 501 | FullDuplexStream { | 499 | FullDuplexStream { |
| 502 | _p: self.build(), | 500 | _p: self.build(), |
| @@ -505,7 +503,7 @@ impl<'d, T: Instance> I2S<'d, T> { | |||
| 505 | } | 503 | } |
| 506 | } | 504 | } |
| 507 | 505 | ||
| 508 | fn build(self) -> PeripheralRef<'d, T> { | 506 | fn build(self) -> Peri<'d, T> { |
| 509 | self.apply_config(); | 507 | self.apply_config(); |
| 510 | self.select_pins(); | 508 | self.select_pins(); |
| 511 | self.setup_interrupt(); | 509 | self.setup_interrupt(); |
| @@ -702,7 +700,7 @@ impl<'d, T: Instance> I2S<'d, T> { | |||
| 702 | 700 | ||
| 703 | /// I2S output | 701 | /// I2S output |
| 704 | pub struct OutputStream<'d, T: Instance, S: Sample, const NB: usize, const NS: usize> { | 702 | pub struct OutputStream<'d, T: Instance, S: Sample, const NB: usize, const NS: usize> { |
| 705 | _p: PeripheralRef<'d, T>, | 703 | _p: Peri<'d, T>, |
| 706 | buffers: MultiBuffering<S, NB, NS>, | 704 | buffers: MultiBuffering<S, NB, NS>, |
| 707 | } | 705 | } |
| 708 | 706 | ||
| @@ -756,7 +754,7 @@ impl<'d, T: Instance, S: Sample, const NB: usize, const NS: usize> OutputStream< | |||
| 756 | 754 | ||
| 757 | /// I2S input | 755 | /// I2S input |
| 758 | pub struct InputStream<'d, T: Instance, S: Sample, const NB: usize, const NS: usize> { | 756 | pub struct InputStream<'d, T: Instance, S: Sample, const NB: usize, const NS: usize> { |
| 759 | _p: PeripheralRef<'d, T>, | 757 | _p: Peri<'d, T>, |
| 760 | buffers: MultiBuffering<S, NB, NS>, | 758 | buffers: MultiBuffering<S, NB, NS>, |
| 761 | } | 759 | } |
| 762 | 760 | ||
| @@ -811,7 +809,7 @@ impl<'d, T: Instance, S: Sample, const NB: usize, const NS: usize> InputStream<' | |||
| 811 | 809 | ||
| 812 | /// I2S full duplex stream (input & output) | 810 | /// I2S full duplex stream (input & output) |
| 813 | pub struct FullDuplexStream<'d, T: Instance, S: Sample, const NB: usize, const NS: usize> { | 811 | pub struct FullDuplexStream<'d, T: Instance, S: Sample, const NB: usize, const NS: usize> { |
| 814 | _p: PeripheralRef<'d, T>, | 812 | _p: Peri<'d, T>, |
| 815 | buffers_out: MultiBuffering<S, NB, NS>, | 813 | buffers_out: MultiBuffering<S, NB, NS>, |
| 816 | buffers_in: MultiBuffering<S, NB, NS>, | 814 | buffers_in: MultiBuffering<S, NB, NS>, |
| 817 | } | 815 | } |
| @@ -1148,7 +1146,7 @@ pub(crate) trait SealedInstance { | |||
| 1148 | 1146 | ||
| 1149 | /// I2S peripheral instance. | 1147 | /// I2S peripheral instance. |
| 1150 | #[allow(private_bounds)] | 1148 | #[allow(private_bounds)] |
| 1151 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | 1149 | pub trait Instance: SealedInstance + PeripheralType + 'static + Send { |
| 1152 | /// Interrupt for this peripheral. | 1150 | /// Interrupt for this peripheral. |
| 1153 | type Interrupt: interrupt::typelevel::Interrupt; | 1151 | type Interrupt: interrupt::typelevel::Interrupt; |
| 1154 | } | 1152 | } |
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 5cd0efa58..d2ff054f4 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -263,7 +263,7 @@ pub use chip::pac; | |||
| 263 | #[cfg(not(feature = "unstable-pac"))] | 263 | #[cfg(not(feature = "unstable-pac"))] |
| 264 | pub(crate) use chip::pac; | 264 | pub(crate) use chip::pac; |
| 265 | pub use chip::{peripherals, Peripherals, EASY_DMA_SIZE}; | 265 | pub use chip::{peripherals, Peripherals, EASY_DMA_SIZE}; |
| 266 | pub use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; | 266 | pub use embassy_hal_internal::{Peri, PeripheralType}; |
| 267 | 267 | ||
| 268 | pub use crate::chip::interrupt; | 268 | pub use crate::chip::interrupt; |
| 269 | #[cfg(feature = "rt")] | 269 | #[cfg(feature = "rt")] |
diff --git a/embassy-nrf/src/nfct.rs b/embassy-nrf/src/nfct.rs index 8b4b6dfe0..8d70ec954 100644 --- a/embassy-nrf/src/nfct.rs +++ b/embassy-nrf/src/nfct.rs | |||
| @@ -13,7 +13,6 @@ use core::future::poll_fn; | |||
| 13 | use core::sync::atomic::{compiler_fence, Ordering}; | 13 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 14 | use core::task::Poll; | 14 | use core::task::Poll; |
| 15 | 15 | ||
| 16 | use embassy_hal_internal::{into_ref, PeripheralRef}; | ||
| 17 | use embassy_sync::waitqueue::AtomicWaker; | 16 | use embassy_sync::waitqueue::AtomicWaker; |
| 18 | pub use vals::{Bitframesdd as SddPat, Discardmode as DiscardMode}; | 17 | pub use vals::{Bitframesdd as SddPat, Discardmode as DiscardMode}; |
| 19 | 18 | ||
| @@ -22,7 +21,7 @@ use crate::pac::nfct::vals; | |||
| 22 | use crate::pac::NFCT; | 21 | use crate::pac::NFCT; |
| 23 | use crate::peripherals::NFCT; | 22 | use crate::peripherals::NFCT; |
| 24 | use crate::util::slice_in_ram; | 23 | use crate::util::slice_in_ram; |
| 25 | use crate::{interrupt, pac, Peripheral}; | 24 | use crate::{interrupt, pac, Peri}; |
| 26 | 25 | ||
| 27 | /// NFCID1 (aka UID) of different sizes. | 26 | /// NFCID1 (aka UID) of different sizes. |
| 28 | #[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] | 27 | #[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] |
| @@ -96,7 +95,7 @@ pub enum Error { | |||
| 96 | 95 | ||
| 97 | /// NFC tag emulator driver. | 96 | /// NFC tag emulator driver. |
| 98 | pub struct NfcT<'d> { | 97 | pub struct NfcT<'d> { |
| 99 | _p: PeripheralRef<'d, NFCT>, | 98 | _p: Peri<'d, NFCT>, |
| 100 | rx_buf: [u8; 256], | 99 | rx_buf: [u8; 256], |
| 101 | tx_buf: [u8; 256], | 100 | tx_buf: [u8; 256], |
| 102 | } | 101 | } |
| @@ -104,12 +103,10 @@ pub struct NfcT<'d> { | |||
| 104 | impl<'d> NfcT<'d> { | 103 | impl<'d> NfcT<'d> { |
| 105 | /// Create an Nfc Tag driver | 104 | /// Create an Nfc Tag driver |
| 106 | pub fn new( | 105 | pub fn new( |
| 107 | _p: impl Peripheral<P = NFCT> + 'd, | 106 | _p: Peri<'d, NFCT>, |
| 108 | _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::NFCT, InterruptHandler> + 'd, | 107 | _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::NFCT, InterruptHandler> + 'd, |
| 109 | config: &Config, | 108 | config: &Config, |
| 110 | ) -> Self { | 109 | ) -> Self { |
| 111 | into_ref!(_p); | ||
| 112 | |||
| 113 | let r = pac::NFCT; | 110 | let r = pac::NFCT; |
| 114 | 111 | ||
| 115 | unsafe { | 112 | unsafe { |
diff --git a/embassy-nrf/src/nvmc.rs b/embassy-nrf/src/nvmc.rs index 6973b4847..c46af0b34 100644 --- a/embassy-nrf/src/nvmc.rs +++ b/embassy-nrf/src/nvmc.rs | |||
| @@ -2,14 +2,13 @@ | |||
| 2 | 2 | ||
| 3 | use core::{ptr, slice}; | 3 | use core::{ptr, slice}; |
| 4 | 4 | ||
| 5 | use embassy_hal_internal::{into_ref, PeripheralRef}; | ||
| 6 | use embedded_storage::nor_flash::{ | 5 | use embedded_storage::nor_flash::{ |
| 7 | ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, | 6 | ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, |
| 8 | }; | 7 | }; |
| 9 | 8 | ||
| 10 | use crate::pac::nvmc::vals; | 9 | use crate::pac::nvmc::vals; |
| 11 | use crate::peripherals::NVMC; | 10 | use crate::peripherals::NVMC; |
| 12 | use crate::{pac, Peripheral}; | 11 | use crate::{pac, Peri}; |
| 13 | 12 | ||
| 14 | #[cfg(not(feature = "_nrf5340-net"))] | 13 | #[cfg(not(feature = "_nrf5340-net"))] |
| 15 | /// Erase size of NVMC flash in bytes. | 14 | /// Erase size of NVMC flash in bytes. |
| @@ -42,13 +41,12 @@ impl NorFlashError for Error { | |||
| 42 | 41 | ||
| 43 | /// Non-Volatile Memory Controller (NVMC) that implements the `embedded-storage` traits. | 42 | /// Non-Volatile Memory Controller (NVMC) that implements the `embedded-storage` traits. |
| 44 | pub struct Nvmc<'d> { | 43 | pub struct Nvmc<'d> { |
| 45 | _p: PeripheralRef<'d, NVMC>, | 44 | _p: Peri<'d, NVMC>, |
| 46 | } | 45 | } |
| 47 | 46 | ||
| 48 | impl<'d> Nvmc<'d> { | 47 | impl<'d> Nvmc<'d> { |
| 49 | /// Create Nvmc driver. | 48 | /// Create Nvmc driver. |
| 50 | pub fn new(_p: impl Peripheral<P = NVMC> + 'd) -> Self { | 49 | pub fn new(_p: Peri<'d, NVMC>) -> Self { |
| 51 | into_ref!(_p); | ||
| 52 | Self { _p } | 50 | Self { _p } |
| 53 | } | 51 | } |
| 54 | 52 | ||
diff --git a/embassy-nrf/src/pdm.rs b/embassy-nrf/src/pdm.rs index 483d1a644..c2a4ba65f 100644 --- a/embassy-nrf/src/pdm.rs +++ b/embassy-nrf/src/pdm.rs | |||
| @@ -8,7 +8,7 @@ use core::sync::atomic::{compiler_fence, Ordering}; | |||
| 8 | use core::task::Poll; | 8 | use core::task::Poll; |
| 9 | 9 | ||
| 10 | use embassy_hal_internal::drop::OnDrop; | 10 | use embassy_hal_internal::drop::OnDrop; |
| 11 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 11 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 12 | use embassy_sync::waitqueue::AtomicWaker; | 12 | use embassy_sync::waitqueue::AtomicWaker; |
| 13 | use fixed::types::I7F1; | 13 | use fixed::types::I7F1; |
| 14 | 14 | ||
| @@ -25,7 +25,7 @@ pub use crate::pac::pdm::vals::Freq as Frequency; | |||
| 25 | feature = "_nrf91", | 25 | feature = "_nrf91", |
| 26 | ))] | 26 | ))] |
| 27 | pub use crate::pac::pdm::vals::Ratio; | 27 | pub use crate::pac::pdm::vals::Ratio; |
| 28 | use crate::{interrupt, pac, Peripheral}; | 28 | use crate::{interrupt, pac}; |
| 29 | 29 | ||
| 30 | /// Interrupt handler | 30 | /// Interrupt handler |
| 31 | pub struct InterruptHandler<T: Instance> { | 31 | pub struct InterruptHandler<T: Instance> { |
| @@ -54,7 +54,7 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 54 | 54 | ||
| 55 | /// PDM microphone interface | 55 | /// PDM microphone interface |
| 56 | pub struct Pdm<'d, T: Instance> { | 56 | pub struct Pdm<'d, T: Instance> { |
| 57 | _peri: PeripheralRef<'d, T>, | 57 | _peri: Peri<'d, T>, |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | /// PDM error | 60 | /// PDM error |
| @@ -89,24 +89,16 @@ pub enum SamplerState { | |||
| 89 | impl<'d, T: Instance> Pdm<'d, T> { | 89 | impl<'d, T: Instance> Pdm<'d, T> { |
| 90 | /// Create PDM driver | 90 | /// Create PDM driver |
| 91 | pub fn new( | 91 | pub fn new( |
| 92 | pdm: impl Peripheral<P = T> + 'd, | 92 | pdm: Peri<'d, T>, |
| 93 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 93 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 94 | clk: impl Peripheral<P = impl GpioPin> + 'd, | 94 | clk: Peri<'d, impl GpioPin>, |
| 95 | din: impl Peripheral<P = impl GpioPin> + 'd, | 95 | din: Peri<'d, impl GpioPin>, |
| 96 | config: Config, | 96 | config: Config, |
| 97 | ) -> Self { | 97 | ) -> Self { |
| 98 | into_ref!(pdm, clk, din); | 98 | Self::new_inner(pdm, clk.into(), din.into(), config) |
| 99 | Self::new_inner(pdm, clk.map_into(), din.map_into(), config) | ||
| 100 | } | 99 | } |
| 101 | 100 | ||
| 102 | fn new_inner( | 101 | fn new_inner(pdm: Peri<'d, T>, clk: Peri<'d, AnyPin>, din: Peri<'d, AnyPin>, config: Config) -> Self { |
| 103 | pdm: PeripheralRef<'d, T>, | ||
| 104 | clk: PeripheralRef<'d, AnyPin>, | ||
| 105 | din: PeripheralRef<'d, AnyPin>, | ||
| 106 | config: Config, | ||
| 107 | ) -> Self { | ||
| 108 | into_ref!(pdm); | ||
| 109 | |||
| 110 | let r = T::regs(); | 102 | let r = T::regs(); |
| 111 | 103 | ||
| 112 | // setup gpio pins | 104 | // setup gpio pins |
| @@ -452,7 +444,7 @@ pub(crate) trait SealedInstance { | |||
| 452 | 444 | ||
| 453 | /// PDM peripheral instance | 445 | /// PDM peripheral instance |
| 454 | #[allow(private_bounds)] | 446 | #[allow(private_bounds)] |
| 455 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | 447 | pub trait Instance: SealedInstance + PeripheralType + 'static + Send { |
| 456 | /// Interrupt for this peripheral | 448 | /// Interrupt for this peripheral |
| 457 | type Interrupt: interrupt::typelevel::Interrupt; | 449 | type Interrupt: interrupt::typelevel::Interrupt; |
| 458 | } | 450 | } |
diff --git a/embassy-nrf/src/ppi/dppi.rs b/embassy-nrf/src/ppi/dppi.rs index 3c7b96df7..686f66987 100644 --- a/embassy-nrf/src/ppi/dppi.rs +++ b/embassy-nrf/src/ppi/dppi.rs | |||
| @@ -1,7 +1,5 @@ | |||
| 1 | use embassy_hal_internal::into_ref; | ||
| 2 | |||
| 3 | use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; | 1 | use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; |
| 4 | use crate::{pac, Peripheral}; | 2 | use crate::{pac, Peri}; |
| 5 | 3 | ||
| 6 | const DPPI_ENABLE_BIT: u32 = 0x8000_0000; | 4 | const DPPI_ENABLE_BIT: u32 = 0x8000_0000; |
| 7 | const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF; | 5 | const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF; |
| @@ -12,14 +10,14 @@ pub(crate) fn regs() -> pac::dppic::Dppic { | |||
| 12 | 10 | ||
| 13 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { | 11 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { |
| 14 | /// Configure PPI channel to trigger `task` on `event`. | 12 | /// Configure PPI channel to trigger `task` on `event`. |
| 15 | pub fn new_one_to_one(ch: impl Peripheral<P = C> + 'd, event: Event<'d>, task: Task<'d>) -> Self { | 13 | pub fn new_one_to_one(ch: Peri<'d, C>, event: Event<'d>, task: Task<'d>) -> Self { |
| 16 | Ppi::new_many_to_many(ch, [event], [task]) | 14 | Ppi::new_many_to_many(ch, [event], [task]) |
| 17 | } | 15 | } |
| 18 | } | 16 | } |
| 19 | 17 | ||
| 20 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { | 18 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { |
| 21 | /// Configure PPI channel to trigger both `task1` and `task2` on `event`. | 19 | /// Configure PPI channel to trigger both `task1` and `task2` on `event`. |
| 22 | pub fn new_one_to_two(ch: impl Peripheral<P = C> + 'd, event: Event<'d>, task1: Task<'d>, task2: Task<'d>) -> Self { | 20 | pub fn new_one_to_two(ch: Peri<'d, C>, event: Event<'d>, task1: Task<'d>, task2: Task<'d>) -> Self { |
| 23 | Ppi::new_many_to_many(ch, [event], [task1, task2]) | 21 | Ppi::new_many_to_many(ch, [event], [task1, task2]) |
| 24 | } | 22 | } |
| 25 | } | 23 | } |
| @@ -28,13 +26,7 @@ impl<'d, C: ConfigurableChannel, const EVENT_COUNT: usize, const TASK_COUNT: usi | |||
| 28 | Ppi<'d, C, EVENT_COUNT, TASK_COUNT> | 26 | Ppi<'d, C, EVENT_COUNT, TASK_COUNT> |
| 29 | { | 27 | { |
| 30 | /// Configure a DPPI channel to trigger all `tasks` when any of the `events` fires. | 28 | /// Configure a DPPI channel to trigger all `tasks` when any of the `events` fires. |
| 31 | pub fn new_many_to_many( | 29 | pub fn new_many_to_many(ch: Peri<'d, C>, events: [Event<'d>; EVENT_COUNT], tasks: [Task<'d>; TASK_COUNT]) -> Self { |
| 32 | ch: impl Peripheral<P = C> + 'd, | ||
| 33 | events: [Event<'d>; EVENT_COUNT], | ||
| 34 | tasks: [Task<'d>; TASK_COUNT], | ||
| 35 | ) -> Self { | ||
| 36 | into_ref!(ch); | ||
| 37 | |||
| 38 | let val = DPPI_ENABLE_BIT | (ch.number() as u32 & DPPI_CHANNEL_MASK); | 30 | let val = DPPI_ENABLE_BIT | (ch.number() as u32 & DPPI_CHANNEL_MASK); |
| 39 | for task in tasks { | 31 | for task in tasks { |
| 40 | if unsafe { task.subscribe_reg().read_volatile() } != 0 { | 32 | if unsafe { task.subscribe_reg().read_volatile() } != 0 { |
diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs index 325e4ce00..531777205 100644 --- a/embassy-nrf/src/ppi/mod.rs +++ b/embassy-nrf/src/ppi/mod.rs | |||
| @@ -18,10 +18,10 @@ | |||
| 18 | use core::marker::PhantomData; | 18 | use core::marker::PhantomData; |
| 19 | use core::ptr::NonNull; | 19 | use core::ptr::NonNull; |
| 20 | 20 | ||
| 21 | use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; | 21 | use embassy_hal_internal::{impl_peripheral, Peri, PeripheralType}; |
| 22 | 22 | ||
| 23 | use crate::pac::common::{Reg, RW, W}; | 23 | use crate::pac::common::{Reg, RW, W}; |
| 24 | use crate::{peripherals, Peripheral}; | 24 | use crate::peripherals; |
| 25 | 25 | ||
| 26 | #[cfg_attr(feature = "_dppi", path = "dppi.rs")] | 26 | #[cfg_attr(feature = "_dppi", path = "dppi.rs")] |
| 27 | #[cfg_attr(feature = "_ppi", path = "ppi.rs")] | 27 | #[cfg_attr(feature = "_ppi", path = "ppi.rs")] |
| @@ -30,7 +30,7 @@ pub(crate) use _version::*; | |||
| 30 | 30 | ||
| 31 | /// PPI channel driver. | 31 | /// PPI channel driver. |
| 32 | pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> { | 32 | pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> { |
| 33 | ch: PeripheralRef<'d, C>, | 33 | ch: Peri<'d, C>, |
| 34 | #[cfg(feature = "_dppi")] | 34 | #[cfg(feature = "_dppi")] |
| 35 | events: [Event<'d>; EVENT_COUNT], | 35 | events: [Event<'d>; EVENT_COUNT], |
| 36 | #[cfg(feature = "_dppi")] | 36 | #[cfg(feature = "_dppi")] |
| @@ -39,16 +39,14 @@ pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize | |||
| 39 | 39 | ||
| 40 | /// PPI channel group driver. | 40 | /// PPI channel group driver. |
| 41 | pub struct PpiGroup<'d, G: Group> { | 41 | pub struct PpiGroup<'d, G: Group> { |
| 42 | g: PeripheralRef<'d, G>, | 42 | g: Peri<'d, G>, |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | impl<'d, G: Group> PpiGroup<'d, G> { | 45 | impl<'d, G: Group> PpiGroup<'d, G> { |
| 46 | /// Create a new PPI group driver. | 46 | /// Create a new PPI group driver. |
| 47 | /// | 47 | /// |
| 48 | /// The group is initialized as containing no channels. | 48 | /// The group is initialized as containing no channels. |
| 49 | pub fn new(g: impl Peripheral<P = G> + 'd) -> Self { | 49 | pub fn new(g: Peri<'d, G>) -> Self { |
| 50 | into_ref!(g); | ||
| 51 | |||
| 52 | let r = regs(); | 50 | let r = regs(); |
| 53 | let n = g.number(); | 51 | let n = g.number(); |
| 54 | r.chg(n).write(|_| ()); | 52 | r.chg(n).write(|_| ()); |
| @@ -210,34 +208,22 @@ pub(crate) trait SealedGroup {} | |||
| 210 | 208 | ||
| 211 | /// Interface for PPI channels. | 209 | /// Interface for PPI channels. |
| 212 | #[allow(private_bounds)] | 210 | #[allow(private_bounds)] |
| 213 | pub trait Channel: SealedChannel + Peripheral<P = Self> + Sized + 'static { | 211 | pub trait Channel: SealedChannel + PeripheralType + Sized + 'static { |
| 214 | /// Returns the number of the channel | 212 | /// Returns the number of the channel |
| 215 | fn number(&self) -> usize; | 213 | fn number(&self) -> usize; |
| 216 | } | 214 | } |
| 217 | 215 | ||
| 218 | /// Interface for PPI channels that can be configured. | 216 | /// Interface for PPI channels that can be configured. |
| 219 | pub trait ConfigurableChannel: Channel + Into<AnyConfigurableChannel> { | 217 | pub trait ConfigurableChannel: Channel + Into<AnyConfigurableChannel> {} |
| 220 | /// Convert into a type erased configurable channel. | ||
| 221 | fn degrade(self) -> AnyConfigurableChannel; | ||
| 222 | } | ||
| 223 | 218 | ||
| 224 | /// Interface for PPI channels that cannot be configured. | 219 | /// Interface for PPI channels that cannot be configured. |
| 225 | pub trait StaticChannel: Channel + Into<AnyStaticChannel> { | 220 | pub trait StaticChannel: Channel + Into<AnyStaticChannel> {} |
| 226 | /// Convert into a type erased static channel. | ||
| 227 | fn degrade(self) -> AnyStaticChannel; | ||
| 228 | } | ||
| 229 | 221 | ||
| 230 | /// Interface for a group of PPI channels. | 222 | /// Interface for a group of PPI channels. |
| 231 | #[allow(private_bounds)] | 223 | #[allow(private_bounds)] |
| 232 | pub trait Group: SealedGroup + Peripheral<P = Self> + Into<AnyGroup> + Sized + 'static { | 224 | pub trait Group: SealedGroup + PeripheralType + Into<AnyGroup> + Sized + 'static { |
| 233 | /// Returns the number of the group. | 225 | /// Returns the number of the group. |
| 234 | fn number(&self) -> usize; | 226 | fn number(&self) -> usize; |
| 235 | /// Convert into a type erased group. | ||
| 236 | fn degrade(self) -> AnyGroup { | ||
| 237 | AnyGroup { | ||
| 238 | number: self.number() as u8, | ||
| 239 | } | ||
| 240 | } | ||
| 241 | } | 227 | } |
| 242 | 228 | ||
| 243 | // ====================== | 229 | // ====================== |
| @@ -255,11 +241,7 @@ impl Channel for AnyStaticChannel { | |||
| 255 | self.number as usize | 241 | self.number as usize |
| 256 | } | 242 | } |
| 257 | } | 243 | } |
| 258 | impl StaticChannel for AnyStaticChannel { | 244 | impl StaticChannel for AnyStaticChannel {} |
| 259 | fn degrade(self) -> AnyStaticChannel { | ||
| 260 | self | ||
| 261 | } | ||
| 262 | } | ||
| 263 | 245 | ||
| 264 | /// The any configurable channel can represent any configurable channel at runtime. | 246 | /// The any configurable channel can represent any configurable channel at runtime. |
| 265 | /// This can be used to have fewer generic parameters in some places. | 247 | /// This can be used to have fewer generic parameters in some places. |
| @@ -273,11 +255,7 @@ impl Channel for AnyConfigurableChannel { | |||
| 273 | self.number as usize | 255 | self.number as usize |
| 274 | } | 256 | } |
| 275 | } | 257 | } |
| 276 | impl ConfigurableChannel for AnyConfigurableChannel { | 258 | impl ConfigurableChannel for AnyConfigurableChannel {} |
| 277 | fn degrade(self) -> AnyConfigurableChannel { | ||
| 278 | self | ||
| 279 | } | ||
| 280 | } | ||
| 281 | 259 | ||
| 282 | #[cfg(not(feature = "_nrf51"))] | 260 | #[cfg(not(feature = "_nrf51"))] |
| 283 | macro_rules! impl_ppi_channel { | 261 | macro_rules! impl_ppi_channel { |
| @@ -291,35 +269,23 @@ macro_rules! impl_ppi_channel { | |||
| 291 | }; | 269 | }; |
| 292 | ($type:ident, $number:expr => static) => { | 270 | ($type:ident, $number:expr => static) => { |
| 293 | impl_ppi_channel!($type, $number); | 271 | impl_ppi_channel!($type, $number); |
| 294 | impl crate::ppi::StaticChannel for peripherals::$type { | 272 | impl crate::ppi::StaticChannel for peripherals::$type {} |
| 295 | fn degrade(self) -> crate::ppi::AnyStaticChannel { | ||
| 296 | use crate::ppi::Channel; | ||
| 297 | crate::ppi::AnyStaticChannel { | ||
| 298 | number: self.number() as u8, | ||
| 299 | } | ||
| 300 | } | ||
| 301 | } | ||
| 302 | |||
| 303 | impl From<peripherals::$type> for crate::ppi::AnyStaticChannel { | 273 | impl From<peripherals::$type> for crate::ppi::AnyStaticChannel { |
| 304 | fn from(val: peripherals::$type) -> Self { | 274 | fn from(val: peripherals::$type) -> Self { |
| 305 | crate::ppi::StaticChannel::degrade(val) | 275 | Self { |
| 276 | number: crate::ppi::Channel::number(&val) as u8, | ||
| 277 | } | ||
| 306 | } | 278 | } |
| 307 | } | 279 | } |
| 308 | }; | 280 | }; |
| 309 | ($type:ident, $number:expr => configurable) => { | 281 | ($type:ident, $number:expr => configurable) => { |
| 310 | impl_ppi_channel!($type, $number); | 282 | impl_ppi_channel!($type, $number); |
| 311 | impl crate::ppi::ConfigurableChannel for peripherals::$type { | 283 | impl crate::ppi::ConfigurableChannel for peripherals::$type {} |
| 312 | fn degrade(self) -> crate::ppi::AnyConfigurableChannel { | ||
| 313 | use crate::ppi::Channel; | ||
| 314 | crate::ppi::AnyConfigurableChannel { | ||
| 315 | number: self.number() as u8, | ||
| 316 | } | ||
| 317 | } | ||
| 318 | } | ||
| 319 | |||
| 320 | impl From<peripherals::$type> for crate::ppi::AnyConfigurableChannel { | 284 | impl From<peripherals::$type> for crate::ppi::AnyConfigurableChannel { |
| 321 | fn from(val: peripherals::$type) -> Self { | 285 | fn from(val: peripherals::$type) -> Self { |
| 322 | crate::ppi::ConfigurableChannel::degrade(val) | 286 | Self { |
| 287 | number: crate::ppi::Channel::number(&val) as u8, | ||
| 288 | } | ||
| 323 | } | 289 | } |
| 324 | } | 290 | } |
| 325 | }; | 291 | }; |
| @@ -351,7 +317,9 @@ macro_rules! impl_group { | |||
| 351 | 317 | ||
| 352 | impl From<peripherals::$type> for crate::ppi::AnyGroup { | 318 | impl From<peripherals::$type> for crate::ppi::AnyGroup { |
| 353 | fn from(val: peripherals::$type) -> Self { | 319 | fn from(val: peripherals::$type) -> Self { |
| 354 | crate::ppi::Group::degrade(val) | 320 | Self { |
| 321 | number: crate::ppi::Group::number(&val) as u8, | ||
| 322 | } | ||
| 355 | } | 323 | } |
| 356 | } | 324 | } |
| 357 | }; | 325 | }; |
diff --git a/embassy-nrf/src/ppi/ppi.rs b/embassy-nrf/src/ppi/ppi.rs index a1beb9dcd..e04dacbc0 100644 --- a/embassy-nrf/src/ppi/ppi.rs +++ b/embassy-nrf/src/ppi/ppi.rs | |||
| @@ -1,7 +1,5 @@ | |||
| 1 | use embassy_hal_internal::into_ref; | ||
| 2 | |||
| 3 | use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; | 1 | use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; |
| 4 | use crate::{pac, Peripheral}; | 2 | use crate::{pac, Peri}; |
| 5 | 3 | ||
| 6 | impl<'d> Task<'d> { | 4 | impl<'d> Task<'d> { |
| 7 | fn reg_val(&self) -> u32 { | 5 | fn reg_val(&self) -> u32 { |
| @@ -21,9 +19,7 @@ pub(crate) fn regs() -> pac::ppi::Ppi { | |||
| 21 | #[cfg(not(feature = "_nrf51"))] // Not for nrf51 because of the fork task | 19 | #[cfg(not(feature = "_nrf51"))] // Not for nrf51 because of the fork task |
| 22 | impl<'d, C: super::StaticChannel> Ppi<'d, C, 0, 1> { | 20 | impl<'d, C: super::StaticChannel> Ppi<'d, C, 0, 1> { |
| 23 | /// Configure PPI channel to trigger `task`. | 21 | /// Configure PPI channel to trigger `task`. |
| 24 | pub fn new_zero_to_one(ch: impl Peripheral<P = C> + 'd, task: Task) -> Self { | 22 | pub fn new_zero_to_one(ch: Peri<'d, C>, task: Task) -> Self { |
| 25 | into_ref!(ch); | ||
| 26 | |||
| 27 | let r = regs(); | 23 | let r = regs(); |
| 28 | let n = ch.number(); | 24 | let n = ch.number(); |
| 29 | r.fork(n).tep().write_value(task.reg_val()); | 25 | r.fork(n).tep().write_value(task.reg_val()); |
| @@ -34,9 +30,7 @@ impl<'d, C: super::StaticChannel> Ppi<'d, C, 0, 1> { | |||
| 34 | 30 | ||
| 35 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { | 31 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { |
| 36 | /// Configure PPI channel to trigger `task` on `event`. | 32 | /// Configure PPI channel to trigger `task` on `event`. |
| 37 | pub fn new_one_to_one(ch: impl Peripheral<P = C> + 'd, event: Event<'d>, task: Task<'d>) -> Self { | 33 | pub fn new_one_to_one(ch: Peri<'d, C>, event: Event<'d>, task: Task<'d>) -> Self { |
| 38 | into_ref!(ch); | ||
| 39 | |||
| 40 | let r = regs(); | 34 | let r = regs(); |
| 41 | let n = ch.number(); | 35 | let n = ch.number(); |
| 42 | r.ch(n).eep().write_value(event.reg_val()); | 36 | r.ch(n).eep().write_value(event.reg_val()); |
| @@ -49,9 +43,7 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { | |||
| 49 | #[cfg(not(feature = "_nrf51"))] // Not for nrf51 because of the fork task | 43 | #[cfg(not(feature = "_nrf51"))] // Not for nrf51 because of the fork task |
| 50 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { | 44 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { |
| 51 | /// Configure PPI channel to trigger both `task1` and `task2` on `event`. | 45 | /// Configure PPI channel to trigger both `task1` and `task2` on `event`. |
| 52 | pub fn new_one_to_two(ch: impl Peripheral<P = C> + 'd, event: Event<'d>, task1: Task<'d>, task2: Task<'d>) -> Self { | 46 | pub fn new_one_to_two(ch: Peri<'d, C>, event: Event<'d>, task1: Task<'d>, task2: Task<'d>) -> Self { |
| 53 | into_ref!(ch); | ||
| 54 | |||
| 55 | let r = regs(); | 47 | let r = regs(); |
| 56 | let n = ch.number(); | 48 | let n = ch.number(); |
| 57 | r.ch(n).eep().write_value(event.reg_val()); | 49 | r.ch(n).eep().write_value(event.reg_val()); |
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index 6247ff6a5..a2e153e26 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs | |||
| @@ -4,34 +4,34 @@ | |||
| 4 | 4 | ||
| 5 | use core::sync::atomic::{compiler_fence, Ordering}; | 5 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 6 | 6 | ||
| 7 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 7 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 8 | 8 | ||
| 9 | use crate::gpio::{convert_drive, AnyPin, OutputDrive, Pin as GpioPin, PselBits, SealedPin as _, DISCONNECTED}; | 9 | use crate::gpio::{convert_drive, AnyPin, OutputDrive, Pin as GpioPin, PselBits, SealedPin as _, DISCONNECTED}; |
| 10 | use crate::pac::gpio::vals as gpiovals; | 10 | use crate::pac::gpio::vals as gpiovals; |
| 11 | use crate::pac::pwm::vals; | 11 | use crate::pac::pwm::vals; |
| 12 | use crate::ppi::{Event, Task}; | 12 | use crate::ppi::{Event, Task}; |
| 13 | use crate::util::slice_in_ram_or; | 13 | use crate::util::slice_in_ram_or; |
| 14 | use crate::{interrupt, pac, Peripheral}; | 14 | use crate::{interrupt, pac}; |
| 15 | 15 | ||
| 16 | /// SimplePwm is the traditional pwm interface you're probably used to, allowing | 16 | /// SimplePwm is the traditional pwm interface you're probably used to, allowing |
| 17 | /// to simply set a duty cycle across up to four channels. | 17 | /// to simply set a duty cycle across up to four channels. |
| 18 | pub struct SimplePwm<'d, T: Instance> { | 18 | pub struct SimplePwm<'d, T: Instance> { |
| 19 | _peri: PeripheralRef<'d, T>, | 19 | _peri: Peri<'d, T>, |
| 20 | duty: [u16; 4], | 20 | duty: [u16; 4], |
| 21 | ch0: Option<PeripheralRef<'d, AnyPin>>, | 21 | ch0: Option<Peri<'d, AnyPin>>, |
| 22 | ch1: Option<PeripheralRef<'d, AnyPin>>, | 22 | ch1: Option<Peri<'d, AnyPin>>, |
| 23 | ch2: Option<PeripheralRef<'d, AnyPin>>, | 23 | ch2: Option<Peri<'d, AnyPin>>, |
| 24 | ch3: Option<PeripheralRef<'d, AnyPin>>, | 24 | ch3: Option<Peri<'d, AnyPin>>, |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | /// SequencePwm allows you to offload the updating of a sequence of duty cycles | 27 | /// SequencePwm allows you to offload the updating of a sequence of duty cycles |
| 28 | /// to up to four channels, as well as repeat that sequence n times. | 28 | /// to up to four channels, as well as repeat that sequence n times. |
| 29 | pub struct SequencePwm<'d, T: Instance> { | 29 | pub struct SequencePwm<'d, T: Instance> { |
| 30 | _peri: PeripheralRef<'d, T>, | 30 | _peri: Peri<'d, T>, |
| 31 | ch0: Option<PeripheralRef<'d, AnyPin>>, | 31 | ch0: Option<Peri<'d, AnyPin>>, |
| 32 | ch1: Option<PeripheralRef<'d, AnyPin>>, | 32 | ch1: Option<Peri<'d, AnyPin>>, |
| 33 | ch2: Option<PeripheralRef<'d, AnyPin>>, | 33 | ch2: Option<Peri<'d, AnyPin>>, |
| 34 | ch3: Option<PeripheralRef<'d, AnyPin>>, | 34 | ch3: Option<Peri<'d, AnyPin>>, |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | /// PWM error | 37 | /// PWM error |
| @@ -54,78 +54,61 @@ pub const PWM_CLK_HZ: u32 = 16_000_000; | |||
| 54 | impl<'d, T: Instance> SequencePwm<'d, T> { | 54 | impl<'d, T: Instance> SequencePwm<'d, T> { |
| 55 | /// Create a new 1-channel PWM | 55 | /// Create a new 1-channel PWM |
| 56 | #[allow(unused_unsafe)] | 56 | #[allow(unused_unsafe)] |
| 57 | pub fn new_1ch( | 57 | pub fn new_1ch(pwm: Peri<'d, T>, ch0: Peri<'d, impl GpioPin>, config: Config) -> Result<Self, Error> { |
| 58 | pwm: impl Peripheral<P = T> + 'd, | 58 | Self::new_inner(pwm, Some(ch0.into()), None, None, None, config) |
| 59 | ch0: impl Peripheral<P = impl GpioPin> + 'd, | ||
| 60 | config: Config, | ||
| 61 | ) -> Result<Self, Error> { | ||
| 62 | into_ref!(ch0); | ||
| 63 | Self::new_inner(pwm, Some(ch0.map_into()), None, None, None, config) | ||
| 64 | } | 59 | } |
| 65 | 60 | ||
| 66 | /// Create a new 2-channel PWM | 61 | /// Create a new 2-channel PWM |
| 67 | #[allow(unused_unsafe)] | 62 | #[allow(unused_unsafe)] |
| 68 | pub fn new_2ch( | 63 | pub fn new_2ch( |
| 69 | pwm: impl Peripheral<P = T> + 'd, | 64 | pwm: Peri<'d, T>, |
| 70 | ch0: impl Peripheral<P = impl GpioPin> + 'd, | 65 | ch0: Peri<'d, impl GpioPin>, |
| 71 | ch1: impl Peripheral<P = impl GpioPin> + 'd, | 66 | ch1: Peri<'d, impl GpioPin>, |
| 72 | config: Config, | 67 | config: Config, |
| 73 | ) -> Result<Self, Error> { | 68 | ) -> Result<Self, Error> { |
| 74 | into_ref!(ch0, ch1); | 69 | Self::new_inner(pwm, Some(ch0.into()), Some(ch1.into()), None, None, config) |
| 75 | Self::new_inner(pwm, Some(ch0.map_into()), Some(ch1.map_into()), None, None, config) | ||
| 76 | } | 70 | } |
| 77 | 71 | ||
| 78 | /// Create a new 3-channel PWM | 72 | /// Create a new 3-channel PWM |
| 79 | #[allow(unused_unsafe)] | 73 | #[allow(unused_unsafe)] |
| 80 | pub fn new_3ch( | 74 | pub fn new_3ch( |
| 81 | pwm: impl Peripheral<P = T> + 'd, | 75 | pwm: Peri<'d, T>, |
| 82 | ch0: impl Peripheral<P = impl GpioPin> + 'd, | 76 | ch0: Peri<'d, impl GpioPin>, |
| 83 | ch1: impl Peripheral<P = impl GpioPin> + 'd, | 77 | ch1: Peri<'d, impl GpioPin>, |
| 84 | ch2: impl Peripheral<P = impl GpioPin> + 'd, | 78 | ch2: Peri<'d, impl GpioPin>, |
| 85 | config: Config, | 79 | config: Config, |
| 86 | ) -> Result<Self, Error> { | 80 | ) -> Result<Self, Error> { |
| 87 | into_ref!(ch0, ch1, ch2); | 81 | Self::new_inner(pwm, Some(ch0.into()), Some(ch1.into()), Some(ch2.into()), None, config) |
| 88 | Self::new_inner( | ||
| 89 | pwm, | ||
| 90 | Some(ch0.map_into()), | ||
| 91 | Some(ch1.map_into()), | ||
| 92 | Some(ch2.map_into()), | ||
| 93 | None, | ||
| 94 | config, | ||
| 95 | ) | ||
| 96 | } | 82 | } |
| 97 | 83 | ||
| 98 | /// Create a new 4-channel PWM | 84 | /// Create a new 4-channel PWM |
| 99 | #[allow(unused_unsafe)] | 85 | #[allow(unused_unsafe)] |
| 100 | pub fn new_4ch( | 86 | pub fn new_4ch( |
| 101 | pwm: impl Peripheral<P = T> + 'd, | 87 | pwm: Peri<'d, T>, |
| 102 | ch0: impl Peripheral<P = impl GpioPin> + 'd, | 88 | ch0: Peri<'d, impl GpioPin>, |
| 103 | ch1: impl Peripheral<P = impl GpioPin> + 'd, | 89 | ch1: Peri<'d, impl GpioPin>, |
| 104 | ch2: impl Peripheral<P = impl GpioPin> + 'd, | 90 | ch2: Peri<'d, impl GpioPin>, |
| 105 | ch3: impl Peripheral<P = impl GpioPin> + 'd, | 91 | ch3: Peri<'d, impl GpioPin>, |
| 106 | config: Config, | 92 | config: Config, |
| 107 | ) -> Result<Self, Error> { | 93 | ) -> Result<Self, Error> { |
| 108 | into_ref!(ch0, ch1, ch2, ch3); | ||
| 109 | Self::new_inner( | 94 | Self::new_inner( |
| 110 | pwm, | 95 | pwm, |
| 111 | Some(ch0.map_into()), | 96 | Some(ch0.into()), |
| 112 | Some(ch1.map_into()), | 97 | Some(ch1.into()), |
| 113 | Some(ch2.map_into()), | 98 | Some(ch2.into()), |
| 114 | Some(ch3.map_into()), | 99 | Some(ch3.into()), |
| 115 | config, | 100 | config, |
| 116 | ) | 101 | ) |
| 117 | } | 102 | } |
| 118 | 103 | ||
| 119 | fn new_inner( | 104 | fn new_inner( |
| 120 | _pwm: impl Peripheral<P = T> + 'd, | 105 | _pwm: Peri<'d, T>, |
| 121 | ch0: Option<PeripheralRef<'d, AnyPin>>, | 106 | ch0: Option<Peri<'d, AnyPin>>, |
| 122 | ch1: Option<PeripheralRef<'d, AnyPin>>, | 107 | ch1: Option<Peri<'d, AnyPin>>, |
| 123 | ch2: Option<PeripheralRef<'d, AnyPin>>, | 108 | ch2: Option<Peri<'d, AnyPin>>, |
| 124 | ch3: Option<PeripheralRef<'d, AnyPin>>, | 109 | ch3: Option<Peri<'d, AnyPin>>, |
| 125 | config: Config, | 110 | config: Config, |
| 126 | ) -> Result<Self, Error> { | 111 | ) -> Result<Self, Error> { |
| 127 | into_ref!(_pwm); | ||
| 128 | |||
| 129 | let r = T::regs(); | 112 | let r = T::regs(); |
| 130 | 113 | ||
| 131 | if let Some(pin) = &ch0 { | 114 | if let Some(pin) = &ch0 { |
| @@ -610,74 +593,54 @@ pub enum CounterMode { | |||
| 610 | impl<'d, T: Instance> SimplePwm<'d, T> { | 593 | impl<'d, T: Instance> SimplePwm<'d, T> { |
| 611 | /// Create a new 1-channel PWM | 594 | /// Create a new 1-channel PWM |
| 612 | #[allow(unused_unsafe)] | 595 | #[allow(unused_unsafe)] |
| 613 | pub fn new_1ch(pwm: impl Peripheral<P = T> + 'd, ch0: impl Peripheral<P = impl GpioPin> + 'd) -> Self { | 596 | pub fn new_1ch(pwm: Peri<'d, T>, ch0: Peri<'d, impl GpioPin>) -> Self { |
| 614 | unsafe { | 597 | unsafe { Self::new_inner(pwm, Some(ch0.into()), None, None, None) } |
| 615 | into_ref!(ch0); | ||
| 616 | Self::new_inner(pwm, Some(ch0.map_into()), None, None, None) | ||
| 617 | } | ||
| 618 | } | 598 | } |
| 619 | 599 | ||
| 620 | /// Create a new 2-channel PWM | 600 | /// Create a new 2-channel PWM |
| 621 | #[allow(unused_unsafe)] | 601 | #[allow(unused_unsafe)] |
| 622 | pub fn new_2ch( | 602 | pub fn new_2ch(pwm: Peri<'d, T>, ch0: Peri<'d, impl GpioPin>, ch1: Peri<'d, impl GpioPin>) -> Self { |
| 623 | pwm: impl Peripheral<P = T> + 'd, | 603 | Self::new_inner(pwm, Some(ch0.into()), Some(ch1.into()), None, None) |
| 624 | ch0: impl Peripheral<P = impl GpioPin> + 'd, | ||
| 625 | ch1: impl Peripheral<P = impl GpioPin> + 'd, | ||
| 626 | ) -> Self { | ||
| 627 | into_ref!(ch0, ch1); | ||
| 628 | Self::new_inner(pwm, Some(ch0.map_into()), Some(ch1.map_into()), None, None) | ||
| 629 | } | 604 | } |
| 630 | 605 | ||
| 631 | /// Create a new 3-channel PWM | 606 | /// Create a new 3-channel PWM |
| 632 | #[allow(unused_unsafe)] | 607 | #[allow(unused_unsafe)] |
| 633 | pub fn new_3ch( | 608 | pub fn new_3ch( |
| 634 | pwm: impl Peripheral<P = T> + 'd, | 609 | pwm: Peri<'d, T>, |
| 635 | ch0: impl Peripheral<P = impl GpioPin> + 'd, | 610 | ch0: Peri<'d, impl GpioPin>, |
| 636 | ch1: impl Peripheral<P = impl GpioPin> + 'd, | 611 | ch1: Peri<'d, impl GpioPin>, |
| 637 | ch2: impl Peripheral<P = impl GpioPin> + 'd, | 612 | ch2: Peri<'d, impl GpioPin>, |
| 638 | ) -> Self { | 613 | ) -> Self { |
| 639 | unsafe { | 614 | unsafe { Self::new_inner(pwm, Some(ch0.into()), Some(ch1.into()), Some(ch2.into()), None) } |
| 640 | into_ref!(ch0, ch1, ch2); | ||
| 641 | Self::new_inner( | ||
| 642 | pwm, | ||
| 643 | Some(ch0.map_into()), | ||
| 644 | Some(ch1.map_into()), | ||
| 645 | Some(ch2.map_into()), | ||
| 646 | None, | ||
| 647 | ) | ||
| 648 | } | ||
| 649 | } | 615 | } |
| 650 | 616 | ||
| 651 | /// Create a new 4-channel PWM | 617 | /// Create a new 4-channel PWM |
| 652 | #[allow(unused_unsafe)] | 618 | #[allow(unused_unsafe)] |
| 653 | pub fn new_4ch( | 619 | pub fn new_4ch( |
| 654 | pwm: impl Peripheral<P = T> + 'd, | 620 | pwm: Peri<'d, T>, |
| 655 | ch0: impl Peripheral<P = impl GpioPin> + 'd, | 621 | ch0: Peri<'d, impl GpioPin>, |
| 656 | ch1: impl Peripheral<P = impl GpioPin> + 'd, | 622 | ch1: Peri<'d, impl GpioPin>, |
| 657 | ch2: impl Peripheral<P = impl GpioPin> + 'd, | 623 | ch2: Peri<'d, impl GpioPin>, |
| 658 | ch3: impl Peripheral<P = impl GpioPin> + 'd, | 624 | ch3: Peri<'d, impl GpioPin>, |
| 659 | ) -> Self { | 625 | ) -> Self { |
| 660 | unsafe { | 626 | unsafe { |
| 661 | into_ref!(ch0, ch1, ch2, ch3); | ||
| 662 | Self::new_inner( | 627 | Self::new_inner( |
| 663 | pwm, | 628 | pwm, |
| 664 | Some(ch0.map_into()), | 629 | Some(ch0.into()), |
| 665 | Some(ch1.map_into()), | 630 | Some(ch1.into()), |
| 666 | Some(ch2.map_into()), | 631 | Some(ch2.into()), |
| 667 | Some(ch3.map_into()), | 632 | Some(ch3.into()), |
| 668 | ) | 633 | ) |
| 669 | } | 634 | } |
| 670 | } | 635 | } |
| 671 | 636 | ||
| 672 | fn new_inner( | 637 | fn new_inner( |
| 673 | _pwm: impl Peripheral<P = T> + 'd, | 638 | _pwm: Peri<'d, T>, |
| 674 | ch0: Option<PeripheralRef<'d, AnyPin>>, | 639 | ch0: Option<Peri<'d, AnyPin>>, |
| 675 | ch1: Option<PeripheralRef<'d, AnyPin>>, | 640 | ch1: Option<Peri<'d, AnyPin>>, |
| 676 | ch2: Option<PeripheralRef<'d, AnyPin>>, | 641 | ch2: Option<Peri<'d, AnyPin>>, |
| 677 | ch3: Option<PeripheralRef<'d, AnyPin>>, | 642 | ch3: Option<Peri<'d, AnyPin>>, |
| 678 | ) -> Self { | 643 | ) -> Self { |
| 679 | into_ref!(_pwm); | ||
| 680 | |||
| 681 | let r = T::regs(); | 644 | let r = T::regs(); |
| 682 | 645 | ||
| 683 | for (i, ch) in [&ch0, &ch1, &ch2, &ch3].into_iter().enumerate() { | 646 | for (i, ch) in [&ch0, &ch1, &ch2, &ch3].into_iter().enumerate() { |
| @@ -896,7 +859,7 @@ pub(crate) trait SealedInstance { | |||
| 896 | 859 | ||
| 897 | /// PWM peripheral instance. | 860 | /// PWM peripheral instance. |
| 898 | #[allow(private_bounds)] | 861 | #[allow(private_bounds)] |
| 899 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static { | 862 | pub trait Instance: SealedInstance + PeripheralType + 'static { |
| 900 | /// Interrupt for this peripheral. | 863 | /// Interrupt for this peripheral. |
| 901 | type Interrupt: interrupt::typelevel::Interrupt; | 864 | type Interrupt: interrupt::typelevel::Interrupt; |
| 902 | } | 865 | } |
diff --git a/embassy-nrf/src/qdec.rs b/embassy-nrf/src/qdec.rs index efd2a134c..69bfab0bb 100644 --- a/embassy-nrf/src/qdec.rs +++ b/embassy-nrf/src/qdec.rs | |||
| @@ -6,18 +6,18 @@ use core::future::poll_fn; | |||
| 6 | use core::marker::PhantomData; | 6 | use core::marker::PhantomData; |
| 7 | use core::task::Poll; | 7 | use core::task::Poll; |
| 8 | 8 | ||
| 9 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 9 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 10 | use embassy_sync::waitqueue::AtomicWaker; | 10 | use embassy_sync::waitqueue::AtomicWaker; |
| 11 | 11 | ||
| 12 | use crate::gpio::{AnyPin, Pin as GpioPin, SealedPin as _}; | 12 | use crate::gpio::{AnyPin, Pin as GpioPin, SealedPin as _}; |
| 13 | use crate::interrupt::typelevel::Interrupt; | 13 | use crate::interrupt::typelevel::Interrupt; |
| 14 | use crate::pac::gpio::vals as gpiovals; | 14 | use crate::pac::gpio::vals as gpiovals; |
| 15 | use crate::pac::qdec::vals; | 15 | use crate::pac::qdec::vals; |
| 16 | use crate::{interrupt, pac, Peripheral}; | 16 | use crate::{interrupt, pac}; |
| 17 | 17 | ||
| 18 | /// Quadrature decoder driver. | 18 | /// Quadrature decoder driver. |
| 19 | pub struct Qdec<'d, T: Instance> { | 19 | pub struct Qdec<'d, T: Instance> { |
| 20 | _p: PeripheralRef<'d, T>, | 20 | _p: Peri<'d, T>, |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | /// QDEC config | 23 | /// QDEC config |
| @@ -62,34 +62,32 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 62 | impl<'d, T: Instance> Qdec<'d, T> { | 62 | impl<'d, T: Instance> Qdec<'d, T> { |
| 63 | /// Create a new QDEC. | 63 | /// Create a new QDEC. |
| 64 | pub fn new( | 64 | pub fn new( |
| 65 | qdec: impl Peripheral<P = T> + 'd, | 65 | qdec: Peri<'d, T>, |
| 66 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 66 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 67 | a: impl Peripheral<P = impl GpioPin> + 'd, | 67 | a: Peri<'d, impl GpioPin>, |
| 68 | b: impl Peripheral<P = impl GpioPin> + 'd, | 68 | b: Peri<'d, impl GpioPin>, |
| 69 | config: Config, | 69 | config: Config, |
| 70 | ) -> Self { | 70 | ) -> Self { |
| 71 | into_ref!(qdec, a, b); | 71 | Self::new_inner(qdec, a.into(), b.into(), None, config) |
| 72 | Self::new_inner(qdec, a.map_into(), b.map_into(), None, config) | ||
| 73 | } | 72 | } |
| 74 | 73 | ||
| 75 | /// Create a new QDEC, with a pin for LED output. | 74 | /// Create a new QDEC, with a pin for LED output. |
| 76 | pub fn new_with_led( | 75 | pub fn new_with_led( |
| 77 | qdec: impl Peripheral<P = T> + 'd, | 76 | qdec: Peri<'d, T>, |
| 78 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 77 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 79 | a: impl Peripheral<P = impl GpioPin> + 'd, | 78 | a: Peri<'d, impl GpioPin>, |
| 80 | b: impl Peripheral<P = impl GpioPin> + 'd, | 79 | b: Peri<'d, impl GpioPin>, |
| 81 | led: impl Peripheral<P = impl GpioPin> + 'd, | 80 | led: Peri<'d, impl GpioPin>, |
| 82 | config: Config, | 81 | config: Config, |
| 83 | ) -> Self { | 82 | ) -> Self { |
| 84 | into_ref!(qdec, a, b, led); | 83 | Self::new_inner(qdec, a.into(), b.into(), Some(led.into()), config) |
| 85 | Self::new_inner(qdec, a.map_into(), b.map_into(), Some(led.map_into()), config) | ||
| 86 | } | 84 | } |
| 87 | 85 | ||
| 88 | fn new_inner( | 86 | fn new_inner( |
| 89 | p: PeripheralRef<'d, T>, | 87 | p: Peri<'d, T>, |
| 90 | a: PeripheralRef<'d, AnyPin>, | 88 | a: Peri<'d, AnyPin>, |
| 91 | b: PeripheralRef<'d, AnyPin>, | 89 | b: Peri<'d, AnyPin>, |
| 92 | led: Option<PeripheralRef<'d, AnyPin>>, | 90 | led: Option<Peri<'d, AnyPin>>, |
| 93 | config: Config, | 91 | config: Config, |
| 94 | ) -> Self { | 92 | ) -> Self { |
| 95 | let r = T::regs(); | 93 | let r = T::regs(); |
| @@ -272,7 +270,7 @@ pub(crate) trait SealedInstance { | |||
| 272 | 270 | ||
| 273 | /// qdec peripheral instance. | 271 | /// qdec peripheral instance. |
| 274 | #[allow(private_bounds)] | 272 | #[allow(private_bounds)] |
| 275 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | 273 | pub trait Instance: SealedInstance + PeripheralType + 'static + Send { |
| 276 | /// Interrupt for this peripheral. | 274 | /// Interrupt for this peripheral. |
| 277 | type Interrupt: interrupt::typelevel::Interrupt; | 275 | type Interrupt: interrupt::typelevel::Interrupt; |
| 278 | } | 276 | } |
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index 17e127700..e6e829f6e 100755 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs | |||
| @@ -8,7 +8,7 @@ use core::ptr; | |||
| 8 | use core::task::Poll; | 8 | use core::task::Poll; |
| 9 | 9 | ||
| 10 | use embassy_hal_internal::drop::OnDrop; | 10 | use embassy_hal_internal::drop::OnDrop; |
| 11 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 11 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 12 | use embassy_sync::waitqueue::AtomicWaker; | 12 | use embassy_sync::waitqueue::AtomicWaker; |
| 13 | use embedded_storage::nor_flash::{ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash}; | 13 | use embedded_storage::nor_flash::{ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash}; |
| 14 | 14 | ||
| @@ -19,7 +19,7 @@ use crate::pac::qspi::vals; | |||
| 19 | pub use crate::pac::qspi::vals::{ | 19 | pub use crate::pac::qspi::vals::{ |
| 20 | Addrmode as AddressMode, Ppsize as WritePageSize, Readoc as ReadOpcode, Spimode as SpiMode, Writeoc as WriteOpcode, | 20 | Addrmode as AddressMode, Ppsize as WritePageSize, Readoc as ReadOpcode, Spimode as SpiMode, Writeoc as WriteOpcode, |
| 21 | }; | 21 | }; |
| 22 | use crate::{interrupt, pac, Peripheral}; | 22 | use crate::{interrupt, pac}; |
| 23 | 23 | ||
| 24 | /// Deep power-down config. | 24 | /// Deep power-down config. |
| 25 | pub struct DeepPowerDownConfig { | 25 | pub struct DeepPowerDownConfig { |
| @@ -139,7 +139,7 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 139 | 139 | ||
| 140 | /// QSPI flash driver. | 140 | /// QSPI flash driver. |
| 141 | pub struct Qspi<'d, T: Instance> { | 141 | pub struct Qspi<'d, T: Instance> { |
| 142 | _peri: PeripheralRef<'d, T>, | 142 | _peri: Peri<'d, T>, |
| 143 | dpm_enabled: bool, | 143 | dpm_enabled: bool, |
| 144 | capacity: u32, | 144 | capacity: u32, |
| 145 | } | 145 | } |
| @@ -147,18 +147,16 @@ pub struct Qspi<'d, T: Instance> { | |||
| 147 | impl<'d, T: Instance> Qspi<'d, T> { | 147 | impl<'d, T: Instance> Qspi<'d, T> { |
| 148 | /// Create a new QSPI driver. | 148 | /// Create a new QSPI driver. |
| 149 | pub fn new( | 149 | pub fn new( |
| 150 | qspi: impl Peripheral<P = T> + 'd, | 150 | qspi: Peri<'d, T>, |
| 151 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 151 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 152 | sck: impl Peripheral<P = impl GpioPin> + 'd, | 152 | sck: Peri<'d, impl GpioPin>, |
| 153 | csn: impl Peripheral<P = impl GpioPin> + 'd, | 153 | csn: Peri<'d, impl GpioPin>, |
| 154 | io0: impl Peripheral<P = impl GpioPin> + 'd, | 154 | io0: Peri<'d, impl GpioPin>, |
| 155 | io1: impl Peripheral<P = impl GpioPin> + 'd, | 155 | io1: Peri<'d, impl GpioPin>, |
| 156 | io2: impl Peripheral<P = impl GpioPin> + 'd, | 156 | io2: Peri<'d, impl GpioPin>, |
| 157 | io3: impl Peripheral<P = impl GpioPin> + 'd, | 157 | io3: Peri<'d, impl GpioPin>, |
| 158 | config: Config, | 158 | config: Config, |
| 159 | ) -> Self { | 159 | ) -> Self { |
| 160 | into_ref!(qspi, sck, csn, io0, io1, io2, io3); | ||
| 161 | |||
| 162 | let r = T::regs(); | 160 | let r = T::regs(); |
| 163 | 161 | ||
| 164 | macro_rules! config_pin { | 162 | macro_rules! config_pin { |
| @@ -664,7 +662,7 @@ pub(crate) trait SealedInstance { | |||
| 664 | 662 | ||
| 665 | /// QSPI peripheral instance. | 663 | /// QSPI peripheral instance. |
| 666 | #[allow(private_bounds)] | 664 | #[allow(private_bounds)] |
| 667 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | 665 | pub trait Instance: SealedInstance + PeripheralType + 'static + Send { |
| 668 | /// Interrupt for this peripheral. | 666 | /// Interrupt for this peripheral. |
| 669 | type Interrupt: interrupt::typelevel::Interrupt; | 667 | type Interrupt: interrupt::typelevel::Interrupt; |
| 670 | } | 668 | } |
diff --git a/embassy-nrf/src/radio/ble.rs b/embassy-nrf/src/radio/ble.rs index 682ca1c79..d42bbe5f6 100644 --- a/embassy-nrf/src/radio/ble.rs +++ b/embassy-nrf/src/radio/ble.rs | |||
| @@ -5,7 +5,6 @@ use core::sync::atomic::{compiler_fence, Ordering}; | |||
| 5 | use core::task::Poll; | 5 | use core::task::Poll; |
| 6 | 6 | ||
| 7 | use embassy_hal_internal::drop::OnDrop; | 7 | use embassy_hal_internal::drop::OnDrop; |
| 8 | use embassy_hal_internal::{into_ref, PeripheralRef}; | ||
| 9 | pub use pac::radio::vals::Mode; | 8 | pub use pac::radio::vals::Mode; |
| 10 | #[cfg(not(feature = "_nrf51"))] | 9 | #[cfg(not(feature = "_nrf51"))] |
| 11 | use pac::radio::vals::Plen as PreambleLength; | 10 | use pac::radio::vals::Plen as PreambleLength; |
| @@ -15,20 +14,19 @@ use crate::pac::radio::vals; | |||
| 15 | use crate::radio::*; | 14 | use crate::radio::*; |
| 16 | pub use crate::radio::{Error, TxPower}; | 15 | pub use crate::radio::{Error, TxPower}; |
| 17 | use crate::util::slice_in_ram_or; | 16 | use crate::util::slice_in_ram_or; |
| 17 | use crate::Peri; | ||
| 18 | 18 | ||
| 19 | /// Radio driver. | 19 | /// Radio driver. |
| 20 | pub struct Radio<'d, T: Instance> { | 20 | pub struct Radio<'d, T: Instance> { |
| 21 | _p: PeripheralRef<'d, T>, | 21 | _p: Peri<'d, T>, |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | impl<'d, T: Instance> Radio<'d, T> { | 24 | impl<'d, T: Instance> Radio<'d, T> { |
| 25 | /// Create a new radio driver. | 25 | /// Create a new radio driver. |
| 26 | pub fn new( | 26 | pub fn new( |
| 27 | radio: impl Peripheral<P = T> + 'd, | 27 | radio: Peri<'d, T>, |
| 28 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 28 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 29 | ) -> Self { | 29 | ) -> Self { |
| 30 | into_ref!(radio); | ||
| 31 | |||
| 32 | let r = T::regs(); | 30 | let r = T::regs(); |
| 33 | 31 | ||
| 34 | r.pcnf1().write(|w| { | 32 | r.pcnf1().write(|w| { |
diff --git a/embassy-nrf/src/radio/ieee802154.rs b/embassy-nrf/src/radio/ieee802154.rs index 083842f4a..2f0bcbe04 100644 --- a/embassy-nrf/src/radio/ieee802154.rs +++ b/embassy-nrf/src/radio/ieee802154.rs | |||
| @@ -4,13 +4,12 @@ use core::sync::atomic::{compiler_fence, Ordering}; | |||
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | 5 | ||
| 6 | use embassy_hal_internal::drop::OnDrop; | 6 | use embassy_hal_internal::drop::OnDrop; |
| 7 | use embassy_hal_internal::{into_ref, PeripheralRef}; | ||
| 8 | 7 | ||
| 9 | use super::{state, Error, Instance, InterruptHandler, RadioState, TxPower}; | 8 | use super::{state, Error, Instance, InterruptHandler, RadioState, TxPower}; |
| 10 | use crate::interrupt::typelevel::Interrupt; | 9 | use crate::interrupt::typelevel::Interrupt; |
| 11 | use crate::interrupt::{self}; | 10 | use crate::interrupt::{self}; |
| 12 | use crate::pac::radio::vals; | 11 | use crate::pac::radio::vals; |
| 13 | use crate::Peripheral; | 12 | use crate::Peri; |
| 14 | 13 | ||
| 15 | /// Default (IEEE compliant) Start of Frame Delimiter | 14 | /// Default (IEEE compliant) Start of Frame Delimiter |
| 16 | pub const DEFAULT_SFD: u8 = 0xA7; | 15 | pub const DEFAULT_SFD: u8 = 0xA7; |
| @@ -33,18 +32,16 @@ pub enum Cca { | |||
| 33 | 32 | ||
| 34 | /// IEEE 802.15.4 radio driver. | 33 | /// IEEE 802.15.4 radio driver. |
| 35 | pub struct Radio<'d, T: Instance> { | 34 | pub struct Radio<'d, T: Instance> { |
| 36 | _p: PeripheralRef<'d, T>, | 35 | _p: Peri<'d, T>, |
| 37 | needs_enable: bool, | 36 | needs_enable: bool, |
| 38 | } | 37 | } |
| 39 | 38 | ||
| 40 | impl<'d, T: Instance> Radio<'d, T> { | 39 | impl<'d, T: Instance> Radio<'d, T> { |
| 41 | /// Create a new IEEE 802.15.4 radio driver. | 40 | /// Create a new IEEE 802.15.4 radio driver. |
| 42 | pub fn new( | 41 | pub fn new( |
| 43 | radio: impl Peripheral<P = T> + 'd, | 42 | radio: Peri<'d, T>, |
| 44 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 43 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 45 | ) -> Self { | 44 | ) -> Self { |
| 46 | into_ref!(radio); | ||
| 47 | |||
| 48 | let r = T::regs(); | 45 | let r = T::regs(); |
| 49 | 46 | ||
| 50 | // Disable and enable to reset peripheral | 47 | // Disable and enable to reset peripheral |
diff --git a/embassy-nrf/src/radio/mod.rs b/embassy-nrf/src/radio/mod.rs index 251f37d3d..982436266 100644 --- a/embassy-nrf/src/radio/mod.rs +++ b/embassy-nrf/src/radio/mod.rs | |||
| @@ -19,11 +19,12 @@ pub mod ieee802154; | |||
| 19 | 19 | ||
| 20 | use core::marker::PhantomData; | 20 | use core::marker::PhantomData; |
| 21 | 21 | ||
| 22 | use embassy_hal_internal::PeripheralType; | ||
| 22 | use embassy_sync::waitqueue::AtomicWaker; | 23 | use embassy_sync::waitqueue::AtomicWaker; |
| 23 | use pac::radio::vals::State as RadioState; | 24 | use pac::radio::vals::State as RadioState; |
| 24 | pub use pac::radio::vals::Txpower as TxPower; | 25 | pub use pac::radio::vals::Txpower as TxPower; |
| 25 | 26 | ||
| 26 | use crate::{interrupt, pac, Peripheral}; | 27 | use crate::{interrupt, pac}; |
| 27 | 28 | ||
| 28 | /// RADIO error. | 29 | /// RADIO error. |
| 29 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 30 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| @@ -94,7 +95,7 @@ macro_rules! impl_radio { | |||
| 94 | 95 | ||
| 95 | /// Radio peripheral instance. | 96 | /// Radio peripheral instance. |
| 96 | #[allow(private_bounds)] | 97 | #[allow(private_bounds)] |
| 97 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | 98 | pub trait Instance: SealedInstance + PeripheralType + 'static + Send { |
| 98 | /// Interrupt for this peripheral. | 99 | /// Interrupt for this peripheral. |
| 99 | type Interrupt: interrupt::typelevel::Interrupt; | 100 | type Interrupt: interrupt::typelevel::Interrupt; |
| 100 | } | 101 | } |
diff --git a/embassy-nrf/src/rng.rs b/embassy-nrf/src/rng.rs index 7a98ab2fb..e75ffda00 100644 --- a/embassy-nrf/src/rng.rs +++ b/embassy-nrf/src/rng.rs | |||
| @@ -10,11 +10,11 @@ use core::task::Poll; | |||
| 10 | 10 | ||
| 11 | use critical_section::{CriticalSection, Mutex}; | 11 | use critical_section::{CriticalSection, Mutex}; |
| 12 | use embassy_hal_internal::drop::OnDrop; | 12 | use embassy_hal_internal::drop::OnDrop; |
| 13 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 13 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 14 | use embassy_sync::waitqueue::WakerRegistration; | 14 | use embassy_sync::waitqueue::WakerRegistration; |
| 15 | 15 | ||
| 16 | use crate::interrupt::typelevel::Interrupt; | 16 | use crate::interrupt::typelevel::Interrupt; |
| 17 | use crate::{interrupt, pac, Peripheral}; | 17 | use crate::{interrupt, pac}; |
| 18 | 18 | ||
| 19 | /// Interrupt handler. | 19 | /// Interrupt handler. |
| 20 | pub struct InterruptHandler<T: Instance> { | 20 | pub struct InterruptHandler<T: Instance> { |
| @@ -56,7 +56,7 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 56 | /// | 56 | /// |
| 57 | /// It has a non-blocking API, and a blocking api through `rand`. | 57 | /// It has a non-blocking API, and a blocking api through `rand`. |
| 58 | pub struct Rng<'d, T: Instance> { | 58 | pub struct Rng<'d, T: Instance> { |
| 59 | _peri: PeripheralRef<'d, T>, | 59 | _peri: Peri<'d, T>, |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | impl<'d, T: Instance> Rng<'d, T> { | 62 | impl<'d, T: Instance> Rng<'d, T> { |
| @@ -67,11 +67,9 @@ impl<'d, T: Instance> Rng<'d, T> { | |||
| 67 | /// | 67 | /// |
| 68 | /// The synchronous API is safe. | 68 | /// The synchronous API is safe. |
| 69 | pub fn new( | 69 | pub fn new( |
| 70 | rng: impl Peripheral<P = T> + 'd, | 70 | rng: Peri<'d, T>, |
| 71 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 71 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 72 | ) -> Self { | 72 | ) -> Self { |
| 73 | into_ref!(rng); | ||
| 74 | |||
| 75 | let this = Self { _peri: rng }; | 73 | let this = Self { _peri: rng }; |
| 76 | 74 | ||
| 77 | this.stop(); | 75 | this.stop(); |
| @@ -250,7 +248,7 @@ pub(crate) trait SealedInstance { | |||
| 250 | 248 | ||
| 251 | /// RNG peripheral instance. | 249 | /// RNG peripheral instance. |
| 252 | #[allow(private_bounds)] | 250 | #[allow(private_bounds)] |
| 253 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | 251 | pub trait Instance: SealedInstance + PeripheralType + 'static + Send { |
| 254 | /// Interrupt for this peripheral. | 252 | /// Interrupt for this peripheral. |
| 255 | type Interrupt: interrupt::typelevel::Interrupt; | 253 | type Interrupt: interrupt::typelevel::Interrupt; |
| 256 | } | 254 | } |
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 00e2b7402..92b6fb01f 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs | |||
| @@ -3,11 +3,12 @@ | |||
| 3 | #![macro_use] | 3 | #![macro_use] |
| 4 | 4 | ||
| 5 | use core::future::poll_fn; | 5 | use core::future::poll_fn; |
| 6 | use core::marker::PhantomData; | ||
| 6 | use core::sync::atomic::{compiler_fence, Ordering}; | 7 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 7 | use core::task::Poll; | 8 | use core::task::Poll; |
| 8 | 9 | ||
| 9 | use embassy_hal_internal::drop::OnDrop; | 10 | use embassy_hal_internal::drop::OnDrop; |
| 10 | use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; | 11 | use embassy_hal_internal::{impl_peripheral, Peri}; |
| 11 | use embassy_sync::waitqueue::AtomicWaker; | 12 | use embassy_sync::waitqueue::AtomicWaker; |
| 12 | pub(crate) use vals::Psel as InputChannel; | 13 | pub(crate) use vals::Psel as InputChannel; |
| 13 | 14 | ||
| @@ -15,7 +16,7 @@ use crate::interrupt::InterruptExt; | |||
| 15 | use crate::pac::saadc::vals; | 16 | use crate::pac::saadc::vals; |
| 16 | use crate::ppi::{ConfigurableChannel, Event, Ppi, Task}; | 17 | use crate::ppi::{ConfigurableChannel, Event, Ppi, Task}; |
| 17 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; | 18 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; |
| 18 | use crate::{interrupt, pac, peripherals, Peripheral}; | 19 | use crate::{interrupt, pac, peripherals}; |
| 19 | 20 | ||
| 20 | /// SAADC error | 21 | /// SAADC error |
| 21 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 22 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| @@ -87,37 +88,32 @@ pub struct ChannelConfig<'d> { | |||
| 87 | /// Acquisition time in microseconds. | 88 | /// Acquisition time in microseconds. |
| 88 | pub time: Time, | 89 | pub time: Time, |
| 89 | /// Positive channel to sample | 90 | /// Positive channel to sample |
| 90 | p_channel: PeripheralRef<'d, AnyInput>, | 91 | p_channel: AnyInput<'d>, |
| 91 | /// An optional negative channel to sample | 92 | /// An optional negative channel to sample |
| 92 | n_channel: Option<PeripheralRef<'d, AnyInput>>, | 93 | n_channel: Option<AnyInput<'d>>, |
| 93 | } | 94 | } |
| 94 | 95 | ||
| 95 | impl<'d> ChannelConfig<'d> { | 96 | impl<'d> ChannelConfig<'d> { |
| 96 | /// Default configuration for single ended channel sampling. | 97 | /// Default configuration for single ended channel sampling. |
| 97 | pub fn single_ended(input: impl Peripheral<P = impl Input> + 'd) -> Self { | 98 | pub fn single_ended(input: impl Input + 'd) -> Self { |
| 98 | into_ref!(input); | ||
| 99 | Self { | 99 | Self { |
| 100 | reference: Reference::INTERNAL, | 100 | reference: Reference::INTERNAL, |
| 101 | gain: Gain::GAIN1_6, | 101 | gain: Gain::GAIN1_6, |
| 102 | resistor: Resistor::BYPASS, | 102 | resistor: Resistor::BYPASS, |
| 103 | time: Time::_10US, | 103 | time: Time::_10US, |
| 104 | p_channel: input.map_into(), | 104 | p_channel: input.degrade_saadc(), |
| 105 | n_channel: None, | 105 | n_channel: None, |
| 106 | } | 106 | } |
| 107 | } | 107 | } |
| 108 | /// Default configuration for differential channel sampling. | 108 | /// Default configuration for differential channel sampling. |
| 109 | pub fn differential( | 109 | pub fn differential(p_input: impl Input + 'd, n_input: impl Input + 'd) -> Self { |
| 110 | p_input: impl Peripheral<P = impl Input> + 'd, | ||
| 111 | n_input: impl Peripheral<P = impl Input> + 'd, | ||
| 112 | ) -> Self { | ||
| 113 | into_ref!(p_input, n_input); | ||
| 114 | Self { | 110 | Self { |
| 115 | reference: Reference::INTERNAL, | 111 | reference: Reference::INTERNAL, |
| 116 | gain: Gain::GAIN1_6, | 112 | gain: Gain::GAIN1_6, |
| 117 | resistor: Resistor::BYPASS, | 113 | resistor: Resistor::BYPASS, |
| 118 | time: Time::_10US, | 114 | time: Time::_10US, |
| 119 | p_channel: p_input.map_into(), | 115 | p_channel: p_input.degrade_saadc(), |
| 120 | n_channel: Some(n_input.map_into()), | 116 | n_channel: Some(n_input.degrade_saadc()), |
| 121 | } | 117 | } |
| 122 | } | 118 | } |
| 123 | } | 119 | } |
| @@ -133,19 +129,17 @@ pub enum CallbackResult { | |||
| 133 | 129 | ||
| 134 | /// One-shot and continuous SAADC. | 130 | /// One-shot and continuous SAADC. |
| 135 | pub struct Saadc<'d, const N: usize> { | 131 | pub struct Saadc<'d, const N: usize> { |
| 136 | _p: PeripheralRef<'d, peripherals::SAADC>, | 132 | _p: Peri<'d, peripherals::SAADC>, |
| 137 | } | 133 | } |
| 138 | 134 | ||
| 139 | impl<'d, const N: usize> Saadc<'d, N> { | 135 | impl<'d, const N: usize> Saadc<'d, N> { |
| 140 | /// Create a new SAADC driver. | 136 | /// Create a new SAADC driver. |
| 141 | pub fn new( | 137 | pub fn new( |
| 142 | saadc: impl Peripheral<P = peripherals::SAADC> + 'd, | 138 | saadc: Peri<'d, peripherals::SAADC>, |
| 143 | _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::SAADC, InterruptHandler> + 'd, | 139 | _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::SAADC, InterruptHandler> + 'd, |
| 144 | config: Config, | 140 | config: Config, |
| 145 | channel_configs: [ChannelConfig; N], | 141 | channel_configs: [ChannelConfig; N], |
| 146 | ) -> Self { | 142 | ) -> Self { |
| 147 | into_ref!(saadc); | ||
| 148 | |||
| 149 | let r = pac::SAADC; | 143 | let r = pac::SAADC; |
| 150 | 144 | ||
| 151 | let Config { resolution, oversample } = config; | 145 | let Config { resolution, oversample } = config; |
| @@ -284,9 +278,9 @@ impl<'d, const N: usize> Saadc<'d, N> { | |||
| 284 | 278 | ||
| 285 | pub async fn run_task_sampler<F, T: TimerInstance, const N0: usize>( | 279 | pub async fn run_task_sampler<F, T: TimerInstance, const N0: usize>( |
| 286 | &mut self, | 280 | &mut self, |
| 287 | timer: &mut T, | 281 | timer: Peri<'_, T>, |
| 288 | ppi_ch1: &mut impl ConfigurableChannel, | 282 | ppi_ch1: Peri<'_, impl ConfigurableChannel>, |
| 289 | ppi_ch2: &mut impl ConfigurableChannel, | 283 | ppi_ch2: Peri<'_, impl ConfigurableChannel>, |
| 290 | frequency: Frequency, | 284 | frequency: Frequency, |
| 291 | sample_counter: u32, | 285 | sample_counter: u32, |
| 292 | bufs: &mut [[[i16; N]; N0]; 2], | 286 | bufs: &mut [[[i16; N]; N0]; 2], |
| @@ -655,14 +649,18 @@ pub(crate) trait SealedInput { | |||
| 655 | 649 | ||
| 656 | /// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal. | 650 | /// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal. |
| 657 | #[allow(private_bounds)] | 651 | #[allow(private_bounds)] |
| 658 | pub trait Input: SealedInput + Into<AnyInput> + Peripheral<P = Self> + Sized + 'static { | 652 | pub trait Input: SealedInput + Sized { |
| 659 | /// Convert this SAADC input to a type-erased `AnyInput`. | 653 | /// Convert this SAADC input to a type-erased `AnyInput`. |
| 660 | /// | 654 | /// |
| 661 | /// This allows using several inputs in situations that might require | 655 | /// This allows using several inputs in situations that might require |
| 662 | /// them to be the same type, like putting them in an array. | 656 | /// them to be the same type, like putting them in an array. |
| 663 | fn degrade_saadc(self) -> AnyInput { | 657 | fn degrade_saadc<'a>(self) -> AnyInput<'a> |
| 658 | where | ||
| 659 | Self: 'a, | ||
| 660 | { | ||
| 664 | AnyInput { | 661 | AnyInput { |
| 665 | channel: self.channel(), | 662 | channel: self.channel(), |
| 663 | _phantom: core::marker::PhantomData, | ||
| 666 | } | 664 | } |
| 667 | } | 665 | } |
| 668 | } | 666 | } |
| @@ -671,23 +669,36 @@ pub trait Input: SealedInput + Into<AnyInput> + Peripheral<P = Self> + Sized + ' | |||
| 671 | /// | 669 | /// |
| 672 | /// This allows using several inputs in situations that might require | 670 | /// This allows using several inputs in situations that might require |
| 673 | /// them to be the same type, like putting them in an array. | 671 | /// them to be the same type, like putting them in an array. |
| 674 | pub struct AnyInput { | 672 | pub struct AnyInput<'a> { |
| 675 | channel: InputChannel, | 673 | channel: InputChannel, |
| 674 | _phantom: PhantomData<&'a ()>, | ||
| 676 | } | 675 | } |
| 677 | 676 | ||
| 678 | impl_peripheral!(AnyInput); | 677 | impl<'a> AnyInput<'a> { |
| 678 | /// Reborrow into a "child" AnyInput. | ||
| 679 | /// | ||
| 680 | /// `self` will stay borrowed until the child AnyInput is dropped. | ||
| 681 | pub fn reborrow(&mut self) -> AnyInput<'_> { | ||
| 682 | // safety: we're returning the clone inside a new Peripheral that borrows | ||
| 683 | // self, so user code can't use both at the same time. | ||
| 684 | Self { | ||
| 685 | channel: self.channel, | ||
| 686 | _phantom: PhantomData, | ||
| 687 | } | ||
| 688 | } | ||
| 689 | } | ||
| 679 | 690 | ||
| 680 | impl SealedInput for AnyInput { | 691 | impl SealedInput for AnyInput<'_> { |
| 681 | fn channel(&self) -> InputChannel { | 692 | fn channel(&self) -> InputChannel { |
| 682 | self.channel | 693 | self.channel |
| 683 | } | 694 | } |
| 684 | } | 695 | } |
| 685 | 696 | ||
| 686 | impl Input for AnyInput {} | 697 | impl Input for AnyInput<'_> {} |
| 687 | 698 | ||
| 688 | macro_rules! impl_saadc_input { | 699 | macro_rules! impl_saadc_input { |
| 689 | ($pin:ident, $ch:ident) => { | 700 | ($pin:ident, $ch:ident) => { |
| 690 | impl_saadc_input!(@local, crate::peripherals::$pin, $ch); | 701 | impl_saadc_input!(@local, crate::Peri<'_, crate::peripherals::$pin>, $ch); |
| 691 | }; | 702 | }; |
| 692 | (@local, $pin:ty, $ch:ident) => { | 703 | (@local, $pin:ty, $ch:ident) => { |
| 693 | impl crate::saadc::SealedInput for $pin { | 704 | impl crate::saadc::SealedInput for $pin { |
| @@ -696,12 +707,6 @@ macro_rules! impl_saadc_input { | |||
| 696 | } | 707 | } |
| 697 | } | 708 | } |
| 698 | impl crate::saadc::Input for $pin {} | 709 | impl crate::saadc::Input for $pin {} |
| 699 | |||
| 700 | impl From<$pin> for crate::saadc::AnyInput { | ||
| 701 | fn from(val: $pin) -> Self { | ||
| 702 | crate::saadc::Input::degrade_saadc(val) | ||
| 703 | } | ||
| 704 | } | ||
| 705 | }; | 710 | }; |
| 706 | } | 711 | } |
| 707 | 712 | ||
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index bd193cfe8..59f5b6d58 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs | |||
| @@ -10,7 +10,7 @@ use core::sync::atomic::{compiler_fence, Ordering}; | |||
| 10 | use core::task::Poll; | 10 | use core::task::Poll; |
| 11 | 11 | ||
| 12 | use embassy_embedded_hal::SetConfig; | 12 | use embassy_embedded_hal::SetConfig; |
| 13 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 13 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 14 | use embassy_sync::waitqueue::AtomicWaker; | 14 | use embassy_sync::waitqueue::AtomicWaker; |
| 15 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; | 15 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; |
| 16 | pub use pac::spim::vals::{Frequency, Order as BitOrder}; | 16 | pub use pac::spim::vals::{Frequency, Order as BitOrder}; |
| @@ -21,7 +21,7 @@ use crate::interrupt::typelevel::Interrupt; | |||
| 21 | use crate::pac::gpio::vals as gpiovals; | 21 | use crate::pac::gpio::vals as gpiovals; |
| 22 | use crate::pac::spim::vals; | 22 | use crate::pac::spim::vals; |
| 23 | use crate::util::slice_in_ram_or; | 23 | use crate::util::slice_in_ram_or; |
| 24 | use crate::{interrupt, pac, Peripheral}; | 24 | use crate::{interrupt, pac}; |
| 25 | 25 | ||
| 26 | /// SPIM error | 26 | /// SPIM error |
| 27 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 27 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| @@ -100,73 +100,61 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 100 | 100 | ||
| 101 | /// SPIM driver. | 101 | /// SPIM driver. |
| 102 | pub struct Spim<'d, T: Instance> { | 102 | pub struct Spim<'d, T: Instance> { |
| 103 | _p: PeripheralRef<'d, T>, | 103 | _p: Peri<'d, T>, |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | impl<'d, T: Instance> Spim<'d, T> { | 106 | impl<'d, T: Instance> Spim<'d, T> { |
| 107 | /// Create a new SPIM driver. | 107 | /// Create a new SPIM driver. |
| 108 | pub fn new( | 108 | pub fn new( |
| 109 | spim: impl Peripheral<P = T> + 'd, | 109 | spim: Peri<'d, T>, |
| 110 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 110 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 111 | sck: impl Peripheral<P = impl GpioPin> + 'd, | 111 | sck: Peri<'d, impl GpioPin>, |
| 112 | miso: impl Peripheral<P = impl GpioPin> + 'd, | 112 | miso: Peri<'d, impl GpioPin>, |
| 113 | mosi: impl Peripheral<P = impl GpioPin> + 'd, | 113 | mosi: Peri<'d, impl GpioPin>, |
| 114 | config: Config, | 114 | config: Config, |
| 115 | ) -> Self { | 115 | ) -> Self { |
| 116 | into_ref!(sck, miso, mosi); | 116 | Self::new_inner(spim, Some(sck.into()), Some(miso.into()), Some(mosi.into()), config) |
| 117 | Self::new_inner( | ||
| 118 | spim, | ||
| 119 | Some(sck.map_into()), | ||
| 120 | Some(miso.map_into()), | ||
| 121 | Some(mosi.map_into()), | ||
| 122 | config, | ||
| 123 | ) | ||
| 124 | } | 117 | } |
| 125 | 118 | ||
| 126 | /// Create a new SPIM driver, capable of TX only (MOSI only). | 119 | /// Create a new SPIM driver, capable of TX only (MOSI only). |
| 127 | pub fn new_txonly( | 120 | pub fn new_txonly( |
| 128 | spim: impl Peripheral<P = T> + 'd, | 121 | spim: Peri<'d, T>, |
| 129 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 122 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 130 | sck: impl Peripheral<P = impl GpioPin> + 'd, | 123 | sck: Peri<'d, impl GpioPin>, |
| 131 | mosi: impl Peripheral<P = impl GpioPin> + 'd, | 124 | mosi: Peri<'d, impl GpioPin>, |
| 132 | config: Config, | 125 | config: Config, |
| 133 | ) -> Self { | 126 | ) -> Self { |
| 134 | into_ref!(sck, mosi); | 127 | Self::new_inner(spim, Some(sck.into()), None, Some(mosi.into()), config) |
| 135 | Self::new_inner(spim, Some(sck.map_into()), None, Some(mosi.map_into()), config) | ||
| 136 | } | 128 | } |
| 137 | 129 | ||
| 138 | /// Create a new SPIM driver, capable of RX only (MISO only). | 130 | /// Create a new SPIM driver, capable of RX only (MISO only). |
| 139 | pub fn new_rxonly( | 131 | pub fn new_rxonly( |
| 140 | spim: impl Peripheral<P = T> + 'd, | 132 | spim: Peri<'d, T>, |
| 141 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 133 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 142 | sck: impl Peripheral<P = impl GpioPin> + 'd, | 134 | sck: Peri<'d, impl GpioPin>, |
| 143 | miso: impl Peripheral<P = impl GpioPin> + 'd, | 135 | miso: Peri<'d, impl GpioPin>, |
| 144 | config: Config, | 136 | config: Config, |
| 145 | ) -> Self { | 137 | ) -> Self { |
| 146 | into_ref!(sck, miso); | 138 | Self::new_inner(spim, Some(sck.into()), Some(miso.into()), None, config) |
| 147 | Self::new_inner(spim, Some(sck.map_into()), Some(miso.map_into()), None, config) | ||
| 148 | } | 139 | } |
| 149 | 140 | ||
| 150 | /// Create a new SPIM driver, capable of TX only (MOSI only), without SCK pin. | 141 | /// Create a new SPIM driver, capable of TX only (MOSI only), without SCK pin. |
| 151 | pub fn new_txonly_nosck( | 142 | pub fn new_txonly_nosck( |
| 152 | spim: impl Peripheral<P = T> + 'd, | 143 | spim: Peri<'d, T>, |
| 153 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 144 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 154 | mosi: impl Peripheral<P = impl GpioPin> + 'd, | 145 | mosi: Peri<'d, impl GpioPin>, |
| 155 | config: Config, | 146 | config: Config, |
| 156 | ) -> Self { | 147 | ) -> Self { |
| 157 | into_ref!(mosi); | 148 | Self::new_inner(spim, None, None, Some(mosi.into()), config) |
| 158 | Self::new_inner(spim, None, None, Some(mosi.map_into()), config) | ||
| 159 | } | 149 | } |
| 160 | 150 | ||
| 161 | fn new_inner( | 151 | fn new_inner( |
| 162 | spim: impl Peripheral<P = T> + 'd, | 152 | spim: Peri<'d, T>, |
| 163 | sck: Option<PeripheralRef<'d, AnyPin>>, | 153 | sck: Option<Peri<'d, AnyPin>>, |
| 164 | miso: Option<PeripheralRef<'d, AnyPin>>, | 154 | miso: Option<Peri<'d, AnyPin>>, |
| 165 | mosi: Option<PeripheralRef<'d, AnyPin>>, | 155 | mosi: Option<Peri<'d, AnyPin>>, |
| 166 | config: Config, | 156 | config: Config, |
| 167 | ) -> Self { | 157 | ) -> Self { |
| 168 | into_ref!(spim); | ||
| 169 | |||
| 170 | let r = T::regs(); | 158 | let r = T::regs(); |
| 171 | 159 | ||
| 172 | // Configure pins | 160 | // Configure pins |
| @@ -511,7 +499,7 @@ pub(crate) trait SealedInstance { | |||
| 511 | 499 | ||
| 512 | /// SPIM peripheral instance | 500 | /// SPIM peripheral instance |
| 513 | #[allow(private_bounds)] | 501 | #[allow(private_bounds)] |
| 514 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static { | 502 | pub trait Instance: SealedInstance + PeripheralType + 'static { |
| 515 | /// Interrupt for this peripheral. | 503 | /// Interrupt for this peripheral. |
| 516 | type Interrupt: interrupt::typelevel::Interrupt; | 504 | type Interrupt: interrupt::typelevel::Interrupt; |
| 517 | } | 505 | } |
diff --git a/embassy-nrf/src/spis.rs b/embassy-nrf/src/spis.rs index 88230fa26..2a3928d25 100644 --- a/embassy-nrf/src/spis.rs +++ b/embassy-nrf/src/spis.rs | |||
| @@ -7,7 +7,7 @@ use core::sync::atomic::{compiler_fence, Ordering}; | |||
| 7 | use core::task::Poll; | 7 | use core::task::Poll; |
| 8 | 8 | ||
| 9 | use embassy_embedded_hal::SetConfig; | 9 | use embassy_embedded_hal::SetConfig; |
| 10 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 10 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 11 | use embassy_sync::waitqueue::AtomicWaker; | 11 | use embassy_sync::waitqueue::AtomicWaker; |
| 12 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; | 12 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; |
| 13 | pub use pac::spis::vals::Order as BitOrder; | 13 | pub use pac::spis::vals::Order as BitOrder; |
| @@ -18,7 +18,7 @@ use crate::interrupt::typelevel::Interrupt; | |||
| 18 | use crate::pac::gpio::vals as gpiovals; | 18 | use crate::pac::gpio::vals as gpiovals; |
| 19 | use crate::pac::spis::vals; | 19 | use crate::pac::spis::vals; |
| 20 | use crate::util::slice_in_ram_or; | 20 | use crate::util::slice_in_ram_or; |
| 21 | use crate::{interrupt, pac, Peripheral}; | 21 | use crate::{interrupt, pac}; |
| 22 | 22 | ||
| 23 | /// SPIS error | 23 | /// SPIS error |
| 24 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 24 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| @@ -98,95 +98,75 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 98 | 98 | ||
| 99 | /// SPIS driver. | 99 | /// SPIS driver. |
| 100 | pub struct Spis<'d, T: Instance> { | 100 | pub struct Spis<'d, T: Instance> { |
| 101 | _p: PeripheralRef<'d, T>, | 101 | _p: Peri<'d, T>, |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | impl<'d, T: Instance> Spis<'d, T> { | 104 | impl<'d, T: Instance> Spis<'d, T> { |
| 105 | /// Create a new SPIS driver. | 105 | /// Create a new SPIS driver. |
| 106 | pub fn new( | 106 | pub fn new( |
| 107 | spis: impl Peripheral<P = T> + 'd, | 107 | spis: Peri<'d, T>, |
| 108 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 108 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 109 | cs: impl Peripheral<P = impl GpioPin> + 'd, | 109 | cs: Peri<'d, impl GpioPin>, |
| 110 | sck: impl Peripheral<P = impl GpioPin> + 'd, | 110 | sck: Peri<'d, impl GpioPin>, |
| 111 | miso: impl Peripheral<P = impl GpioPin> + 'd, | 111 | miso: Peri<'d, impl GpioPin>, |
| 112 | mosi: impl Peripheral<P = impl GpioPin> + 'd, | 112 | mosi: Peri<'d, impl GpioPin>, |
| 113 | config: Config, | 113 | config: Config, |
| 114 | ) -> Self { | 114 | ) -> Self { |
| 115 | into_ref!(cs, sck, miso, mosi); | ||
| 116 | Self::new_inner( | 115 | Self::new_inner( |
| 117 | spis, | 116 | spis, |
| 118 | cs.map_into(), | 117 | cs.into(), |
| 119 | Some(sck.map_into()), | 118 | Some(sck.into()), |
| 120 | Some(miso.map_into()), | 119 | Some(miso.into()), |
| 121 | Some(mosi.map_into()), | 120 | Some(mosi.into()), |
| 122 | config, | 121 | config, |
| 123 | ) | 122 | ) |
| 124 | } | 123 | } |
| 125 | 124 | ||
| 126 | /// Create a new SPIS driver, capable of TX only (MISO only). | 125 | /// Create a new SPIS driver, capable of TX only (MISO only). |
| 127 | pub fn new_txonly( | 126 | pub fn new_txonly( |
| 128 | spis: impl Peripheral<P = T> + 'd, | 127 | spis: Peri<'d, T>, |
| 129 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 128 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 130 | cs: impl Peripheral<P = impl GpioPin> + 'd, | 129 | cs: Peri<'d, impl GpioPin>, |
| 131 | sck: impl Peripheral<P = impl GpioPin> + 'd, | 130 | sck: Peri<'d, impl GpioPin>, |
| 132 | miso: impl Peripheral<P = impl GpioPin> + 'd, | 131 | miso: Peri<'d, impl GpioPin>, |
| 133 | config: Config, | 132 | config: Config, |
| 134 | ) -> Self { | 133 | ) -> Self { |
| 135 | into_ref!(cs, sck, miso); | 134 | Self::new_inner(spis, cs.into(), Some(sck.into()), Some(miso.into()), None, config) |
| 136 | Self::new_inner( | ||
| 137 | spis, | ||
| 138 | cs.map_into(), | ||
| 139 | Some(sck.map_into()), | ||
| 140 | Some(miso.map_into()), | ||
| 141 | None, | ||
| 142 | config, | ||
| 143 | ) | ||
| 144 | } | 135 | } |
| 145 | 136 | ||
| 146 | /// Create a new SPIS driver, capable of RX only (MOSI only). | 137 | /// Create a new SPIS driver, capable of RX only (MOSI only). |
| 147 | pub fn new_rxonly( | 138 | pub fn new_rxonly( |
| 148 | spis: impl Peripheral<P = T> + 'd, | 139 | spis: Peri<'d, T>, |
| 149 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 140 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 150 | cs: impl Peripheral<P = impl GpioPin> + 'd, | 141 | cs: Peri<'d, impl GpioPin>, |
| 151 | sck: impl Peripheral<P = impl GpioPin> + 'd, | 142 | sck: Peri<'d, impl GpioPin>, |
| 152 | mosi: impl Peripheral<P = impl GpioPin> + 'd, | 143 | mosi: Peri<'d, impl GpioPin>, |
| 153 | config: Config, | 144 | config: Config, |
| 154 | ) -> Self { | 145 | ) -> Self { |
| 155 | into_ref!(cs, sck, mosi); | 146 | Self::new_inner(spis, cs.into(), Some(sck.into()), None, Some(mosi.into()), config) |
| 156 | Self::new_inner( | ||
| 157 | spis, | ||
| 158 | cs.map_into(), | ||
| 159 | Some(sck.map_into()), | ||
| 160 | None, | ||
| 161 | Some(mosi.map_into()), | ||
| 162 | config, | ||
| 163 | ) | ||
| 164 | } | 147 | } |
| 165 | 148 | ||
| 166 | /// Create a new SPIS driver, capable of TX only (MISO only) without SCK pin. | 149 | /// Create a new SPIS driver, capable of TX only (MISO only) without SCK pin. |
| 167 | pub fn new_txonly_nosck( | 150 | pub fn new_txonly_nosck( |
| 168 | spis: impl Peripheral<P = T> + 'd, | 151 | spis: Peri<'d, T>, |
| 169 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 152 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 170 | cs: impl Peripheral<P = impl GpioPin> + 'd, | 153 | cs: Peri<'d, impl GpioPin>, |
| 171 | miso: impl Peripheral<P = impl GpioPin> + 'd, | 154 | miso: Peri<'d, impl GpioPin>, |
| 172 | config: Config, | 155 | config: Config, |
| 173 | ) -> Self { | 156 | ) -> Self { |
| 174 | into_ref!(cs, miso); | 157 | Self::new_inner(spis, cs.into(), None, Some(miso.into()), None, config) |
| 175 | Self::new_inner(spis, cs.map_into(), None, Some(miso.map_into()), None, config) | ||
| 176 | } | 158 | } |
| 177 | 159 | ||
| 178 | fn new_inner( | 160 | fn new_inner( |
| 179 | spis: impl Peripheral<P = T> + 'd, | 161 | spis: Peri<'d, T>, |
| 180 | cs: PeripheralRef<'d, AnyPin>, | 162 | cs: Peri<'d, AnyPin>, |
| 181 | sck: Option<PeripheralRef<'d, AnyPin>>, | 163 | sck: Option<Peri<'d, AnyPin>>, |
| 182 | miso: Option<PeripheralRef<'d, AnyPin>>, | 164 | miso: Option<Peri<'d, AnyPin>>, |
| 183 | mosi: Option<PeripheralRef<'d, AnyPin>>, | 165 | mosi: Option<Peri<'d, AnyPin>>, |
| 184 | config: Config, | 166 | config: Config, |
| 185 | ) -> Self { | 167 | ) -> Self { |
| 186 | compiler_fence(Ordering::SeqCst); | 168 | compiler_fence(Ordering::SeqCst); |
| 187 | 169 | ||
| 188 | into_ref!(spis, cs); | ||
| 189 | |||
| 190 | let r = T::regs(); | 170 | let r = T::regs(); |
| 191 | 171 | ||
| 192 | // Configure pins. | 172 | // Configure pins. |
| @@ -485,7 +465,7 @@ pub(crate) trait SealedInstance { | |||
| 485 | 465 | ||
| 486 | /// SPIS peripheral instance | 466 | /// SPIS peripheral instance |
| 487 | #[allow(private_bounds)] | 467 | #[allow(private_bounds)] |
| 488 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static { | 468 | pub trait Instance: SealedInstance + PeripheralType + 'static { |
| 489 | /// Interrupt for this peripheral. | 469 | /// Interrupt for this peripheral. |
| 490 | type Interrupt: interrupt::typelevel::Interrupt; | 470 | type Interrupt: interrupt::typelevel::Interrupt; |
| 491 | } | 471 | } |
diff --git a/embassy-nrf/src/temp.rs b/embassy-nrf/src/temp.rs index 1488c5c24..44be0f6d1 100644 --- a/embassy-nrf/src/temp.rs +++ b/embassy-nrf/src/temp.rs | |||
| @@ -4,13 +4,12 @@ use core::future::poll_fn; | |||
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | 5 | ||
| 6 | use embassy_hal_internal::drop::OnDrop; | 6 | use embassy_hal_internal::drop::OnDrop; |
| 7 | use embassy_hal_internal::{into_ref, PeripheralRef}; | ||
| 8 | use embassy_sync::waitqueue::AtomicWaker; | 7 | use embassy_sync::waitqueue::AtomicWaker; |
| 9 | use fixed::types::I30F2; | 8 | use fixed::types::I30F2; |
| 10 | 9 | ||
| 11 | use crate::interrupt::InterruptExt; | 10 | use crate::interrupt::InterruptExt; |
| 12 | use crate::peripherals::TEMP; | 11 | use crate::peripherals::TEMP; |
| 13 | use crate::{interrupt, pac, Peripheral}; | 12 | use crate::{interrupt, pac, Peri}; |
| 14 | 13 | ||
| 15 | /// Interrupt handler. | 14 | /// Interrupt handler. |
| 16 | pub struct InterruptHandler { | 15 | pub struct InterruptHandler { |
| @@ -27,7 +26,7 @@ impl interrupt::typelevel::Handler<interrupt::typelevel::TEMP> for InterruptHand | |||
| 27 | 26 | ||
| 28 | /// Builtin temperature sensor driver. | 27 | /// Builtin temperature sensor driver. |
| 29 | pub struct Temp<'d> { | 28 | pub struct Temp<'d> { |
| 30 | _peri: PeripheralRef<'d, TEMP>, | 29 | _peri: Peri<'d, TEMP>, |
| 31 | } | 30 | } |
| 32 | 31 | ||
| 33 | static WAKER: AtomicWaker = AtomicWaker::new(); | 32 | static WAKER: AtomicWaker = AtomicWaker::new(); |
| @@ -35,11 +34,9 @@ static WAKER: AtomicWaker = AtomicWaker::new(); | |||
| 35 | impl<'d> Temp<'d> { | 34 | impl<'d> Temp<'d> { |
| 36 | /// Create a new temperature sensor driver. | 35 | /// Create a new temperature sensor driver. |
| 37 | pub fn new( | 36 | pub fn new( |
| 38 | _peri: impl Peripheral<P = TEMP> + 'd, | 37 | _peri: Peri<'d, TEMP>, |
| 39 | _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::TEMP, InterruptHandler> + 'd, | 38 | _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::TEMP, InterruptHandler> + 'd, |
| 40 | ) -> Self { | 39 | ) -> Self { |
| 41 | into_ref!(_peri); | ||
| 42 | |||
| 43 | // Enable interrupt that signals temperature values | 40 | // Enable interrupt that signals temperature values |
| 44 | interrupt::TEMP.unpend(); | 41 | interrupt::TEMP.unpend(); |
| 45 | unsafe { interrupt::TEMP.enable() }; | 42 | unsafe { interrupt::TEMP.enable() }; |
diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs index a9aeb40fa..5b58b0a50 100644 --- a/embassy-nrf/src/timer.rs +++ b/embassy-nrf/src/timer.rs | |||
| @@ -6,11 +6,11 @@ | |||
| 6 | 6 | ||
| 7 | #![macro_use] | 7 | #![macro_use] |
| 8 | 8 | ||
| 9 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 9 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 10 | 10 | ||
| 11 | use crate::pac; | ||
| 11 | use crate::pac::timer::vals; | 12 | use crate::pac::timer::vals; |
| 12 | use crate::ppi::{Event, Task}; | 13 | use crate::ppi::{Event, Task}; |
| 13 | use crate::{pac, Peripheral}; | ||
| 14 | 14 | ||
| 15 | pub(crate) trait SealedInstance { | 15 | pub(crate) trait SealedInstance { |
| 16 | /// The number of CC registers this instance has. | 16 | /// The number of CC registers this instance has. |
| @@ -20,7 +20,7 @@ pub(crate) trait SealedInstance { | |||
| 20 | 20 | ||
| 21 | /// Basic Timer instance. | 21 | /// Basic Timer instance. |
| 22 | #[allow(private_bounds)] | 22 | #[allow(private_bounds)] |
| 23 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | 23 | pub trait Instance: SealedInstance + PeripheralType + 'static + Send { |
| 24 | /// Interrupt for this peripheral. | 24 | /// Interrupt for this peripheral. |
| 25 | type Interrupt: crate::interrupt::typelevel::Interrupt; | 25 | type Interrupt: crate::interrupt::typelevel::Interrupt; |
| 26 | } | 26 | } |
| @@ -84,7 +84,7 @@ pub enum Frequency { | |||
| 84 | 84 | ||
| 85 | /// Timer driver. | 85 | /// Timer driver. |
| 86 | pub struct Timer<'d, T: Instance> { | 86 | pub struct Timer<'d, T: Instance> { |
| 87 | _p: PeripheralRef<'d, T>, | 87 | _p: Peri<'d, T>, |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | impl<'d, T: Instance> Timer<'d, T> { | 90 | impl<'d, T: Instance> Timer<'d, T> { |
| @@ -92,7 +92,7 @@ impl<'d, T: Instance> Timer<'d, T> { | |||
| 92 | /// | 92 | /// |
| 93 | /// This can be useful for triggering tasks via PPI | 93 | /// This can be useful for triggering tasks via PPI |
| 94 | /// `Uarte` uses this internally. | 94 | /// `Uarte` uses this internally. |
| 95 | pub fn new(timer: impl Peripheral<P = T> + 'd) -> Self { | 95 | pub fn new(timer: Peri<'d, T>) -> Self { |
| 96 | Self::new_inner(timer, false) | 96 | Self::new_inner(timer, false) |
| 97 | } | 97 | } |
| 98 | 98 | ||
| @@ -100,13 +100,11 @@ impl<'d, T: Instance> Timer<'d, T> { | |||
| 100 | /// | 100 | /// |
| 101 | /// This can be useful for triggering tasks via PPI | 101 | /// This can be useful for triggering tasks via PPI |
| 102 | /// `Uarte` uses this internally. | 102 | /// `Uarte` uses this internally. |
| 103 | pub fn new_counter(timer: impl Peripheral<P = T> + 'd) -> Self { | 103 | pub fn new_counter(timer: Peri<'d, T>) -> Self { |
| 104 | Self::new_inner(timer, true) | 104 | Self::new_inner(timer, true) |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | fn new_inner(timer: impl Peripheral<P = T> + 'd, _is_counter: bool) -> Self { | 107 | fn new_inner(timer: Peri<'d, T>, _is_counter: bool) -> Self { |
| 108 | into_ref!(timer); | ||
| 109 | |||
| 110 | let regs = T::regs(); | 108 | let regs = T::regs(); |
| 111 | 109 | ||
| 112 | let this = Self { _p: timer }; | 110 | let this = Self { _p: timer }; |
| @@ -229,7 +227,7 @@ impl<'d, T: Instance> Timer<'d, T> { | |||
| 229 | /// When the register's CAPTURE task is triggered, the timer will store the current value of its counter in the register | 227 | /// When the register's CAPTURE task is triggered, the timer will store the current value of its counter in the register |
| 230 | pub struct Cc<'d, T: Instance> { | 228 | pub struct Cc<'d, T: Instance> { |
| 231 | n: usize, | 229 | n: usize, |
| 232 | _p: PeripheralRef<'d, T>, | 230 | _p: Peri<'d, T>, |
| 233 | } | 231 | } |
| 234 | 232 | ||
| 235 | impl<'d, T: Instance> Cc<'d, T> { | 233 | impl<'d, T: Instance> Cc<'d, T> { |
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs index bfce00f1b..083b54b99 100644 --- a/embassy-nrf/src/twim.rs +++ b/embassy-nrf/src/twim.rs | |||
| @@ -10,7 +10,7 @@ use core::sync::atomic::Ordering::SeqCst; | |||
| 10 | use core::task::Poll; | 10 | use core::task::Poll; |
| 11 | 11 | ||
| 12 | use embassy_embedded_hal::SetConfig; | 12 | use embassy_embedded_hal::SetConfig; |
| 13 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 13 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 14 | use embassy_sync::waitqueue::AtomicWaker; | 14 | use embassy_sync::waitqueue::AtomicWaker; |
| 15 | #[cfg(feature = "time")] | 15 | #[cfg(feature = "time")] |
| 16 | use embassy_time::{Duration, Instant}; | 16 | use embassy_time::{Duration, Instant}; |
| @@ -23,7 +23,7 @@ use crate::interrupt::typelevel::Interrupt; | |||
| 23 | use crate::pac::gpio::vals as gpiovals; | 23 | use crate::pac::gpio::vals as gpiovals; |
| 24 | use crate::pac::twim::vals; | 24 | use crate::pac::twim::vals; |
| 25 | use crate::util::slice_in_ram; | 25 | use crate::util::slice_in_ram; |
| 26 | use crate::{gpio, interrupt, pac, Peripheral}; | 26 | use crate::{gpio, interrupt, pac}; |
| 27 | 27 | ||
| 28 | /// TWIM config. | 28 | /// TWIM config. |
| 29 | #[non_exhaustive] | 29 | #[non_exhaustive] |
| @@ -114,20 +114,18 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 114 | 114 | ||
| 115 | /// TWI driver. | 115 | /// TWI driver. |
| 116 | pub struct Twim<'d, T: Instance> { | 116 | pub struct Twim<'d, T: Instance> { |
| 117 | _p: PeripheralRef<'d, T>, | 117 | _p: Peri<'d, T>, |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | impl<'d, T: Instance> Twim<'d, T> { | 120 | impl<'d, T: Instance> Twim<'d, T> { |
| 121 | /// Create a new TWI driver. | 121 | /// Create a new TWI driver. |
| 122 | pub fn new( | 122 | pub fn new( |
| 123 | twim: impl Peripheral<P = T> + 'd, | 123 | twim: Peri<'d, T>, |
| 124 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 124 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 125 | sda: impl Peripheral<P = impl GpioPin> + 'd, | 125 | sda: Peri<'d, impl GpioPin>, |
| 126 | scl: impl Peripheral<P = impl GpioPin> + 'd, | 126 | scl: Peri<'d, impl GpioPin>, |
| 127 | config: Config, | 127 | config: Config, |
| 128 | ) -> Self { | 128 | ) -> Self { |
| 129 | into_ref!(twim, sda, scl); | ||
| 130 | |||
| 131 | let r = T::regs(); | 129 | let r = T::regs(); |
| 132 | 130 | ||
| 133 | // Configure pins | 131 | // Configure pins |
| @@ -847,7 +845,7 @@ pub(crate) trait SealedInstance { | |||
| 847 | 845 | ||
| 848 | /// TWIM peripheral instance. | 846 | /// TWIM peripheral instance. |
| 849 | #[allow(private_bounds)] | 847 | #[allow(private_bounds)] |
| 850 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static { | 848 | pub trait Instance: SealedInstance + PeripheralType + 'static { |
| 851 | /// Interrupt for this peripheral. | 849 | /// Interrupt for this peripheral. |
| 852 | type Interrupt: interrupt::typelevel::Interrupt; | 850 | type Interrupt: interrupt::typelevel::Interrupt; |
| 853 | } | 851 | } |
diff --git a/embassy-nrf/src/twis.rs b/embassy-nrf/src/twis.rs index 60de2ed9d..3e4d537ae 100644 --- a/embassy-nrf/src/twis.rs +++ b/embassy-nrf/src/twis.rs | |||
| @@ -8,7 +8,7 @@ use core::sync::atomic::compiler_fence; | |||
| 8 | use core::sync::atomic::Ordering::SeqCst; | 8 | use core::sync::atomic::Ordering::SeqCst; |
| 9 | use core::task::Poll; | 9 | use core::task::Poll; |
| 10 | 10 | ||
| 11 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 11 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 12 | use embassy_sync::waitqueue::AtomicWaker; | 12 | use embassy_sync::waitqueue::AtomicWaker; |
| 13 | #[cfg(feature = "time")] | 13 | #[cfg(feature = "time")] |
| 14 | use embassy_time::{Duration, Instant}; | 14 | use embassy_time::{Duration, Instant}; |
| @@ -19,7 +19,7 @@ use crate::interrupt::typelevel::Interrupt; | |||
| 19 | use crate::pac::gpio::vals as gpiovals; | 19 | use crate::pac::gpio::vals as gpiovals; |
| 20 | use crate::pac::twis::vals; | 20 | use crate::pac::twis::vals; |
| 21 | use crate::util::slice_in_ram_or; | 21 | use crate::util::slice_in_ram_or; |
| 22 | use crate::{gpio, interrupt, pac, Peripheral}; | 22 | use crate::{gpio, interrupt, pac}; |
| 23 | 23 | ||
| 24 | /// TWIS config. | 24 | /// TWIS config. |
| 25 | #[non_exhaustive] | 25 | #[non_exhaustive] |
| @@ -141,20 +141,18 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 141 | 141 | ||
| 142 | /// TWIS driver. | 142 | /// TWIS driver. |
| 143 | pub struct Twis<'d, T: Instance> { | 143 | pub struct Twis<'d, T: Instance> { |
| 144 | _p: PeripheralRef<'d, T>, | 144 | _p: Peri<'d, T>, |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | impl<'d, T: Instance> Twis<'d, T> { | 147 | impl<'d, T: Instance> Twis<'d, T> { |
| 148 | /// Create a new TWIS driver. | 148 | /// Create a new TWIS driver. |
| 149 | pub fn new( | 149 | pub fn new( |
| 150 | twis: impl Peripheral<P = T> + 'd, | 150 | twis: Peri<'d, T>, |
| 151 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 151 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 152 | sda: impl Peripheral<P = impl GpioPin> + 'd, | 152 | sda: Peri<'d, impl GpioPin>, |
| 153 | scl: impl Peripheral<P = impl GpioPin> + 'd, | 153 | scl: Peri<'d, impl GpioPin>, |
| 154 | config: Config, | 154 | config: Config, |
| 155 | ) -> Self { | 155 | ) -> Self { |
| 156 | into_ref!(twis, sda, scl); | ||
| 157 | |||
| 158 | let r = T::regs(); | 156 | let r = T::regs(); |
| 159 | 157 | ||
| 160 | // Configure pins | 158 | // Configure pins |
| @@ -791,7 +789,7 @@ pub(crate) trait SealedInstance { | |||
| 791 | 789 | ||
| 792 | /// TWIS peripheral instance. | 790 | /// TWIS peripheral instance. |
| 793 | #[allow(private_bounds)] | 791 | #[allow(private_bounds)] |
| 794 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static { | 792 | pub trait Instance: SealedInstance + PeripheralType + 'static { |
| 795 | /// Interrupt for this peripheral. | 793 | /// Interrupt for this peripheral. |
| 796 | type Interrupt: interrupt::typelevel::Interrupt; | 794 | type Interrupt: interrupt::typelevel::Interrupt; |
| 797 | } | 795 | } |
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index ebb4dd941..b44edfe84 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs | |||
| @@ -19,7 +19,7 @@ use core::sync::atomic::{compiler_fence, AtomicU8, Ordering}; | |||
| 19 | use core::task::Poll; | 19 | use core::task::Poll; |
| 20 | 20 | ||
| 21 | use embassy_hal_internal::drop::OnDrop; | 21 | use embassy_hal_internal::drop::OnDrop; |
| 22 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 22 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 23 | use embassy_sync::waitqueue::AtomicWaker; | 23 | use embassy_sync::waitqueue::AtomicWaker; |
| 24 | // Re-export SVD variants to allow user to directly set values. | 24 | // Re-export SVD variants to allow user to directly set values. |
| 25 | pub use pac::uarte::vals::{Baudrate, ConfigParity as Parity}; | 25 | pub use pac::uarte::vals::{Baudrate, ConfigParity as Parity}; |
| @@ -32,7 +32,7 @@ use crate::pac::uarte::vals; | |||
| 32 | use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; | 32 | use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; |
| 33 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; | 33 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; |
| 34 | use crate::util::slice_in_ram_or; | 34 | use crate::util::slice_in_ram_or; |
| 35 | use crate::{interrupt, pac, Peripheral}; | 35 | use crate::{interrupt, pac}; |
| 36 | 36 | ||
| 37 | /// UARTE config. | 37 | /// UARTE config. |
| 38 | #[derive(Clone)] | 38 | #[derive(Clone)] |
| @@ -141,56 +141,54 @@ pub struct Uarte<'d, T: Instance> { | |||
| 141 | /// | 141 | /// |
| 142 | /// This can be obtained via [`Uarte::split`], or created directly. | 142 | /// This can be obtained via [`Uarte::split`], or created directly. |
| 143 | pub struct UarteTx<'d, T: Instance> { | 143 | pub struct UarteTx<'d, T: Instance> { |
| 144 | _p: PeripheralRef<'d, T>, | 144 | _p: Peri<'d, T>, |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | /// Receiver part of the UARTE driver. | 147 | /// Receiver part of the UARTE driver. |
| 148 | /// | 148 | /// |
| 149 | /// This can be obtained via [`Uarte::split`], or created directly. | 149 | /// This can be obtained via [`Uarte::split`], or created directly. |
| 150 | pub struct UarteRx<'d, T: Instance> { | 150 | pub struct UarteRx<'d, T: Instance> { |
| 151 | _p: PeripheralRef<'d, T>, | 151 | _p: Peri<'d, T>, |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | impl<'d, T: Instance> Uarte<'d, T> { | 154 | impl<'d, T: Instance> Uarte<'d, T> { |
| 155 | /// Create a new UARTE without hardware flow control | 155 | /// Create a new UARTE without hardware flow control |
| 156 | pub fn new( | 156 | pub fn new( |
| 157 | uarte: impl Peripheral<P = T> + 'd, | 157 | uarte: Peri<'d, T>, |
| 158 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 158 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 159 | rxd: impl Peripheral<P = impl GpioPin> + 'd, | 159 | rxd: Peri<'d, impl GpioPin>, |
| 160 | txd: impl Peripheral<P = impl GpioPin> + 'd, | 160 | txd: Peri<'d, impl GpioPin>, |
| 161 | config: Config, | 161 | config: Config, |
| 162 | ) -> Self { | 162 | ) -> Self { |
| 163 | into_ref!(uarte, rxd, txd); | 163 | Self::new_inner(uarte, rxd.into(), txd.into(), None, None, config) |
| 164 | Self::new_inner(uarte, rxd.map_into(), txd.map_into(), None, None, config) | ||
| 165 | } | 164 | } |
| 166 | 165 | ||
| 167 | /// Create a new UARTE with hardware flow control (RTS/CTS) | 166 | /// Create a new UARTE with hardware flow control (RTS/CTS) |
| 168 | pub fn new_with_rtscts( | 167 | pub fn new_with_rtscts( |
| 169 | uarte: impl Peripheral<P = T> + 'd, | 168 | uarte: Peri<'d, T>, |
| 170 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 169 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 171 | rxd: impl Peripheral<P = impl GpioPin> + 'd, | 170 | rxd: Peri<'d, impl GpioPin>, |
| 172 | txd: impl Peripheral<P = impl GpioPin> + 'd, | 171 | txd: Peri<'d, impl GpioPin>, |
| 173 | cts: impl Peripheral<P = impl GpioPin> + 'd, | 172 | cts: Peri<'d, impl GpioPin>, |
| 174 | rts: impl Peripheral<P = impl GpioPin> + 'd, | 173 | rts: Peri<'d, impl GpioPin>, |
| 175 | config: Config, | 174 | config: Config, |
| 176 | ) -> Self { | 175 | ) -> Self { |
| 177 | into_ref!(uarte, rxd, txd, cts, rts); | ||
| 178 | Self::new_inner( | 176 | Self::new_inner( |
| 179 | uarte, | 177 | uarte, |
| 180 | rxd.map_into(), | 178 | rxd.into(), |
| 181 | txd.map_into(), | 179 | txd.into(), |
| 182 | Some(cts.map_into()), | 180 | Some(cts.into()), |
| 183 | Some(rts.map_into()), | 181 | Some(rts.into()), |
| 184 | config, | 182 | config, |
| 185 | ) | 183 | ) |
| 186 | } | 184 | } |
| 187 | 185 | ||
| 188 | fn new_inner( | 186 | fn new_inner( |
| 189 | uarte: PeripheralRef<'d, T>, | 187 | uarte: Peri<'d, T>, |
| 190 | rxd: PeripheralRef<'d, AnyPin>, | 188 | rxd: Peri<'d, AnyPin>, |
| 191 | txd: PeripheralRef<'d, AnyPin>, | 189 | txd: Peri<'d, AnyPin>, |
| 192 | cts: Option<PeripheralRef<'d, AnyPin>>, | 190 | cts: Option<Peri<'d, AnyPin>>, |
| 193 | rts: Option<PeripheralRef<'d, AnyPin>>, | 191 | rts: Option<Peri<'d, AnyPin>>, |
| 194 | config: Config, | 192 | config: Config, |
| 195 | ) -> Self { | 193 | ) -> Self { |
| 196 | let r = T::regs(); | 194 | let r = T::regs(); |
| @@ -239,9 +237,9 @@ impl<'d, T: Instance> Uarte<'d, T> { | |||
| 239 | /// This is useful to concurrently transmit and receive from independent tasks. | 237 | /// This is useful to concurrently transmit and receive from independent tasks. |
| 240 | pub fn split_with_idle<U: TimerInstance>( | 238 | pub fn split_with_idle<U: TimerInstance>( |
| 241 | self, | 239 | self, |
| 242 | timer: impl Peripheral<P = U> + 'd, | 240 | timer: Peri<'d, U>, |
| 243 | ppi_ch1: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd, | 241 | ppi_ch1: Peri<'d, impl ConfigurableChannel + 'd>, |
| 244 | ppi_ch2: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd, | 242 | ppi_ch2: Peri<'d, impl ConfigurableChannel + 'd>, |
| 245 | ) -> (UarteTx<'d, T>, UarteRxWithIdle<'d, T, U>) { | 243 | ) -> (UarteTx<'d, T>, UarteRxWithIdle<'d, T, U>) { |
| 246 | (self.tx, self.rx.with_idle(timer, ppi_ch1, ppi_ch2)) | 244 | (self.tx, self.rx.with_idle(timer, ppi_ch1, ppi_ch2)) |
| 247 | } | 245 | } |
| @@ -283,11 +281,7 @@ impl<'d, T: Instance> Uarte<'d, T> { | |||
| 283 | } | 281 | } |
| 284 | } | 282 | } |
| 285 | 283 | ||
| 286 | pub(crate) fn configure_tx_pins( | 284 | pub(crate) fn configure_tx_pins(r: pac::uarte::Uarte, txd: Peri<'_, AnyPin>, cts: Option<Peri<'_, AnyPin>>) { |
| 287 | r: pac::uarte::Uarte, | ||
| 288 | txd: PeripheralRef<'_, AnyPin>, | ||
| 289 | cts: Option<PeripheralRef<'_, AnyPin>>, | ||
| 290 | ) { | ||
| 291 | txd.set_high(); | 285 | txd.set_high(); |
| 292 | txd.conf().write(|w| { | 286 | txd.conf().write(|w| { |
| 293 | w.set_dir(gpiovals::Dir::OUTPUT); | 287 | w.set_dir(gpiovals::Dir::OUTPUT); |
| @@ -306,11 +300,7 @@ pub(crate) fn configure_tx_pins( | |||
| 306 | r.psel().cts().write_value(cts.psel_bits()); | 300 | r.psel().cts().write_value(cts.psel_bits()); |
| 307 | } | 301 | } |
| 308 | 302 | ||
| 309 | pub(crate) fn configure_rx_pins( | 303 | pub(crate) fn configure_rx_pins(r: pac::uarte::Uarte, rxd: Peri<'_, AnyPin>, rts: Option<Peri<'_, AnyPin>>) { |
| 310 | r: pac::uarte::Uarte, | ||
| 311 | rxd: PeripheralRef<'_, AnyPin>, | ||
| 312 | rts: Option<PeripheralRef<'_, AnyPin>>, | ||
| 313 | ) { | ||
| 314 | rxd.conf().write(|w| { | 304 | rxd.conf().write(|w| { |
| 315 | w.set_dir(gpiovals::Dir::INPUT); | 305 | w.set_dir(gpiovals::Dir::INPUT); |
| 316 | w.set_input(gpiovals::Input::CONNECT); | 306 | w.set_input(gpiovals::Input::CONNECT); |
| @@ -356,33 +346,26 @@ pub(crate) fn configure(r: pac::uarte::Uarte, config: Config, hardware_flow_cont | |||
| 356 | impl<'d, T: Instance> UarteTx<'d, T> { | 346 | impl<'d, T: Instance> UarteTx<'d, T> { |
| 357 | /// Create a new tx-only UARTE without hardware flow control | 347 | /// Create a new tx-only UARTE without hardware flow control |
| 358 | pub fn new( | 348 | pub fn new( |
| 359 | uarte: impl Peripheral<P = T> + 'd, | 349 | uarte: Peri<'d, T>, |
| 360 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 350 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 361 | txd: impl Peripheral<P = impl GpioPin> + 'd, | 351 | txd: Peri<'d, impl GpioPin>, |
| 362 | config: Config, | 352 | config: Config, |
| 363 | ) -> Self { | 353 | ) -> Self { |
| 364 | into_ref!(uarte, txd); | 354 | Self::new_inner(uarte, txd.into(), None, config) |
| 365 | Self::new_inner(uarte, txd.map_into(), None, config) | ||
| 366 | } | 355 | } |
| 367 | 356 | ||
| 368 | /// Create a new tx-only UARTE with hardware flow control (RTS/CTS) | 357 | /// Create a new tx-only UARTE with hardware flow control (RTS/CTS) |
| 369 | pub fn new_with_rtscts( | 358 | pub fn new_with_rtscts( |
| 370 | uarte: impl Peripheral<P = T> + 'd, | 359 | uarte: Peri<'d, T>, |
| 371 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 360 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 372 | txd: impl Peripheral<P = impl GpioPin> + 'd, | 361 | txd: Peri<'d, impl GpioPin>, |
| 373 | cts: impl Peripheral<P = impl GpioPin> + 'd, | 362 | cts: Peri<'d, impl GpioPin>, |
| 374 | config: Config, | 363 | config: Config, |
| 375 | ) -> Self { | 364 | ) -> Self { |
| 376 | into_ref!(uarte, txd, cts); | 365 | Self::new_inner(uarte, txd.into(), Some(cts.into()), config) |
| 377 | Self::new_inner(uarte, txd.map_into(), Some(cts.map_into()), config) | ||
| 378 | } | 366 | } |
| 379 | 367 | ||
| 380 | fn new_inner( | 368 | fn new_inner(uarte: Peri<'d, T>, txd: Peri<'d, AnyPin>, cts: Option<Peri<'d, AnyPin>>, config: Config) -> Self { |
| 381 | uarte: PeripheralRef<'d, T>, | ||
| 382 | txd: PeripheralRef<'d, AnyPin>, | ||
| 383 | cts: Option<PeripheralRef<'d, AnyPin>>, | ||
| 384 | config: Config, | ||
| 385 | ) -> Self { | ||
| 386 | let r = T::regs(); | 369 | let r = T::regs(); |
| 387 | 370 | ||
| 388 | configure(r, config, cts.is_some()); | 371 | configure(r, config, cts.is_some()); |
| @@ -539,25 +522,23 @@ impl<'a, T: Instance> Drop for UarteTx<'a, T> { | |||
| 539 | impl<'d, T: Instance> UarteRx<'d, T> { | 522 | impl<'d, T: Instance> UarteRx<'d, T> { |
| 540 | /// Create a new rx-only UARTE without hardware flow control | 523 | /// Create a new rx-only UARTE without hardware flow control |
| 541 | pub fn new( | 524 | pub fn new( |
| 542 | uarte: impl Peripheral<P = T> + 'd, | 525 | uarte: Peri<'d, T>, |
| 543 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 526 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 544 | rxd: impl Peripheral<P = impl GpioPin> + 'd, | 527 | rxd: Peri<'d, impl GpioPin>, |
| 545 | config: Config, | 528 | config: Config, |
| 546 | ) -> Self { | 529 | ) -> Self { |
| 547 | into_ref!(uarte, rxd); | 530 | Self::new_inner(uarte, rxd.into(), None, config) |
| 548 | Self::new_inner(uarte, rxd.map_into(), None, config) | ||
| 549 | } | 531 | } |
| 550 | 532 | ||
| 551 | /// Create a new rx-only UARTE with hardware flow control (RTS/CTS) | 533 | /// Create a new rx-only UARTE with hardware flow control (RTS/CTS) |
| 552 | pub fn new_with_rtscts( | 534 | pub fn new_with_rtscts( |
| 553 | uarte: impl Peripheral<P = T> + 'd, | 535 | uarte: Peri<'d, T>, |
| 554 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 536 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 555 | rxd: impl Peripheral<P = impl GpioPin> + 'd, | 537 | rxd: Peri<'d, impl GpioPin>, |
| 556 | rts: impl Peripheral<P = impl GpioPin> + 'd, | 538 | rts: Peri<'d, impl GpioPin>, |
| 557 | config: Config, | 539 | config: Config, |
| 558 | ) -> Self { | 540 | ) -> Self { |
| 559 | into_ref!(uarte, rxd, rts); | 541 | Self::new_inner(uarte, rxd.into(), Some(rts.into()), config) |
| 560 | Self::new_inner(uarte, rxd.map_into(), Some(rts.map_into()), config) | ||
| 561 | } | 542 | } |
| 562 | 543 | ||
| 563 | /// Check for errors and clear the error register if an error occured. | 544 | /// Check for errors and clear the error register if an error occured. |
| @@ -568,12 +549,7 @@ impl<'d, T: Instance> UarteRx<'d, T> { | |||
| 568 | ErrorSource::from_bits_truncate(err_bits.0).check() | 549 | ErrorSource::from_bits_truncate(err_bits.0).check() |
| 569 | } | 550 | } |
| 570 | 551 | ||
| 571 | fn new_inner( | 552 | fn new_inner(uarte: Peri<'d, T>, rxd: Peri<'d, AnyPin>, rts: Option<Peri<'d, AnyPin>>, config: Config) -> Self { |
| 572 | uarte: PeripheralRef<'d, T>, | ||
| 573 | rxd: PeripheralRef<'d, AnyPin>, | ||
| 574 | rts: Option<PeripheralRef<'d, AnyPin>>, | ||
| 575 | config: Config, | ||
| 576 | ) -> Self { | ||
| 577 | let r = T::regs(); | 553 | let r = T::regs(); |
| 578 | 554 | ||
| 579 | configure(r, config, rts.is_some()); | 555 | configure(r, config, rts.is_some()); |
| @@ -592,14 +568,12 @@ impl<'d, T: Instance> UarteRx<'d, T> { | |||
| 592 | /// Upgrade to an instance that supports idle line detection. | 568 | /// Upgrade to an instance that supports idle line detection. |
| 593 | pub fn with_idle<U: TimerInstance>( | 569 | pub fn with_idle<U: TimerInstance>( |
| 594 | self, | 570 | self, |
| 595 | timer: impl Peripheral<P = U> + 'd, | 571 | timer: Peri<'d, U>, |
| 596 | ppi_ch1: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd, | 572 | ppi_ch1: Peri<'d, impl ConfigurableChannel + 'd>, |
| 597 | ppi_ch2: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd, | 573 | ppi_ch2: Peri<'d, impl ConfigurableChannel + 'd>, |
| 598 | ) -> UarteRxWithIdle<'d, T, U> { | 574 | ) -> UarteRxWithIdle<'d, T, U> { |
| 599 | let timer = Timer::new(timer); | 575 | let timer = Timer::new(timer); |
| 600 | 576 | ||
| 601 | into_ref!(ppi_ch1, ppi_ch2); | ||
| 602 | |||
| 603 | let r = T::regs(); | 577 | let r = T::regs(); |
| 604 | 578 | ||
| 605 | // BAUDRATE register values are `baudrate * 2^32 / 16000000` | 579 | // BAUDRATE register values are `baudrate * 2^32 / 16000000` |
| @@ -617,7 +591,7 @@ impl<'d, T: Instance> UarteRx<'d, T> { | |||
| 617 | timer.cc(0).short_compare_stop(); | 591 | timer.cc(0).short_compare_stop(); |
| 618 | 592 | ||
| 619 | let mut ppi_ch1 = Ppi::new_one_to_two( | 593 | let mut ppi_ch1 = Ppi::new_one_to_two( |
| 620 | ppi_ch1.map_into(), | 594 | ppi_ch1.into(), |
| 621 | Event::from_reg(r.events_rxdrdy()), | 595 | Event::from_reg(r.events_rxdrdy()), |
| 622 | timer.task_clear(), | 596 | timer.task_clear(), |
| 623 | timer.task_start(), | 597 | timer.task_start(), |
| @@ -625,7 +599,7 @@ impl<'d, T: Instance> UarteRx<'d, T> { | |||
| 625 | ppi_ch1.enable(); | 599 | ppi_ch1.enable(); |
| 626 | 600 | ||
| 627 | let mut ppi_ch2 = Ppi::new_one_to_one( | 601 | let mut ppi_ch2 = Ppi::new_one_to_one( |
| 628 | ppi_ch2.map_into(), | 602 | ppi_ch2.into(), |
| 629 | timer.cc(0).event_compare(), | 603 | timer.cc(0).event_compare(), |
| 630 | Task::from_reg(r.tasks_stoprx()), | 604 | Task::from_reg(r.tasks_stoprx()), |
| 631 | ); | 605 | ); |
| @@ -992,7 +966,7 @@ pub(crate) trait SealedInstance { | |||
| 992 | 966 | ||
| 993 | /// UARTE peripheral instance. | 967 | /// UARTE peripheral instance. |
| 994 | #[allow(private_bounds)] | 968 | #[allow(private_bounds)] |
| 995 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | 969 | pub trait Instance: SealedInstance + PeripheralType + 'static + Send { |
| 996 | /// Interrupt for this peripheral. | 970 | /// Interrupt for this peripheral. |
| 997 | type Interrupt: interrupt::typelevel::Interrupt; | 971 | type Interrupt: interrupt::typelevel::Interrupt; |
| 998 | } | 972 | } |
diff --git a/embassy-nrf/src/usb/mod.rs b/embassy-nrf/src/usb/mod.rs index 06dae694b..6cc1b0111 100644 --- a/embassy-nrf/src/usb/mod.rs +++ b/embassy-nrf/src/usb/mod.rs | |||
| @@ -11,7 +11,7 @@ use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; | |||
| 11 | use core::task::Poll; | 11 | use core::task::Poll; |
| 12 | 12 | ||
| 13 | use cortex_m::peripheral::NVIC; | 13 | use cortex_m::peripheral::NVIC; |
| 14 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 14 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 15 | use embassy_sync::waitqueue::AtomicWaker; | 15 | use embassy_sync::waitqueue::AtomicWaker; |
| 16 | use embassy_usb_driver as driver; | 16 | use embassy_usb_driver as driver; |
| 17 | use embassy_usb_driver::{Direction, EndpointAddress, EndpointError, EndpointInfo, EndpointType, Event, Unsupported}; | 17 | use embassy_usb_driver::{Direction, EndpointAddress, EndpointError, EndpointInfo, EndpointType, Event, Unsupported}; |
| @@ -20,7 +20,7 @@ use self::vbus_detect::VbusDetect; | |||
| 20 | use crate::interrupt::typelevel::Interrupt; | 20 | use crate::interrupt::typelevel::Interrupt; |
| 21 | use crate::pac::usbd::vals; | 21 | use crate::pac::usbd::vals; |
| 22 | use crate::util::slice_in_ram; | 22 | use crate::util::slice_in_ram; |
| 23 | use crate::{interrupt, pac, Peripheral}; | 23 | use crate::{interrupt, pac}; |
| 24 | 24 | ||
| 25 | static BUS_WAKER: AtomicWaker = AtomicWaker::new(); | 25 | static BUS_WAKER: AtomicWaker = AtomicWaker::new(); |
| 26 | static EP0_WAKER: AtomicWaker = AtomicWaker::new(); | 26 | static EP0_WAKER: AtomicWaker = AtomicWaker::new(); |
| @@ -87,7 +87,7 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 87 | 87 | ||
| 88 | /// USB driver. | 88 | /// USB driver. |
| 89 | pub struct Driver<'d, T: Instance, V: VbusDetect> { | 89 | pub struct Driver<'d, T: Instance, V: VbusDetect> { |
| 90 | _p: PeripheralRef<'d, T>, | 90 | _p: Peri<'d, T>, |
| 91 | alloc_in: Allocator, | 91 | alloc_in: Allocator, |
| 92 | alloc_out: Allocator, | 92 | alloc_out: Allocator, |
| 93 | vbus_detect: V, | 93 | vbus_detect: V, |
| @@ -96,12 +96,10 @@ pub struct Driver<'d, T: Instance, V: VbusDetect> { | |||
| 96 | impl<'d, T: Instance, V: VbusDetect> Driver<'d, T, V> { | 96 | impl<'d, T: Instance, V: VbusDetect> Driver<'d, T, V> { |
| 97 | /// Create a new USB driver. | 97 | /// Create a new USB driver. |
| 98 | pub fn new( | 98 | pub fn new( |
| 99 | usb: impl Peripheral<P = T> + 'd, | 99 | usb: Peri<'d, T>, |
| 100 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 100 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 101 | vbus_detect: V, | 101 | vbus_detect: V, |
| 102 | ) -> Self { | 102 | ) -> Self { |
| 103 | into_ref!(usb); | ||
| 104 | |||
| 105 | T::Interrupt::unpend(); | 103 | T::Interrupt::unpend(); |
| 106 | unsafe { T::Interrupt::enable() }; | 104 | unsafe { T::Interrupt::enable() }; |
| 107 | 105 | ||
| @@ -169,7 +167,7 @@ impl<'d, T: Instance, V: VbusDetect + 'd> driver::Driver<'d> for Driver<'d, T, V | |||
| 169 | 167 | ||
| 170 | /// USB bus. | 168 | /// USB bus. |
| 171 | pub struct Bus<'d, T: Instance, V: VbusDetect> { | 169 | pub struct Bus<'d, T: Instance, V: VbusDetect> { |
| 172 | _p: PeripheralRef<'d, T>, | 170 | _p: Peri<'d, T>, |
| 173 | power_available: bool, | 171 | power_available: bool, |
| 174 | vbus_detect: V, | 172 | vbus_detect: V, |
| 175 | } | 173 | } |
| @@ -592,7 +590,7 @@ impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> { | |||
| 592 | 590 | ||
| 593 | /// USB control pipe. | 591 | /// USB control pipe. |
| 594 | pub struct ControlPipe<'d, T: Instance> { | 592 | pub struct ControlPipe<'d, T: Instance> { |
| 595 | _p: PeripheralRef<'d, T>, | 593 | _p: Peri<'d, T>, |
| 596 | max_packet_size: u16, | 594 | max_packet_size: u16, |
| 597 | } | 595 | } |
| 598 | 596 | ||
| @@ -779,7 +777,7 @@ pub(crate) trait SealedInstance { | |||
| 779 | 777 | ||
| 780 | /// USB peripheral instance. | 778 | /// USB peripheral instance. |
| 781 | #[allow(private_bounds)] | 779 | #[allow(private_bounds)] |
| 782 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | 780 | pub trait Instance: SealedInstance + PeripheralType + 'static + Send { |
| 783 | /// Interrupt for this peripheral. | 781 | /// Interrupt for this peripheral. |
| 784 | type Interrupt: interrupt::typelevel::Interrupt; | 782 | type Interrupt: interrupt::typelevel::Interrupt; |
| 785 | } | 783 | } |
diff --git a/embassy-nrf/src/wdt.rs b/embassy-nrf/src/wdt.rs index f7812258c..11cfa398e 100644 --- a/embassy-nrf/src/wdt.rs +++ b/embassy-nrf/src/wdt.rs | |||
| @@ -3,9 +3,11 @@ | |||
| 3 | //! This HAL implements a basic watchdog timer with 1..=8 handles. | 3 | //! This HAL implements a basic watchdog timer with 1..=8 handles. |
| 4 | //! Once the watchdog has been started, it cannot be stopped. | 4 | //! Once the watchdog has been started, it cannot be stopped. |
| 5 | 5 | ||
| 6 | use core::marker::PhantomData; | ||
| 7 | |||
| 6 | use crate::pac::wdt::vals; | 8 | use crate::pac::wdt::vals; |
| 7 | pub use crate::pac::wdt::vals::{Halt as HaltConfig, Sleep as SleepConfig}; | 9 | pub use crate::pac::wdt::vals::{Halt as HaltConfig, Sleep as SleepConfig}; |
| 8 | use crate::peripherals; | 10 | use crate::{peripherals, Peri}; |
| 9 | 11 | ||
| 10 | const MIN_TICKS: u32 = 15; | 12 | const MIN_TICKS: u32 = 15; |
| 11 | 13 | ||
| @@ -61,7 +63,7 @@ impl Default for Config { | |||
| 61 | 63 | ||
| 62 | /// Watchdog driver. | 64 | /// Watchdog driver. |
| 63 | pub struct Watchdog { | 65 | pub struct Watchdog { |
| 64 | _private: (), | 66 | _wdt: Peri<'static, peripherals::WDT>, |
| 65 | } | 67 | } |
| 66 | 68 | ||
| 67 | impl Watchdog { | 69 | impl Watchdog { |
| @@ -74,9 +76,9 @@ impl Watchdog { | |||
| 74 | /// `N` must be between 1 and 8, inclusive. | 76 | /// `N` must be between 1 and 8, inclusive. |
| 75 | #[inline] | 77 | #[inline] |
| 76 | pub fn try_new<const N: usize>( | 78 | pub fn try_new<const N: usize>( |
| 77 | wdt: peripherals::WDT, | 79 | wdt: Peri<'static, peripherals::WDT>, |
| 78 | config: Config, | 80 | config: Config, |
| 79 | ) -> Result<(Self, [WatchdogHandle; N]), peripherals::WDT> { | 81 | ) -> Result<(Self, [WatchdogHandle; N]), Peri<'static, peripherals::WDT>> { |
| 80 | assert!(N >= 1 && N <= 8); | 82 | assert!(N >= 1 && N <= 8); |
| 81 | 83 | ||
| 82 | let r = crate::pac::WDT; | 84 | let r = crate::pac::WDT; |
| @@ -110,11 +112,19 @@ impl Watchdog { | |||
| 110 | r.tasks_start().write_value(1); | 112 | r.tasks_start().write_value(1); |
| 111 | } | 113 | } |
| 112 | 114 | ||
| 113 | let this = Self { _private: () }; | 115 | let this = Self { _wdt: wdt }; |
| 114 | 116 | ||
| 115 | let mut handles = [const { WatchdogHandle { index: 0 } }; N]; | 117 | let mut handles = [const { |
| 118 | WatchdogHandle { | ||
| 119 | _wdt: PhantomData, | ||
| 120 | index: 0, | ||
| 121 | } | ||
| 122 | }; N]; | ||
| 116 | for i in 0..N { | 123 | for i in 0..N { |
| 117 | handles[i] = WatchdogHandle { index: i as u8 }; | 124 | handles[i] = WatchdogHandle { |
| 125 | _wdt: PhantomData, | ||
| 126 | index: i as u8, | ||
| 127 | }; | ||
| 118 | handles[i].pet(); | 128 | handles[i].pet(); |
| 119 | } | 129 | } |
| 120 | 130 | ||
| @@ -155,6 +165,7 @@ impl Watchdog { | |||
| 155 | 165 | ||
| 156 | /// Watchdog handle. | 166 | /// Watchdog handle. |
| 157 | pub struct WatchdogHandle { | 167 | pub struct WatchdogHandle { |
| 168 | _wdt: PhantomData<Peri<'static, peripherals::WDT>>, | ||
| 158 | index: u8, | 169 | index: u8, |
| 159 | } | 170 | } |
| 160 | 171 | ||
| @@ -183,6 +194,9 @@ impl WatchdogHandle { | |||
| 183 | /// Watchdog must be initialized and `index` must be between `0` and `N-1` | 194 | /// Watchdog must be initialized and `index` must be between `0` and `N-1` |
| 184 | /// where `N` is the handle count when initializing. | 195 | /// where `N` is the handle count when initializing. |
| 185 | pub unsafe fn steal(index: u8) -> Self { | 196 | pub unsafe fn steal(index: u8) -> Self { |
| 186 | Self { index } | 197 | Self { |
| 198 | _wdt: PhantomData, | ||
| 199 | index, | ||
| 200 | } | ||
| 187 | } | 201 | } |
| 188 | } | 202 | } |
