Skip to main content

proka_bootloader/
output.rs

1//! The output module, which provides framebuffer info and
2//! its utilities.
3
4/// The framebuffer structure, which provides basic 5
5/// elements:
6///
7/// - Framebuffer base address;
8/// - Framebuffer height;
9/// - Framebuffer width;
10/// - Framebuffer BPB
11/// - Framebuffer pitch
12///
13/// You can use it to do output/graphics operations.
14#[repr(C, packed)]
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16#[cfg_attr(feature = "default", derive(Default))]
17pub struct Framebuffer {
18    fb_addr: u64,
19    width: u32,
20    height: u32,
21    bpp: u8,
22    pitch: u16,
23}
24
25impl Framebuffer {
26    /// Creates a nee framebuffer object.
27    ///
28    /// Note: This method will automatically create by
29    /// bootloader entry, if you are using kernel, this
30    /// method is not needed and not usable.
31    #[cfg(feature = "loader_main")]
32    pub fn new(addr: u64, width: u32, height: u32, bpp: u8, pitch: u16) -> Self {
33        Self {
34            fb_addr: addr,
35            width,
36            height,
37            bpp,
38            pitch,
39        }
40    }
41
42    /// Get the framebuffer address.
43    pub fn address(&self) -> u64 {
44        self.fb_addr
45    }
46
47    /// Get the framebuffer width.
48    pub fn width(&self) -> u32 {
49        self.width
50    }
51
52    /// Get the framebuffer height.
53    pub fn height(&self) -> u32 {
54        self.height
55    }
56
57    /// Get the framebuffer BPP.
58    pub fn bpp(&self) -> u8 {
59        self.bpp
60    }
61
62    /// Get the framebuffer pitch.
63    pub fn pitch(&self) -> u16 {
64        self.pitch
65    }
66}