Merge branch 'embassy-rs:main' into stm32-pwm-pin-config
This commit is contained in:
commit
5e3cfc7b5c
@ -18,6 +18,7 @@ Rust's <a href="https://rust-lang.github.io/async-book/">async/await</a> allows
|
|||||||
- <a href="https://github.com/esp-rs">esp-rs</a>, for the Espressif Systems ESP32 series of chips.
|
- <a href="https://github.com/esp-rs">esp-rs</a>, for the Espressif Systems ESP32 series of chips.
|
||||||
- Embassy HAL support for Espressif chips, as well as Async WiFi, Bluetooth and ESP-NOW, is being developed in the [esp-rs/esp-hal](https://github.com/esp-rs/esp-hal) repository.
|
- Embassy HAL support for Espressif chips, as well as Async WiFi, Bluetooth and ESP-NOW, is being developed in the [esp-rs/esp-hal](https://github.com/esp-rs/esp-hal) repository.
|
||||||
- <a href="https://github.com/ch32-rs/ch32-hal">ch32-hal</a>, for the WCH 32-bit RISC-V(CH32V) series of chips.
|
- <a href="https://github.com/ch32-rs/ch32-hal">ch32-hal</a>, for the WCH 32-bit RISC-V(CH32V) series of chips.
|
||||||
|
- <a href="https://github.com/AlexCharlton/mpfs-hal">mpfs-hal</a>, for the Microchip PolarFire SoC.
|
||||||
|
|
||||||
- **Time that Just Works** -
|
- **Time that Just Works** -
|
||||||
No more messing with hardware timers. <a href="https://docs.embassy.dev/embassy-time">embassy_time</a> provides Instant, Duration and Timer types that are globally available and never overflow.
|
No more messing with hardware timers. <a href="https://docs.embassy.dev/embassy-time">embassy_time</a> provides Instant, Duration and Timer types that are globally available and never overflow.
|
||||||
|
|||||||
@ -169,12 +169,12 @@ where
|
|||||||
|
|
||||||
self.sm.set_enable(true);
|
self.sm.set_enable(true);
|
||||||
|
|
||||||
self.sm.tx().dma_push(self.dma.reborrow(), write).await;
|
self.sm.tx().dma_push(self.dma.reborrow(), write, false).await;
|
||||||
|
|
||||||
let mut status = 0;
|
let mut status = 0;
|
||||||
self.sm
|
self.sm
|
||||||
.rx()
|
.rx()
|
||||||
.dma_pull(self.dma.reborrow(), slice::from_mut(&mut status))
|
.dma_pull(self.dma.reborrow(), slice::from_mut(&mut status), false)
|
||||||
.await;
|
.await;
|
||||||
status
|
status
|
||||||
}
|
}
|
||||||
@ -201,13 +201,16 @@ where
|
|||||||
// self.cs.set_low();
|
// self.cs.set_low();
|
||||||
self.sm.set_enable(true);
|
self.sm.set_enable(true);
|
||||||
|
|
||||||
self.sm.tx().dma_push(self.dma.reborrow(), slice::from_ref(&cmd)).await;
|
self.sm
|
||||||
self.sm.rx().dma_pull(self.dma.reborrow(), read).await;
|
.tx()
|
||||||
|
.dma_push(self.dma.reborrow(), slice::from_ref(&cmd), false)
|
||||||
|
.await;
|
||||||
|
self.sm.rx().dma_pull(self.dma.reborrow(), read, false).await;
|
||||||
|
|
||||||
let mut status = 0;
|
let mut status = 0;
|
||||||
self.sm
|
self.sm
|
||||||
.rx()
|
.rx()
|
||||||
.dma_pull(self.dma.reborrow(), slice::from_mut(&mut status))
|
.dma_pull(self.dma.reborrow(), slice::from_mut(&mut status), false)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
#[cfg(feature = "defmt")]
|
#[cfg(feature = "defmt")]
|
||||||
|
|||||||
@ -12,3 +12,5 @@ async traits in `embedded-hal` and `embedded-hal-async`. You can also use these
|
|||||||
For the ESP32 series, there is an link:https://github.com/esp-rs/esp-hal[esp-hal] which you can use.
|
For the ESP32 series, there is an link:https://github.com/esp-rs/esp-hal[esp-hal] which you can use.
|
||||||
|
|
||||||
For the WCH 32-bit RISC-V series, there is an link:https://github.com/ch32-rs/ch32-hal[ch32-hal], which you can use.
|
For the WCH 32-bit RISC-V series, there is an link:https://github.com/ch32-rs/ch32-hal[ch32-hal], which you can use.
|
||||||
|
|
||||||
|
For the Microchip PolarFire SoC, there is link:https://github.com/AlexCharlton/mpfs-hal[mpfs-hal].
|
||||||
@ -31,6 +31,7 @@ The Embassy project maintains HALs for select hardware, but you can still use HA
|
|||||||
* link:https://docs.embassy.dev/embassy-rp/[embassy-rp], for the Raspberry Pi RP2040 microcontroller.
|
* link:https://docs.embassy.dev/embassy-rp/[embassy-rp], for the Raspberry Pi RP2040 microcontroller.
|
||||||
* link:https://github.com/esp-rs[esp-rs], for the Espressif Systems ESP32 series of chips.
|
* link:https://github.com/esp-rs[esp-rs], for the Espressif Systems ESP32 series of chips.
|
||||||
* link:https://github.com/ch32-rs/ch32-hal[ch32-hal], for the WCH 32-bit RISC-V(CH32V) series of chips.
|
* link:https://github.com/ch32-rs/ch32-hal[ch32-hal], for the WCH 32-bit RISC-V(CH32V) series of chips.
|
||||||
|
* link:https://github.com/AlexCharlton/mpfs-hal[mpfs-hal], for the Microchip PolarFire SoC.
|
||||||
|
|
||||||
NOTE: A common question is if one can use the Embassy HALs standalone. Yes, it is possible! There are no dependency on the executor within the HALs. You can even use them without async,
|
NOTE: A common question is if one can use the Embassy HALs standalone. Yes, it is possible! There are no dependency on the executor within the HALs. You can even use them without async,
|
||||||
as they implement both the link:https://github.com/rust-embedded/embedded-hal[Embedded HAL] blocking and async traits.
|
as they implement both the link:https://github.com/rust-embedded/embedded-hal[Embedded HAL] blocking and async traits.
|
||||||
|
|||||||
@ -362,6 +362,7 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineRx<'d, PIO, SM> {
|
|||||||
&'a mut self,
|
&'a mut self,
|
||||||
ch: PeripheralRef<'a, C>,
|
ch: PeripheralRef<'a, C>,
|
||||||
data: &'a mut [W],
|
data: &'a mut [W],
|
||||||
|
bswap: bool,
|
||||||
) -> Transfer<'a, C> {
|
) -> Transfer<'a, C> {
|
||||||
let pio_no = PIO::PIO_NO;
|
let pio_no = PIO::PIO_NO;
|
||||||
let p = ch.regs();
|
let p = ch.regs();
|
||||||
@ -379,6 +380,7 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineRx<'d, PIO, SM> {
|
|||||||
w.set_chain_to(ch.number());
|
w.set_chain_to(ch.number());
|
||||||
w.set_incr_read(false);
|
w.set_incr_read(false);
|
||||||
w.set_incr_write(true);
|
w.set_incr_write(true);
|
||||||
|
w.set_bswap(bswap);
|
||||||
w.set_en(true);
|
w.set_en(true);
|
||||||
});
|
});
|
||||||
compiler_fence(Ordering::SeqCst);
|
compiler_fence(Ordering::SeqCst);
|
||||||
@ -447,7 +449,12 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineTx<'d, PIO, SM> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Prepare a DMA transfer to TX FIFO.
|
/// Prepare a DMA transfer to TX FIFO.
|
||||||
pub fn dma_push<'a, C: Channel, W: Word>(&'a mut self, ch: PeripheralRef<'a, C>, data: &'a [W]) -> Transfer<'a, C> {
|
pub fn dma_push<'a, C: Channel, W: Word>(
|
||||||
|
&'a mut self,
|
||||||
|
ch: PeripheralRef<'a, C>,
|
||||||
|
data: &'a [W],
|
||||||
|
bswap: bool,
|
||||||
|
) -> Transfer<'a, C> {
|
||||||
let pio_no = PIO::PIO_NO;
|
let pio_no = PIO::PIO_NO;
|
||||||
let p = ch.regs();
|
let p = ch.regs();
|
||||||
p.read_addr().write_value(data.as_ptr() as u32);
|
p.read_addr().write_value(data.as_ptr() as u32);
|
||||||
@ -464,6 +471,7 @@ impl<'d, PIO: Instance, const SM: usize> StateMachineTx<'d, PIO, SM> {
|
|||||||
w.set_chain_to(ch.number());
|
w.set_chain_to(ch.number());
|
||||||
w.set_incr_read(true);
|
w.set_incr_read(true);
|
||||||
w.set_incr_write(false);
|
w.set_incr_write(false);
|
||||||
|
w.set_bswap(bswap);
|
||||||
w.set_en(true);
|
w.set_en(true);
|
||||||
});
|
});
|
||||||
compiler_fence(Ordering::SeqCst);
|
compiler_fence(Ordering::SeqCst);
|
||||||
|
|||||||
@ -173,7 +173,7 @@ impl<'l, P: Instance, const S: usize> PioHD44780<'l, P, S> {
|
|||||||
sm.set_enable(true);
|
sm.set_enable(true);
|
||||||
|
|
||||||
// display on and cursor on and blinking, reset display
|
// display on and cursor on and blinking, reset display
|
||||||
sm.tx().dma_push(dma.reborrow(), &[0x81u8, 0x0f, 1]).await;
|
sm.tx().dma_push(dma.reborrow(), &[0x81u8, 0x0f, 1], false).await;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
dma: dma.map_into(),
|
dma: dma.map_into(),
|
||||||
@ -198,6 +198,6 @@ impl<'l, P: Instance, const S: usize> PioHD44780<'l, P, S> {
|
|||||||
// set cursor to 1:15
|
// set cursor to 1:15
|
||||||
self.buf[38..].copy_from_slice(&[0x80, 0xcf]);
|
self.buf[38..].copy_from_slice(&[0x80, 0xcf]);
|
||||||
|
|
||||||
self.sm.tx().dma_push(self.dma.reborrow(), &self.buf).await;
|
self.sm.tx().dma_push(self.dma.reborrow(), &self.buf, false).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,6 +90,6 @@ impl<'a, P: Instance, const S: usize> PioI2sOut<'a, P, S> {
|
|||||||
|
|
||||||
/// Return an in-prograss dma transfer future. Awaiting it will guarentee a complete transfer.
|
/// Return an in-prograss dma transfer future. Awaiting it will guarentee a complete transfer.
|
||||||
pub fn write<'b>(&'b mut self, buff: &'b [u32]) -> Transfer<'b, AnyChannel> {
|
pub fn write<'b>(&'b mut self, buff: &'b [u32]) -> Transfer<'b, AnyChannel> {
|
||||||
self.sm.tx().dma_push(self.dma.reborrow(), buff)
|
self.sm.tx().dma_push(self.dma.reborrow(), buff, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -111,7 +111,7 @@ impl<'d, P: Instance, const S: usize, const N: usize> PioWs2812<'d, P, S, N> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DMA transfer
|
// DMA transfer
|
||||||
self.sm.tx().dma_push(self.dma.reborrow(), &words).await;
|
self.sm.tx().dma_push(self.dma.reborrow(), &words, false).await;
|
||||||
|
|
||||||
Timer::after_micros(55).await;
|
Timer::after_micros(55).await;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,6 +85,7 @@ unsafe fn on_interrupt(r: Regs, s: &'static State) {
|
|||||||
|
|
||||||
compiler_fence(Ordering::SeqCst);
|
compiler_fence(Ordering::SeqCst);
|
||||||
s.rx_waker.wake();
|
s.rx_waker.wake();
|
||||||
|
s.tx_waker.wake();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
@ -592,7 +593,7 @@ async fn flush(info: &Info, state: &State) -> Result<(), Error> {
|
|||||||
|
|
||||||
// future which completes when Transmission complete is detected
|
// future which completes when Transmission complete is detected
|
||||||
let abort = poll_fn(move |cx| {
|
let abort = poll_fn(move |cx| {
|
||||||
state.rx_waker.register(cx.waker());
|
state.tx_waker.register(cx.waker());
|
||||||
|
|
||||||
let sr = sr(r).read();
|
let sr = sr(r).read();
|
||||||
if sr.tc() {
|
if sr.tc() {
|
||||||
@ -2019,6 +2020,7 @@ enum Kind {
|
|||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
rx_waker: AtomicWaker,
|
rx_waker: AtomicWaker,
|
||||||
|
tx_waker: AtomicWaker,
|
||||||
tx_rx_refcount: AtomicU8,
|
tx_rx_refcount: AtomicU8,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2026,6 +2028,7 @@ impl State {
|
|||||||
const fn new() -> Self {
|
const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
rx_waker: AtomicWaker::new(),
|
rx_waker: AtomicWaker::new(),
|
||||||
|
tx_waker: AtomicWaker::new(),
|
||||||
tx_rx_refcount: AtomicU8::new(0),
|
tx_rx_refcount: AtomicU8::new(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,12 +8,12 @@ use embassy_hal_internal::PeripheralRef;
|
|||||||
use embedded_io_async::ReadReady;
|
use embedded_io_async::ReadReady;
|
||||||
use futures_util::future::{select, Either};
|
use futures_util::future::{select, Either};
|
||||||
|
|
||||||
use super::{
|
use super::{rdr, reconfigure, set_baudrate, sr, Config, ConfigError, Error, Info, State, UartRx};
|
||||||
clear_interrupt_flags, rdr, reconfigure, set_baudrate, sr, Config, ConfigError, Error, Info, State, UartRx,
|
|
||||||
};
|
|
||||||
use crate::dma::ReadableRingBuffer;
|
use crate::dma::ReadableRingBuffer;
|
||||||
use crate::gpio::{AnyPin, SealedPin as _};
|
use crate::gpio::{AnyPin, SealedPin as _};
|
||||||
use crate::mode::Async;
|
use crate::mode::Async;
|
||||||
|
#[cfg(any(usart_v3, usart_v4))]
|
||||||
|
use crate::pac::usart::regs;
|
||||||
use crate::time::Hertz;
|
use crate::time::Hertz;
|
||||||
use crate::usart::{Regs, Sr};
|
use crate::usart::{Regs, Sr};
|
||||||
|
|
||||||
@ -254,7 +254,12 @@ fn clear_idle_flag(r: Regs) -> Sr {
|
|||||||
|
|
||||||
// This read also clears the error and idle interrupt flags on v1.
|
// This read also clears the error and idle interrupt flags on v1.
|
||||||
unsafe { rdr(r).read_volatile() };
|
unsafe { rdr(r).read_volatile() };
|
||||||
clear_interrupt_flags(r, sr);
|
#[cfg(any(usart_v3, usart_v4))]
|
||||||
|
{
|
||||||
|
let mut clear_idle = regs::Icr(0);
|
||||||
|
clear_idle.set_idle(true);
|
||||||
|
r.icr().write_value(clear_idle);
|
||||||
|
}
|
||||||
|
|
||||||
r.cr1().modify(|w| w.set_idleie(true));
|
r.cr1().modify(|w| w.set_idleie(true));
|
||||||
|
|
||||||
|
|||||||
@ -72,8 +72,8 @@ async fn main(_spawner: Spawner) {
|
|||||||
loop {
|
loop {
|
||||||
let (rx, tx) = sm.rx_tx();
|
let (rx, tx) = sm.rx_tx();
|
||||||
join(
|
join(
|
||||||
tx.dma_push(dma_out_ref.reborrow(), &dout),
|
tx.dma_push(dma_out_ref.reborrow(), &dout, false),
|
||||||
rx.dma_pull(dma_in_ref.reborrow(), &mut din),
|
rx.dma_pull(dma_in_ref.reborrow(), &mut din, false),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
for i in 0..din.len() {
|
for i in 0..din.len() {
|
||||||
|
|||||||
@ -72,8 +72,8 @@ async fn main(_spawner: Spawner) {
|
|||||||
loop {
|
loop {
|
||||||
let (rx, tx) = sm.rx_tx();
|
let (rx, tx) = sm.rx_tx();
|
||||||
join(
|
join(
|
||||||
tx.dma_push(dma_out_ref.reborrow(), &dout),
|
tx.dma_push(dma_out_ref.reborrow(), &dout, false),
|
||||||
rx.dma_pull(dma_in_ref.reborrow(), &mut din),
|
rx.dma_pull(dma_in_ref.reborrow(), &mut din, false),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
for i in 0..din.len() {
|
for i in 0..din.len() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user