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

Fix size and orientation issues #9

Merged
merged 3 commits into from
Apr 4, 2022

Conversation

brianmay
Copy link
Contributor

Fixes #7
Fixes #8

src/lib.rs Outdated
@@ -64,8 +64,6 @@ where
pub enum Orientation {
Portrait = 0b0000_0000, // no inverting
Landscape = 0b0110_0000, // invert column and page/column order
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also be setting this to just 0b0010_0000 as the 2nd bit can be inverted if required.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it wouldn't be more straightforward to have a flat enum for all the possible combinations rather than the "invert x/y".

Copy link
Contributor Author

@brianmay brianmay Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is going to be a lot of combinations. Basically there are 3 bits, so 222 = 8 combinations. Think it might be more confusing, not less confusing.

Although personally, wondering if it would be better just to have:

pub enum Orientation {
    Portrait,
    Landscape,
}

And have the set_orientation function map that to the correct value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also worth noting, yes, we really do need to support all of 8 combinations. Depending on how the display is mounted and if the hardware reverses the image or not.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm the main issue I have with this is that splitting the orientation enum and the "revert" values seem confusing. We could do something like

pub enum Orientation {
    Portrait(bool, bool), // x/y invert
    Landscape(bool, bool), // x/y invert
}

Or possibly introduce a new sub-enum for "inversion" and use that as the inner value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. Not sure I can see how this could be less confusing. Also most of the code only needs to know if it is Portrait/Landscape. If the display is inverted or not makes no difference. i.e. the invert parameters are only really needed to configure the MADCTL register and don't matter afterward. In fact the invert parameters have no real meaning outside the MADCTL because there is no real way to know what the hardware is doing with them. Maybe setting invert_x will invert the display, or maybe setting invert_x will restore the display.

Maybe that is the problem though. We use the set_orientation to set parameters that are not orientation. You wouldn't set the RGB/BGR value here. But the problem being it is interconnected. When setting orientation you typically will (always) have to adjust the invert values at the same time. Which is why we do it in the set_orientation call.

@almindor
Copy link
Owner

Sorry about the delay, I need to get my setup in working order again after losing an mcu to a short. I should be able to test these in a week or so.

@brianmay brianmay force-pushed the fix_orientation_size branch from db1dea2 to 0a08c13 Compare March 31, 2022 21:41
@brianmay
Copy link
Contributor Author

Updated to remove merge conflicts. Change to clear no longer as invasive. Will update again once #14 is merged.

@brianmay
Copy link
Contributor Author

brianmay commented Apr 1, 2022

Rebased to latest master.

@brianmay brianmay force-pushed the fix_orientation_size branch from b6e2e0b to 76cb310 Compare April 1, 2022 05:43
src/lib.rs Outdated
@@ -64,8 +64,6 @@ where
pub enum Orientation {
Portrait = 0b0000_0000, // no inverting
Landscape = 0b0110_0000, // invert column and page/column order
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it wouldn't be more straightforward to have a flat enum for all the possible combinations rather than the "invert x/y".

@@ -67,10 +67,10 @@ where
}

fn fill_solid(&mut self, area: &Rectangle, color: Self::Color) -> Result<(), Self::Error> {
let fb_size = self.model.framebuffer_size();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still conflicted about this. Framebuffer_size is supposed to be "the whole pixel memory" which in case of clear is what we want AFAICS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear doesn't use fill_solid. At least not with this version. So nothing here is going to affect the clear function.

However I do have an alternative approach. Will add another commit, see if you like that any better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a framebuffer_size function and use that now, hopefully this will address your concern here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having said that, there is still the problem that both "whole pixel memory" and "displayable area" both need to start at 0,0. I don't think the concept is very usable as is.

@brianmay brianmay force-pushed the fix_orientation_size branch from 76cb310 to 7d21bbf Compare April 1, 2022 22:52
@brianmay brianmay force-pushed the fix_orientation_size branch from 7d21bbf to c7c0ee3 Compare April 1, 2022 23:09
@@ -242,6 +251,19 @@ where
.map_err(|_| Error::DisplayError)
}

fn framebuffer_size(&self) -> (u16, u16)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about making this return a Size object. That would clarify which one is width vs height. But Size objects use u32 dimensions. And pixel_count in graphics.rs uses usize dimensions. And usize::from works fine for u16, but fails for u32. So I stuck with the above for now.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u32 as usize should be safe in 32bit+ machines of course there are very special edge cases (there's a whole thing with ptrsize vs usize in rust). for our purposes and expected display sizes I think it's 100% safe to just case that way.

@almindor
Copy link
Owner

almindor commented Apr 4, 2022

@brianmay what is instead of having "two world" (model vs display/lib) we unify the framebuffer_size in the model by either enforcing the orientation knowledge in the model, or by making it into fn frabebuffer_size(&self, orientation: Orientation) (provided Orientation has all the required info as I'd like).

This way we can keep a single source of size info. Same can be done for display_size then.

@brianmay
Copy link
Contributor Author

brianmay commented Apr 4, 2022

@brianmay what is instead of having "two world" (model vs display/lib) we unify the framebuffer_size in the model by either enforcing the orientation knowledge in the model, or by making it into fn frabebuffer_size(&self, orientation: Orientation) (provided Orientation has all the required info as I'd like).

This way we can keep a single source of size info. Same can be done for display_size then.

I would be happy with both of these approaches. At present the model has no state information, the display is the authoritative source for all information. We probably should keep this unless we have a good reason to change it (e.g. if RGB/BGR config requires it). If so, then the later option would suffice. Also note that we only need to know the Portrait/Landscape stuff, we don't need to know bout the invert stuff here.

Copy link
Owner

@almindor almindor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to merge this and then follow up with a PR to clarify with the orientation being pushed into Model::*_size() functions instead.

@almindor almindor merged commit da7d7f8 into almindor:master Apr 4, 2022
@brianmay brianmay deleted the fix_orientation_size branch April 4, 2022 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

screen size hardcoded and does not change with orientation screen orientations are hardcoded
2 participants