use super::display::Display;
use super::mode::displaymode::DisplayMode;
use super::mode::raw::RawMode;
use super::properties::DisplayRotation;
use super::properties::DisplaySize;
use display_interface::WriteOnlyDataCommand;
#[derive(Clone)]
pub struct Builder {
display_size: DisplaySize,
rotation: DisplayRotation,
}
impl Default for Builder {
fn default() -> Self {
Self::new()
}
}
impl Builder {
pub fn new() -> Self {
Self {
display_size: DisplaySize::Display128x128,
rotation: DisplayRotation::Rotate0,
}
}
pub fn with_size(&self, display_size: DisplaySize) -> Self {
Self {
display_size,
..*self
}
}
pub fn with_rotation(&self, rotation: DisplayRotation) -> Self {
Self { rotation, ..*self }
}
#[cfg(feature = "buffered")]
pub fn connect_interface<DI>(
&self,
display_interface: DI,
buffer: &'static mut [u8],
) -> DisplayMode<RawMode<DI>>
where
DI: WriteOnlyDataCommand,
{
assert_eq!(buffer.len(), 128 * 128 * 2);
let properties = Display::new(display_interface, self.display_size, self.rotation);
DisplayMode::<RawMode<DI>>::new(properties, buffer)
}
#[cfg(not(feature = "buffered"))]
pub fn connect_interface<DI>(&self, display_interface: DI) -> DisplayMode<RawMode<DI>>
where
DI: WriteOnlyDataCommand,
{
let properties = Display::new(display_interface, self.display_size, self.rotation);
DisplayMode::<RawMode<DI>>::new(properties)
}
}