use core::marker::PhantomData;
use hal::{
self,
digital::{ErrorType, OutputPin},
};
use crate::{
displayrotation::DisplayRotation,
displaysize::DisplaySize,
mode::{displaymode::DisplayMode, raw::RawMode},
properties::DisplayProperties,
};
#[derive(Clone, Copy)]
pub struct Builder {
display_size: DisplaySize,
rotation: DisplayRotation,
}
impl Default for Builder {
fn default() -> Self {
Self::new()
}
}
impl Builder {
pub fn new() -> Builder {
Builder {
display_size: DisplaySize::Display128x160,
rotation: DisplayRotation::Rotate0,
}
}
}
impl Builder {
pub fn with_size(self, display_size: DisplaySize) -> Self {
Self {
display_size,
..self
}
}
pub fn with_rotation(self, rotation: DisplayRotation) -> Self {
Self { rotation, ..self }
}
pub fn connect<DI>(self, interface: DI) -> DisplayMode<RawMode<DI>>
where
DI: display_interface::WriteOnlyDataCommand,
{
let properties = DisplayProperties::new(interface, self.display_size, self.rotation);
DisplayMode::<RawMode<DI>>::new(properties)
}
}
#[derive(Clone, Copy)]
pub struct NoOutputPin<PinE = ()> {
_m: PhantomData<PinE>,
}
impl<PinE> NoOutputPin<PinE> {
pub fn new() -> Self {
Self { _m: PhantomData }
}
}
impl<PinE: hal::digital::Error> ErrorType for NoOutputPin<PinE> {
type Error = PinE;
}
impl<PinE: hal::digital::Error> OutputPin for NoOutputPin<PinE> {
fn set_low(&mut self) -> Result<(), PinE> {
Ok(())
}
fn set_high(&mut self) -> Result<(), PinE> {
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::NoOutputPin;
use embedded_hal::digital::OutputPin;
#[derive(Debug)]
enum SomeError {}
impl hal::digital::Error for SomeError {
fn kind(&self) -> embedded_hal::digital::ErrorKind {
embedded_hal::digital::ErrorKind::Other
}
}
struct SomeDriver<P: OutputPin<Error = SomeError>> {
#[allow(dead_code)]
p: P,
}
#[test]
fn test_output_pin() {
let p = NoOutputPin::new();
let _d = SomeDriver { p };
assert!(true);
}
}