use core::marker::PhantomData;
use hal::{self, digital::v2::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::Display128x64,
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> OutputPin for NoOutputPin<PinE> {
type Error = 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::v2::OutputPin;
enum SomeError {}
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);
}
}