Skip to content

Commit ee81f83

Browse files
committed
Replace bwrbit with DisplayMode enum
1 parent da241ac commit ee81f83

24 files changed

Lines changed: 125 additions & 71 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: 21 additions & 13 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),
@@ -104,16 +105,23 @@ impl ColorType for TriColor {
104105
const BITS_PER_PIXEL_PER_BUFFER: usize = 1;
105106
const BUFFER_COUNT: usize = 2;
106107

107-
fn bitmask(&self, bwrbit: bool, pos: u32) -> (u8, u16) {
108+
fn bitmask(&self, mode: DisplayMode, pos: u32) -> (u8, u16) {
108109
let bit = 0x80 >> (pos % 8);
109-
let mask = match self {
110-
TriColor::Black => (bit as u16) << 8,
111-
TriColor::White => (bit as u16) << 8 | bit as u16,
112-
TriColor::Chromatic => if bwrbit {
113-
// (bit as u16) << 8
114-
0u16
115-
} else {
116-
(bit as u16) << 8 | bit as u16
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,
117125
},
118126
};
119127
(!bit, mask)
@@ -123,7 +131,7 @@ impl ColorType for TriColor {
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 })

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)