xl9555-hal 0.3.0

embedded-hal driver for the XL9555 GPIO expander
Documentation
#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum PinId {
    P0 = 0,
    P1,
    P2,
    P3,
    P4,
    P5,
    P6,
    P7,
    P8,
    P9,
    P10,
    P11,
    P12,
    P13,
    P14,
    P15,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum Port {
    Port0,
    Port1,
}

pub enum Direction {
    Output,
    Input,
}

#[derive(Clone, Copy, PartialEq, Debug)]
#[repr(u8)]
pub enum WaitMode {
    None = 0,
    Falling = 1,
    Rising = 2,
    Low = 3,
    High = 4,
    AnyEdge = 5,
}

impl From<u8> for PinId {
    fn from(value: u8) -> Self {
        match value {
            0 => PinId::P0,
            1 => PinId::P1,
            2 => PinId::P2,
            3 => PinId::P3,
            4 => PinId::P4,
            5 => PinId::P5,
            6 => PinId::P6,
            7 => PinId::P7,
            8 => PinId::P8,
            9 => PinId::P9,
            10 => PinId::P10,
            11 => PinId::P11,
            12 => PinId::P12,
            13 => PinId::P13,
            14 => PinId::P14,
            15 => PinId::P15,
            _ => panic!("Invalid PinId value: {}. Must be between 0 and 15.", value),
        }
    }
}

impl PinId {
    pub(crate) fn port(self) -> Port {
        if (self as u8) < 8 {
            Port::Port0
        } else {
            Port::Port1
        }
    }

    pub(crate) fn bit(self) -> u8 {
        (self as u8) & 0x07
    }

    pub(crate) fn mask(self) -> u8 {
        1 << self.bit()
    }
}