Skip to content

Commit 36ad03a

Browse files
Merge #215
215: Add fmt::Write impl for Serial<USART, PINS> r=TeXitoi a=therealprof This allows to send formatted output directly to the serial port instead of having to split it as found in #214. Signed-off-by: Daniel Egger <[email protected]> Co-authored-by: Daniel Egger <[email protected]>
2 parents 9ef9b2d + 3660505 commit 36ad03a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2020
- Allow for skipping an ongoing DMA transfer if not using double buffering.
2121
- Change DMA traits to `embedded-dma`.
2222
- Use bitbanding during clock enabling and peripheral reset to avoid data races.
23+
- Add missing `Write` implementation for `Serial` and implemented better error handling.
2324

2425
### Added
2526

src/serial.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,12 +1862,26 @@ halUsart! {
18621862
UART10: (uart10, apb2enr, 7, uart10en, pclk2),
18631863
}
18641864

1865+
impl<USART, PINS> fmt::Write for Serial<USART, PINS>
1866+
where
1867+
Serial<USART, PINS>: serial::Write<u8>,
1868+
{
1869+
fn write_str(&mut self, s: &str) -> fmt::Result {
1870+
s.as_bytes()
1871+
.iter()
1872+
.try_for_each(|c| block!(self.write(*c)))
1873+
.map_err(|_| fmt::Error)
1874+
}
1875+
}
1876+
18651877
impl<USART> fmt::Write for Tx<USART>
18661878
where
18671879
Tx<USART>: serial::Write<u8>,
18681880
{
18691881
fn write_str(&mut self, s: &str) -> fmt::Result {
1870-
let _ = s.as_bytes().iter().map(|c| block!(self.write(*c))).last();
1871-
Ok(())
1882+
s.as_bytes()
1883+
.iter()
1884+
.try_for_each(|c| block!(self.write(*c)))
1885+
.map_err(|_| fmt::Error)
18721886
}
18731887
}

0 commit comments

Comments
 (0)