-
Notifications
You must be signed in to change notification settings - Fork 60
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
Conversation
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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. |
db1dea2
to
0a08c13
Compare
Updated to remove merge conflicts. Change to |
0a08c13
to
b6e2e0b
Compare
Rebased to latest master. |
b6e2e0b
to
76cb310
Compare
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 |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
76cb310
to
7d21bbf
Compare
7d21bbf
to
c7c0ee3
Compare
@@ -242,6 +251,19 @@ where | |||
.map_err(|_| Error::DisplayError) | |||
} | |||
|
|||
fn framebuffer_size(&self) -> (u16, u16) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@brianmay what is instead of having "two world" (model vs display/lib) we unify the This way we can keep a single source of size info. Same can be done for |
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. |
There was a problem hiding this 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.
Fixes #7
Fixes #8