Skip to content

Commit

Permalink
Fix size and orientation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmay committed Apr 1, 2022
1 parent 0af9ad0 commit 22f7702
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,16 @@ where
}

fn clear(&mut self, color: Self::Color) -> Result<(), Self::Error>
where
Self: Sized,
{
let fb_size = self.model.framebuffer_size();
let pixel_count = usize::from(fb_size.0) * usize::from(fb_size.1);
let colors = core::iter::repeat(color).take(pixel_count); // blank entire HW RAM contents

match self.orientation {
Orientation::Portrait | Orientation::PortraitSwapped => {
Orientation::Portrait => {
self.set_pixels(0, 0, fb_size.0, fb_size.1, colors)
}
Orientation::Landscape | Orientation::LandscapeSwapped => {
Orientation::Landscape => {
self.set_pixels(0, 0, fb_size.1, fb_size.0, colors)
}
}
Expand All @@ -121,6 +119,10 @@ where
{
fn size(&self) -> Size {
let ds = self.model.display_size();
Size::new(u32::from(ds.0), u32::from(ds.1))
let (width, height) = match self.orientation {
Orientation::Portrait => (ds.0, ds.1),
Orientation::Landscape => (ds.1, ds.0)
};
Size::new(u32::from(width), u32::from(height))
}
}
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ where
pub enum Orientation {
Portrait = 0b0000_0000, // no inverting
Landscape = 0b0110_0000, // invert column and page/column order
PortraitSwapped = 0b1100_0000, // invert page and column order
LandscapeSwapped = 0b1010_0000, // invert page and page/column order
}

impl Default for Orientation {
Expand Down Expand Up @@ -151,8 +149,10 @@ where
///
/// Sets display [Orientation]
///
pub fn set_orientation(&mut self, orientation: Orientation) -> Result<(), Error<RST::Error>> {
let value = self.madctl | ((orientation as u8) & 0b1110_0000);
pub fn set_orientation(&mut self, orientation: Orientation, invert_x: bool, invert_y: bool) -> Result<(), Error<RST::Error>> {
let mut value = self.madctl | ((orientation as u8) & 0b1110_0000);
if invert_x { value = value ^ 0x40 };
if invert_y { value = value ^ 0x80 };
self.write_command(Instruction::MADCTL)?;
self.write_data(&[value])?;
self.orientation = orientation;
Expand Down

0 comments on commit 22f7702

Please sign in to comment.