From 842fad768267e4b62237289e96ba8110edb6b874 Mon Sep 17 00:00:00 2001 From: Yuri Iozzelli Date: Sun, 4 Mar 2018 15:43:28 +0100 Subject: [PATCH] Use enum for orientation --- src/lib.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2b4f1ff..b86f49d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,6 +23,13 @@ pub enum Error { Spi(E), } +pub enum Orientation { + Portrait, + PortraitFlipped, + Landscape, + LandscapeFlipped, +} + pub struct Ili9341 { spi: SPI, cs: CS, @@ -168,31 +175,28 @@ where self.set_window(x0, y0, x1, y1)?; self.write_raw(data) } - pub fn set_rotation(&mut self, mode: u8) -> Result<(), Error> { - match mode%4 { - 0 => { + pub fn set_orientation(&mut self, mode: Orientation) -> Result<(), Error> { + match mode { + Orientation::Portrait => { self.width = 240; self.height = 320; self.command(Command::MemoryAccessControl, &[0x40|0x08]) }, - 1 => { + Orientation::Landscape => { self.width = 320; self.height = 240; self.command(Command::MemoryAccessControl, &[0x20|0x08]) }, - 2 => { + Orientation::PortraitFlipped => { self.width = 240; self.height = 320; self.command(Command::MemoryAccessControl, &[0x80|0x08]) }, - 3 => { + Orientation::LandscapeFlipped => { self.width = 320; self.height = 240; self.command(Command::MemoryAccessControl, &[0x40|0x80|0x20|0x08]) - } - _ => { - unreachable!(); - } + }, } } pub fn width(&self) -> usize {