Split Ili9341 constructor in two

This commit is contained in:
Vadim Kaushan 2020-01-28 20:02:35 +03:00
parent 5b03a86bb0
commit d9ab0601b7
No known key found for this signature in database
GPG key ID: A501C5DF67C05C4E

View file

@ -66,21 +66,21 @@ pub enum Orientation {
/// - As soon as a pixel is received, an internal counter is incremented, /// - As soon as a pixel is received, an internal counter is incremented,
/// and the next word will fill the next pixel (the adjacent on the right, or /// and the next word will fill the next pixel (the adjacent on the right, or
/// the first of the next row if the row ended) /// the first of the next row if the row ended)
pub struct Ili9341<SPI, CS, DC, RESET> { pub struct Ili9341<IFACE, RESET> {
interface: SpiInterface<SPI, CS, DC>, interface: IFACE,
reset: RESET, reset: RESET,
width: usize, width: usize,
height: usize, height: usize,
} }
impl<SpiE, PinE, SPI, CS, DC, RESET> Ili9341<SPI, CS, DC, RESET> impl<SpiE, PinE, SPI, CS, DC, RESET> Ili9341<SpiInterface<SPI, CS, DC>, RESET>
where where
SPI: Transfer<u8, Error = SpiE> + Write<u8, Error = SpiE>, SPI: Transfer<u8, Error = SpiE> + Write<u8, Error = SpiE>,
CS: OutputPin<Error = PinE>, CS: OutputPin<Error = PinE>,
DC: OutputPin<Error = PinE>, DC: OutputPin<Error = PinE>,
RESET: OutputPin<Error = PinE>, RESET: OutputPin<Error = PinE>,
{ {
pub fn new<DELAY: DelayMs<u16>>( pub fn new_spi<DELAY: DelayMs<u16>>(
spi: SPI, spi: SPI,
cs: CS, cs: CS,
dc: DC, dc: DC,
@ -88,6 +88,20 @@ where
delay: &mut DELAY, delay: &mut DELAY,
) -> Result<Self, Error<SpiE, PinE>> { ) -> Result<Self, Error<SpiE, PinE>> {
let interface = SpiInterface::new(spi, cs, dc); let interface = SpiInterface::new(spi, cs, dc);
Self::new(interface, reset, delay)
}
}
impl<SpiE, PinE, IFACE, RESET> Ili9341<IFACE, RESET>
where
IFACE: Interface<Error=Error<SpiE, PinE>>,
RESET: OutputPin<Error = PinE>,
{
pub fn new<DELAY: DelayMs<u16>>(
interface: IFACE,
reset: RESET,
delay: &mut DELAY,
) -> Result<Self, Error<SpiE, PinE>> {
let mut ili9341 = Ili9341 { let mut ili9341 = Ili9341 {
interface, interface,
reset, reset,
@ -266,11 +280,9 @@ use embedded_graphics::drawable;
use embedded_graphics::{drawable::Pixel, pixelcolor::Rgb565, Drawing}; use embedded_graphics::{drawable::Pixel, pixelcolor::Rgb565, Drawing};
#[cfg(feature = "graphics")] #[cfg(feature = "graphics")]
impl<SpiE, PinE, SPI, CS, DC, RESET> Drawing<Rgb565> for Ili9341<SPI, CS, DC, RESET> impl<SpiE, PinE, IFACE, RESET> Drawing<Rgb565> for Ili9341<IFACE, RESET>
where where
SPI: Transfer<u8, Error = SpiE> + Write<u8, Error = SpiE>, IFACE: Interface<Error=Error<SpiE, PinE>>,
CS: OutputPin<Error = PinE>,
DC: OutputPin<Error = PinE>,
RESET: OutputPin<Error = PinE>, RESET: OutputPin<Error = PinE>,
SpiE: Debug, SpiE: Debug,
PinE: Debug, PinE: Debug,