diff --git a/src/driver.rs b/src/driver.rs index 779bfda..3f8cce9 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -227,8 +227,8 @@ where start: (u16, u16), end: (u16, u16), ) -> Result<(), DisplayError> { - Command::ColumnAddressSet(start.0, end.0.saturating_sub(1)).send(&mut self.interface)?; - Command::RowAddressSet(start.1, end.1.saturating_sub(1)).send(&mut self.interface)?; + Command::ColumnAddressSet(start.0, end.0).send(&mut self.interface)?; + Command::RowAddressSet(start.1, end.1).send(&mut self.interface)?; Ok(()) } @@ -268,15 +268,17 @@ where ) -> Result<(), DisplayError> { Command::MemoryWrite.send(interface)?; - let num_pages = (lower_right.1 - upper_left.1) as usize + 1; + // Number of rows to process (Y range) + let num_pages = (lower_right.1 - upper_left.1 + 1) as usize; - let starting_page = (upper_left.1) as usize; + // Starting row (Y coordinate) + let starting_page = upper_left.1 as usize; - // Calculate start and end X coordinates for each page + // X coordinates (columns) for the rectangle let page_lower = upper_left.0 as usize; - let page_upper = lower_right.0 as usize; + let page_upper = ((lower_right.0 + 1) as usize).min(disp_width); // +1 to include the last column - // TODO: improve this + // Process the buffer in rows (chunks of disp_width) buffer .chunks(disp_width) .skip(starting_page) diff --git a/src/mode/basic.rs b/src/mode/basic.rs index 32f65ad..6c3f1b8 100644 --- a/src/mode/basic.rs +++ b/src/mode/basic.rs @@ -35,7 +35,7 @@ where /// /// This method may return an error if there are communication issues with the display. pub fn clear(&mut self) -> Result<(), DisplayError> { - self.set_draw_area((0, 0), self.dimensions())?; + self.set_draw_area((0, 0), self.bounds())?; self.clear_fit() } } diff --git a/src/mode/graphics.rs b/src/mode/graphics.rs index a5d2cb8..5f994d1 100644 --- a/src/mode/graphics.rs +++ b/src/mode/graphics.rs @@ -106,14 +106,17 @@ where return Ok(()); } - let (width, height) = self.dimensions(); + let (bound_width, bound_height) = self.bounds(); + let (screen_width, screen_height) = self.dimensions(); // Determine witch bytes need to be sent let disp_min_x = self.mode.min_x; let disp_min_y = self.mode.min_y; - let (disp_max_x, disp_max_y) = - ((self.mode.max_x).min(width), (self.mode.max_y).min(height)); + let (disp_max_x, disp_max_y) = ( + (self.mode.max_x).min(bound_width), + (self.mode.max_y).min(bound_height), + ); // reset idle state self.mode.min_x = u16::MAX; @@ -138,7 +141,7 @@ where Self::flush_buffer_chunks( &mut self.interface, self.mode.buffer.as_mut(), - width as usize, + screen_width as usize, (disp_min_x, disp_min_y), (disp_max_x, disp_max_y), ) @@ -152,7 +155,7 @@ where Self::flush_buffer_chunks( &mut self.interface, self.mode.buffer.as_mut(), - height as usize, + screen_height as usize, (disp_min_y, disp_min_x), (disp_max_y, disp_max_x), )