axdriver_display/lib.rs
1//! Common traits and types for graphics display device drivers.
2
3#![no_std]
4
5#[doc(no_inline)]
6pub use axdriver_base::{BaseDriverOps, DevError, DevResult, DeviceType};
7
8/// The information of the graphics device.
9#[derive(Debug, Clone, Copy)]
10pub struct DisplayInfo {
11 /// The visible width.
12 pub width: u32,
13 /// The visible height.
14 pub height: u32,
15 /// The base virtual address of the framebuffer.
16 pub fb_base_vaddr: usize,
17 /// The size of the framebuffer in bytes.
18 pub fb_size: usize,
19}
20
21/// The framebuffer.
22///
23/// It's a special memory buffer that mapped from the device memory.
24pub struct FrameBuffer<'a> {
25 _raw: &'a mut [u8],
26}
27
28impl<'a> FrameBuffer<'a> {
29 /// Use the given raw pointer and size as the framebuffer.
30 ///
31 /// # Safety
32 ///
33 /// Caller must ensure that the given memory region is valid and accessible.
34 pub unsafe fn from_raw_parts_mut(ptr: *mut u8, len: usize) -> Self {
35 Self {
36 _raw: unsafe { core::slice::from_raw_parts_mut(ptr, len) },
37 }
38 }
39
40 /// Use the given slice as the framebuffer.
41 pub fn from_slice(slice: &'a mut [u8]) -> Self {
42 Self { _raw: slice }
43 }
44}
45
46/// Operations that require a graphics device driver to implement.
47pub trait DisplayDriverOps: BaseDriverOps {
48 /// Get the display information.
49 fn info(&self) -> DisplayInfo;
50
51 /// Get the framebuffer.
52 fn fb(&self) -> FrameBuffer<'_>;
53
54 /// Whether need to flush the framebuffer to the screen.
55 fn need_flush(&self) -> bool;
56
57 /// Flush framebuffer to the screen.
58 fn flush(&mut self) -> DevResult;
59}