Skip to main content

bd18378/
registers.rs

1use strum::FromRepr;
2
3/// The `WriteRegister` enum represents various writeable registers
4/// of the ROHM BD18378 LED Driver IC, along with their corresponding hexadecimal addresses.
5#[derive(Debug, Clone, Copy, FromRepr)]
6#[repr(u8)]
7pub enum WriteRegister {
8    
9    // LED current calibration registers
10    ChannelCalibration00 = 0x48,
11    ChannelCalibration01 = 0x49,
12    ChannelCalibration02 = 0x4A,
13    ChannelCalibration03 = 0x4B,
14    ChannelCalibration04 = 0x4C,
15    ChannelCalibration05 = 0x4D,
16    ChannelCalibration06 = 0x4E,
17    ChannelCalibration07 = 0x4F,
18    ChannelCalibration08 = 0x50,
19    ChannelCalibration09 = 0x51,
20    ChannelCalibration10 = 0x52,
21    ChannelCalibration11 = 0x53,
22    
23    // LED enable registers
24    ChannelEnable00To05 = 0x56,
25    ChannelEnable06To11 = 0x57,
26    
27    // IC reset register
28    StatusReset = 0x6B,
29    SoftwareReset = 0x6C,
30    
31    // Reserved registers used during IC initialization
32    Reserved79 = 0x79,
33    Reserved7A = 0x7A,
34    Reserved7B = 0x7B,
35    ReservedB5 = 0xB5,
36    ReservedB6 = 0xB6,
37    ReservedB7 = 0xB7,
38    ReservedB8 = 0xB8,
39    ReservedB9 = 0xB9,
40}
41
42impl TryFrom<u8> for WriteRegister {
43    type Error = ();
44
45    fn try_from(value: u8) -> Result<Self, Self::Error> {
46        let reg = WriteRegister::from_repr(value);
47        match reg {
48            Some(reg) => Ok(reg),
49            None => Err(()),
50        }
51    }
52}
53
54#[derive(Debug, Clone, Copy)]
55#[repr(u8)]
56pub enum ReadRegister {
57    Status = 0xA8,
58}