Skip to main content

ax_display/
lib.rs

1//! [ArceOS](https://github.com/arceos-org/arceos) display module.
2//!
3//! Currently only supports direct writing to the framebuffer.
4
5#![no_std]
6
7#[macro_use]
8extern crate log;
9
10#[doc(no_inline)]
11pub use ax_driver::prelude::DisplayInfo;
12use ax_driver::{AxDeviceContainer, prelude::*};
13use ax_lazyinit::LazyInit;
14use ax_sync::Mutex;
15
16static MAIN_DISPLAY: LazyInit<Mutex<AxDisplayDevice>> = LazyInit::new();
17
18/// Initializes the display subsystem by underlayer devices.
19pub fn init_display(mut display_devs: AxDeviceContainer<AxDisplayDevice>) {
20    info!("Initialize display subsystem...");
21
22    if let Some(dev) = display_devs.take_one() {
23        info!("  use display device 0: {:?}", dev.device_name());
24        MAIN_DISPLAY.init_once(Mutex::new(dev));
25    } else {
26        warn!("  No display device found!");
27    }
28}
29
30/// Checks if there is a display device.
31pub fn has_display() -> bool {
32    MAIN_DISPLAY.is_inited()
33}
34
35/// Gets the framebuffer information.
36pub fn framebuffer_info() -> DisplayInfo {
37    MAIN_DISPLAY.lock().info()
38}
39
40/// Flushes the framebuffer, i.e. show on the screen.
41pub fn framebuffer_flush() -> bool {
42    MAIN_DISPLAY.lock().flush().is_ok()
43}