hd44780-controller 0.1.0-alpha.2

HD44780 LCD controller with async/sync support for embedded-hal
Documentation
use crate::device::*;

use super::*;

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SetBacklight(pub bool);

impl SyncCommand for SetBacklight {
    type Ret = ();

    type Err = super::Error;

    fn execute<D: SyncDevice + ?Sized>(&self, dev: &mut D) -> Result<Self::Ret, Self::Err> {
        dev.set_backlight(self.0);
        dev.flush().map_err(|_| super::Error::DeviceError)?;
        dev.delay_us(50);

        Ok(())
    }
}

#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
impl AsyncCommand for SetBacklight {
    type Ret = ();

    type Err = super::Error;

    async fn execute_async<D: AsyncDevice + ?Sized>(
        &self,
        dev: &mut D,
    ) -> Result<Self::Ret, Self::Err> {
        dev.set_backlight(self.0);
        dev.flush_async()
            .await
            .map_err(|_| super::Error::DeviceError)?;
        dev.delay_us_async(50).await;

        Ok(())
    }
}