Skip to content

Commit f24daad

Browse files
credmontylerwhall
authored andcommitted
zephyr::uart::uart_poll_in(): Change return to a Result<Option<char>, u32>
1 parent 214bc7a commit f24daad

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

rust-app/zephyr/src/uart.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::device::Device;
44
pub trait UartSyscalls {
55
fn uart_poll_out(device: &Device, out_char: char);
66

7-
fn uart_poll_in(device: &Device, in_char: &mut char) -> i32;
7+
fn uart_poll_in(device: &Device) -> Result<Option<char>, u32>;
88

99
fn uart_err_check(device: &Device) -> i32;
1010

@@ -27,16 +27,23 @@ macro_rules! trait_impl {
2727
}
2828

2929
#[inline(always)]
30-
fn uart_poll_in(device: &Device, in_char: &mut char) -> i32 {
30+
fn uart_poll_in(device: &Device) -> Result<Option<char>, u32> {
3131
let mut munge: u8 = 0;
32-
let rc: i32 = unsafe {
32+
let rc = unsafe {
3333
zephyr_sys::syscalls::$context::uart_poll_in(
3434
device as *const _ as *mut _,
3535
&mut munge,
3636
)
37-
};
38-
*in_char = munge as char;
39-
rc
37+
}
38+
.neg_err()
39+
.map(|_| munge as char);
40+
41+
// remap a return value of -1 from uart_poll_in() to Ok(None)
42+
match rc {
43+
Ok(c) => Ok(Some(c)),
44+
Err(1) => Ok(None),
45+
Err(e) => Err(e),
46+
}
4047
}
4148

4249
#[inline(always)]

0 commit comments

Comments
 (0)