mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-23 00:16:17 +04:00
aarch64/fb: add 8x16 font
This commit is contained in:
parent
b47c4758bf
commit
7b8359eeef
@ -198,6 +198,6 @@ pub fn init() {
|
|||||||
info!("framebuffer: init end\n{:#x?}", fb);
|
info!("framebuffer: init end\n{:#x?}", fb);
|
||||||
*FRAME_BUFFER.lock() = Some(fb);
|
*FRAME_BUFFER.lock() = Some(fb);
|
||||||
}
|
}
|
||||||
Err(err) => error!("framebuffer init failed: {}", err),
|
Err(err) => warn!("framebuffer init failed: {}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
//! Framebuffer console display driver for ARM64
|
//! Framebuffer console display driver for ARM64
|
||||||
|
|
||||||
use super::board::fb::{FramebufferInfo, FRAME_BUFFER};
|
use super::fb::{FramebufferInfo, FRAME_BUFFER};
|
||||||
|
use super::fonts::{Font, Font8x16};
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use core::fmt::{self, Write};
|
use core::fmt;
|
||||||
|
use core::marker::PhantomData;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
use log::*;
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
@ -25,41 +28,35 @@ impl Default for ConsoleChar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CHAR_WIDTH: u16 = 8;
|
|
||||||
const CHAR_HEIGHT: u16 = 16;
|
|
||||||
|
|
||||||
/// Character buffer
|
/// Character buffer
|
||||||
struct ConsoleBuffer {
|
struct ConsoleBuffer<F: Font> {
|
||||||
num_row: u16,
|
num_row: usize,
|
||||||
num_col: u16,
|
num_col: usize,
|
||||||
buf: Vec<Vec<ConsoleChar>>,
|
buf: Vec<Vec<ConsoleChar>>,
|
||||||
|
font: PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConsoleBuffer {
|
impl<F: Font> ConsoleBuffer<F> {
|
||||||
fn new(num_row: u16, num_col: u16) -> ConsoleBuffer {
|
fn new(num_row: usize, num_col: usize) -> ConsoleBuffer<F> {
|
||||||
ConsoleBuffer {
|
ConsoleBuffer {
|
||||||
num_row,
|
num_row,
|
||||||
num_col,
|
num_col,
|
||||||
buf: vec![vec![ConsoleChar::default(); num_col as usize]; num_row as usize],
|
buf: vec![vec![ConsoleChar::default(); num_col]; num_row],
|
||||||
|
font: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read one character at `(row, col)`.
|
|
||||||
fn read(&self, row: u16, col: u16) -> ConsoleChar {
|
|
||||||
self.buf[row as usize][col as usize]
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Write one character at `(row, col)`.
|
/// Write one character at `(row, col)`.
|
||||||
/// TODO: font & color
|
/// TODO: color
|
||||||
fn write(&mut self, row: u16, col: u16, ch: ConsoleChar) {
|
fn write(&mut self, row: usize, col: usize, ch: ConsoleChar) {
|
||||||
self.buf[row as usize][col as usize] = ch;
|
self.buf[row][col] = ch;
|
||||||
|
|
||||||
let off_x = col * CHAR_WIDTH;
|
let off_x = col * F::WIDTH;
|
||||||
let off_y = row * CHAR_HEIGHT;
|
let off_y = row * F::HEIGHT;
|
||||||
if let Some(fb) = FRAME_BUFFER.lock().as_mut() {
|
if let Some(fb) = FRAME_BUFFER.lock().as_mut() {
|
||||||
for y in 0..CHAR_HEIGHT {
|
for y in 0..F::HEIGHT {
|
||||||
for x in 0..CHAR_WIDTH {
|
for x in 0..F::WIDTH {
|
||||||
let pixel = if ch.color.0 == 0 { 0 } else { !0 };
|
let pixel = if ch.color.0 != 0 && F::get(ch.ascii_char, x, y) { !0 } else { 0 };
|
||||||
fb.write((off_x + x) as u32, (off_y + y) as u32, pixel);
|
fb.write((off_x + x) as u32, (off_y + y) as u32, pixel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,7 +64,7 @@ impl ConsoleBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Delete one character at `(row, col)`.
|
/// Delete one character at `(row, col)`.
|
||||||
fn delete(&mut self, row: u16, col: u16) {
|
fn delete(&mut self, row: usize, col: usize) {
|
||||||
self.write(row, col, ConsoleChar::default());
|
self.write(row, col, ConsoleChar::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +73,7 @@ impl ConsoleBuffer {
|
|||||||
fn new_line(&mut self) {
|
fn new_line(&mut self) {
|
||||||
for i in 1..self.num_row {
|
for i in 1..self.num_row {
|
||||||
for j in 0..self.num_col {
|
for j in 0..self.num_col {
|
||||||
self.write(i - 1, j, self.read(i, j));
|
self.write(i - 1, j, self.buf[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for j in 0..self.num_col {
|
for j in 0..self.num_col {
|
||||||
@ -86,8 +83,8 @@ impl ConsoleBuffer {
|
|||||||
|
|
||||||
/// Clear the entire buffer and screen.
|
/// Clear the entire buffer and screen.
|
||||||
fn clear(&mut self) {
|
fn clear(&mut self) {
|
||||||
for i in 0..self.num_row as usize {
|
for i in 0..self.num_row {
|
||||||
for j in 0..self.num_col as usize {
|
for j in 0..self.num_col {
|
||||||
self.buf[i][j] = ConsoleChar::default()
|
self.buf[i][j] = ConsoleChar::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,38 +95,32 @@ impl ConsoleBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Console structure
|
/// Console structure
|
||||||
pub struct Console {
|
pub struct Console<F: Font> {
|
||||||
/// current color
|
/// current color
|
||||||
color: Color,
|
color: Color,
|
||||||
/// cursor row
|
/// cursor row
|
||||||
row: u16,
|
row: usize,
|
||||||
/// cursor column
|
/// cursor column
|
||||||
col: u16,
|
col: usize,
|
||||||
/// number of rows
|
|
||||||
num_row: u16,
|
|
||||||
/// number of columns
|
|
||||||
num_col: u16,
|
|
||||||
/// character buffer
|
/// character buffer
|
||||||
buf: ConsoleBuffer,
|
buf: ConsoleBuffer<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Console {
|
impl<F: Font> Console<F> {
|
||||||
fn new(fb: &FramebufferInfo) -> Console {
|
fn new(fb: &FramebufferInfo) -> Console<F> {
|
||||||
let num_row = fb.yres as u16 / CHAR_HEIGHT;
|
let num_row = fb.yres as usize / F::HEIGHT;
|
||||||
let num_col = fb.xres as u16 / CHAR_WIDTH;
|
let num_col = fb.xres as usize / F::WIDTH;
|
||||||
Console {
|
Console {
|
||||||
color: Color(1),
|
color: Color(1),
|
||||||
row: 0,
|
row: 0,
|
||||||
col: 0,
|
col: 0,
|
||||||
num_row,
|
|
||||||
num_col,
|
|
||||||
buf: ConsoleBuffer::new(num_row, num_col),
|
buf: ConsoleBuffer::new(num_row, num_col),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_line(&mut self) {
|
fn new_line(&mut self) {
|
||||||
self.col = 0;
|
self.col = 0;
|
||||||
if self.row < self.num_row - 1 {
|
if self.row < self.buf.num_row - 1 {
|
||||||
self.row += 1;
|
self.row += 1;
|
||||||
} else {
|
} else {
|
||||||
self.buf.new_line();
|
self.buf.new_line();
|
||||||
@ -144,14 +135,14 @@ impl Console {
|
|||||||
self.buf.delete(self.row, self.col);
|
self.buf.delete(self.row, self.col);
|
||||||
} else if self.row > 0 {
|
} else if self.row > 0 {
|
||||||
self.row -= 1;
|
self.row -= 1;
|
||||||
self.col = self.num_col - 1;
|
self.col = self.buf.num_col - 1;
|
||||||
self.buf.delete(self.row, self.col);
|
self.buf.delete(self.row, self.col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b'\n' => self.new_line(),
|
b'\n' => self.new_line(),
|
||||||
b'\r' => self.col = 0,
|
b'\r' => self.col = 0,
|
||||||
byte => {
|
byte => {
|
||||||
if self.col >= self.num_col {
|
if self.col >= self.buf.num_col {
|
||||||
self.new_line();
|
self.new_line();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +164,7 @@ impl Console {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Write for Console {
|
impl<F: Font> fmt::Write for Console<F> {
|
||||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||||
for byte in s.bytes() {
|
for byte in s.bytes() {
|
||||||
self.write_byte(byte)
|
self.write_byte(byte)
|
||||||
@ -183,7 +174,7 @@ impl fmt::Write for Console {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref CONSOLE: Mutex<Option<Console>> = Mutex::new(None);
|
pub static ref CONSOLE: Mutex<Option<Console<Font8x16>>> = Mutex::new(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initialize console driver
|
/// Initialize console driver
|
||||||
@ -192,7 +183,9 @@ pub fn init() {
|
|||||||
*CONSOLE.lock() = Some(Console::new(&fb.fb_info));
|
*CONSOLE.lock() = Some(Console::new(&fb.fb_info));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(console) = CONSOLE.lock().as_mut() {
|
if !CONSOLE.lock().is_none() {
|
||||||
console.write_str("Hello Raspberry Pi!\n").unwrap();
|
info!("console: init end");
|
||||||
|
} else {
|
||||||
|
warn!("console: init failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4629
kernel/src/arch/aarch64/driver/fonts/font8x16.rs
Normal file
4629
kernel/src/arch/aarch64/driver/fonts/font8x16.rs
Normal file
File diff suppressed because it is too large
Load Diff
12
kernel/src/arch/aarch64/driver/fonts/mod.rs
Normal file
12
kernel/src/arch/aarch64/driver/fonts/mod.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
//! Console font
|
||||||
|
|
||||||
|
mod font8x16;
|
||||||
|
|
||||||
|
pub use self::font8x16::Font8x16;
|
||||||
|
|
||||||
|
pub trait Font {
|
||||||
|
const HEIGHT: usize;
|
||||||
|
const WIDTH: usize;
|
||||||
|
|
||||||
|
fn get(byte: u8, x: usize, y: usize) -> bool;
|
||||||
|
}
|
@ -3,6 +3,10 @@
|
|||||||
use super::board;
|
use super::board;
|
||||||
use once::*;
|
use once::*;
|
||||||
|
|
||||||
|
pub use self::board::fb;
|
||||||
|
pub use self::board::serial;
|
||||||
|
|
||||||
|
pub mod fonts;
|
||||||
pub mod console;
|
pub mod console;
|
||||||
|
|
||||||
/// Initialize ARM64 common drivers
|
/// Initialize ARM64 common drivers
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Serial driver for aarch64.
|
//! Serial driver for aarch64.
|
||||||
|
|
||||||
use super::board::serial::*;
|
use super::driver::serial::*;
|
||||||
use super::driver::console::CONSOLE;
|
use super::driver::console::CONSOLE;
|
||||||
use core::fmt::{Arguments, Write};
|
use core::fmt::{Arguments, Write};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user