mirror of
https://github.com/laanwj/k210-sdk-stuff.git
synced 2024-11-22 09:26:21 +04:00
rust: Split out some structures from k210-console
This commit is contained in:
parent
69636c4005
commit
0fbf997b0d
46
rust/k210-console/src/color.rs
Normal file
46
rust/k210-console/src/color.rs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
use k210_shared::board::lcd_colors::rgb565;
|
||||||
|
|
||||||
|
/** Basic color math. */
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub struct Color {
|
||||||
|
pub r: u8,
|
||||||
|
pub g: u8,
|
||||||
|
pub b: u8,
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub a: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Color {
|
||||||
|
pub const fn new(r: u8, g: u8, b: u8) -> Color {
|
||||||
|
Color { r, g, b, a: 255 }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn new_rgba(r: u8, g: u8, b: u8, a: u8) -> Color {
|
||||||
|
Color { r, g, b, a: a }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn from_rgb565(val: u16) -> Color {
|
||||||
|
let rs = ((val >> 11) & 0x1f) as u8;
|
||||||
|
let gs = ((val >> 5) & 0x3f) as u8;
|
||||||
|
let bs = ((val >> 0) & 0x1f) as u8;
|
||||||
|
Color {
|
||||||
|
r: (rs << 3) | (rs >> 2),
|
||||||
|
g: (gs << 2) | (gs >> 4),
|
||||||
|
b: (bs << 3) | (bs >> 2),
|
||||||
|
a: 255,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn from_rgba32(val: u32) -> Color {
|
||||||
|
Color {
|
||||||
|
r: ((val >> 24) & 0xff) as u8,
|
||||||
|
g: ((val >> 16) & 0xff) as u8,
|
||||||
|
b: ((val >> 8) & 0xff) as u8,
|
||||||
|
a: ((val >> 0) & 0xff) as u8,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn to_rgb565(&self) -> u16 {
|
||||||
|
rgb565(self.r, self.g, self.b)
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
use k210_shared::board::lcd_colors::rgb565;
|
use k210_shared::board::lcd_colors::rgb565;
|
||||||
|
use crate::coord::Coord;
|
||||||
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};
|
||||||
@ -12,63 +13,7 @@ const DEF_BG: u16 = rgb565(0, 0, 0);
|
|||||||
|
|
||||||
pub type ScreenImage = [u32; DISP_PIXELS / 2];
|
pub type ScreenImage = [u32; DISP_PIXELS / 2];
|
||||||
|
|
||||||
/** Basic color math. */
|
pub use crate::color::Color;
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
pub struct Color {
|
|
||||||
r: u8,
|
|
||||||
g: u8,
|
|
||||||
b: u8,
|
|
||||||
#[allow(dead_code)]
|
|
||||||
a: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Color {
|
|
||||||
pub const fn new(r: u8, g: u8, b: u8) -> Color {
|
|
||||||
Color { r, g, b, a: 255 }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const fn new_rgba(r: u8, g: u8, b: u8, a: u8) -> Color {
|
|
||||||
Color { r, g, b, a: a }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const fn from_rgb565(val: u16) -> Color {
|
|
||||||
let rs = ((val >> 11) & 0x1f) as u8;
|
|
||||||
let gs = ((val >> 5) & 0x3f) as u8;
|
|
||||||
let bs = ((val >> 0) & 0x1f) as u8;
|
|
||||||
Color {
|
|
||||||
r: (rs << 3) | (rs >> 2),
|
|
||||||
g: (gs << 2) | (gs >> 4),
|
|
||||||
b: (bs << 3) | (bs >> 2),
|
|
||||||
a: 255,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const fn from_rgba32(val: u32) -> Color {
|
|
||||||
Color {
|
|
||||||
r: ((val >> 24) & 0xff) as u8,
|
|
||||||
g: ((val >> 16) & 0xff) as u8,
|
|
||||||
b: ((val >> 8) & 0xff) as u8,
|
|
||||||
a: ((val >> 0) & 0xff) as u8,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const fn to_rgb565(&self) -> u16 {
|
|
||||||
rgb565(self.r, self.g, self.b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Integer screen coordinate. */
|
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
pub struct Coord {
|
|
||||||
x: u16,
|
|
||||||
y: u16,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Coord {
|
|
||||||
fn new(x: u16, y: u16) -> Self {
|
|
||||||
Self { x, y }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Cell flags. */
|
/** Cell flags. */
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
12
rust/k210-console/src/coord.rs
Normal file
12
rust/k210-console/src/coord.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/** Integer screen coordinate. */
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub struct Coord {
|
||||||
|
pub x: u16,
|
||||||
|
pub y: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Coord {
|
||||||
|
pub fn new(x: u16, y: u16) -> Self {
|
||||||
|
Self { x, y }
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
|
pub mod color;
|
||||||
pub mod console;
|
pub mod console;
|
||||||
|
pub mod coord;
|
||||||
pub mod cp437;
|
pub mod cp437;
|
||||||
pub mod cp437_8x8;
|
pub mod cp437_8x8;
|
||||||
pub mod palette_xterm256;
|
pub mod palette_xterm256;
|
||||||
|
Loading…
Reference in New Issue
Block a user