mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-21 22:32:29 +00:00
Update embassy-rp
This commit is contained in:
parent
65a82d02d1
commit
bff0ad9286
@ -417,7 +417,7 @@ impl AnyPin {
|
||||
Self { pin_port }
|
||||
}
|
||||
|
||||
pub fn unborrow_and_degrade<'a>(pin: impl Unborrow<Target = impl Pin + 'a> + 'a) -> Unborrowed<'a, Self> {
|
||||
pub(crate) fn unborrow_and_degrade<'a>(pin: impl Unborrow<Target = impl Pin + 'a> + 'a) -> Unborrowed<'a, Self> {
|
||||
Unborrowed::new(AnyPin {
|
||||
pin_port: pin.unborrow().pin_port(),
|
||||
})
|
||||
|
@ -1,11 +1,11 @@
|
||||
#![macro_use]
|
||||
use core::future::Future;
|
||||
use core::marker::PhantomData;
|
||||
use core::pin::Pin as FuturePin;
|
||||
use core::task::{Context, Poll};
|
||||
|
||||
use embassy::waitqueue::AtomicWaker;
|
||||
use embassy_cortex_m::interrupt::{Interrupt, InterruptExt};
|
||||
use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
|
||||
use embassy_hal_common::{unborrow, unsafe_impl_unborrow, Unborrowed};
|
||||
|
||||
use crate::pac::common::{Reg, RW};
|
||||
use crate::pac::SIO;
|
||||
@ -177,13 +177,13 @@ unsafe fn IO_IRQ_BANK0() {
|
||||
}
|
||||
|
||||
struct InputFuture<'a, T: Pin> {
|
||||
pin: &'a mut T,
|
||||
pin: Unborrowed<'a, T>,
|
||||
level: InterruptTrigger,
|
||||
phantom: PhantomData<&'a mut AnyPin>,
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> InputFuture<'d, T> {
|
||||
pub fn new(pin: &'d mut T, level: InterruptTrigger) -> Self {
|
||||
pub fn new(pin: impl Unborrow<Target = T> + 'd, level: InterruptTrigger) -> Self {
|
||||
unborrow!(pin);
|
||||
unsafe {
|
||||
let irq = interrupt::IO_IRQ_BANK0::steal();
|
||||
irq.disable();
|
||||
@ -215,11 +215,7 @@ impl<'d, T: Pin> InputFuture<'d, T> {
|
||||
irq.enable();
|
||||
}
|
||||
|
||||
Self {
|
||||
pin,
|
||||
level,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Self { pin, level }
|
||||
}
|
||||
}
|
||||
|
||||
@ -419,8 +415,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
|
||||
/// set while not in output mode, so the pin's level will be 'remembered' when it is not in output
|
||||
/// mode.
|
||||
pub struct Flex<'d, T: Pin> {
|
||||
pin: T,
|
||||
phantom: PhantomData<&'d mut T>,
|
||||
pin: Unborrowed<'d, T>,
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> Flex<'d, T> {
|
||||
@ -438,10 +433,7 @@ impl<'d, T: Pin> Flex<'d, T> {
|
||||
});
|
||||
}
|
||||
|
||||
Self {
|
||||
pin,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Self { pin }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -667,7 +659,25 @@ pub trait Pin: Unborrow<Target = Self> + sealed::Pin {
|
||||
pub struct AnyPin {
|
||||
pin_bank: u8,
|
||||
}
|
||||
|
||||
impl AnyPin {
|
||||
pub(crate) fn unborrow_and_degrade<'a>(pin: impl Unborrow<Target = impl Pin + 'a> + 'a) -> Unborrowed<'a, Self> {
|
||||
Unborrowed::new(AnyPin {
|
||||
pin_bank: pin.unborrow().pin_bank(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! unborrow_and_degrade {
|
||||
($($name:ident),*) => {
|
||||
$(
|
||||
let $name = $crate::gpio::AnyPin::unborrow_and_degrade($name);
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
unsafe_impl_unborrow!(AnyPin);
|
||||
|
||||
impl Pin for AnyPin {}
|
||||
impl sealed::Pin for AnyPin {
|
||||
fn pin_bank(&self) -> u8 {
|
||||
|
@ -1,7 +1,5 @@
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use embassy_embedded_hal::SetConfig;
|
||||
use embassy_hal_common::unborrow;
|
||||
use embassy_hal_common::{unborrow, Unborrowed};
|
||||
pub use embedded_hal_02::spi::{Phase, Polarity};
|
||||
|
||||
use crate::gpio::sealed::Pin as _;
|
||||
@ -33,8 +31,7 @@ impl Default for Config {
|
||||
}
|
||||
|
||||
pub struct Spi<'d, T: Instance> {
|
||||
inner: T,
|
||||
phantom: PhantomData<&'d mut T>,
|
||||
inner: Unborrowed<'d, T>,
|
||||
}
|
||||
|
||||
fn div_roundup(a: u32, b: u32) -> u32 {
|
||||
@ -63,48 +60,41 @@ fn calc_prescs(freq: u32) -> (u8, u8) {
|
||||
impl<'d, T: Instance> Spi<'d, T> {
|
||||
pub fn new(
|
||||
inner: impl Unborrow<Target = T> + 'd,
|
||||
clk: impl Unborrow<Target = impl ClkPin<T>> + 'd,
|
||||
mosi: impl Unborrow<Target = impl MosiPin<T>> + 'd,
|
||||
miso: impl Unborrow<Target = impl MisoPin<T>> + 'd,
|
||||
clk: impl Unborrow<Target = impl ClkPin<T> + 'd> + 'd,
|
||||
mosi: impl Unborrow<Target = impl MosiPin<T> + 'd> + 'd,
|
||||
miso: impl Unborrow<Target = impl MisoPin<T> + 'd> + 'd,
|
||||
config: Config,
|
||||
) -> Self {
|
||||
unborrow!(clk, mosi, miso);
|
||||
Self::new_inner(
|
||||
inner,
|
||||
Some(clk.degrade()),
|
||||
Some(mosi.degrade()),
|
||||
Some(miso.degrade()),
|
||||
None,
|
||||
config,
|
||||
)
|
||||
unborrow_and_degrade!(clk, mosi, miso);
|
||||
Self::new_inner(inner, Some(clk), Some(mosi), Some(miso), None, config)
|
||||
}
|
||||
|
||||
pub fn new_txonly(
|
||||
inner: impl Unborrow<Target = T> + 'd,
|
||||
clk: impl Unborrow<Target = impl ClkPin<T>> + 'd,
|
||||
mosi: impl Unborrow<Target = impl MosiPin<T>> + 'd,
|
||||
clk: impl Unborrow<Target = impl ClkPin<T> + 'd> + 'd,
|
||||
mosi: impl Unborrow<Target = impl MosiPin<T> + 'd> + 'd,
|
||||
config: Config,
|
||||
) -> Self {
|
||||
unborrow!(clk, mosi);
|
||||
Self::new_inner(inner, Some(clk.degrade()), Some(mosi.degrade()), None, None, config)
|
||||
unborrow_and_degrade!(clk, mosi);
|
||||
Self::new_inner(inner, Some(clk), Some(mosi), None, None, config)
|
||||
}
|
||||
|
||||
pub fn new_rxonly(
|
||||
inner: impl Unborrow<Target = T> + 'd,
|
||||
clk: impl Unborrow<Target = impl ClkPin<T>> + 'd,
|
||||
miso: impl Unborrow<Target = impl MisoPin<T>> + 'd,
|
||||
clk: impl Unborrow<Target = impl ClkPin<T> + 'd> + 'd,
|
||||
miso: impl Unborrow<Target = impl MisoPin<T> + 'd> + 'd,
|
||||
config: Config,
|
||||
) -> Self {
|
||||
unborrow!(clk, miso);
|
||||
Self::new_inner(inner, Some(clk.degrade()), None, Some(miso.degrade()), None, config)
|
||||
unborrow_and_degrade!(clk, miso);
|
||||
Self::new_inner(inner, Some(clk), None, Some(miso), None, config)
|
||||
}
|
||||
|
||||
fn new_inner(
|
||||
inner: impl Unborrow<Target = T> + 'd,
|
||||
clk: Option<AnyPin>,
|
||||
mosi: Option<AnyPin>,
|
||||
miso: Option<AnyPin>,
|
||||
cs: Option<AnyPin>,
|
||||
clk: Option<Unborrowed<'d, AnyPin>>,
|
||||
mosi: Option<Unborrowed<'d, AnyPin>>,
|
||||
miso: Option<Unborrowed<'d, AnyPin>>,
|
||||
cs: Option<Unborrowed<'d, AnyPin>>,
|
||||
config: Config,
|
||||
) -> Self {
|
||||
unborrow!(inner);
|
||||
@ -137,10 +127,7 @@ impl<'d, T: Instance> Spi<'d, T> {
|
||||
pin.io().ctrl().write(|w| w.set_funcsel(1));
|
||||
}
|
||||
}
|
||||
Self {
|
||||
inner,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
pub fn blocking_write(&mut self, data: &[u8]) -> Result<(), Error> {
|
||||
|
@ -1,6 +1,4 @@
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use embassy_hal_common::unborrow;
|
||||
use embassy_hal_common::{unborrow, Unborrowed};
|
||||
use gpio::Pin;
|
||||
|
||||
use crate::{gpio, pac, peripherals, Unborrow};
|
||||
@ -23,8 +21,7 @@ impl Default for Config {
|
||||
}
|
||||
|
||||
pub struct Uart<'d, T: Instance> {
|
||||
inner: T,
|
||||
phantom: PhantomData<&'d mut T>,
|
||||
inner: Unborrowed<'d, T>,
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> Uart<'d, T> {
|
||||
@ -78,10 +75,7 @@ impl<'d, T: Instance> Uart<'d, T> {
|
||||
cts.io().ctrl().write(|w| w.set_funcsel(2));
|
||||
rts.io().ctrl().write(|w| w.set_funcsel(2));
|
||||
}
|
||||
Self {
|
||||
inner,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
pub fn send(&mut self, data: &[u8]) {
|
||||
|
Loading…
Reference in New Issue
Block a user