Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,14 @@ impl ColorType for TriColor {
const BUFFER_COUNT: usize = 2;
fn bitmask(&self, bwrbit: bool, pos: u32) -> (u8, u16) {
let bit = 0x80 >> (pos % 8);
match self {
TriColor::Black => (!bit, 0u16),
TriColor::White => (!bit, bit as u16),
TriColor::Chromatic => (
!bit,
if bwrbit {
(bit as u16) << 8
} else {
(bit as u16) << 8 | bit as u16
},
),

match (self, bwrbit) {
(TriColor::Black, true) => (!bit, (bit as u16) << 8),
(TriColor::Black, false) => (!bit, 0u16),
(TriColor::White, true) => (!bit, bit as u16 | ((bit as u16) << 8)),
(TriColor::White, false) => (!bit, bit as u16),
(TriColor::Chromatic, true) => (!bit, bit as u16),
(TriColor::Chromatic, false) => (!bit, (bit as u16) << 8 | bit as u16),
}
}
}
Expand Down Expand Up @@ -547,15 +544,15 @@ mod tests {

assert_eq!(
TriColor::Black.bitmask(true, 0),
(0b01111111, u16::from_le_bytes([0b00000000, 0b00000000]))
(0b01111111, u16::from_le_bytes([0b00000000, 0b10000000]))
);
assert_eq!(
TriColor::White.bitmask(true, 0),
(0b01111111, u16::from_le_bytes([0b10000000, 0b00000000]))
(0b01111111, u16::from_le_bytes([0b10000000, 0b10000000]))
);
assert_eq!(
TriColor::Chromatic.bitmask(true, 0),
(0b01111111, u16::from_le_bytes([0b00000000, 0b10000000]))
(0b01111111, u16::from_le_bytes([0b10000000, 0b00000000]))
);
}
}
6 changes: 3 additions & 3 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const fn line_bytes(width: u32, bits_per_pixel: usize) -> usize {
/// Other displays, like [crate::epd5in83b_v2] in opposite, will draw color pixel if bit is
/// cleared for that pixel, which is a `BWRBIT = false` mode.
///
/// BWRBIT=true: chromatic doesn't override white, white bit cleared for black, white bit set for white, both bits set for chromatic
/// BWRBIT=true: chromatic doesn't override white, white bit cleared for black, white bit set for white, both bits set for chromatic. chromatic needs to be set to white when not used
/// BWRBIT=false: chromatic does override white, both bits cleared for black, white bit set for white, red bit set for black
pub struct Display<
const WIDTH: u32,
Expand Down Expand Up @@ -482,7 +482,7 @@ mod tests {
std::println!("{:?}", bw_buffer);
std::println!("{:?}", chromatic_buffer);

assert_eq!(bw_buffer, [128, 0]);
assert_eq!(chromatic_buffer, [64, 0]);
assert_eq!(bw_buffer, [192, 0]);
assert_eq!(chromatic_buffer, [160, 0]);
}
}
Loading