1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-22 08:06:17 +04:00

Rust style docs and cargo fmt

This commit is contained in:
Runji Wang 2019-11-01 14:06:43 +08:00
parent 74b13a449a
commit 91a4860b64
2 changed files with 193 additions and 140 deletions

View File

@ -1,6 +1,5 @@
//! Framebuffer
use crate::fs::vga::{self, fb_fix_screeninfo, fb_var_screeninfo};
use alloc::string::String;
use core::fmt;
use lazy_static::lazy_static;
@ -235,64 +234,6 @@ impl Framebuffer {
pub fn clear(&mut self) {
self.fill(0, self.fb_info.screen_size, 0);
}
pub fn fill_var_screeninfo(&self, var_info: &mut fb_var_screeninfo) {
var_info.xres = self.fb_info.xres;
var_info.yres = self.fb_info.yres;
var_info.xres_virtual = self.fb_info.xres_virtual;
var_info.yres_virtual = self.fb_info.yres_virtual;
var_info.xoffset = self.fb_info.xoffset;
var_info.yoffset = self.fb_info.yoffset;
var_info.bits_per_pixel = self.fb_info.depth as u32;
var_info.blue = vga::fb_bitfield {
offset: 0 as u32,
length: self.fb_info.depth as u32 / 4,
msb_right: 1 as u32,
};
var_info.green = vga::fb_bitfield {
offset: self.fb_info.depth as u32 / 4,
length: self.fb_info.depth as u32 / 4,
msb_right: 1 as u32,
};
var_info.red = vga::fb_bitfield {
offset: self.fb_info.depth as u32 / 2,
length: self.fb_info.depth as u32 / 4,
msb_right: 1 as u32,
};
var_info.transp = vga::fb_bitfield {
offset: self.fb_info.depth as u32 * 3 / 4,
length: self.fb_info.depth as u32 / 4,
msb_right: 1 as u32,
};
}
pub fn fill_fix_screeninfo(&self, fix_info: &mut fb_fix_screeninfo) {
// pub id: [u8; 16], /* identification string eg "TT Builtin" */
fix_info.smem_start = self.fb_info.paddr as u64;
/* (physical address) */
fix_info.smem_len = self.fb_info.screen_size as u32;
fix_info.type_ = vga::FB_TYPE_PACKED_PIXELS;
// fix_info.type_aux = self.fb_info.type_aux;
fix_info.visual = vga::FB_VISUAL_TRUECOLOR;
// fix_info.xpanstep = 0;
// fix_info.ypanstep = 0;
// fix_info.ywrapstep = 0;
fix_info.line_length = self.fb_info.xres * self.fb_info.depth as u32 / 8;
fix_info.mmio_start = 0 as u64;
/* (physical address) */
fix_info.mmio_len = 0 as u32;
fix_info.accel = vga::FB_ACCEL_NONE;
/* specific chip/card we have */
// fix_info.capabilities = self.fb_info.capabilities;
// pub reserved: [u16; 2], /* Reserved for future compatibility */
}
}
use rcore_console::embedded_graphics::prelude::*;

View File

@ -1,6 +1,6 @@
use rcore_fs::vfs::*;
use crate::drivers::gpu::fb::FRAME_BUFFER;
use crate::drivers::gpu::fb::{FramebufferInfo, FRAME_BUFFER};
use crate::memory::phys_to_virt;
use alloc::{string::String, sync::Arc, vec::Vec};
use core::any::Any;
@ -56,19 +56,21 @@ impl INode for Vga {
})
}
fn io_control(&self, cmd: u32, data: usize) -> Result<()> {
info!("cmd {:#x} , data {:#x} vga not support ioctl !", cmd, data);
const FBIOGET_VSCREENINFO: u32 = 0x4600;
const FBIOGET_FSCREENINFO: u32 = 0x4602;
match cmd {
FBIOGET_FSCREENINFO => {
let fb_fix_info = unsafe { &mut *(data as *mut fb_fix_screeninfo) };
let fb_fix_info = unsafe { &mut *(data as *mut FbFixScreeninfo) };
if let Some(fb) = FRAME_BUFFER.lock().as_ref() {
fb.fill_fix_screeninfo(fb_fix_info);
fb_fix_info.fill_from(&fb.fb_info);
}
Ok(())
}
FBIOGET_VSCREENINFO => {
let fb_var_info = unsafe { &mut *(data as *mut fb_var_screeninfo) };
let fb_var_info = unsafe { &mut *(data as *mut FbVarScreeninfo) };
if let Some(fb) = FRAME_BUFFER.lock().as_ref() {
fb.fill_var_screeninfo(fb_var_info);
fb_var_info.fill_from(&fb.fb_info);
}
Ok(())
}
@ -77,101 +79,211 @@ impl INode for Vga {
Err(FsError::NotSupported)
}
}
//let fb_fix_info = unsafe{ &mut *(data as *mut fb_fix_screeninfo) };
//Ok(())
}
fn as_any_ref(&self) -> &dyn Any {
self
}
}
const FBIOGET_FSCREENINFO: u32 = 0x4602;
const FBIOGET_VSCREENINFO: u32 = 0x4600;
#[repr(u32)]
#[derive(Debug, Copy, Clone)]
enum FbType {
/// Packed Pixels
PackedPixels = 0,
/// Non interleaved planes
Planes = 1,
/// Interleaved planes
InterleavedPlanes = 2,
/// Text/attributes
Text = 3,
/// EGA/VGA planes
VgaPlanes = 4,
/// Type identified by a V4L2 FOURCC
FourCC = 5,
}
pub const FB_TYPE_PACKED_PIXELS: u32 = 0; /* Packed Pixels */
pub const FB_TYPE_PLANES: u32 = 1; /* Non interleaved planes */
pub const FB_TYPE_INTERLEAVED_PLANES: u32 = 2; /* Interleaved planes */
pub const FB_TYPE_TEXT: u32 = 3; /* Text/attributes */
pub const FB_TYPE_VGA_PLANES: u32 = 4; /* EGA/VGA planes */
pub const FB_TYPE_FOURCC: u32 = 5; /* Type identified by a V4L2 FOURCC */
#[repr(u32)]
#[derive(Debug, Copy, Clone)]
enum FbVisual {
/// Monochr. 1=Black 0=White
Mono01 = 0,
/// Monochr. 1=White 0=Black
Mono10 = 1,
/// True color
TrueColor = 2,
/// Pseudo color (like atari)
PseudoColor = 3,
/// Direct color
DirectColor = 4,
/// Pseudo color readonly
StaticPseudoColor = 5,
/// Visual identified by a V4L2 FOURCC
FourCC = 6,
}
pub const FB_VISUAL_MONO01: u32 = 0; /* Monochr. 1=Black 0=White */
pub const FB_VISUAL_MONO10: u32 = 1; /* Monochr. 1=White 0=Black */
pub const FB_VISUAL_TRUECOLOR: u32 = 2; /* True color */
pub const FB_VISUAL_PSEUDOCOLOR: u32 = 3; /* Pseudo color (like atari) */
pub const FB_VISUAL_DIRECTCOLOR: u32 = 4; /* Direct color */
pub const FB_VISUAL_STATIC_PSEUDOCOLOR: u32 = 5; /* Pseudo color readonly */
pub const FB_VISUAL_FOURCC: u32 = 6; /* Visual identified by a V4L2 FOURCC */
pub const FB_ACCEL_NONE: u32 = 0; /* no hardware accelerator */
/// No hardware accelerator
const FB_ACCEL_NONE: u32 = 0;
#[repr(C)]
pub struct fb_fix_screeninfo {
pub id: [u8; 16], /* identification string eg "TT Builtin" */
pub smem_start: u64, /* Start of frame buffer mem */
/* (physical address) */
pub smem_len: u32, /* Length of frame buffer mem */
pub type_: u32, /* see FB_TYPE_* */
pub type_aux: u32, /* Interleave for interleaved Planes */
pub visual: u32, /* see FB_VISUAL_* */
pub xpanstep: u16, /* zero if no hardware panning */
pub ypanstep: u16, /* zero if no hardware panning */
pub ywrapstep: u16, /* zero if no hardware ywrap */
pub line_length: u32, /* length of a line in bytes */
pub mmio_start: u64, /* Start of Memory Mapped I/O */
/* (physical address) */
pub mmio_len: u32, /* Length of Memory Mapped I/O */
pub accel: u32, /* Indicate to driver which */
/* specific chip/card we have */
pub capabilities: u16, /* see FB_CAP_* */
pub reserved: [u16; 2], /* Reserved for future compatibility */
#[derive(Debug)]
struct FbFixScreeninfo {
/// identification string eg "TT Builtin"
id: [u8; 16],
/// Start of frame buffer mem (physical address)
smem_start: u64,
/// Length of frame buffer mem
smem_len: u32,
/// see FB_TYPE_*
type_: FbType,
/// Interleave for interleaved Planes
type_aux: u32,
/// see FB_VISUAL_*
visual: FbVisual,
/// zero if no hardware panning
xpanstep: u16,
/// zero if no hardware panning
ypanstep: u16,
/// zero if no hardware ywrap
ywrapstep: u16,
/// length of a line in bytes
line_length: u32,
/// Start of Memory Mapped I/O (physical address)
mmio_start: u64,
/// Length of Memory Mapped I/O
mmio_len: u32,
/// Indicate to driver which specific chip/card we have
accel: u32,
/// see FB_CAP_*
capabilities: u16,
/// Reserved for future compatibility
reserved: [u16; 2],
}
#[repr(C)]
pub struct fb_var_screeninfo {
pub xres: u32, /* visible resolution */
pub yres: u32,
pub xres_virtual: u32, /* virtual resolution */
pub yres_virtual: u32,
pub xoffset: u32, /* offset from virtual to visible */
pub yoffset: u32, /* resolution */
#[derive(Debug)]
struct FbVarScreeninfo {
/// visible resolution x
xres: u32,
/// visible resolution y
yres: u32,
/// virtual resolution x
xres_virtual: u32,
/// virtual resolution y
yres_virtual: u32,
/// offset from virtual to visible x
xoffset: u32,
/// offset from virtual to visible y
yoffset: u32,
pub bits_per_pixel: u32, /* guess what */
pub grayscale: u32, /* 0 = color, 1 = grayscale, */
/* >1 = FOURCC */
pub red: fb_bitfield, /* bitfield in fb mem if true color, */
pub green: fb_bitfield, /* else only length is significant */
pub blue: fb_bitfield,
pub transp: fb_bitfield, /* transparency */
/// guess what
bits_per_pixel: u32,
/// 0 = color, 1 = grayscale, >1 = FOURCC
grayscale: u32,
/// bitfield in fb mem if true color, else only length is significant
red: FbBitfield,
green: FbBitfield,
blue: FbBitfield,
transp: FbBitfield,
pub nonstd: u32, /* != 0 Non standard pixel format */
/// != 0 Non standard pixel format
nonstd: u32,
pub activate: u32, /* see FB_ACTIVATE_* */
/// see FB_ACTIVATE_*
activate: u32,
pub height: u32, /* height of picture in mm */
pub width: u32, /* width of picture in mm */
pub accel_flags: u32, /* (OBSOLETE) see fb_info.flags */
/// height of picture in mm
height: u32,
/// width of picture in mm
width: u32,
/// (OBSOLETE) see fb_info.flags
accel_flags: u32,
/* Timing: All values in pixclocks, except pixclock (of course) */
pub pixclock: u32, /* pixel clock in ps (pico seconds) */
pub left_margin: u32, /* time from sync to picture */
pub right_margin: u32, /* time from picture to sync */
pub upper_margin: u32, /* time from sync to picture */
pub lower_margin: u32,
pub hsync_len: u32, /* length of horizontal sync */
pub vsync_len: u32, /* length of vertical sync */
pub sync: u32, /* see FB_SYNC_* */
pub vmode: u32, /* see FB_VMODE_* */
pub rotate: u32, /* angle we rotate counter clockwise */
pub colorspace: u32, /* colorspace for FOURCC-based modes */
pub reserved: [u32; 4], /* Reserved for future compatibility */
/// pixel clock in ps (pico seconds)
pixclock: u32,
/// time from sync to picture
left_margin: u32,
/// time from picture to sync
right_margin: u32,
/// time from sync to picture
upper_margin: u32,
lower_margin: u32,
/// length of horizontal sync
hsync_len: u32,
/// length of vertical sync
vsync_len: u32,
/// see FB_SYNC_*
sync: u32,
/// see FB_VMODE_*
vmode: u32,
/// angle we rotate counter clockwise
rotate: u32,
/// colorspace for FOURCC-based modes
colorspace: u32,
/// Reserved for future compatibility
reserved: [u32; 4],
}
#[repr(C)]
pub struct fb_bitfield {
pub offset: u32, /* beginning of bitfield */
pub length: u32, /* length of bitfield */
pub msb_right: u32, /* != 0 : Most significant bit is */
/* right */
#[derive(Debug)]
struct FbBitfield {
/// beginning of bitfield
offset: u32,
/// length of bitfield
length: u32,
/// != 0 : Most significant bit is right
msb_right: u32,
}
impl FbVarScreeninfo {
fn fill_from(&mut self, fb_info: &FramebufferInfo) {
self.xres = fb_info.xres;
self.yres = fb_info.yres;
self.xres_virtual = fb_info.xres_virtual;
self.yres_virtual = fb_info.yres_virtual;
self.xoffset = fb_info.xoffset;
self.yoffset = fb_info.yoffset;
self.bits_per_pixel = fb_info.depth as u32;
self.blue = FbBitfield {
offset: 0,
length: fb_info.depth as u32 / 4,
msb_right: 1,
};
self.green = FbBitfield {
offset: fb_info.depth as u32 / 4,
length: fb_info.depth as u32 / 4,
msb_right: 1,
};
self.red = FbBitfield {
offset: fb_info.depth as u32 / 2,
length: fb_info.depth as u32 / 4,
msb_right: 1,
};
self.transp = FbBitfield {
offset: fb_info.depth as u32 * 3 / 4,
length: fb_info.depth as u32 / 4,
msb_right: 1,
};
}
}
impl FbFixScreeninfo {
fn fill_from(&mut self, fb_info: &FramebufferInfo) {
self.smem_start = fb_info.paddr as u64;
self.smem_len = fb_info.screen_size as u32;
self.type_ = FbType::PackedPixels;
// self.type_aux = fb_info.type_aux;
self.visual = FbVisual::TrueColor;
// self.xpanstep = 0;
// self.ypanstep = 0;
// self.ywrapstep = 0;
self.line_length = fb_info.xres * fb_info.depth as u32 / 8;
self.mmio_start = 0;
self.mmio_len = 0;
self.accel = FB_ACCEL_NONE;
}
}