Skip to content

Commit df3b279

Browse files
Fix embedded_graphics code + typo in chapter 3
Compiles now
1 parent 2cf0675 commit df3b279

File tree

1 file changed

+8
-3
lines changed
  • blog/content/edition-3/posts/03-screen-output

1 file changed

+8
-3
lines changed

blog/content/edition-3/posts/03-screen-output/index.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ Fortunately, there is the nice `no_std`-compatible [`embedded-graphics`] crate,
312312

313313
```rust ,hl_lines=3
314314
// in kernel/src/framebuffer.rs
315-
use embedded_graphics::pixelcolor::Rgb888;
315+
use embedded_graphics::pixelcolor::{Rgb888, RgbColor};
316316

317317
pub struct Display {
318318
framebuffer: FrameBuffer,
@@ -330,7 +330,12 @@ impl Display {
330330
(info.width, info.height)
331331
}
332332

333-
if let Ok((x @ 0..width, y @ 0..height)) = coordinates.try_into() {
333+
let (x, y) = {
334+
let c: (i32, i32) = coordinates.into();
335+
(c.0 as usize, c.1 as usize)
336+
};
337+
338+
if (0..width).contains(&x) && (0..height).contains(&y) {
334339
let color = Color { red: color.r(), green: color.g(), blue: color.b()};
335340
set_pixel_in(&mut self.framebuffer, Position { x, y }, color);
336341
}
@@ -363,7 +368,7 @@ impl embedded_graphics::draw_target::DrawTarget for Display {
363368

364369

365370

366-
draw shapes and pixels directly onto the framebuffer. That's fine and all, but how is one able to go from that to displaying text on the screen? Understanding this requires taking a deep dive into how characters are rendered behind the scenes.
371+
So far, we have drawn shapes and pixels directly onto the framebuffer. That's fine and all, but how is one able to go from that to displaying text on the screen? Understanding this requires taking a deep dive into how characters are rendered behind the scenes.
367372

368373
When a key is pressed on the keyboard, it sends a character code to the CPU. It's the CPU's job at that point to then interpret the character code and match it with an image to draw on the screen. The image is then sent to either the GPU or the framebuffer (the latter in our case) to be drawn on the screen, and the user sees that image as a letter, number, CJK character, emoji, or whatever else he or she wanted to have displayed by pressing that key.
369374

0 commit comments

Comments
 (0)