use super::command::Command;
use display_interface::{DisplayError, WriteOnlyDataCommand};
pub trait NewZeroed {
fn new_zeroed() -> Self;
}
impl<const N: usize> NewZeroed for [u8; N] {
fn new_zeroed() -> Self {
[0u8; N]
}
}
pub trait DisplaySize {
const WIDTH: u8;
const HEIGHT: u8;
const DRIVER_COLS: u8 = 128;
const DRIVER_ROWS: u8 = 64;
const OFFSETX: u8 = 0;
const OFFSETY: u8 = 0;
type Buffer: AsMut<[u8]> + NewZeroed;
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError>;
}
#[derive(Debug, Copy, Clone)]
pub struct DisplaySize128x64;
impl DisplaySize for DisplaySize128x64 {
const WIDTH: u8 = 128;
const HEIGHT: u8 = 64;
type Buffer = [u8; Self::WIDTH as usize * Self::HEIGHT as usize / 8];
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(true, false).send(iface)
}
}
#[derive(Debug, Copy, Clone)]
pub struct DisplaySize128x32;
impl DisplaySize for DisplaySize128x32 {
const WIDTH: u8 = 128;
const HEIGHT: u8 = 32;
type Buffer = [u8; Self::WIDTH as usize * Self::HEIGHT as usize / 8];
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(false, false).send(iface)
}
}
#[derive(Debug, Copy, Clone)]
pub struct DisplaySize96x16;
impl DisplaySize for DisplaySize96x16 {
const WIDTH: u8 = 96;
const HEIGHT: u8 = 16;
type Buffer = [u8; Self::WIDTH as usize * Self::HEIGHT as usize / 8];
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(false, false).send(iface)
}
}
#[derive(Debug, Copy, Clone)]
pub struct DisplaySize72x40;
impl DisplaySize for DisplaySize72x40 {
const WIDTH: u8 = 72;
const HEIGHT: u8 = 40;
const OFFSETX: u8 = 28;
const OFFSETY: u8 = 0;
type Buffer = [u8; Self::WIDTH as usize * Self::HEIGHT as usize / 8];
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(true, false).send(iface)?;
Command::InternalIref(true, true).send(iface)
}
}
#[derive(Debug, Copy, Clone)]
pub struct DisplaySize64x48;
impl DisplaySize for DisplaySize64x48 {
const WIDTH: u8 = 64;
const HEIGHT: u8 = 48;
const OFFSETX: u8 = 32;
const OFFSETY: u8 = 0;
type Buffer = [u8; Self::WIDTH as usize * Self::HEIGHT as usize / 8];
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(true, false).send(iface)
}
}
#[derive(Debug, Copy, Clone)]
pub struct DisplaySize64x32;
impl DisplaySize for DisplaySize64x32 {
const WIDTH: u8 = 64;
const HEIGHT: u8 = 32;
const OFFSETX: u8 = 32;
const OFFSETY: u8 = 0;
type Buffer = [u8; Self::WIDTH as usize * Self::HEIGHT as usize / 8];
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(true, false).send(iface)
}
}