Merge pull request 'improve async TX API for UART' (#6) from improve-tx-async-api into main
Some checks failed
shared-hal-ci / Check build (push) Has been cancelled
shared-hal-ci / Check formatting (push) Has been cancelled
shared-hal-ci / Check Documentation Build (push) Has been cancelled
shared-hal-ci / Clippy (push) Has been cancelled
va108xx-ci / Check build (push) Has been cancelled
va108xx-ci / Run Tests (push) Has been cancelled
va108xx-ci / Check formatting (push) Has been cancelled
va108xx-ci / Check Documentation Build (push) Has been cancelled
va108xx-ci / Clippy (push) Has been cancelled
va416xx-ci / Check build (push) Has been cancelled
va416xx-ci / Run Tests (push) Has been cancelled
va416xx-ci / Check formatting (push) Has been cancelled
va416xx-ci / Check Documentation Build (push) Has been cancelled
va416xx-ci / Clippy (push) Has been cancelled
Some checks failed
shared-hal-ci / Check build (push) Has been cancelled
shared-hal-ci / Check formatting (push) Has been cancelled
shared-hal-ci / Check Documentation Build (push) Has been cancelled
shared-hal-ci / Clippy (push) Has been cancelled
va108xx-ci / Check build (push) Has been cancelled
va108xx-ci / Run Tests (push) Has been cancelled
va108xx-ci / Check formatting (push) Has been cancelled
va108xx-ci / Check Documentation Build (push) Has been cancelled
va108xx-ci / Clippy (push) Has been cancelled
va416xx-ci / Check build (push) Has been cancelled
va416xx-ci / Run Tests (push) Has been cancelled
va416xx-ci / Check formatting (push) Has been cancelled
va416xx-ci / Check Documentation Build (push) Has been cancelled
va416xx-ci / Clippy (push) Has been cancelled
Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
@@ -15,7 +15,6 @@ use embassy_example as _;
|
|||||||
|
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_time::{Duration, Instant, Ticker};
|
use embassy_time::{Duration, Instant, Ticker};
|
||||||
use embedded_io_async::Write;
|
|
||||||
use va108xx_hal::{
|
use va108xx_hal::{
|
||||||
gpio::{Output, PinState},
|
gpio::{Output, PinState},
|
||||||
pac::{self, interrupt},
|
pac::{self, interrupt},
|
||||||
@@ -70,8 +69,8 @@ async fn main(_spawner: Spawner) {
|
|||||||
led0.toggle();
|
led0.toggle();
|
||||||
led1.toggle();
|
led1.toggle();
|
||||||
led2.toggle();
|
led2.toggle();
|
||||||
let _written = async_tx
|
async_tx
|
||||||
.write(STR_LIST[idx].as_bytes())
|
.write_all(STR_LIST[idx].as_bytes())
|
||||||
.await
|
.await
|
||||||
.expect("writing failed");
|
.expect("writing failed");
|
||||||
idx += 1;
|
idx += 1;
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ use defmt_rtt as _;
|
|||||||
use embassy_example::EXTCLK_FREQ;
|
use embassy_example::EXTCLK_FREQ;
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_time::{Duration, Instant, Ticker};
|
use embassy_time::{Duration, Instant, Ticker};
|
||||||
use embedded_io_async::Write;
|
|
||||||
use va416xx_hal::{
|
use va416xx_hal::{
|
||||||
clock::ClockConfigurator,
|
clock::ClockConfigurator,
|
||||||
gpio::{Output, PinState},
|
gpio::{Output, PinState},
|
||||||
@@ -69,8 +68,8 @@ async fn main(_spawner: Spawner) {
|
|||||||
loop {
|
loop {
|
||||||
defmt::println!("Current time: {}", Instant::now().as_secs());
|
defmt::println!("Current time: {}", Instant::now().as_secs());
|
||||||
led.toggle();
|
led.toggle();
|
||||||
let _written = async_tx
|
async_tx
|
||||||
.write(STR_LIST[idx].as_bytes())
|
.write_all(STR_LIST[idx].as_bytes())
|
||||||
.await
|
.await
|
||||||
.expect("writing failed");
|
.expect("writing failed");
|
||||||
idx += 1;
|
idx += 1;
|
||||||
|
|||||||
@@ -177,6 +177,27 @@ impl TxAsync {
|
|||||||
Self(tx)
|
Self(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Write a buffer asynchronously.
|
||||||
|
///
|
||||||
|
/// This implementation is not side effect free, and a started future might have already
|
||||||
|
/// written part of the passed buffer.
|
||||||
|
pub async fn write(&mut self, buf: &[u8]) -> Result<usize, TxOverrunError> {
|
||||||
|
let fut = unsafe { TxFuture::new(&mut self.0, buf) };
|
||||||
|
fut.await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Write an entire buffer into this writer.
|
||||||
|
///
|
||||||
|
/// This function calls `write()` in a loop until exactly `buf.len()` bytes have
|
||||||
|
/// been written, waiting if needed.
|
||||||
|
///
|
||||||
|
/// This function is not side-effect-free on cancel (AKA "cancel-safe"), i.e. if you cancel (drop) a returned
|
||||||
|
/// future that hasn't completed yet, some bytes might have already been written.
|
||||||
|
pub async fn write_all(&mut self, buf: &[u8]) -> Result<(), TxOverrunError> {
|
||||||
|
let fut = <Self as embedded_io_async::Write>::write_all(self, buf);
|
||||||
|
fut.await
|
||||||
|
}
|
||||||
|
|
||||||
pub fn release(self) -> Tx {
|
pub fn release(self) -> Tx {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
@@ -203,8 +224,7 @@ impl Write for TxAsync {
|
|||||||
/// This implementation is not side effect free, and a started future might have already
|
/// This implementation is not side effect free, and a started future might have already
|
||||||
/// written part of the passed buffer.
|
/// written part of the passed buffer.
|
||||||
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
|
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
|
||||||
let fut = unsafe { TxFuture::new(&mut self.0, buf) };
|
self.write(buf).await
|
||||||
fut.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn flush(&mut self) -> Result<(), Self::Error> {
|
async fn flush(&mut self) -> Result<(), Self::Error> {
|
||||||
|
|||||||
Reference in New Issue
Block a user