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" ) ]
78use 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
9192impl 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 {
123131impl 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 } )
0 commit comments