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