diff --git a/embassy-nrf-examples/Cargo.toml b/embassy-nrf-examples/Cargo.toml index 1f67b6a8..432e8950 100644 --- a/embassy-nrf-examples/Cargo.toml +++ b/embassy-nrf-examples/Cargo.toml @@ -28,5 +28,5 @@ cortex-m = { version = "0.7.1", features = ["inline-asm"] } cortex-m-rt = "0.6.13" embedded-hal = { version = "0.2.4" } panic-probe = "0.1.0" -nrf52840-hal = { version = "0.12.0" } +nrf52840-hal = { version = "0.12.1" } futures = { version = "0.3.8", default-features = false, features = ["async-await"] } \ No newline at end of file diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index 6324792f..419b7f33 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml @@ -35,8 +35,8 @@ nrf52832-pac = { version = "0.9.0", optional = true } nrf52833-pac = { version = "0.9.0", optional = true } nrf52840-pac = { version = "0.9.0", optional = true } -nrf52810-hal = { version = "0.12.0", optional = true } -#nrf52811-hal = { version = "0.12.0", optional = true } # doesn't exist yet -nrf52832-hal = { version = "0.12.0", optional = true } -nrf52833-hal = { version = "0.12.0", optional = true } -nrf52840-hal = { version = "0.12.0", optional = true } +nrf52810-hal = { version = "0.12.1", optional = true } +#nrf52811-hal = { version = "0.12.1", optional = true } # doesn't exist yet +nrf52832-hal = { version = "0.12.1", optional = true } +nrf52833-hal = { version = "0.12.1", optional = true } +nrf52840-hal = { version = "0.12.1", optional = true } diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index 5cbba486..848687f7 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs @@ -15,7 +15,6 @@ use embassy::io::{AsyncBufRead, AsyncWrite, Result}; use embassy::util::WakerRegistration; use embedded_hal::digital::v2::OutputPin; -use crate::hal::gpio::Port as GpioPort; use crate::hal::ppi::ConfigurablePpi; use crate::interrupt::{self, Interrupt}; use crate::pac; @@ -72,14 +71,6 @@ pub struct BufferedUarte< inner: PeripheralMutex>, } -#[cfg(any(feature = "52833", feature = "52840"))] -fn port_bit(port: GpioPort) -> bool { - match port { - GpioPort::Port0 => false, - GpioPort::Port1 => true, - } -} - impl<'a, U: Instance, T: TimerInstance, P1: ConfigurablePpi, P2: ConfigurablePpi> BufferedUarte<'a, U, T, P1, P2> { @@ -97,25 +88,19 @@ impl<'a, U: Instance, T: TimerInstance, P1: ConfigurablePpi, P2: ConfigurablePpi ) -> Self { // Select pins uarte.psel.rxd.write(|w| { - let w = unsafe { w.pin().bits(pins.rxd.pin()) }; - #[cfg(any(feature = "52833", feature = "52840"))] - let w = w.port().bit(port_bit(pins.rxd.port())); + unsafe { w.bits(pins.rxd.psel_bits()) }; w.connect().connected() }); pins.txd.set_high().unwrap(); uarte.psel.txd.write(|w| { - let w = unsafe { w.pin().bits(pins.txd.pin()) }; - #[cfg(any(feature = "52833", feature = "52840"))] - let w = w.port().bit(port_bit(pins.txd.port())); + unsafe { w.bits(pins.txd.psel_bits()) }; w.connect().connected() }); // Optional pins uarte.psel.cts.write(|w| { if let Some(ref pin) = pins.cts { - let w = unsafe { w.pin().bits(pin.pin()) }; - #[cfg(any(feature = "52833", feature = "52840"))] - let w = w.port().bit(port_bit(pin.port())); + unsafe { w.bits(pin.psel_bits()) }; w.connect().connected() } else { w.connect().disconnected() @@ -124,15 +109,14 @@ impl<'a, U: Instance, T: TimerInstance, P1: ConfigurablePpi, P2: ConfigurablePpi uarte.psel.rts.write(|w| { if let Some(ref pin) = pins.rts { - let w = unsafe { w.pin().bits(pin.pin()) }; - #[cfg(any(feature = "52833", feature = "52840"))] - let w = w.port().bit(port_bit(pin.port())); + unsafe { w.bits(pin.psel_bits()) }; w.connect().connected() } else { w.connect().disconnected() } }); + // Enable UARTE instance uarte.enable.write(|w| w.enable().enabled()); diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index cb7f5a5b..1dc178f2 100644 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs @@ -3,7 +3,7 @@ use core::pin::Pin; use core::task::Poll; use crate::fmt::{assert, assert_eq, *}; -use crate::hal::gpio::{Output, Pin as GpioPin, Port as GpioPort, PushPull}; +use crate::hal::gpio::{Output, Pin as GpioPin, PushPull}; use crate::interrupt::{self}; use crate::pac::QSPI; @@ -59,43 +59,31 @@ pub struct Qspi { inner: PeripheralMutex, } -fn port_bit(port: GpioPort) -> bool { - match port { - GpioPort::Port0 => false, - GpioPort::Port1 => true, - } -} - impl Qspi { pub fn new(qspi: QSPI, irq: interrupt::QSPI, config: Config) -> Self { qspi.psel.sck.write(|w| { let pin = &config.pins.sck; - let w = unsafe { w.pin().bits(pin.pin()) }; - let w = w.port().bit(port_bit(pin.port())); + unsafe { w.bits(pin.psel_bits()) }; w.connect().connected() }); qspi.psel.csn.write(|w| { let pin = &config.pins.csn; - let w = unsafe { w.pin().bits(pin.pin()) }; - let w = w.port().bit(port_bit(pin.port())); + unsafe { w.bits(pin.psel_bits()) }; w.connect().connected() }); qspi.psel.io0.write(|w| { let pin = &config.pins.io0; - let w = unsafe { w.pin().bits(pin.pin()) }; - let w = w.port().bit(port_bit(pin.port())); + unsafe { w.bits(pin.psel_bits()) }; w.connect().connected() }); qspi.psel.io1.write(|w| { let pin = &config.pins.io1; - let w = unsafe { w.pin().bits(pin.pin()) }; - let w = w.port().bit(port_bit(pin.port())); + unsafe { w.bits(pin.psel_bits()) }; w.connect().connected() }); qspi.psel.io2.write(|w| { if let Some(ref pin) = config.pins.io2 { - let w = unsafe { w.pin().bits(pin.pin()) }; - let w = w.port().bit(port_bit(pin.port())); + unsafe { w.bits(pin.psel_bits()) }; w.connect().connected() } else { w.connect().disconnected() @@ -103,8 +91,7 @@ impl Qspi { }); qspi.psel.io3.write(|w| { if let Some(ref pin) = config.pins.io3 { - let w = unsafe { w.pin().bits(pin.pin()) }; - let w = w.port().bit(port_bit(pin.port())); + unsafe { w.bits(pin.psel_bits()) }; w.connect().connected() } else { w.connect().disconnected() diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index 3c0f6e04..b7232963 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs @@ -5,7 +5,6 @@ use core::task::Poll; use embassy::util::WakerRegistration; use futures::future::poll_fn; -use crate::hal::gpio::Port as GpioPort; use crate::interrupt::{self, Interrupt}; use crate::util::peripheral::{PeripheralMutex, PeripheralState}; use crate::{pac, slice_in_ram_or}; @@ -33,14 +32,6 @@ pub struct Spim { inner: PeripheralMutex>, } -#[cfg(any(feature = "52833", feature = "52840"))] -fn port_bit(port: GpioPort) -> bool { - match port { - GpioPort::Port0 => false, - GpioPort::Port1 => true, - } -} - pub struct Config { pub pins: Pins, pub frequency: Frequency, @@ -54,26 +45,20 @@ impl Spim { // Select pins. r.psel.sck.write(|w| { - let w = unsafe { w.pin().bits(config.pins.sck.pin()) }; - #[cfg(any(feature = "52833", feature = "52840"))] - let w = w.port().bit(port_bit(config.pins.sck.port())); + unsafe { w.bits(config.pins.sck.psel_bits()) }; w.connect().connected() }); match config.pins.mosi { Some(mosi) => r.psel.mosi.write(|w| { - let w = unsafe { w.pin().bits(mosi.pin()) }; - #[cfg(any(feature = "52833", feature = "52840"))] - let w = w.port().bit(port_bit(mosi.port())); + unsafe { w.bits(mosi.psel_bits()) }; w.connect().connected() }), None => r.psel.mosi.write(|w| w.connect().disconnected()), } match config.pins.miso { Some(miso) => r.psel.miso.write(|w| { - let w = unsafe { w.pin().bits(miso.pin()) }; - #[cfg(any(feature = "52833", feature = "52840"))] - let w = w.port().bit(port_bit(miso.port())); + unsafe { w.bits(miso.psel_bits()) }; w.connect().connected() }), None => r.psel.miso.write(|w| w.connect().disconnected()), diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 0cc9790b..aea01f95 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs @@ -13,8 +13,6 @@ use embassy::interrupt::InterruptExt; use embassy::util::Signal; use crate::fmt::{assert, *}; -#[cfg(any(feature = "52833", feature = "52840"))] -use crate::hal::gpio::Port as GpioPort; use crate::hal::pac; use crate::hal::prelude::*; use crate::hal::target_constants::EASY_DMA_SIZE; @@ -40,15 +38,6 @@ pub struct State { rx_done: Signal, } -// TODO: Remove when https://github.com/nrf-rs/nrf-hal/pull/276 has landed -#[cfg(any(feature = "52833", feature = "52840"))] -fn port_bit(port: GpioPort) -> bool { - match port { - GpioPort::Port0 => false, - GpioPort::Port1 => true, - } -} - impl Uarte where T: Instance, @@ -72,26 +61,20 @@ where assert!(uarte.enable.read().enable().is_disabled()); uarte.psel.rxd.write(|w| { - let w = unsafe { w.pin().bits(pins.rxd.pin()) }; - #[cfg(any(feature = "52833", feature = "52840"))] - let w = w.port().bit(port_bit(pins.rxd.port())); + unsafe { w.bits(pins.rxd.psel_bits()) }; w.connect().connected() }); pins.txd.set_high().unwrap(); uarte.psel.txd.write(|w| { - let w = unsafe { w.pin().bits(pins.txd.pin()) }; - #[cfg(any(feature = "52833", feature = "52840"))] - let w = w.port().bit(port_bit(pins.txd.port())); + unsafe { w.bits(pins.txd.psel_bits()) }; w.connect().connected() }); // Optional pins uarte.psel.cts.write(|w| { if let Some(ref pin) = pins.cts { - let w = unsafe { w.pin().bits(pin.pin()) }; - #[cfg(any(feature = "52833", feature = "52840"))] - let w = w.port().bit(port_bit(pin.port())); + unsafe { w.bits(pin.psel_bits()) }; w.connect().connected() } else { w.connect().disconnected() @@ -100,9 +83,7 @@ where uarte.psel.rts.write(|w| { if let Some(ref pin) = pins.rts { - let w = unsafe { w.pin().bits(pin.pin()) }; - #[cfg(any(feature = "52833", feature = "52840"))] - let w = w.port().bit(port_bit(pin.port())); + unsafe { w.bits(pin.psel_bits()) }; w.connect().connected() } else { w.connect().disconnected()