Skip to content
This repository was archived by the owner on Jun 26, 2026. It is now read-only.

Commit 151f528

Browse files
committed
bump AXI uart16550 crate
1 parent 86a96e9 commit 151f528

5 files changed

Lines changed: 28 additions & 31 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88

99
# [unreleased]
1010

11+
- TX futures borrow buffer for their lifetime now.
12+
- Constructor is now `unsafe`.
13+
- Async TX write method now returns a future.
14+
1115
# [v0.1.0] 2025-11-28
1216

1317
Initial release.

Cargo.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
[package]
22
name = "axi-uart16550"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
description = "AXI UART16550 IP core driver"
5-
author = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
65
rust-version = "1.85.1"
76
edition = "2024"
87
homepage = "https://egit.irs.uni-stuttgart.de/rust/axi-uart16550"
@@ -11,19 +10,19 @@ license = "MIT OR Apache-2.0"
1110

1211
[dependencies]
1312
derive-mmio = "0.6"
14-
bitbybit = "1.4"
13+
bitbybit = "2"
1514
arbitrary-int = "2"
1615
nb = "1"
1716
libm = "0.2"
1817
critical-section = "1"
1918
thiserror = { version = "2", default-features = false }
20-
fugit = "0.3"
19+
fugit = "0.4"
2120
embedded-hal-async = "1"
2221
embedded-hal-nb = "1"
2322
embedded-io = "0.7"
2423
embedded-io-async = "0.7"
25-
embassy-sync = "0.7"
26-
raw-slicee = "0.1"
24+
embassy-sync = "0.8"
25+
raw-buffer = "0.1"
2726

2827
[features]
2928
default = ["1-waker"]

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ check:
1313
cargo check
1414

1515
embedded:
16-
cargo build --target armv7a-none-eabi
16+
cargo build --target armv7a-none-eabihf
1717

1818
test:
1919
cargo nextest r

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn calculate_error_rate_from_div(
6161
if baudrate == 0 || div == 0 {
6262
return Err(DivisorZeroError);
6363
}
64-
let actual = (clk_in.raw() as f32) / (16.0 * div as f32);
64+
let actual = (clk_in.to_raw() as f32) / (16.0 * div as f32);
6565
Ok(libm::fabsf(actual - baudrate as f32) / baudrate as f32)
6666
}
6767

@@ -140,7 +140,7 @@ impl ClockConfig {
140140
return Err(DivisorZeroError);
141141
}
142142
// Rounding integer division, by adding half the divisor to the dividend.
143-
Ok((clk_in.raw() + (8 * baudrate)) / (16 * baudrate))
143+
Ok((clk_in.to_raw() + (8 * baudrate)) / (16 * baudrate))
144144
}
145145
}
146146

src/tx_async.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use core::{cell::RefCell, convert::Infallible, sync::atomic::AtomicBool};
2020
use critical_section::Mutex;
2121
use embassy_sync::waitqueue::AtomicWaker;
2222
use embedded_hal_async::delay::DelayNs;
23-
use raw_slice::RawBufSlice;
23+
use raw_buffer::RawBufSlice;
2424

2525
use crate::{
2626
FIFO_DEPTH, Tx,
@@ -130,23 +130,15 @@ impl TxContext {
130130
}
131131

132132
/// TX future structure.
133-
pub struct TxFuture {
133+
pub struct TxFuture<'tx, 'buf> {
134134
waker_idx: usize,
135135
reg_block: registers::MmioRegisters<'static>,
136+
phantom: core::marker::PhantomData<(&'tx (), &'buf ())>,
136137
}
137138

138-
impl TxFuture {
139+
impl<'tx, 'buf> TxFuture<'tx, 'buf> {
139140
/// Create a new TX future which can be used for asynchronous TX operations.
140-
///
141-
/// # Safety
142-
///
143-
/// This function stores the raw pointer of the passed data slice. The user MUST ensure
144-
/// that the slice outlives the data structure.
145-
pub unsafe fn new(
146-
tx: &mut Tx,
147-
waker_idx: usize,
148-
data: &[u8],
149-
) -> Result<Self, InvalidWakerIndex> {
141+
pub fn new(tx: &mut Tx, waker_idx: usize, data: &'buf [u8]) -> Result<Self, InvalidWakerIndex> {
150142
TX_DONE[waker_idx].store(false, core::sync::atomic::Ordering::Relaxed);
151143
tx.disable_interrupt();
152144
tx.reset_fifo();
@@ -168,11 +160,12 @@ impl TxFuture {
168160
Ok(Self {
169161
waker_idx,
170162
reg_block: unsafe { tx.regs.clone() },
163+
phantom: core::marker::PhantomData,
171164
})
172165
}
173166
}
174167

175-
impl Future for TxFuture {
168+
impl Future for TxFuture<'_, '_> {
176169
type Output = usize;
177170

178171
fn poll(
@@ -192,7 +185,7 @@ impl Future for TxFuture {
192185
}
193186
}
194187

195-
impl Drop for TxFuture {
188+
impl Drop for TxFuture<'_, '_> {
196189
fn drop(&mut self) {
197190
let mut tx = Tx::new(unsafe { self.reg_block.clone() });
198191
tx.disable_interrupt();
@@ -212,7 +205,12 @@ impl<D: DelayNs> TxAsync<D> {
212205
/// The delay function is a [DelayNs] provider which is used to allow flushing the
213206
/// device properly. This is because even when a write finished, the UART might still
214207
/// be busy shifting the last byte out.
215-
pub fn new(tx: Tx, waker_idx: usize, delay: D) -> Result<Self, InvalidWakerIndex> {
208+
///
209+
/// # Safety
210+
///
211+
/// The user MUST ensure that the `Drop` method of all futures generated with this driver
212+
/// is called on transfer cancellation. By default, this does not require any special handling.
213+
pub unsafe fn new(tx: Tx, waker_idx: usize, delay: D) -> Result<Self, InvalidWakerIndex> {
216214
if waker_idx >= NUM_WAKERS {
217215
return Err(InvalidWakerIndex(waker_idx));
218216
}
@@ -227,12 +225,8 @@ impl<D: DelayNs> TxAsync<D> {
227225
///
228226
/// This implementation is not side effect free, and a started future might have already
229227
/// written part of the passed buffer.
230-
pub async fn write(&mut self, buf: &[u8]) -> usize {
231-
if buf.is_empty() {
232-
return 0;
233-
}
234-
let fut = unsafe { TxFuture::new(&mut self.tx, self.waker_idx, buf).unwrap() };
235-
fut.await
228+
pub fn write<'buf>(&mut self, buf: &'buf [u8]) -> TxFuture<'_, 'buf> {
229+
TxFuture::new(&mut self.tx, self.waker_idx, buf).unwrap()
236230
}
237231

238232
/// Flush this output stream, ensuring that all intermediately buffered contents reach their destination.

0 commit comments

Comments
 (0)