xl9555-hal 0.3.0

embedded-hal driver for the XL9555 GPIO expander
Documentation
use crate::types::Port::{self};

#[repr(u8)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[allow(dead_code)]
pub(crate) enum Reg {
    INPUT0 = 0x00,
    INPUT1 = 0x01,
    OUTPUT0 = 0x02,
    OUTPUT1 = 0x03,
    POLARITY0 = 0x04,
    POLARITY1 = 0x05,
    CONFIG0 = 0x06,
    CONFIG1 = 0x07,
}

impl Reg {
    pub(crate) const fn addr(self) -> u8 {
        self as u8
    }

    pub(crate) const fn addr_arr(self) -> [u8; 1] {
        [self as u8]
    }
}

impl Port {
    pub(crate) const fn input_reg(self) -> Reg {
        match self {
            Self::Port0 => Reg::INPUT0,
            Self::Port1 => Reg::INPUT1,
        }
    }

    pub(crate) const fn output_reg(self) -> Reg {
        match self {
            Self::Port0 => Reg::OUTPUT0,
            Self::Port1 => Reg::OUTPUT1,
        }
    }

    #[allow(dead_code)]
    pub(crate) const fn polarity_reg(self) -> Reg {
        match self {
            Self::Port0 => Reg::POLARITY0,
            Self::Port1 => Reg::POLARITY1,
        }
    }

    pub(crate) const fn config_reg(self) -> Reg {
        match self {
            Self::Port0 => Reg::CONFIG0,
            Self::Port1 => Reg::CONFIG1,
        }
    }

    pub(crate) const fn index(self) -> usize {
        self as usize
    }
}