Skip to content

Commit

Permalink
Merge pull request #41 from michaelbeaumont/epd2in9b
Browse files Browse the repository at this point in the history
Add epd2in9bc support
  • Loading branch information
caemor authored Mar 27, 2020
2 parents c62ee89 + 9167c64 commit 79c2524
Show file tree
Hide file tree
Showing 9 changed files with 520 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ epd.update_and_display_frame(&mut spi, &display.buffer())?;
| [2.13 Inch B/W (A)](https://www.waveshare.com/product/2.13inch-e-paper-hat.htm) | Black, White ||| | |
| [2.9 Inch B/W (A)](https://www.waveshare.com/product/2.9inch-e-paper-module.htm) | Black, White |||||
| [1.54 Inch B/W/R (B)](https://www.waveshare.com/product/modules/oleds-lcds/e-paper/1.54inch-e-paper-module-b.htm) | Black, White, Red |||||
| [2.9 Inch B/W/R (B/C)](https://www.waveshare.com/product/displays/e-paper/epaper-2/2.9inch-e-paper-module-b.htm) | Black, White, Red |||||

### [1]: 7.5 Inch B/W V2 (A)

Expand Down
11 changes: 11 additions & 0 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ pub enum Color {
White,
}

/// Only for the Black/White/Color-Displays
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum TriColor {
/// Black color
Black,
/// White color
White,
/// Chromatic color
Chromatic,
}

//TODO: Rename get_bit_value to bit() and get_byte_value to byte() ?

impl Color {
Expand Down
2 changes: 1 addition & 1 deletion src/epd1in54/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//! .into_styled(PrimitiveStyle::with_stroke(Black, 1))
//! .draw(&mut display);
//!
//! // Display updated frame
//!// Display updated frame
//!epd.update_frame(&mut spi, &display.buffer())?;
//!epd.display_frame(&mut spi)?;
//!
Expand Down
16 changes: 14 additions & 2 deletions src/epd1in54b/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,13 @@ where
&mut self,
spi: &mut SPI,
black: &[u8],
red: &[u8],
chromatic: &[u8],
) -> Result<(), SPI::Error> {
self.update_achromatic_frame(spi, black)?;
self.update_chromatic_frame(spi, chromatic)
}

fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.send_resolution(spi)?;

Expand All @@ -113,10 +118,17 @@ where
let expanded = expand_bits(*b);
self.interface.data(spi, &expanded)?;
}
Ok(())
}

fn update_chromatic_frame(
&mut self,
spi: &mut SPI,
chromatic: &[u8],
) -> Result<(), SPI::Error> {
self.interface
.cmd(spi, Command::DATA_START_TRANSMISSION_2)?;
self.interface.data(spi, red)?;
self.interface.data(spi, chromatic)?;
Ok(())
}
}
Expand Down
39 changes: 39 additions & 0 deletions src/epd2in9bc/command.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//! SPI Commands for the Waveshare 2.9" (B/C) E-Ink Display
use crate::traits;

#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[derive(Copy, Clone)]
pub(crate) enum Command {
PANEL_SETTING = 0x00,

POWER_SETTING = 0x01,
POWER_OFF = 0x02,
POWER_ON = 0x04,
BOOSTER_SOFT_START = 0x06,
DEEP_SLEEP = 0x07,
DATA_START_TRANSMISSION_1 = 0x10,
DISPLAY_REFRESH = 0x12,
DATA_START_TRANSMISSION_2 = 0x13,

LUT_FOR_VCOM = 0x20,
LUT_WHITE_TO_WHITE = 0x21,
LUT_BLACK_TO_WHITE = 0x22,
LUT_WHITE_TO_BLACK = 0x23,
LUT_BLACK_TO_BLACK = 0x24,

PLL_CONTROL = 0x30,
TEMPERATURE_SENSOR_COMMAND = 0x40,
TEMPERATURE_SENSOR_SELECTION = 0x41,
VCOM_AND_DATA_INTERVAL_SETTING = 0x50,
RESOLUTION_SETTING = 0x61,
VCM_DC_SETTING = 0x82,
POWER_SAVING = 0xE3,
}

impl traits::Command for Command {
/// Returns the address of the command
fn address(self) -> u8 {
self as u8
}
}
51 changes: 51 additions & 0 deletions src/epd2in9bc/graphics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use crate::epd2in9bc::{DEFAULT_BACKGROUND_COLOR, HEIGHT, NUM_DISPLAY_BITS, WIDTH};
use crate::graphics::{Display, DisplayRotation};
use embedded_graphics::pixelcolor::BinaryColor;
use embedded_graphics::prelude::*;

/// Full size buffer for use with the 2in9b/c EPD
///
/// Can also be manually constructed and be used together with VarDisplay
pub struct Display2in9bc {
buffer: [u8; NUM_DISPLAY_BITS as usize],
rotation: DisplayRotation,
}

impl Default for Display2in9bc {
fn default() -> Self {
Display2in9bc {
buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value(); NUM_DISPLAY_BITS as usize],
rotation: DisplayRotation::default(),
}
}
}

impl DrawTarget<BinaryColor> for Display2in9bc {
type Error = core::convert::Infallible;

fn draw_pixel(&mut self, pixel: Pixel<BinaryColor>) -> Result<(), Self::Error> {
self.draw_helper(WIDTH, HEIGHT, pixel)
}

fn size(&self) -> Size {
Size::new(WIDTH, HEIGHT)
}
}

impl Display for Display2in9bc {
fn buffer(&self) -> &[u8] {
&self.buffer
}

fn get_mut_buffer(&mut self) -> &mut [u8] {
&mut self.buffer
}

fn set_rotation(&mut self, rotation: DisplayRotation) {
self.rotation = rotation;
}

fn rotation(&self) -> DisplayRotation {
self.rotation
}
}
Loading

0 comments on commit 79c2524

Please sign in to comment.