ove/console.rs
1// Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4//
5// This file is part of oveRTOS.
6
7//! Low-level console I/O for oveRTOS.
8//!
9//! Provides single-character read/write access to the platform console
10//! (typically a UART). For formatted output, use the [`crate::log`] function
11//! or the [`crate::log_fmt!`] macro instead.
12
13use crate::bindings;
14
15/// Non-blocking read of a single character from the console.
16///
17/// Returns `Some(c)` where `c` is in `0..=127`, or `None` if no character
18/// is currently available.
19pub fn getchar() -> Option<i32> {
20 let c = unsafe { bindings::ove_console_getchar() };
21 if c < 0 { None } else { Some(c) }
22}
23
24/// Write a single character to the console output.
25///
26/// `c` should be a valid ASCII byte value (`0..=127`).
27pub fn putchar(c: i32) {
28 unsafe { bindings::ove_console_putchar(c) }
29}