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

Improve I2C Flush (Update) Speed #94

Merged
merged 8 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/interface/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ where
for _ in 0..=height {
let start_index = page_offset + upper_left.0 as usize;
let end_index = page_offset + lower_right.0 as usize;
let sub_buf = &buf[start_index..=end_index];
let sub_buf = &buf[start_index..end_index];

page_offset += disp_width;

Expand Down
48 changes: 34 additions & 14 deletions src/mode/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,31 +155,51 @@ where
return Ok(());
}

let display_size = self.properties.get_size();
let (width, height) = display_size.dimensions();
let (width, height) = self.get_dimensions();

// Determine which bytes need to be sent
let disp_min_x = self.min_x;
let disp_min_y = self.min_y;

let disp_max_x = (self.max_x + 1).min(width);
let disp_max_y = (self.max_y | 7).min(height);

// Tell the display to update only the part that has changed
self.properties
.set_draw_area((disp_min_x, disp_min_y), (disp_max_x, disp_max_y))?;
let (disp_max_x, disp_max_y) = match self.properties.get_rotation() {
DisplayRotation::Rotate0 | DisplayRotation::Rotate180 => {
((self.max_x + 1).min(width), (self.max_y | 7).min(height))
}
DisplayRotation::Rotate90 | DisplayRotation::Rotate270 => {
((self.max_x | 7).min(width), (self.max_y + 1).min(height))
}
};

self.min_x = width - 1;
self.max_x = 0;
self.min_y = width - 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be height?

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'm pretty sure it is correct as it is since the width and height take into account the display's orientation. Just for fun, I tried swapping width and height in line 169 and got a really cool (but unfortunately incorrect) vertically mirrored display.

self.max_y = 0;

self.properties.bounded_draw(
&self.buffer,
width as usize,
(disp_min_x, disp_min_y),
(disp_max_x, disp_max_y),
)
// Tell the display to update only the part that has changed
match self.properties.get_rotation() {
DisplayRotation::Rotate0 | DisplayRotation::Rotate180 => {
self.properties
.set_draw_area((disp_min_x, disp_min_y), (disp_max_x, disp_max_y))?;

self.properties.bounded_draw(
&self.buffer,
width as usize,
(disp_min_x, disp_min_y),
(disp_max_x, disp_max_y),
)
}
DisplayRotation::Rotate90 | DisplayRotation::Rotate270 => {
self.properties
.set_draw_area((disp_min_y, disp_min_x), (disp_max_y, disp_max_x))?;

self.properties.bounded_draw(
&self.buffer,
height as usize,
(disp_min_y, disp_min_x),
(disp_max_y, disp_max_x),
)
}
}
}

/// Turn a pixel on or off. A non-zero `value` is treated as on, `0` as off. If the X and Y
Expand Down