use super::*; use atmega_hal::{clock::MHz16, delay::Delay}; use avr_hal_generic::port::{ mode::{Io, Output}, Pin, PinOps, }; impl Lcd10168 { pub fn builder() -> UnconnectedLcd10168Builder { Lcd10168Builder::new() } } pub struct Unconnected; pub struct Connected(Pin); impl Connected { pub fn new(pin: Pin) -> Self { Self(pin) } pub fn into_inner(self) -> Pin { self.0 } } pub struct Lcd10168Builder { rst: R, sce: S, dc: D, din: I, clk: C, } pub type UnconnectedLcd10168Builder = Lcd10168Builder; impl UnconnectedLcd10168Builder { pub fn new() -> Self { Self { rst: Unconnected, sce: Unconnected, dc: Unconnected, din: Unconnected, clk: Unconnected, } } } impl Lcd10168Builder { pub fn reset( self, pin: Pin, ) -> Lcd10168Builder, S, D, I, C> { Lcd10168Builder { rst: Connected::new(pin.into_output()), sce: self.sce, dc: self.dc, din: self.din, clk: self.clk, } } } impl Lcd10168Builder { pub fn chip_enable( self, pin: Pin, ) -> Lcd10168Builder, D, I, C> { Lcd10168Builder { rst: self.rst, sce: Connected::new(pin.into_output()), dc: self.dc, din: self.din, clk: self.clk, } } } impl Lcd10168Builder { pub fn data_command( self, pin: Pin, ) -> Lcd10168Builder, I, C> { Lcd10168Builder { rst: self.rst, sce: self.sce, dc: Connected::new(pin.into_output()), din: self.din, clk: self.clk, } } } impl Lcd10168Builder { pub fn data_in( self, pin: Pin, ) -> Lcd10168Builder, C> { Lcd10168Builder { rst: self.rst, sce: self.sce, dc: self.dc, din: Connected::new(pin.into_output()), clk: self.clk, } } } impl Lcd10168Builder { pub fn clock( self, pin: Pin, ) -> Lcd10168Builder> { Lcd10168Builder { rst: self.rst, sce: self.sce, dc: self.dc, din: self.din, clk: Connected::new(pin.into_output()), } } } impl Lcd10168Builder, Connected, Connected, Connected, Connected> { pub fn build(self) -> Lcd10168 { Lcd10168 { rst: self.rst.into_inner(), sce: self.sce.into_inner(), dc: self.dc.into_inner(), din: self.din.into_inner(), clk: self.clk.into_inner(), delay: Delay::::new(), } } }