Skip to content

Commit 2cf0675

Browse files
authored
Merge pull request #1269 from proudmuslim-dev/patch-3
Fix typos in code for `embedded_graphics` crate in chapter 3
2 parents 916ad36 + c9683a2 commit 2cf0675

File tree

1 file changed

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

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,22 +312,24 @@ 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;
315316

316317
pub struct Display {
317-
framebuffer: Framebuffer,
318+
framebuffer: FrameBuffer,
318319
}
319320

320321
impl Display {
321-
pub fn new(framebuffer: Framebuffer) -> Display {
322+
pub fn new(framebuffer: FrameBuffer) -> Display {
322323
Self { framebuffer }
323324
}
324325

325-
fn draw_pixel(&mut self, pixel: Pixel) {
326+
fn draw_pixel(&mut self, Pixel(coordinates, color): Pixel<Rgb888>) {
326327
// ignore any pixels that are out of bounds.
327328
let (width, height) = {
328329
let info = self.framebuffer.info();
329330
(info.width, info.height)
330331
}
332+
331333
if let Ok((x @ 0..width, y @ 0..height)) = coordinates.try_into() {
332334
let color = Color { red: color.r(), green: color.g(), blue: color.b()};
333335
set_pixel_in(&mut self.framebuffer, Position { x, y }, color);
@@ -336,7 +338,7 @@ impl Display {
336338
}
337339

338340
impl embedded_graphics::draw_target::DrawTarget for Display {
339-
type Color = embedded_graphics::pixelcolor::Rgb888;
341+
type Color = Rgb888;
340342

341343
/// Drawing operations can never fail.
342344
type Error = core::convert::Infallible;
@@ -345,9 +347,10 @@ impl embedded_graphics::draw_target::DrawTarget for Display {
345347
where
346348
I: IntoIterator<Item = Pixel<Self::Color>>,
347349
{
348-
for Pixel(coordinates, color) in pixels.into_iter() {
350+
for pixel in pixels.into_iter() {
349351
self.draw_pixel(pixel);
350352
}
353+
351354
Ok(())
352355
}
353356
}

0 commit comments

Comments
 (0)