From 1ca54d9ed6f5ca7d53e7f2064bb870e3119169eb Mon Sep 17 00:00:00 2001 From: Berkus Decker Date: Wed, 2 Nov 2022 14:47:42 +0200 Subject: [PATCH] =?UTF-8?q?fix(console):=20=F0=9F=90=9B=20Fix=20unicode=20?= =?UTF-8?q?character=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (At the expense of about 3kb code size.) --- machine/src/platform/rpi3/mini_uart.rs | 8 ++++++-- machine/src/platform/rpi3/pl011_uart.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/machine/src/platform/rpi3/mini_uart.rs b/machine/src/platform/rpi3/mini_uart.rs index 5d1160e..35578b5 100644 --- a/machine/src/platform/rpi3/mini_uart.rs +++ b/machine/src/platform/rpi3/mini_uart.rs @@ -284,7 +284,11 @@ impl ConsoleOps for PreparedMiniUart { if #[cfg(not(feature = "noserial"))] { /// Send a character fn write_char(&self, c: char) { - self.write_byte(c as u8); + let mut b = [0u8; 4]; + let _ = c.encode_utf8(&mut b); + for x in 0..c.len_utf8() { + self.write_byte(b[x]); + } } /// Display a string @@ -299,7 +303,7 @@ impl ConsoleOps for PreparedMiniUart { } } - /// Receive a character + /// Receive a character -- FIXME: needs a state machine to read UTF-8 chars! fn read_char(&self) -> char { let mut ret = self.read_byte() as char; diff --git a/machine/src/platform/rpi3/pl011_uart.rs b/machine/src/platform/rpi3/pl011_uart.rs index e67d8aa..c57e6ae 100644 --- a/machine/src/platform/rpi3/pl011_uart.rs +++ b/machine/src/platform/rpi3/pl011_uart.rs @@ -401,10 +401,15 @@ impl SerialOps for PreparedPL011Uart { } } +// @todo Seems like a blanket implementation of ConsoleOps is in order.. impl ConsoleOps for PreparedPL011Uart { /// Send a character fn write_char(&self, c: char) { - self.write_byte(c as u8) + let mut b = [0u8; 4]; + let _ = c.encode_utf8(&mut b); + for x in 0..c.len_utf8() { + self.write_byte(b[x]); + } } /// Display a string @@ -419,7 +424,7 @@ impl ConsoleOps for PreparedPL011Uart { } } - /// Receive a character + /// Receive a character -- FIXME: needs a state machine to read UTF-8 chars! fn read_char(&self) -> char { let mut ret = self.read_byte() as char;