Skip to content

Commit ef0f6da

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

24 files changed

Lines changed: 814 additions & 104 deletions

File tree

examples/epd4in2_variable_size.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ fn main() -> Result<(), std::io::Error> {
7070
let (x, y, width, height) = (50, 50, 250, 250);
7171

7272
let mut buffer = [epd4in2::DEFAULT_BACKGROUND_COLOR.get_byte_value(); 62500]; //250*250
73-
let mut display = VarDisplay::new(width, height, &mut buffer, false).unwrap();
73+
let mut display =
74+
VarDisplay::new(width, height, &mut buffer, DisplayMode::BwrBitOff as u8).unwrap();
7475
display.set_rotation(DisplayRotation::Rotate0);
7576
draw_text(&mut display, "Rotate 0!", 5, 50);
7677

src/color.rs

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! EPD representation of multicolor with separate buffers
44
//! for each bit makes it hard to properly represent colors here
55
6+
use crate::prelude::DisplayMode;
67
#[cfg(feature = "graphics")]
78
use embedded_graphics_core::pixelcolor::BinaryColor;
89
#[cfg(feature = "graphics")]
@@ -77,21 +78,21 @@ pub trait ColorType: PixelColor {
7778

7879
/// Return the data used to set a pixel color
7980
///
80-
/// * bwrbit is used to tell the value of the unused bit when a chromatic
81+
/// * MODE is used to tell the value of the unused bit when a chromatic
8182
/// color is set (TriColor only as for now)
8283
/// * pos is the pixel position in the line, used to know which pixels must be set
8384
///
8485
/// Return values are :
8586
/// * .0 is the mask used to exclude this pixel from the byte (eg: 0x7F in BiColor)
8687
/// * .1 are the bits used to set the color in the byte (eg: 0x80 in BiColor)
8788
/// this is u16 because we set 2 bytes in case of split buffer
88-
fn bitmask(&self, bwrbit: bool, pos: u32) -> (u8, u16);
89+
fn bitmask(&self, mode: DisplayMode, pos: u32) -> (u8, u16);
8990
}
9091

9192
impl ColorType for Color {
9293
const BITS_PER_PIXEL_PER_BUFFER: usize = 1;
9394
const BUFFER_COUNT: usize = 1;
94-
fn bitmask(&self, _bwrbit: bool, pos: u32) -> (u8, u16) {
95+
fn bitmask(&self, _mode: DisplayMode, pos: u32) -> (u8, u16) {
9596
let bit = 0x80 >> (pos % 8);
9697
match self {
9798
Color::Black => (!bit, 0u16),
@@ -103,27 +104,34 @@ impl ColorType for Color {
103104
impl ColorType for TriColor {
104105
const BITS_PER_PIXEL_PER_BUFFER: usize = 1;
105106
const BUFFER_COUNT: usize = 2;
106-
fn bitmask(&self, bwrbit: bool, pos: u32) -> (u8, u16) {
107+
108+
fn bitmask(&self, mode: DisplayMode, pos: u32) -> (u8, u16) {
107109
let bit = 0x80 >> (pos % 8);
108-
match self {
109-
TriColor::Black => (!bit, 0u16),
110-
TriColor::White => (!bit, bit as u16),
111-
TriColor::Chromatic => (
112-
!bit,
113-
if bwrbit {
114-
(bit as u16) << 8
115-
} else {
116-
(bit as u16) << 8 | bit as u16
117-
},
118-
),
119-
}
110+
let mask = match mode {
111+
DisplayMode::BwrBitOnColorInverted => match self {
112+
TriColor::Black => (bit as u16) << 8,
113+
TriColor::White => (bit as u16) << 8 | bit as u16,
114+
TriColor::Chromatic => 0u16,
115+
},
116+
DisplayMode::BwrBitOn => match self {
117+
TriColor::Black => 0u16,
118+
TriColor::White => bit as u16,
119+
TriColor::Chromatic => (bit as u16) << 8,
120+
},
121+
DisplayMode::BwrBitOff => match self {
122+
TriColor::Black => 0u16,
123+
TriColor::White => bit as u16,
124+
TriColor::Chromatic => (bit as u16) << 8 | bit as u16,
125+
},
126+
};
127+
(!bit, mask)
120128
}
121129
}
122130

123131
impl ColorType for OctColor {
124132
const BITS_PER_PIXEL_PER_BUFFER: usize = 4;
125133
const BUFFER_COUNT: usize = 1;
126-
fn bitmask(&self, _bwrbit: bool, pos: u32) -> (u8, u16) {
134+
fn bitmask(&self, _mode: DisplayMode, pos: u32) -> (u8, u16) {
127135
let mask = !(0xF0 >> (pos % 2));
128136
let bits = self.get_nibble() as u16;
129137
(mask, if pos % 2 == 1 { bits } else { bits << 4 })
@@ -307,16 +315,16 @@ impl From<BinaryColor> for Color {
307315
impl From<embedded_graphics_core::pixelcolor::Rgb888> for Color {
308316
fn from(rgb: embedded_graphics_core::pixelcolor::Rgb888) -> Self {
309317
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
318+
match rgb {
319+
RgbColor::BLACK => Color::Black,
320+
RgbColor::WHITE => Color::White,
321+
_ => {
322+
// choose closest color
323+
if (rgb.r() as u16 + rgb.g() as u16 + rgb.b() as u16) > 255 * 3 / 2 {
324+
Color::White
325+
} else {
326+
Color::Black
327+
}
320328
}
321329
}
322330
}
@@ -369,13 +377,11 @@ impl From<BinaryColor> for TriColor {
369377
impl From<embedded_graphics_core::pixelcolor::Rgb888> for TriColor {
370378
fn from(rgb: embedded_graphics_core::pixelcolor::Rgb888) -> Self {
371379
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 {
380+
match rgb {
381+
RgbColor::BLACK => TriColor::Black,
382+
RgbColor::WHITE => TriColor::White,
377383
// there is no good approximation here since we don't know which color is 'chromatic'
378-
TriColor::Chromatic
384+
_ => TriColor::Chromatic,
379385
}
380386
}
381387
}

src/epd1in54/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ use crate::interface::DisplayInterface;
7575
pub type Display1in54 = crate::graphics::Display<
7676
WIDTH,
7777
HEIGHT,
78-
false,
78+
{ crate::graphics::DisplayMode::BwrBitOff as u8 },
7979
{ buffer_len(WIDTH as usize, HEIGHT as usize) },
8080
Color,
8181
>;

src/epd1in54b/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::buffer_len;
3434
pub type Display1in54b = crate::graphics::Display<
3535
WIDTH,
3636
HEIGHT,
37-
false,
37+
{ crate::graphics::DisplayMode::BwrBitOff as u8 },
3838
{ buffer_len(WIDTH as usize, HEIGHT as usize) },
3939
Color,
4040
>;

src/epd1in54c/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::buffer_len;
3131
pub type Display1in54c = crate::graphics::Display<
3232
WIDTH,
3333
HEIGHT,
34-
false,
34+
{ crate::graphics::DisplayMode::BwrBitOff as u8 },
3535
{ buffer_len(WIDTH as usize, HEIGHT as usize) },
3636
Color,
3737
>;

src/epd2in13_v2/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use self::constants::{LUT_FULL_UPDATE, LUT_PARTIAL_UPDATE};
3333
pub type Display2in13 = crate::graphics::Display<
3434
WIDTH,
3535
HEIGHT,
36-
false,
36+
{ crate::graphics::DisplayMode::BwrBitOff as u8 },
3737
{ buffer_len(WIDTH as usize, HEIGHT as usize) },
3838
Color,
3939
>;

src/epd2in13bc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ use crate::buffer_len;
8888
pub type Display2in13bc = crate::graphics::Display<
8989
WIDTH,
9090
HEIGHT,
91-
true,
91+
{ crate::graphics::DisplayMode::BwrBitOn as u8 },
9292
{ buffer_len(WIDTH as usize, HEIGHT as usize * 2) },
9393
TriColor,
9494
>;

src/epd2in7b/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::buffer_len;
3636
pub type Display2in7b = crate::graphics::Display<
3737
WIDTH,
3838
HEIGHT,
39-
false,
39+
{ crate::graphics::DisplayMode::BwrBitOff as u8 },
4040
{ buffer_len(WIDTH as usize, HEIGHT as usize) },
4141
Color,
4242
>;

src/epd2in9/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use crate::interface::DisplayInterface;
7171
pub type Display2in9 = crate::graphics::Display<
7272
WIDTH,
7373
HEIGHT,
74-
false,
74+
{ crate::graphics::DisplayMode::BwrBitOff as u8 },
7575
{ buffer_len(WIDTH as usize, HEIGHT as usize) },
7676
Color,
7777
>;

src/epd2in9_v2/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use crate::traits::QuickRefresh;
9494
pub type Display2in9 = crate::graphics::Display<
9595
WIDTH,
9696
HEIGHT,
97-
false,
97+
{ crate::graphics::DisplayMode::BwrBitOff as u8 },
9898
{ buffer_len(WIDTH as usize, HEIGHT as usize) },
9999
Color,
100100
>;

0 commit comments

Comments
 (0)