1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
/* Copyright (c) [2023] [Syswonder Community]
* [Rukos] is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
//! Common traits and types for graphics display device drivers.
#![no_std]
#[doc(no_inline)]
pub use driver_common::{BaseDriverOps, DevError, DevResult, DeviceType};
/// The information of the graphics device.
#[derive(Debug, Clone, Copy)]
pub struct DisplayInfo {
/// The visible width.
pub width: u32,
/// The visible height.
pub height: u32,
/// The base virtual address of the framebuffer.
pub fb_base_vaddr: usize,
/// The size of the framebuffer in bytes.
pub fb_size: usize,
}
/// The framebuffer.
///
/// It's a special memory buffer that mapped from the device memory.
pub struct FrameBuffer<'a> {
_raw: &'a mut [u8],
}
impl<'a> FrameBuffer<'a> {
/// Use the given raw pointer and size as the framebuffer.
///
/// # Safety
///
/// Caller must insure that the given memory region is valid and accessible.
pub unsafe fn from_raw_parts_mut(ptr: *mut u8, len: usize) -> Self {
Self {
_raw: core::slice::from_raw_parts_mut(ptr, len),
}
}
/// Use the given slice as the framebuffer.
pub fn from_slice(slice: &'a mut [u8]) -> Self {
Self { _raw: slice }
}
}
/// Operations that require a graphics device driver to implement.
pub trait DisplayDriverOps: BaseDriverOps {
/// Get the display information.
fn info(&self) -> DisplayInfo;
/// Get the framebuffer.
fn fb(&self) -> FrameBuffer;
/// Whether need to flush the framebuffer to the screen.
fn need_flush(&self) -> bool;
/// Flush framebuffer to the screen.
fn flush(&mut self) -> DevResult;
}