mirror of
https://github.com/yuri91/ili9341-rs.git
synced 2024-11-25 08:00:59 +00:00
rustfmt
This commit is contained in:
parent
e7ab490e53
commit
5a15e029a3
1 changed files with 55 additions and 23 deletions
54
src/lib.rs
54
src/lib.rs
|
@ -67,7 +67,13 @@ where
|
||||||
DC: OutputPin,
|
DC: OutputPin,
|
||||||
RESET: OutputPin,
|
RESET: OutputPin,
|
||||||
{
|
{
|
||||||
pub fn new<DELAY: DelayMs<u16>>(spi: SPI, cs: CS, dc: DC, reset: RESET, delay: &mut DELAY) -> Result<Self, Error<E>> {
|
pub fn new<DELAY: DelayMs<u16>>(
|
||||||
|
spi: SPI,
|
||||||
|
cs: CS,
|
||||||
|
dc: DC,
|
||||||
|
reset: RESET,
|
||||||
|
delay: &mut DELAY,
|
||||||
|
) -> Result<Self, Error<E>> {
|
||||||
let mut ili9341 = Ili9341 {
|
let mut ili9341 = Ili9341 {
|
||||||
spi,
|
spi,
|
||||||
cs,
|
cs,
|
||||||
|
@ -145,11 +151,15 @@ where
|
||||||
self.cs.set_low();
|
self.cs.set_low();
|
||||||
|
|
||||||
self.dc.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.dc.set_high();
|
||||||
for d in data.into_iter() {
|
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();
|
self.cs.set_high();
|
||||||
|
@ -159,7 +169,9 @@ where
|
||||||
self.cs.set_low();
|
self.cs.set_low();
|
||||||
|
|
||||||
self.dc.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.dc.set_high();
|
||||||
self.spi.write(data).map_err(Error::Spi)?;
|
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 iterator is useful to avoid wasting memory by holding a buffer for
|
||||||
/// the whole screen when it is not necessary.
|
/// the whole screen when it is not necessary.
|
||||||
pub fn draw_iter<I: IntoIterator<Item=u16>>(&mut self, x0: u16, y0: u16, x1: u16, y1: u16, data: I) -> Result<(), Error<E>> {
|
pub fn draw_iter<I: IntoIterator<Item = u16>>(
|
||||||
|
&mut self,
|
||||||
|
x0: u16,
|
||||||
|
y0: u16,
|
||||||
|
x1: u16,
|
||||||
|
y1: u16,
|
||||||
|
data: I,
|
||||||
|
) -> Result<(), Error<E>> {
|
||||||
self.set_window(x0, y0, x1, y1)?;
|
self.set_window(x0, y0, x1, y1)?;
|
||||||
self.write_iter(data)
|
self.write_iter(data)
|
||||||
}
|
}
|
||||||
|
@ -211,7 +230,14 @@ where
|
||||||
///
|
///
|
||||||
/// The expected format is rgb565, and the two bytes for a pixel
|
/// The expected format is rgb565, and the two bytes for a pixel
|
||||||
/// are in big endian order.
|
/// are in big endian order.
|
||||||
pub fn draw_raw(&mut self, x0: u16, y0: u16, x1: u16, y1: u16, data: &[u8]) -> Result<(), Error<E>> {
|
pub fn draw_raw(
|
||||||
|
&mut self,
|
||||||
|
x0: u16,
|
||||||
|
y0: u16,
|
||||||
|
x1: u16,
|
||||||
|
y1: u16,
|
||||||
|
data: &[u8],
|
||||||
|
) -> Result<(), Error<E>> {
|
||||||
self.set_window(x0, y0, x1, y1)?;
|
self.set_window(x0, y0, x1, y1)?;
|
||||||
self.write_raw(data)
|
self.write_raw(data)
|
||||||
}
|
}
|
||||||
|
@ -222,22 +248,22 @@ where
|
||||||
self.width = WIDTH;
|
self.width = WIDTH;
|
||||||
self.height = HEIGHT;
|
self.height = HEIGHT;
|
||||||
self.command(Command::MemoryAccessControl, &[0x40 | 0x08])
|
self.command(Command::MemoryAccessControl, &[0x40 | 0x08])
|
||||||
},
|
}
|
||||||
Orientation::Landscape => {
|
Orientation::Landscape => {
|
||||||
self.width = HEIGHT;
|
self.width = HEIGHT;
|
||||||
self.height = WIDTH;
|
self.height = WIDTH;
|
||||||
self.command(Command::MemoryAccessControl, &[0x20 | 0x08])
|
self.command(Command::MemoryAccessControl, &[0x20 | 0x08])
|
||||||
},
|
}
|
||||||
Orientation::PortraitFlipped => {
|
Orientation::PortraitFlipped => {
|
||||||
self.width = WIDTH;
|
self.width = WIDTH;
|
||||||
self.height = HEIGHT;
|
self.height = HEIGHT;
|
||||||
self.command(Command::MemoryAccessControl, &[0x80 | 0x08])
|
self.command(Command::MemoryAccessControl, &[0x80 | 0x08])
|
||||||
},
|
}
|
||||||
Orientation::LandscapeFlipped => {
|
Orientation::LandscapeFlipped => {
|
||||||
self.width = HEIGHT;
|
self.width = HEIGHT;
|
||||||
self.height = WIDTH;
|
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
|
/// Get the current screen width. It can change based on the current orientation
|
||||||
|
@ -269,7 +295,13 @@ where
|
||||||
T: Iterator<Item = drawable::Pixel>,
|
T: Iterator<Item = drawable::Pixel>,
|
||||||
{
|
{
|
||||||
for (pos, color) in item_pixels {
|
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");
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue