Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for epd2in9b_v4 #199

Merged
merged 3 commits into from
Oct 29, 2024
Merged

Add support for epd2in9b_v4 #199

merged 3 commits into from
Oct 29, 2024

Conversation

tomcheung
Copy link
Contributor

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
  // 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::<AnyIOPin>::None,
       Option::<AnyOutputPin>::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)?;

@auto-assign auto-assign bot requested a review from caemor May 15, 2024 09:12
@caemor
Copy link
Owner

caemor commented Oct 29, 2024

Thanks!

@caemor caemor merged commit b28b4bf into caemor:main Oct 29, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants