hd44780_controller/device/
pcf8574.rs

1use super::i2c_expander_device::{I2cExpanderDevice, I2cPacketAssembler, State};
2
3pub type PCF8574Device<I, D> = I2cExpanderDevice<I, D, PCF8574>;
4
5pub struct PCF8574;
6
7impl I2cPacketAssembler for PCF8574 {
8    type Payload = [u8; 1];
9
10    fn assemble_i2c_packet(state: &State) -> Self::Payload {
11        let mut packet = 0u8;
12
13        // registers
14        if state.rs {
15            packet |= 1 << 0;
16        }
17        if state.rw {
18            packet |= 1 << 1;
19        }
20        if state.e {
21            packet |= 1 << 2;
22        }
23        if state.bl {
24            packet |= 1 << 3;
25        }
26
27        // data
28        packet |= (state.data & 0x0f) << 4;
29
30        [packet]
31    }
32}