From 9acb915fb9dabeef33a40a38d8236ea8044d5f01 Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Wed, 23 Aug 2023 08:24:47 -0700 Subject: [PATCH] Implement the `ufmt_write::uWrite` trait for the USB Serial JTAG driver (#751) * Implement the `ufmt_write::uWrite` trait for the USB Serial JTAG driver * Update CHANGELOG --- CHANGELOG.md | 1 + esp-hal-common/src/usb_serial_jtag.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46b1f4570..31f51746a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add GPIO (output) and delay functionality to `esp32c6-lp-hal` (#715) - Implement RTCIO pullup, pulldown and hold control for Xtensa MCUs (#684) - Add GPIO input support and implement additional `embedded-hal` output traits for the C6's LP core [#720] +- Implement `ufmt_write::uWrite` trait for USB Serial JTAG (#751) ### Changed diff --git a/esp-hal-common/src/usb_serial_jtag.rs b/esp-hal-common/src/usb_serial_jtag.rs index 0e4e494ea..ff4cddf0c 100644 --- a/esp-hal-common/src/usb_serial_jtag.rs +++ b/esp-hal-common/src/usb_serial_jtag.rs @@ -240,6 +240,25 @@ impl core::fmt::Write for UsbSerialJtag<'_> { } } +#[cfg(feature = "ufmt")] +impl ufmt_write::uWrite for UsbSerialJtag<'_> { + type Error = Error; + + #[inline] + fn write_str(&mut self, s: &str) -> Result<(), Self::Error> { + self.write_bytes(s.as_bytes())?; + Ok(()) + } + + #[inline] + fn write_char(&mut self, ch: char) -> Result<(), Self::Error> { + let mut buffer = [0u8; 4]; + self.write_bytes(ch.encode_utf8(&mut buffer).as_bytes())?; + + Ok(()) + } +} + impl embedded_hal::serial::Read for UsbSerialJtag<'_> { type Error = Error;