mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-17 14:57:49 +00:00
Compare commits
4 Commits
514736b1d8
...
2cf0675a2d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cf0675a2d | ||
|
|
916ad36e78 | ||
|
|
3c2e91fa4e | ||
|
|
c9683a2cd9 |
@@ -165,7 +165,7 @@ pub struct Color {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
By marking the sturcts and their fields as `pub`, we make them accessible from the parent `kernel` module.
|
By marking the structs and their fields as `pub`, we make them accessible from the parent `kernel` module.
|
||||||
We use the `#[derive]` attribute to implement the [`Debug`], [`Clone`], [`Copy`], [`PartialEq`], and [`Eq`] traits of Rust's core library.
|
We use the `#[derive]` attribute to implement the [`Debug`], [`Clone`], [`Copy`], [`PartialEq`], and [`Eq`] traits of Rust's core library.
|
||||||
These traits allow us to duplicate, compare, and print the structs.
|
These traits allow us to duplicate, compare, and print the structs.
|
||||||
|
|
||||||
@@ -312,22 +312,24 @@ Fortunately, there is the nice `no_std`-compatible [`embedded-graphics`] crate,
|
|||||||
|
|
||||||
```rust ,hl_lines=3
|
```rust ,hl_lines=3
|
||||||
// in kernel/src/framebuffer.rs
|
// in kernel/src/framebuffer.rs
|
||||||
|
use embedded_graphics::pixelcolor::Rgb888;
|
||||||
|
|
||||||
pub struct Display {
|
pub struct Display {
|
||||||
framebuffer: Framebuffer,
|
framebuffer: FrameBuffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display {
|
impl Display {
|
||||||
pub fn new(framebuffer: Framebuffer) -> Display {
|
pub fn new(framebuffer: FrameBuffer) -> Display {
|
||||||
Self { framebuffer }
|
Self { framebuffer }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_pixel(&mut self, pixel: Pixel) {
|
fn draw_pixel(&mut self, Pixel(coordinates, color): Pixel<Rgb888>) {
|
||||||
// ignore any pixels that are out of bounds.
|
// ignore any pixels that are out of bounds.
|
||||||
let (width, height) = {
|
let (width, height) = {
|
||||||
let info = self.framebuffer.info();
|
let info = self.framebuffer.info();
|
||||||
(info.width, info.height)
|
(info.width, info.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok((x @ 0..width, y @ 0..height)) = coordinates.try_into() {
|
if let Ok((x @ 0..width, y @ 0..height)) = coordinates.try_into() {
|
||||||
let color = Color { red: color.r(), green: color.g(), blue: color.b()};
|
let color = Color { red: color.r(), green: color.g(), blue: color.b()};
|
||||||
set_pixel_in(&mut self.framebuffer, Position { x, y }, color);
|
set_pixel_in(&mut self.framebuffer, Position { x, y }, color);
|
||||||
@@ -336,7 +338,7 @@ impl Display {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl embedded_graphics::draw_target::DrawTarget for Display {
|
impl embedded_graphics::draw_target::DrawTarget for Display {
|
||||||
type Color = embedded_graphics::pixelcolor::Rgb888;
|
type Color = Rgb888;
|
||||||
|
|
||||||
/// Drawing operations can never fail.
|
/// Drawing operations can never fail.
|
||||||
type Error = core::convert::Infallible;
|
type Error = core::convert::Infallible;
|
||||||
@@ -345,9 +347,10 @@ impl embedded_graphics::draw_target::DrawTarget for Display {
|
|||||||
where
|
where
|
||||||
I: IntoIterator<Item = Pixel<Self::Color>>,
|
I: IntoIterator<Item = Pixel<Self::Color>>,
|
||||||
{
|
{
|
||||||
for Pixel(coordinates, color) in pixels.into_iter() {
|
for pixel in pixels.into_iter() {
|
||||||
self.draw_pixel(pixel);
|
self.draw_pixel(pixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user