Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

screen orientations are hardcoded #7

Closed
brianmay opened this issue Mar 17, 2022 · 4 comments · Fixed by #9 or #14
Closed

screen orientations are hardcoded #7

brianmay opened this issue Mar 17, 2022 · 4 comments · Fixed by #9 or #14

Comments

@brianmay
Copy link
Contributor

brianmay commented Mar 17, 2022

Some screens require different madctl 0x26 settings, and e.g. will appear reversed without.

For a possible solution see: yuri91/ili9341-rs@8a4aee9

Although I tend to wonder if maybe this solution is overkill. All that is required I think is for the set_orientation function to take a parameter for the required madctl parameter, and an orientation parameter so it can work out the size (see #8).

@brianmay
Copy link
Contributor Author

This would be my recommended fix:

--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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
@@ -64,8 +64,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 {
@@ -147,9 +145,12 @@ where
     ///
     /// Sets display [Orientation]
     ///
-    pub fn set_orientation(&mut self, orientation: Orientation) -> Result<(), Error<RST::Error>> {
+    pub fn set_orientation(&mut self, orientation: Orientation, invertx: bool, inverty: bool) -> Result<(), Error<RST::Error>> {
         self.write_command(Instruction::MADCTL)?;
-        self.write_data(&[orientation as u8])?;
+        let mut data = orientation as u8;
+        if invertx { data = data ^ 0x40 };
+        if inverty { data = data ^ 0x80 };
+        self.write_data(&[data])?;
         self.orientation = orientation;
         Ok(())
     }

If this is acceptable I can do a PR.

@almindor
Copy link
Owner

Could we close this one in favor of #8 please? (or the other way around)

@brianmay
Copy link
Contributor Author

Doesn't bother me if we do. I considered them distinct issues when I opened the reports, but there was considerable overlap so I used one PR to solve both of them.

brianmay added a commit to brianmay/mipidsi that referenced this issue Mar 31, 2022
@brianmay
Copy link
Contributor Author

I think this was accidentally closed :-)

brianmay added a commit to brianmay/mipidsi that referenced this issue Apr 1, 2022
brianmay added a commit to brianmay/mipidsi that referenced this issue Apr 1, 2022
brianmay added a commit to brianmay/mipidsi that referenced this issue Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants