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 98e64a6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 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))
}
}
23 changes: 16 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! This crate provides a generic ddisplay driver to connect to TFT displays
//! that implement the [MIPI DSI](https://www.mipi.org/specifications/dsi).
//! Currently only supports SPI with DC pin setups via the [display_interface]
//!
//!
//! An optional batching of draws is supported via the `batch` feature (default on)
//!
//! ## Example
Expand Down Expand Up @@ -64,10 +64,8 @@ where
#[repr(u8)]
#[derive(Copy, Clone)]
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
Portrait = 0b0000_0000, // no inverting
Landscape = 0b0110_0000, // invert column and page/column order
}

impl Default for Orientation {
Expand Down Expand Up @@ -151,8 +149,19 @@ 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 ^= 0x40
};
if invert_y {
value ^= 0x80
};
self.write_command(Instruction::MADCTL)?;
self.write_data(&[value])?;
self.orientation = orientation;
Expand Down

0 comments on commit 98e64a6

Please sign in to comment.