Skip to content

Commit 2a7e3bd

Browse files
committed
Add EPD 4in2bc support
1 parent f98c121 commit 2a7e3bd

4 files changed

Lines changed: 697 additions & 17 deletions

File tree

src/color.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl ColorType for Color {
103103
impl ColorType for TriColor {
104104
const BITS_PER_PIXEL_PER_BUFFER: usize = 1;
105105
const BUFFER_COUNT: usize = 2;
106+
106107
fn bitmask(&self, bwrbit: bool, pos: u32) -> (u8, u16) {
107108
let bit = 0x80 >> (pos % 8);
108109
match self {
@@ -307,16 +308,16 @@ impl From<BinaryColor> for Color {
307308
impl From<embedded_graphics_core::pixelcolor::Rgb888> for Color {
308309
fn from(rgb: embedded_graphics_core::pixelcolor::Rgb888) -> Self {
309310
use embedded_graphics_core::pixelcolor::RgbColor;
310-
if rgb == RgbColor::BLACK {
311-
Color::Black
312-
} else if rgb == RgbColor::WHITE {
313-
Color::White
314-
} else {
315-
// choose closest color
316-
if (rgb.r() as u16 + rgb.g() as u16 + rgb.b() as u16) > 255 * 3 / 2 {
317-
Color::White
318-
} else {
319-
Color::Black
311+
match rgb {
312+
RgbColor::BLACK => Color::Black,
313+
RgbColor::WHITE => Color::White,
314+
_ => {
315+
// choose closest color
316+
if (rgb.r() as u16 + rgb.g() as u16 + rgb.b() as u16) > 255 * 3 / 2 {
317+
Color::White
318+
} else {
319+
Color::Black
320+
}
320321
}
321322
}
322323
}
@@ -369,13 +370,11 @@ impl From<BinaryColor> for TriColor {
369370
impl From<embedded_graphics_core::pixelcolor::Rgb888> for TriColor {
370371
fn from(rgb: embedded_graphics_core::pixelcolor::Rgb888) -> Self {
371372
use embedded_graphics_core::pixelcolor::RgbColor;
372-
if rgb == RgbColor::BLACK {
373-
TriColor::Black
374-
} else if rgb == RgbColor::WHITE {
375-
TriColor::White
376-
} else {
373+
match rgb {
374+
RgbColor::BLACK => TriColor::Black,
375+
RgbColor::WHITE => TriColor::White,
377376
// there is no good approximation here since we don't know which color is 'chromatic'
378-
TriColor::Chromatic
377+
_ => TriColor::Chromatic,
379378
}
380379
}
381380
}

src/epd4in2/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use crate::interface::DisplayInterface;
5858
use crate::traits::{InternalWiAdditions, QuickRefresh, RefreshLut, WaveshareDisplay};
5959

6060
//The Lookup Tables for the Display
61-
mod constants;
61+
pub(crate) mod constants;
6262
use crate::epd4in2::constants::*;
6363

6464
/// Width of the display

0 commit comments

Comments
 (0)