mirror of
https://github.com/laanwj/k210-sdk-stuff.git
synced 2024-11-22 09:26:21 +04:00
rust: Pass in font for k210-console
Allow the user code to specify which font to use.
This commit is contained in:
parent
f9620a47c3
commit
fa38e28491
@ -5,7 +5,7 @@
|
|||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use k210_console::console::{Console, ScreenImage};
|
use k210_console::console::{Console, ScreenImage};
|
||||||
use k210_console::cp437_8x8::GLYPH_BY_FILL;
|
use k210_console::cp437_8x8::{FONT, GLYPH_BY_FILL};
|
||||||
use k210_hal::Peripherals;
|
use k210_hal::Peripherals;
|
||||||
use k210_hal::prelude::*;
|
use k210_hal::prelude::*;
|
||||||
use k210_hal::stdout::Stdout;
|
use k210_hal::stdout::Stdout;
|
||||||
@ -107,7 +107,7 @@ fn main() -> ! {
|
|||||||
dvp.set_auto(false);
|
dvp.set_auto(false);
|
||||||
|
|
||||||
let mut image: ScreenImage = [0; DISP_PIXELS / 2];
|
let mut image: ScreenImage = [0; DISP_PIXELS / 2];
|
||||||
let mut console: Console = Console::new(None);
|
let mut console: Console = Console::new(&FONT, None);
|
||||||
writeln!(stdout, "Starting frame loop").unwrap();
|
writeln!(stdout, "Starting frame loop").unwrap();
|
||||||
loop {
|
loop {
|
||||||
dvp.get_image();
|
dvp.get_image();
|
||||||
|
@ -78,7 +78,7 @@ for (bd, ch) in charset.items():
|
|||||||
|
|
||||||
with open(outfile, 'w') as f:
|
with open(outfile, 'w') as f:
|
||||||
f.write(f'/* Auto-generated from {infile} by gencolorfont.py */\n')
|
f.write(f'/* Auto-generated from {infile} by gencolorfont.py */\n')
|
||||||
f.write(f'pub static CHARDATA: [[u32; {m}]; {n}] = [\n')
|
f.write(f'pub static FONT: [[u32; {m}]; {n}] = [\n')
|
||||||
for bd in charset_by_ch:
|
for bd in charset_by_ch:
|
||||||
f.write(' [')
|
f.write(' [')
|
||||||
for val in bd:
|
for val in bd:
|
||||||
|
@ -2,7 +2,6 @@ use core::fmt;
|
|||||||
|
|
||||||
use k210_shared::board::lcd_colors::rgb565;
|
use k210_shared::board::lcd_colors::rgb565;
|
||||||
use crate::cp437;
|
use crate::cp437;
|
||||||
use crate::cp437_8x8;
|
|
||||||
use crate::palette_xterm256::PALETTE;
|
use crate::palette_xterm256::PALETTE;
|
||||||
|
|
||||||
pub use k210_shared::board::def::{DISP_WIDTH,DISP_HEIGHT,DISP_PIXELS};
|
pub use k210_shared::board::def::{DISP_WIDTH,DISP_HEIGHT,DISP_PIXELS};
|
||||||
@ -15,9 +14,10 @@ const DEF_BG: u16 = rgb565(0, 0, 0);
|
|||||||
pub type ScreenImage = [u32; DISP_PIXELS / 2];
|
pub type ScreenImage = [u32; DISP_PIXELS / 2];
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
* - pass in font and unicode mapping instead of hardcoding cp437
|
* - pass in unicode to font mapping instead of hardcoding cp437
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** Basic color math. */
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct Color {
|
pub struct Color {
|
||||||
r: u8,
|
r: u8,
|
||||||
@ -62,6 +62,7 @@ impl Color {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Integer screen coordinate. */
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct Coord {
|
pub struct Coord {
|
||||||
x: u16,
|
x: u16,
|
||||||
@ -117,6 +118,8 @@ enum Sgr {
|
|||||||
|
|
||||||
/** Visual attributes of console */
|
/** Visual attributes of console */
|
||||||
pub struct Console {
|
pub struct Console {
|
||||||
|
/** Standard font */
|
||||||
|
pub font: &'static [[u8; 8]],
|
||||||
/** Color font */
|
/** Color font */
|
||||||
pub color_font: Option<&'static [[u32; 32]]>,
|
pub color_font: Option<&'static [[u32; 32]]>,
|
||||||
/** Dirty flag */
|
/** Dirty flag */
|
||||||
@ -145,9 +148,9 @@ pub struct Console {
|
|||||||
|
|
||||||
impl Console {
|
impl Console {
|
||||||
/** Create new, empty console */
|
/** Create new, empty console */
|
||||||
pub fn new(color_font: Option<&'static [[u32; 32]]>) -> Console {
|
pub fn new(font: &'static [[u8; 8]], color_font: Option<&'static [[u32; 32]]>) -> Console {
|
||||||
Console {
|
Console {
|
||||||
color_font,
|
font, color_font,
|
||||||
dirty: false,
|
dirty: false,
|
||||||
cells: [Cell {
|
cells: [Cell {
|
||||||
fg: DEF_FG,
|
fg: DEF_FG,
|
||||||
@ -190,7 +193,7 @@ impl Console {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let glyph = &cp437_8x8::FONT[usize::from(cell.ch)];
|
let glyph = &self.font[usize::from(cell.ch)];
|
||||||
let mut image_ofs = image_base;
|
let mut image_ofs = image_base;
|
||||||
let is_cursor =
|
let is_cursor =
|
||||||
self.cursor_visible && (y == self.cursor_pos.y) && (x == self.cursor_pos.x);
|
self.cursor_visible && (y == self.cursor_pos.y) && (x == self.cursor_pos.x);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* Auto-generated from honeybadger160_24.png by gencolorfont.py */
|
/* Auto-generated from honeybadger160_24.png by gencolorfont.py */
|
||||||
pub static CHARDATA: [[u32; 32]; 106] = [
|
pub static FONT: [[u32; 32]; 106] = [
|
||||||
[0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, ],
|
[0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, ],
|
||||||
[0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000ffff, 0xffffffff, 0x00000000, 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xff9dffbe, 0xffffffff, 0xffffffff, 0xffffffff, 0xf4cef3a5, 0xf3c6f408, 0xf48cf510, 0xffffffff, 0xfdd4f384, 0xf384f384, 0xf384f384, 0xffffffff, 0xfed9f384, 0xf384f384, 0xf384f384, ],
|
[0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000ffff, 0xffffffff, 0x00000000, 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xff9dffbe, 0xffffffff, 0xffffffff, 0xffffffff, 0xf4cef3a5, 0xf3c6f408, 0xf48cf510, 0xffffffff, 0xfdd4f384, 0xf384f384, 0xf384f384, 0xffffffff, 0xfed9f384, 0xf384f384, 0xf384f384, ],
|
||||||
[0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000ffff, 0x00000000, 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffdd, 0xffffffff, 0xffffffff, 0xffffffff, 0xffbbfee4, 0xf572fdb3, 0xfe16fe78, 0xfefaffff, 0xffffffbb, 0xf384f384, 0xf384f384, 0xf384f4ce, 0xff5cffff, 0xf384f384, 0xf384f384, 0xf384f384, 0xf3a5fdd4, ],
|
[0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000ffff, 0x00000000, 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffdd, 0xffffffff, 0xffffffff, 0xffffffff, 0xffbbfee4, 0xf572fdb3, 0xfe16fe78, 0xfefaffff, 0xffffffbb, 0xf384f384, 0xf384f384, 0xf384f4ce, 0xff5cffff, 0xf384f384, 0xf384f384, 0xf384f384, 0xf3a5fdd4, ],
|
||||||
|
@ -21,7 +21,7 @@ use k210_shared::soc::sysctl;
|
|||||||
use riscv_rt::entry;
|
use riscv_rt::entry;
|
||||||
|
|
||||||
use k210_console::console::{Color, Console, ScreenImage, DISP_HEIGHT, DISP_WIDTH, DISP_PIXELS, CellFlags};
|
use k210_console::console::{Color, Console, ScreenImage, DISP_HEIGHT, DISP_WIDTH, DISP_PIXELS, CellFlags};
|
||||||
use k210_console::cp437;
|
use k210_console::{cp437, cp437_8x8};
|
||||||
use k210_console::palette_xterm256::PALETTE;
|
use k210_console::palette_xterm256::PALETTE;
|
||||||
|
|
||||||
/** Connect pins to internal functions */
|
/** Connect pins to internal functions */
|
||||||
@ -133,7 +133,7 @@ fn main() -> ! {
|
|||||||
lcd.clear(lcd_colors::PURPLE);
|
lcd.clear(lcd_colors::PURPLE);
|
||||||
|
|
||||||
let mut image: ScreenImage = [0; DISP_PIXELS / 2];
|
let mut image: ScreenImage = [0; DISP_PIXELS / 2];
|
||||||
let mut console: Console = Console::new(Some(&example_colorfont::CHARDATA));
|
let mut console: Console = Console::new(&cp437_8x8::FONT, Some(&example_colorfont::FONT));
|
||||||
|
|
||||||
/* Make a border */
|
/* Make a border */
|
||||||
let fg = Color::new(0x40, 0x40, 0x40);
|
let fg = Color::new(0x40, 0x40, 0x40);
|
||||||
|
@ -22,6 +22,7 @@ use k210_shared::soc::spi::SPIExt;
|
|||||||
use k210_shared::soc::sysctl;
|
use k210_shared::soc::sysctl;
|
||||||
use riscv_rt::entry;
|
use riscv_rt::entry;
|
||||||
use k210_console::console::{Console, ScreenImage, DISP_HEIGHT, DISP_WIDTH, DISP_PIXELS};
|
use k210_console::console::{Console, ScreenImage, DISP_HEIGHT, DISP_WIDTH, DISP_PIXELS};
|
||||||
|
use k210_console::cp437_8x8;
|
||||||
use buffered_uart;
|
use buffered_uart;
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
@ -100,7 +101,7 @@ fn main() -> ! {
|
|||||||
let mut lcd = LCD::new(spi, &dmac, dma_channel::CHANNEL0);
|
let mut lcd = LCD::new(spi, &dmac, dma_channel::CHANNEL0);
|
||||||
lcd.init();
|
lcd.init();
|
||||||
lcd.set_direction(lcd::direction::YX_LRUD);
|
lcd.set_direction(lcd::direction::YX_LRUD);
|
||||||
let mut console: Console = Console::new(None);
|
let mut console: Console = Console::new(&cp437_8x8::FONT, None);
|
||||||
|
|
||||||
writeln!(console, "\x1b[48;2;128;192;255;38;5;0m TERMINAL \x1b[0m \x1b[38;2;128;128;128m\x1b[0m").unwrap();
|
writeln!(console, "\x1b[48;2;128;192;255;38;5;0m TERMINAL \x1b[0m \x1b[38;2;128;128;128m\x1b[0m").unwrap();
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ use k210_shared::soc::spi::SPIExt;
|
|||||||
use k210_shared::soc::sysctl;
|
use k210_shared::soc::sysctl;
|
||||||
use riscv_rt::entry;
|
use riscv_rt::entry;
|
||||||
use k210_console::console::{Console, ScreenImage, DISP_HEIGHT, DISP_WIDTH, DISP_PIXELS};
|
use k210_console::console::{Console, ScreenImage, DISP_HEIGHT, DISP_WIDTH, DISP_PIXELS};
|
||||||
|
use k210_console::cp437_8x8;
|
||||||
use buffered_uart;
|
use buffered_uart;
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
@ -100,7 +101,7 @@ fn main() -> ! {
|
|||||||
let mut lcd = LCD::new(spi, &dmac, dma_channel::CHANNEL0);
|
let mut lcd = LCD::new(spi, &dmac, dma_channel::CHANNEL0);
|
||||||
lcd.init();
|
lcd.init();
|
||||||
lcd.set_direction(lcd::direction::YX_LRUD);
|
lcd.set_direction(lcd::direction::YX_LRUD);
|
||||||
let mut console: Console = Console::new(None);
|
let mut console: Console = Console::new(&cp437_8x8::FONT, None);
|
||||||
|
|
||||||
writeln!(console, "\x1b[48;2;128;192;255;38;5;0m WEATHER \x1b[0m \x1b[38;2;128;128;128m\x1b[0m").unwrap();
|
writeln!(console, "\x1b[48;2;128;192;255;38;5;0m WEATHER \x1b[0m \x1b[38;2;128;128;128m\x1b[0m").unwrap();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user