diff --git a/examples/embedded_linux_epd1in54/src/main.rs b/examples/embedded_linux_epd1in54/src/main.rs index 2eaed77..1c35601 100644 --- a/examples/embedded_linux_epd1in54/src/main.rs +++ b/examples/embedded_linux_epd1in54/src/main.rs @@ -27,10 +27,12 @@ use lin_hal::Delay; extern crate embedded_hal; use embedded_hal::digital::{InputPin}; +//TODO: Remove when linux_embedded_hal implements InputPin struct HackInputPin<'a> { pin: &'a Pin } +//TODO: Remove when linux_embedded_hal implements InputPin impl<'a> HackInputPin<'a> { fn new(p : &'a Pin) -> HackInputPin { HackInputPin { @@ -39,15 +41,16 @@ impl<'a> HackInputPin<'a> { } } -//TODO: make it safer?? or handle the errors better? -// now it defaults to is_low if an error appears +//TODO: Remove when linux_embedded_hal implements InputPin +// for now it defaults to is_low if an error appears +// could be handled better! impl<'a> InputPin for HackInputPin<'a> { fn is_low(&self) -> bool { self.pin.get_value().unwrap_or(0) == 0 } fn is_high(&self) -> bool { - self.pin.get_value().unwrap_or(0) == 1 + !self.is_low() } } @@ -71,12 +74,13 @@ fn main() { spi.configure(&options).expect("spi configuration"); // Configure Digital I/O Pin to be used as Chip Select for SPI - let cs = Pin::new(26);//BCM7 CE0 - cs.export().expect("cs export"); - while !cs.is_exported() {} - cs.set_direction(Direction::Out).expect("CS Direction"); - cs.set_value(1).expect("CS Value set to 1"); + let cs_pin = Pin::new(26);//BCM7 CE0 + cs_pin.export().expect("cs_pin export"); + while !cs_pin.is_exported() {} + cs_pin.set_direction(Direction::Out).expect("cs_pin Direction"); + cs_pin.set_value(1).expect("cs_pin Value set to 1"); + // Configure Busy Input Pin let busy = Pin::new(5);//pin 29 busy.export().expect("busy export"); while !busy.is_exported() {} @@ -84,35 +88,36 @@ fn main() { //busy.set_value(1).expect("busy Value set to 1"); let busy_in = HackInputPin::new(&busy); + // Configure Data/Command OutputPin let dc = Pin::new(6); //pin 31 //bcm6 dc.export().expect("dc export"); while !dc.is_exported() {} dc.set_direction(Direction::Out).expect("dc Direction"); dc.set_value(1).expect("dc Value set to 1"); + // Configure Reset OutputPin let rst = Pin::new(16); //pin 36 //bcm16 rst.export().expect("rst export"); while !rst.is_exported() {} rst.set_direction(Direction::Out).expect("rst Direction"); rst.set_value(1).expect("rst Value set to 1"); + // Configure Delay let delay = Delay {}; - - + // Setup of the needed pins is finished here + // Now the "real" usage of the eink-waveshare-rs crate begins - //TODO: wait for Digital::InputPin - //fixed currently with the HackInputPin, see further above - let mut epd = EPD1in54::new(spi, cs, busy_in, dc, rst, delay).expect("eink inialize error"); + let mut epd = EPD1in54::new(spi, cs_pin, busy_in, dc, rst, delay).expect("eink inialize error"); - let mut buffer = [0u8, epd4in2.get_width() / 8 * epd4in2.get_height()]; + let mut buffer = [0u8, epd.get_width() as u8 / 8 * epd.get_height() as u8]; //let mut buffer = [0u8; 15000]; // draw something - let mut graphics = Graphics::new(400, 300, &mut buffer); + let mut graphics = Graphics::new(200, 200, &mut buffer); graphics.clear(&Color::White); - graphics.draw_line(0,0,400,300, &Color::Black); + graphics.draw_line(0,0,200,200, &Color::Black); graphics.draw_filled_rectangle(200,200, 230, 230, &Color::Black); graphics.draw_line(202,202,218,228, &Color::White); @@ -125,30 +130,30 @@ fn main() { graphics.draw_vertical_line(200, 50, 200, &Color::Black); - epd4in2.update_and_display_frame(graphics.get_buffer()).expect("display and transfer error"); + epd.update_and_display_frame(graphics.get_buffer()).expect("display and transfer error"); - epd4in2.delay_ms(3000); + epd.delay_ms(3000); - epd4in2.clear_frame().expect("clear frame error"); + epd.clear_frame().expect("clear frame error"); //Test fast updating a bit more let mut small_buffer = [0x00; 128]; let mut circle_graphics = Graphics::new(32,32, &mut small_buffer); circle_graphics.draw_circle(16,16, 10, &Color::Black); - epd4in2.update_partial_frame(circle_graphics.get_buffer(), 16,16, 32, 32).expect("Partial Window Error"); - epd4in2.display_frame().expect("Display Frame Error"); + epd.update_partial_frame(circle_graphics.get_buffer(), 16,16, 32, 32).expect("Partial Window Error"); + epd.display_frame().expect("Display Frame Error"); - epd4in2.update_partial_frame(circle_graphics.get_buffer(), 128,64, 32, 32).expect("Partial Window Error"); - epd4in2.display_frame().expect("Display Frame Error"); + epd.update_partial_frame(circle_graphics.get_buffer(), 128,64, 32, 32).expect("Partial Window Error"); + epd.display_frame().expect("Display Frame Error"); - epd4in2.update_partial_frame(circle_graphics.get_buffer(), 320,24, 32, 32).expect("Partial Window Error"); - epd4in2.display_frame().expect("Display Frame Error"); + epd.update_partial_frame(circle_graphics.get_buffer(), 320,24, 32, 32).expect("Partial Window Error"); + epd.display_frame().expect("Display Frame Error"); - epd4in2.update_partial_frame(circle_graphics.get_buffer(), 160,240, 32, 32).expect("Partial Window Error"); - epd4in2.display_frame().expect("Display Frame Error"); + epd.update_partial_frame(circle_graphics.get_buffer(), 160,240, 32, 32).expect("Partial Window Error"); + epd.display_frame().expect("Display Frame Error"); - epd4in2.delay_ms(3000); + epd.delay_ms(3000); @@ -157,9 +162,9 @@ fn main() { graphics.draw_string_8x8(16, 16, "hello", &Color::Black); graphics.draw_char_8x8(250, 250, '#', &Color::Black); graphics.draw_char_8x8(300, 16, '7', &Color::Black); - epd4in2.update_and_display_frame(graphics.get_buffer()).expect("display and transfer error"); + epd.update_and_display_frame(graphics.get_buffer()).expect("display and transfer error"); - epd4in2.delay_ms(3000); + epd.delay_ms(3000); - epd4in2.sleep().expect("sleeping error"); + epd.sleep().expect("sleeping error"); }