From 5a15e029a3929a550f0837dc37172e0d7898b12b Mon Sep 17 00:00:00 2001 From: Yuri Iozzelli Date: Tue, 19 Jun 2018 23:30:04 +0200 Subject: [PATCH] rustfmt --- src/lib.rs | 78 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 23 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e178cbc..abb89da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,9 +65,15 @@ where SPI: spi::Transfer + spi::Write, CS: OutputPin, DC: OutputPin, - RESET: OutputPin, + RESET: OutputPin, { - pub fn new>(spi: SPI, cs: CS, dc: DC, reset: RESET, delay: &mut DELAY) -> Result> { + pub fn new>( + spi: SPI, + cs: CS, + dc: DC, + reset: RESET, + delay: &mut DELAY, + ) -> Result> { let mut ili9341 = Ili9341 { spi, cs, @@ -141,15 +147,19 @@ where self.cs.set_high(); Ok(()) } - fn write_iter>(&mut self, data: I) -> Result<(), Error> { + fn write_iter>(&mut self, data: I) -> Result<(), Error> { self.cs.set_low(); self.dc.set_low(); - self.spi.write(&[Command::MemoryWrite as u8]).map_err(Error::Spi)?; + self.spi + .write(&[Command::MemoryWrite as u8]) + .map_err(Error::Spi)?; self.dc.set_high(); for d in data.into_iter() { - self.spi.write(&[(d>>8) as u8, (d&0xff) as u8]).map_err(Error::Spi)?; + self.spi + .write(&[(d >> 8) as u8, (d & 0xff) as u8]) + .map_err(Error::Spi)?; } self.cs.set_high(); @@ -159,7 +169,9 @@ where self.cs.set_low(); self.dc.set_low(); - self.spi.write(&[Command::MemoryWrite as u8]).map_err(Error::Spi)?; + self.spi + .write(&[Command::MemoryWrite as u8]) + .map_err(Error::Spi)?; self.dc.set_high(); self.spi.write(data).map_err(Error::Spi)?; @@ -197,7 +209,14 @@ where /// /// The iterator is useful to avoid wasting memory by holding a buffer for /// the whole screen when it is not necessary. - pub fn draw_iter>(&mut self, x0: u16, y0: u16, x1: u16, y1: u16, data: I) -> Result<(), Error> { + pub fn draw_iter>( + &mut self, + x0: u16, + y0: u16, + x1: u16, + y1: u16, + data: I, + ) -> Result<(), Error> { self.set_window(x0, y0, x1, y1)?; self.write_iter(data) } @@ -211,7 +230,14 @@ where /// /// The expected format is rgb565, and the two bytes for a pixel /// are in big endian order. - pub fn draw_raw(&mut self, x0: u16, y0: u16, x1: u16, y1: u16, data: &[u8]) -> Result<(), Error> { + pub fn draw_raw( + &mut self, + x0: u16, + y0: u16, + x1: u16, + y1: u16, + data: &[u8], + ) -> Result<(), Error> { self.set_window(x0, y0, x1, y1)?; self.write_raw(data) } @@ -221,23 +247,23 @@ where Orientation::Portrait => { self.width = WIDTH; self.height = HEIGHT; - self.command(Command::MemoryAccessControl, &[0x40|0x08]) - }, + self.command(Command::MemoryAccessControl, &[0x40 | 0x08]) + } Orientation::Landscape => { self.width = HEIGHT; self.height = WIDTH; - self.command(Command::MemoryAccessControl, &[0x20|0x08]) - }, + self.command(Command::MemoryAccessControl, &[0x20 | 0x08]) + } Orientation::PortraitFlipped => { self.width = WIDTH; self.height = HEIGHT; - self.command(Command::MemoryAccessControl, &[0x80|0x08]) - }, + self.command(Command::MemoryAccessControl, &[0x80 | 0x08]) + } Orientation::LandscapeFlipped => { self.width = HEIGHT; self.height = WIDTH; - self.command(Command::MemoryAccessControl, &[0x40|0x80|0x20|0x08]) - }, + self.command(Command::MemoryAccessControl, &[0x40 | 0x80 | 0x20 | 0x08]) + } } } /// Get the current screen width. It can change based on the current orientation @@ -256,7 +282,7 @@ use embedded_graphics::Drawing; use embedded_graphics::drawable; #[cfg(feature = "graphics")] -impl Drawing for Ili9341 +impl Drawing for Ili9341 where SPI: spi::Transfer + spi::Write, CS: OutputPin, @@ -265,13 +291,19 @@ where E: Debug, { fn draw(&mut self, item_pixels: T) - where - T: Iterator, - { - for (pos, color) in item_pixels { - self.draw_raw(pos.0 as u16, pos.0 as u16, pos.1 as u16, pos.1 as u16, if color != 0 {&[1]} else {&[0]}).expect("Failed to communicate with device"); - } + where + T: Iterator, + { + for (pos, color) in item_pixels { + self.draw_raw( + pos.0 as u16, + pos.0 as u16, + pos.1 as u16, + pos.1 as u16, + if color != 0 { &[1] } else { &[0] }, + ).expect("Failed to communicate with device"); } + } } #[derive(Clone, Copy)]