From be44c24eeab1bdb89c596ffda5f4cf126c3f4794 Mon Sep 17 00:00:00 2001 From: Grant Miller Date: Mon, 10 May 2021 17:15:59 -0500 Subject: [PATCH] Use Result alias --- src/lib.rs | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 95fefa6..16a0373 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,8 @@ pub use embedded_hal::spi::MODE_0 as SPI_MODE; pub use display_interface::DisplayError; +type Result = core::result::Result; + /// Trait that defines display size information pub trait DisplaySize { /// Width in pixels @@ -81,7 +83,7 @@ where delay: &mut DELAY, mode: Orientation, _display_size: SIZE, - ) -> Result + ) -> Result where DELAY: DelayMs, SIZE: DisplaySize, @@ -129,17 +131,17 @@ where Ok(ili9341) } - fn command(&mut self, cmd: Command, args: &[u8]) -> Result<(), DisplayError> { + fn command(&mut self, cmd: Command, args: &[u8]) -> Result { self.interface.send_commands(U8Iter(&mut once(cmd as u8)))?; self.interface.send_data(U8Iter(&mut args.iter().cloned())) } - fn write_iter>(&mut self, data: I) -> Result<(), DisplayError> { + fn write_iter>(&mut self, data: I) -> Result { self.command(Command::MemoryWrite, &[])?; self.interface.send_data(U16BEIter(&mut data.into_iter())) } - fn set_window(&mut self, x0: u16, y0: u16, x1: u16, y1: u16) -> Result<(), DisplayError> { + fn set_window(&mut self, x0: u16, y0: u16, x1: u16, y1: u16) -> Result { self.command( Command::ColumnAddressSet, &[ @@ -165,7 +167,7 @@ where &mut self, fixed_top_lines: u16, fixed_bottom_lines: u16, - ) -> Result { + ) -> Result { let height = match self.mode { Orientation::Landscape | Orientation::LandscapeFlipped => self.width, Orientation::Portrait | Orientation::PortraitFlipped => self.height, @@ -187,11 +189,7 @@ where Ok(Scroller::new(fixed_top_lines, fixed_bottom_lines, height)) } - pub fn scroll_vertically( - &mut self, - scroller: &mut Scroller, - num_lines: u16, - ) -> Result<(), DisplayError> { + pub fn scroll_vertically(&mut self, scroller: &mut Scroller, num_lines: u16) -> Result { scroller.top_offset += num_lines; if scroller.top_offset > (scroller.height - scroller.fixed_bottom_lines) { scroller.top_offset = scroller.fixed_top_lines @@ -223,7 +221,7 @@ where x1: u16, y1: u16, data: I, - ) -> Result<(), DisplayError> { + ) -> Result { self.set_window(x0, y0, x1, y1)?; self.write_iter(data) } @@ -237,20 +235,13 @@ where /// video memory. /// /// The expected format is rgb565. - pub fn draw_raw( - &mut self, - x0: u16, - y0: u16, - x1: u16, - y1: u16, - data: &[u16], - ) -> Result<(), DisplayError> { + pub fn draw_raw(&mut self, x0: u16, y0: u16, x1: u16, y1: u16, data: &[u16]) -> Result { self.set_window(x0, y0, x1, y1)?; self.write_iter(data.iter().cloned()) } /// Change the orientation of the screen - pub fn set_orientation(&mut self, mode: Orientation) -> Result<(), DisplayError> { + pub fn set_orientation(&mut self, mode: Orientation) -> Result { let was_landscape = match self.mode { Orientation::Landscape | Orientation::LandscapeFlipped => true, Orientation::Portrait | Orientation::PortraitFlipped => false,