Commit c1d0551d authored by Rafael Caricio's avatar Rafael Caricio
Browse files

Support drawing images to display

parent 6c1ca960
Pipeline #3775 failed with stage
in 8 minutes and 13 seconds
......@@ -99,6 +99,7 @@ name = "card10-l0dable"
version = "0.1.1"
dependencies = [
"card10-sys 0.1.0",
"embedded-graphics 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -161,6 +162,20 @@ dependencies = [
"volatile-register 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "draw-image"
version = "0.0.0"
dependencies = [
"card10-l0dable 0.1.1",
"cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)",
"embedded-graphics 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "embedded-graphics"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "env_logger"
version = "0.6.2"
......@@ -442,6 +457,7 @@ dependencies = [
"checksum clang-sys 0.28.1 (registry+https://github.com/rust-lang/crates.io-index)" = "81de550971c976f176130da4b2978d3b524eaa0fd9ac31f3ceb5ae1231fb4853"
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
"checksum cortex-m 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3df5de9a9829f2ccb7defa8945fa020c6614cd2f6ba9b5f33db9241dcc01985e"
"checksum embedded-graphics 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "704679bfcb66cc748ec185ae62ccd5b03311a53793372e2abf1ff9a7e9875ff7"
"checksum env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3"
"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
"checksum fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
......
......@@ -5,11 +5,13 @@ members = [
"card10-l0dable",
"example",
"rkanoid",
"draw-image",
]
default-members = [
"example",
"rkanoid",
"draw-image",
]
[profile.release]
......
......@@ -134,6 +134,7 @@ extension (e.g `example` must be renamed as `example.elf`).
| card10-l0dable | High-level crate for building l0dables |
| example | l0dable example |
| rkanoid | Arkanoid clone |
| draw-image | Example of drawing a static image to the display |
## Misc
......
......@@ -18,4 +18,5 @@ description = "make l0dables for the Card10 (CCCamp 2019) badge"
[dependencies]
card10-sys = { path = "../card10-sys", version = "^0.1" }
embedded-graphics = "0.5.2"
......@@ -3,6 +3,10 @@ use card10_sys::*;
use core::mem::{transmute, uninitialized};
use core::ops::{Index, IndexMut};
use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::Pixel;
use embedded_graphics::Drawing;
mod font;
pub use font::*;
mod text;
......@@ -71,6 +75,23 @@ impl<'d> IndexMut<(u16, u16)> for FrameBuffer<'d> {
}
}
impl<'d> Drawing<Rgb565> for FrameBuffer<'d> {
fn draw<T>(&mut self, item: T)
where
T: IntoIterator<Item = Pixel<Rgb565>>,
{
for Pixel(coord, color) in item {
let x = coord[0] as u16;
let y = coord[1] as u16;
if x >= Display::W || y >= Display::H {
continue;
}
self[(x, y)] = RawColor::rgb8(color.r(), color.g(), color.b());
}
}
}
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct RawColor([u8; 2]);
......
use super::{Font, FrameBuffer, RawColor};
use crate::Display;
use core::fmt::Write;
use super::{FrameBuffer, Font, RawColor};
use crate::{Display};
pub struct TextRenderer<'a, 'd, 'f> {
pub framebuffer: &'a mut FrameBuffer<'d>,
......
[package]
name = "draw-image"
version = "0.0.0"
authors = ["Rafael Caricio <crates.rs@caric.io>"]
edition = "2018"
[dependencies]
card10-l0dable = { path = "../card10-l0dable" }
embedded-graphics = { version = "0.5.2" }
[build-dependencies]
cc = "1.0"
[[bin]]
name = "draw-image"
path = "src/main.rs"
Draw Image
==========
Images need to be converted to a bitmap of 16BPP for inclusion with `include_bytes!()`. You can convert an image using:
```
convert image.png -flip -type truecolor -define bmp:subtype=RGB565 -depth 16 -strip image.bmp
```
then
```
tail -c $bytes image.bmp > image.raw // where $bytes is w * h * 2
```
This will remove the BMP header leaving the raw pixel data E.g 160x80 image will have 160 * 80 * 2 bytes of raw data.
\ No newline at end of file
#![no_std]
#![no_main]
use card10_l0dable::*;
use embedded_graphics::prelude::*;
use embedded_graphics::image::Image16BPP;
use embedded_graphics::pixelcolor::Rgb565;
main!(main);
fn main() {
let display = Display::open();
let mut framebuffer = display.framebuffer();
let image: Image16BPP<Rgb565> =
Image16BPP::new(include_bytes!("applewatch-160x80.raw"), 160, 80);
framebuffer.draw(&image);
framebuffer.send();
loop {
let buttons = Buttons::read();
if buttons.left_top() {
break;
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment