Added bitmap blitting

This commit is contained in:
Sebastian 2018-09-11 22:44:00 +02:00
parent 23883c9bce
commit c4466aa703
4 changed files with 116 additions and 1 deletions

42
src/logo.rs Normal file
View File

@ -0,0 +1,42 @@
use st7735::bitmaps::ColorBitmap;
const LOGO_PX : [u16; 1024] = [
0x4081, 0x4880, 0x4880, 0x2861, 0x38c1, 0x38c1, 0x30a1, 0x3081, 0x2861, 0x1861, 0x1061, 0x28a1, 0x3060, 0x2861, 0x821, 0x1041, 0x1861, 0x821, 0x821, 0x1, 0x821, 0x1841, 0x2061, 0x1841, 0x2061, 0x2881, 0x38a1, 0x5122, 0x2104, 0x5a48, 0x5a48, 0x6aea,
0x40a1, 0x4060, 0x4060, 0x2860, 0x48a0, 0x48a0, 0x40a0, 0x3880, 0x3880, 0x3060, 0x3060, 0x2040, 0x3060, 0x3080, 0x821, 0x1882, 0x3124, 0x1861, 0x2060, 0x2061, 0x2061, 0x2880, 0x2881, 0x28a1, 0x38a1, 0x40e2, 0x4922, 0x59a4, 0x6226, 0x8b49, 0x834a, 0x800,
0x48e2, 0x3860, 0x3860, 0x3880, 0x4080, 0x48a0, 0x4080, 0x3880, 0x3080, 0x3060, 0x2860, 0x3060, 0x2860, 0x2860, 0x1800, 0xe71c, 0xffff, 0x2860, 0x3081, 0x30a1, 0x3081, 0x38a1, 0x30a1, 0x38c1, 0x40c1, 0x4901, 0x5142, 0x5163, 0x5162, 0x5983, 0x5183, 0x5163,
0x6143, 0x6040, 0x5060, 0x3881, 0x2861, 0x4880, 0x40a0, 0x48a0, 0x3880, 0x1041, 0x1021, 0x1021, 0x2061, 0x40a0, 0x830b, 0xffff, 0xffff, 0xb514, 0x38a0, 0x40a1, 0x40c1, 0x40c0, 0x40c1, 0x40c1, 0x40c1, 0x40c1, 0x40c1, 0x40e1, 0x38c1, 0x38c1, 0x40c1, 0x40e2,
0x6183, 0x5820, 0x6820, 0x5060, 0x1041, 0x4080, 0x48a0, 0x2860, 0x821, 0x801, 0x821, 0x821, 0x821, 0x2020, 0xffff, 0xef1b, 0xacd2, 0xffff, 0x5984, 0x40c1, 0x48c1, 0x48c1, 0x40c1, 0x40c1, 0x48c1, 0x48e1, 0x40c1, 0x40c1, 0x40e1, 0x40c1, 0x40c1, 0x40c1,
0x6182, 0x5881, 0x5820, 0x6020, 0x50c0, 0x50a0, 0x48a0, 0x1021, 0x1, 0x1, 0x801, 0x1, 0x1, 0x8c71, 0xffff, 0x7aca, 0xacb2, 0xffff, 0xde99, 0x4060, 0x50e1, 0x48c0, 0x40c1, 0x48c1, 0x48c1, 0x48e1, 0x48c1, 0x50e1, 0x48e1, 0x48e1, 0x48e1, 0x48c1,
0x6142, 0x60e1, 0x3001, 0x5800, 0x58a0, 0x58c0, 0x3880, 0x1, 0x0, 0x1, 0x0, 0x1, 0x1082, 0xffff, 0xffdf, 0xd638, 0x8b4b, 0xffff, 0xffff, 0x7aca, 0x48c0, 0x48c1, 0x48c1, 0x48c1, 0x48c1, 0x48c1, 0x48c1, 0x48c1, 0x40c1, 0x48c1, 0x40c1, 0x40c1,
0x5942, 0x6140, 0x5081, 0x70a1, 0x9ac4, 0x7161, 0x2860, 0x0, 0x1, 0x1, 0x0, 0x0, 0xb5b7, 0xffff, 0xffff, 0x69a5, 0x4020, 0xffff, 0xffff, 0xf7be, 0x3840, 0x48c0, 0x40a0, 0x50c1, 0x48c0, 0x40c1, 0x40a1, 0x40c1, 0x48c0, 0x40a1, 0x40a1, 0x40a1,
0x5922, 0x6140, 0x2061, 0x4000, 0xd304, 0xc2e5, 0x2840, 0x1, 0x1, 0x0, 0x1, 0x39e7, 0xffff, 0x8b8e, 0xffff, 0x832b, 0x832c, 0xf7be, 0xdeba, 0xffff, 0x9c0f, 0x40a1, 0x48a1, 0x48c1, 0x48a1, 0x40c1, 0x40a1, 0x40c1, 0x40a1, 0x40a0, 0x40a1, 0x40a1,
0x5922, 0x5921, 0x58e1, 0xeb04, 0xdb44, 0xc2e3, 0x801, 0x821, 0x0, 0x1, 0x0, 0xe73c, 0xffff, 0x72ca, 0xb4f3, 0x9c30, 0x6a27, 0xffdf, 0x9bce, 0xe6da, 0xffff, 0x38a1, 0x3880, 0x40a1, 0x38a1, 0x48a1, 0x40a1, 0x48a1, 0x48a1, 0x40a0, 0x38a1, 0x38a1,
0x5922, 0x6121, 0xb2a3, 0xaa61, 0x9a40, 0x6940, 0x1020, 0x801, 0x1, 0x1, 0x632d, 0xffff, 0xe6db, 0xef3c, 0x8b8d, 0xc596, 0xc5d6, 0xe71c, 0x40a1, 0xa451, 0xffff, 0xbd75, 0x4880, 0x48a0, 0x48a0, 0x40a1, 0x30a1, 0x38a1, 0x38a1, 0x3081, 0x38a1, 0x40a1,
0x5902, 0x6121, 0x7160, 0x6940, 0x9200, 0x7160, 0x6100, 0x801, 0x1, 0x0, 0xffff, 0xd69a, 0xef3c, 0xdeba, 0x6a28, 0xffdf, 0x7aaa, 0xd638, 0x4881, 0xffff, 0xbd96, 0xffff, 0x51a5, 0x38a1, 0x38a1, 0x40a1, 0x40a1, 0x40a1, 0x40a0, 0x48a1, 0x3881, 0x38a1,
0x5922, 0x6121, 0x6120, 0x2040, 0x8180, 0x89c0, 0x7980, 0x6100, 0x0, 0x9cd3, 0xffff, 0x3145, 0x3820, 0xb4f3, 0xffff, 0x940f, 0x8bae, 0x8b6d, 0xc5f7, 0x9bef, 0x93cf, 0xffff, 0xe6fb, 0x3800, 0x3881, 0x4081, 0x3081, 0x3081, 0x3881, 0x3881, 0x3881, 0x38a1,
0x5922, 0x5901, 0x50e0, 0x801, 0x0, 0x0, 0x1840, 0x2881, 0x3103, 0xffff, 0xa555, 0x2021, 0x3881, 0x3860, 0x93ef, 0x4081, 0xffff, 0x6a89, 0x8bce, 0x2000, 0xde79, 0xbd75, 0xffff, 0x7aeb, 0x3881, 0x3880, 0x3081, 0x3881, 0x3881, 0x3881, 0x3081, 0x3881,
0x5902, 0x50e1, 0x48e0, 0x801, 0x0, 0x0, 0x0, 0x0, 0xc618, 0xffff, 0x821, 0x1841, 0x3881, 0x3860, 0xbd55, 0xffff, 0xffff, 0xffff, 0xffdf, 0x7b0a, 0x83ef, 0x9c50, 0xe6fb, 0xffdf, 0x2820, 0x3881, 0x3881, 0x3881, 0x3881, 0x4880, 0x3881, 0x3081,
0x5902, 0x50e1, 0x48c1, 0x1, 0x1, 0x1, 0x1, 0x4a49, 0xffff, 0x73ae, 0x1, 0x1861, 0x40a2, 0x5a08, 0xde79, 0xffdf, 0x4903, 0xbd96, 0xffff, 0xa3cd, 0x93ef, 0xbdf7, 0xc5b6, 0xffff, 0x9c51, 0x3881, 0x2061, 0x2861, 0x2881, 0x3081, 0x3081, 0x2861,
0x5902, 0x50e1, 0x40c1, 0x801, 0x1, 0x1, 0x0, 0xef7d, 0xf79e, 0x0, 0x1, 0x2861, 0x3082, 0x5a08, 0xe6db, 0xf7be, 0x2861, 0xb555, 0xffff, 0x9c50, 0x72aa, 0xad55, 0xbdb6, 0xef5d, 0xffff, 0x38a2, 0x3081, 0x2861, 0x3081, 0x2861, 0x2861, 0x2061,
0x5902, 0x50e2, 0x40c1, 0x821, 0x0, 0x1, 0x738e, 0xffff, 0x4a49, 0x10a3, 0x6b4d, 0x1020, 0x3882, 0x4082, 0xb514, 0xffff, 0x3882, 0xce18, 0xffdf, 0x4902, 0xa4f4, 0x6b0c, 0xad55, 0x4186, 0xffff, 0xc5b6, 0x2820, 0x3081, 0x3881, 0x3061, 0x3061, 0x3061,
0x5903, 0x50e2, 0x40c1, 0x821, 0x1, 0x20, 0xffff, 0xc639, 0x0, 0x9cf3, 0xffff, 0x3186, 0x4041, 0x9bae, 0xa474, 0x61eb, 0x2864, 0x20c4, 0x6b6d, 0x940f, 0x83ae, 0x62aa, 0xffff, 0xef5d, 0xffff, 0xffff, 0x59e7, 0x3082, 0x3881, 0x3861, 0x3881, 0x3061,
0x6103, 0x58e2, 0x40c1, 0x1021, 0x0, 0xa534, 0xffff, 0x18e4, 0x2945, 0x9cf4, 0xce79, 0x9471, 0xce17, 0xde79, 0x1041, 0x0, 0x3145, 0x4a08, 0x1021, 0x41c7, 0x940f, 0x6b4d, 0xb555, 0x4986, 0x1800, 0xffdf, 0xef3c, 0x1800, 0x2861, 0x3061, 0x2861, 0x2061,
0x6103, 0x58e3, 0x40c2, 0x1841, 0x2104, 0xffff, 0x9cd3, 0x2945, 0xffff, 0xdedb, 0xffff, 0xf79e, 0x4a69, 0x0, 0xb596, 0xffff, 0xef5d, 0x9492, 0x1021, 0x821, 0x1082, 0xbdf8, 0xbd96, 0xe6bb, 0xa4d3, 0x72ec, 0xffff, 0x732d, 0x2062, 0x2061, 0x2861, 0x3061,
0x6125, 0x5903, 0x48c2, 0x800, 0xd69a, 0xffff, 0x0, 0x8c10, 0x738e, 0x21, 0xffdf, 0xffff, 0xc638, 0xffff, 0xc513, 0x3000, 0x0, 0x1021, 0x1041, 0x1041, 0x21, 0x801, 0xce59, 0x9c71, 0x1000, 0xbd76, 0xffff, 0xffff, 0x3040, 0x2862, 0x1861, 0x2861,
0x6926, 0x5905, 0x48e4, 0x6aab, 0xffff, 0x6b4d, 0x2041, 0xa430, 0x7bef, 0x1, 0x2124, 0xffff, 0xffff, 0xf79e, 0xbcd2, 0xa3ae, 0x0, 0x1062, 0x1041, 0x1042, 0x822, 0x1062, 0x0, 0x8c30, 0xffff, 0x836e, 0x30e4, 0xffff, 0xa4b2, 0x3061, 0x2861, 0x2861,
0x6928, 0x6107, 0x4865, 0xf7be, 0xef5d, 0x0, 0x1021, 0x5081, 0x1042, 0x1, 0x1, 0x0, 0x3187, 0x4a4b, 0x83cf, 0xb5b7, 0xef3d, 0x2105, 0x823, 0x822, 0x1043, 0x1042, 0x1042, 0x821, 0x624b, 0xffff, 0xbd76, 0xb555, 0xffff, 0x30e3, 0x2861, 0x3061,
0x7129, 0x690a, 0xac54, 0xffff, 0x39a7, 0x0, 0x800, 0x1000, 0x1, 0x0, 0x1, 0x1, 0x2, 0x3, 0x3, 0x1, 0x526a, 0x7bcf, 0x802, 0x824, 0x1029, 0x102d, 0x102d, 0x823, 0x1843, 0x30e5, 0xef5d, 0xffff, 0xffff, 0xce18, 0x3000, 0x3882,
0x792b, 0x694d, 0xffff, 0xffdf, 0xbdf7, 0xc638, 0xc638, 0xc638, 0xc638, 0xc638, 0xc638, 0xc638, 0xc639, 0xc63a, 0xc63a, 0xc639, 0xc639, 0xc618, 0xc63a, 0xc63d, 0xc63e, 0xc6bf, 0xc63d, 0xc63a, 0xc638, 0xc638, 0xce38, 0xffff, 0xffff, 0xffff, 0x6294, 0x2883,
0x792c, 0x79f1, 0xef3e, 0xe6fe, 0xe6dd, 0xdedb, 0xdedb, 0xdedb, 0xdedc, 0xdedb, 0xdedc, 0xdedc, 0xdedd, 0xe6fe, 0xdedd, 0xe6de, 0xde9f, 0xe7ff, 0xe7ff, 0xe7ff, 0xe7ff, 0xe7ff, 0xdf7f, 0xdeff, 0xdedc, 0xdedb, 0xdedb, 0xdedb, 0xdedc, 0xdefc, 0x526d, 0x2061,
0x796f, 0x7191, 0x7237, 0x597b, 0x3055, 0x809, 0x2, 0x3, 0x2, 0x1087, 0x188a, 0x9, 0x815, 0x52bb, 0x17e, 0x147e, 0x27bf, 0x37bf, 0x3f9f, 0x67bf, 0x57bf, 0x3f9f, 0x275f, 0x17e, 0x12, 0x316c, 0x0, 0x0, 0x5, 0x80d, 0x2061, 0x1041,
0x814e, 0x7191, 0xb4db, 0x615e, 0xa4bc, 0x947b, 0xad36, 0x6330, 0x9cb5, 0x8c55, 0x8416, 0xa4fa, 0x54be, 0x86bf, 0x77fe, 0x7ffe, 0xa7ff, 0x9fdf, 0xbfff, 0xbfdf, 0xd7ff, 0x7fbf, 0xc7df, 0x8f5f, 0x2159, 0xdedd, 0x4209, 0xd679, 0x630f, 0x6b39, 0x1841, 0x821,
0x816f, 0x79b2, 0xac3b, 0x937f, 0xb53f, 0x83ff, 0x647e, 0x7b54, 0x8417, 0x39b5, 0x41b7, 0x8e1e, 0x7ffe, 0x87fe, 0x7ffe, 0x4ffe, 0x9fff, 0x77ff, 0xb7ff, 0xa7df, 0x8fdf, 0x97df, 0x9fdf, 0x9fdf, 0x3b7e, 0x7c1b, 0x528c, 0x6b51, 0x637d, 0x1012, 0x1862, 0x821,
0x896f, 0x79d3, 0x7a1a, 0x7a5f, 0x6b1f, 0x545f, 0x373f, 0x3ebe, 0x2979, 0x11fc, 0x567e, 0x77fe, 0x67fd, 0x5ffd, 0x67fd, 0x6ffe, 0x77fe, 0x6fff, 0x67ff, 0x5fdf, 0x5fdf, 0x57df, 0x5fdf, 0x5fbf, 0x577f, 0x80d, 0x805, 0x870, 0x18b4, 0x2070, 0x1045, 0x1021,
0x896f, 0x79d4, 0x7a3a, 0x7a7f, 0x733f, 0x54bf, 0x3f1f, 0x4ffe, 0x7f1f, 0xaffe, 0x8ffe, 0x87fe, 0x77fe, 0x77fe, 0x77fe, 0x6ffe, 0x87fe, 0x87ff, 0x6fff, 0x67df, 0x5fbf, 0x5fbf, 0x5fbf, 0x5fbf, 0x579f, 0x3d3b, 0x1031, 0x82b, 0x211b, 0x2072, 0x1025, 0x1042,
];
pub const LOGO : ColorBitmap = ColorBitmap {
width : 4,
height : 4,
pixels : &LOGO_PX,
};

View File

@ -23,9 +23,12 @@ mod systick;
mod printer;
mod max6675;
mod st7735;
mod logo;
use printer::UsartPrinter;
use st7735::gfx::{PrimitveGFX, GFX};
use st7735::bitmaps::BitmapGFX;
fn configure_clocks(rcc: &mut rcc::RCC) {
@ -124,15 +127,24 @@ fn run(mut scs: scs::Instance, mut p: hcl::platform::Instance) {
st7735io.init();
st7735io.set_orientation(st7735::DisplayOrientation::Landscape);
st7735io.fill_rect(0, 0, 160, 128, st7735::COLOR_BLACK);
systick::delay_ms(100);
st7735io.fill_rect(4, 4, 76, 60, st7735::COLOR_RED);
systick::delay_ms(100);
st7735io.fill_rect(4, 64, 76, 60, st7735::COLOR_GREEN);
systick::delay_ms(100);
st7735io.fill_rect(80, 4, 76, 60, st7735::COLOR_BLUE);
systick::delay_ms(100);
st7735io.fill_rect(80, 64, 76, 60, st7735::COLOR_YELLOW);
systick::delay_ms(100);
st7735io.draw_circle(80, 64, 20, st7735::COLOR_MAGENTA);
st7735io.draw_line(4, 4, 80, 64, st7735::COLOR_GREEN);
systick::delay_ms(2000);
systick::delay_ms(100);
//st7735io.draw_color_bitmap(10, 10, &logo::LOGO);
systick::delay_ms(5000);
}
let (st7735, mut spi, mut gpio) = st7735io.done();

19
src/st7735/bitmaps.rs Normal file
View File

@ -0,0 +1,19 @@
use st7735::gfx::PrimitveGFX;
pub struct ColorBitmap {
pub width: u8,
pub height: u8,
pub pixels: &'static [u16],
}
pub struct MonoBitmap {
pub width: u8,
pub height: u8,
pub pixels: &'static [u8],
}
pub trait BitmapGFX : PrimitveGFX {
fn draw_color_bitmap(&mut self, x : u8, y: u8, bitmap: &ColorBitmap);
fn draw_mono_bitmap(&mut self, x : u8, y: u8, bitmap: &MonoBitmap,
color_set : u16, color_unset : u16);
}

View File

@ -8,6 +8,7 @@ use systick::delay_ms;
mod commands;
mod init;
pub mod gfx;
pub mod bitmaps;
use st7735::commands::*;
@ -502,3 +503,44 @@ impl<SPIAddr, GPIOAddr> gfx::PrimitveGFX for St7735IO<SPIAddr, GPIOAddr>
impl<SPIAddr, GPIOAddr> gfx::GFX for St7735IO<SPIAddr, GPIOAddr>
where SPIAddr: Location,
GPIOAddr: Location {}
impl<SPIAddr, GPIOAddr> bitmaps::BitmapGFX for St7735IO<SPIAddr, GPIOAddr>
where SPIAddr: Location,
GPIOAddr: Location {
fn draw_color_bitmap(&mut self, x : u8, y: u8, bitmap: &bitmaps::ColorBitmap) {
if x >= self.st7735.width || y >= self.st7735.height {
return;
}
if((x + bitmap.width - 1) >= self.st7735.width) {
return;
}
if((y + bitmap.height - 1) >= self.st7735.height) {
return;
}
self.set_addr_win(x, y, x + bitmap.width - 1, y + bitmap.height - 1);
self.set_rs();
self.reset_cs();
for i in 0..bitmap.height {
for j in 0..bitmap.width {
let color = bitmap.pixels[(i * bitmap.width + j) as usize];
self.write_color_bytes(color);
delay_ms(1);
}
}
self.set_cs();
}
fn draw_mono_bitmap(&mut self, x : u8, y: u8, bitmap: &bitmaps::MonoBitmap,
color_set : u16, color_unset : u16) {
}
}