caemor / epd-waveshare

Drivers for various EPDs from Waveshare
ISC License
221 stars 131 forks source link

Add support for epd2in9b_v4 #199

Open tomcheung opened 4 months ago

tomcheung commented 4 months ago

Add support support for epd2in9b_v4, reference from c source code https://github.com/waveshareteam/e-Paper/blob/master/RaspberryPi_JetsonNano/c/lib/e-Paper/EPD_2in9b_V4.c

Also support for partial display and red color

Here is the testing code with EPS32

Testing code ```rust // It is necessary to call this function once. Otherwise some patches to the runtime // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 esp_idf_svc::sys::link_patches(); // Bind the log crate to the ESP Logging facilities esp_idf_svc::log::EspLogger::initialize_default(); log::set_max_level(log::LevelFilter::Debug); let peripheral = Peripherals::take().unwrap(); let bus_config = DriverConfig::new(); let config = Config::new().baudrate(10u32.MHz().into()); let sclk: AnyOutputPin = peripheral.pins.gpio13.into(); let sdo: AnyOutputPin = peripheral.pins.gpio14.into(); let cs: AnyOutputPin = peripheral.pins.gpio15.into(); let mut spi = SpiDeviceDriver::new_single( peripheral.spi3, sclk, sdo, Option::::None, Option::::Some(cs), &bus_config, &config )?; let busy = PinDriver::input(peripheral.pins.gpio25)?; let mut dc = PinDriver::output(peripheral.pins.gpio27)?; let mut rst = PinDriver::output(peripheral.pins.gpio26)?; let mut delay = Ets; let mut test_epd = Epd2in9b::new(&mut spi, busy, dc, rst, &mut delay, Some(50_000))?; let mut display = Display2in9::default(); display.set_rotation(DisplayRotation::Rotate90); display.clear(Color::White)?; let style = MonoTextStyleBuilder::new() .font(&embedded_graphics::mono_font::ascii::FONT_10X20) .text_color(Color::Black) .build(); let _ = Text::new("Hello World", Point { x: 30, y: 30 }, style) .draw(&mut display); test_epd.update_and_display_frame(&mut spi, display.buffer(), &mut delay)?; Delay::new_default().delay_ms(500); display.clear(Color::White)?; test_epd.update_and_display_frame_base(&mut spi, &mut display.buffer(), &mut delay)?; const PARTIAL_DISPLAY_SIZE: u32 = 120; let mut partial_display = Display::< PARTIAL_DISPLAY_SIZE, PARTIAL_DISPLAY_SIZE, false, { buffer_len(PARTIAL_DISPLAY_SIZE as usize, PARTIAL_DISPLAY_SIZE as usize) }, Color >::default(); partial_display.clear(Color::White)?; let stroke_style = PrimitiveStyle::with_stroke(Color::Black, 2); let _ = Rectangle::with_corners(Point { x: 0, y: 0 }, Point { x: PARTIAL_DISPLAY_SIZE as i32, y: PARTIAL_DISPLAY_SIZE as i32 }) .into_styled(stroke_style) .draw(&mut partial_display); for i in 1..11 { let _ = Line::new(Point { x: i * 10, y: 0 }, Point { x: PARTIAL_DISPLAY_SIZE as i32, y: i * 10 }) .into_styled(stroke_style) .draw(&mut partial_display); test_epd.update_partial_frame(&mut spi, &mut delay, &partial_display.buffer(), 15, 15, PARTIAL_DISPLAY_SIZE, PARTIAL_DISPLAY_SIZE)?; test_epd.display_frame_partial(&mut spi, &mut delay)?; } Ets::delay_ms(500); test_epd.sleep(&mut spi, &mut delay)?; ```