use display_interface::{DisplayError, WriteOnlyDataCommand};
use embedded_hal::{delay::DelayNs, digital::OutputPin};
use crate::{
command::{Command, SendSt7565Command},
types::StaticIndicatorMode,
DisplaySpecs, Error,
};
use super::ST7565;
impl<DI, SPECS, MODE, const WIDTH: usize, const HEIGHT: usize, const PAGES: usize>
ST7565<DI, SPECS, MODE, WIDTH, HEIGHT, PAGES>
where
DI: WriteOnlyDataCommand,
SPECS: DisplaySpecs<WIDTH, HEIGHT, PAGES>,
{
pub fn set_static_indicator(
&mut self,
mode: Option<StaticIndicatorMode>,
) -> Result<(), DisplayError> {
self.interface
.send_command(Command::StaticIndicatorSet { mode })
}
pub fn set_line_offset(&mut self, offset: u8) -> Result<(), DisplayError> {
self.interface
.send_command(Command::DisplayStartLineSet { address: offset })
}
pub fn set_inverted(&mut self, inverted: bool) -> Result<(), DisplayError> {
self.interface
.send_command(Command::DisplayNormalReverse { reverse: inverted })
}
pub fn display_all_points(&mut self, enable: bool) -> Result<(), DisplayError> {
self.interface
.send_command(Command::DisplayAllPoints { on: enable })
}
pub fn set_display_on(&mut self, on: bool) -> Result<(), DisplayError> {
self.interface.send_command(Command::DisplayOnOff { on })
}
pub fn reset<RST, DELAY, PinE>(
&mut self,
rst: &mut RST,
delay: &mut DELAY,
) -> Result<(), Error<PinE>>
where
RST: OutputPin<Error = PinE>,
DELAY: DelayNs,
{
rst.set_low().map_err(Error::Pin)?;
delay.delay_ms(1);
rst.set_high().map_err(Error::Pin)?;
delay.delay_ms(1);
self.interface
.send_command(Command::LcdBiasSet {
bias_mode_1: SPECS::BIAS_MODE_1,
})
.map_err(Error::Comm)?;
self.interface
.send_command(Command::AdcSelect {
reverse: SPECS::FLIP_COLUMNS,
})
.map_err(Error::Comm)?;
self.interface
.send_command(Command::CommonOutputModeSelect {
reverse: SPECS::FLIP_ROWS,
})
.map_err(Error::Comm)?;
self.interface
.send_command(Command::DisplayNormalReverse {
reverse: SPECS::INVERTED,
})
.map_err(Error::Comm)?;
self.interface
.send_command(Command::BoosterRatioSet {
stepup_value: SPECS::BOOSTER_RATIO,
})
.map_err(Error::Comm)?;
self.interface
.send_command(Command::VoltageRegulatorInternalResistorSet {
resistor_ratio: SPECS::VOLTAGE_REGULATOR_RESISTOR_RATIO,
})
.map_err(Error::Comm)?;
self.interface
.send_command(Command::ElectronicVolumeSet {
volume_value: SPECS::ELECTRONIC_VOLUME,
})
.map_err(Error::Comm)?;
self.interface
.send_command(Command::PowerControlSet {
mode: SPECS::POWER_CONTROL,
})
.map_err(Error::Comm)?;
self.interface
.send_command(Command::DisplayStartLineSet { address: 0 })
.map_err(Error::Comm)?;
Ok(())
}
}