tca9534_driver_rs/
registers.rs1#[derive(Debug, Copy, Clone)]
7pub enum Register {
8 InputPort = 0x00,
11
12 OutputPort = 0x01,
15
16 Polarity = 0x02,
19
20 Config = 0x03,
25}
26
27impl Register {
28 pub fn addr(self) -> u8 {
30 self as u8
31 }
32}
33
34#[cfg(feature = "defmt")]
35impl defmt::Format for Register {
36 fn format(&self, fmt: defmt::Formatter) {
37 match *self {
38 Register::InputPort => defmt::write!(fmt, "InputPort"),
39 Register::OutputPort => defmt::write!(fmt, "OutputPort"),
40 Register::Polarity => defmt::write!(fmt, "Polarity"),
41 Register::Config => defmt::write!(fmt, "Config"),
42 }
43 }
44}
45
46#[derive(Debug, Copy, Clone, PartialEq)]
48pub enum PinConfig {
49 Input = 1,
51 Output = 0,
53}
54
55impl PinConfig {
56 pub fn bits(self) -> u8 {
58 self as u8
59 }
60}
61
62#[cfg(feature = "defmt")]
63impl defmt::Format for PinConfig {
64 fn format(&self, fmt: defmt::Formatter) {
65 match *self {
66 PinConfig::Input => defmt::write!(fmt, "Input"),
67 PinConfig::Output => defmt::write!(fmt, "Output"),
68 }
69 }
70}
71
72#[derive(Debug, Copy, Clone, PartialEq)]
74pub enum PinPolarity {
75 Normal = 0,
77 Inverted = 1,
79}
80
81impl PinPolarity {
82 pub fn bits(self) -> u8 {
84 self as u8
85 }
86}
87
88#[cfg(feature = "defmt")]
89impl defmt::Format for PinPolarity {
90 fn format(&self, fmt: defmt::Formatter) {
91 match *self {
92 PinPolarity::Normal => defmt::write!(fmt, "Normal"),
93 PinPolarity::Inverted => defmt::write!(fmt, "Inverted"),
94 }
95 }
96}
97
98#[derive(Debug, Copy, Clone, PartialEq)]
100pub enum PinLevel {
101 Low = 0,
103 High = 1,
105}
106
107impl PinLevel {
108 pub fn bits(self) -> u8 {
110 self as u8
111 }
112}
113
114#[cfg(feature = "defmt")]
115impl defmt::Format for PinLevel {
116 fn format(&self, fmt: defmt::Formatter) {
117 match *self {
118 PinLevel::Low => defmt::write!(fmt, "Low"),
119 PinLevel::High => defmt::write!(fmt, "High"),
120 }
121 }
122}
123
124pub type Pin = u8;
126
127pub type PortValue = u8;
129
130pub mod config {
132 pub const ALL_INPUTS: u8 = 0xFF;
134
135 pub const ALL_OUTPUTS: u8 = 0x00;
137
138 pub const ALL_NORMAL_POLARITY: u8 = 0x00;
140
141 pub const ALL_INVERTED_POLARITY: u8 = 0xFF;
143
144 pub const ALL_OUTPUTS_LOW: u8 = 0x00;
146
147 pub const ALL_OUTPUTS_HIGH: u8 = 0xFF;
149}
150
151pub mod addresses {
153 pub const ADDR_000: u8 = 0x20;
155 pub const ADDR_001: u8 = 0x21;
157 pub const ADDR_010: u8 = 0x22;
159 pub const ADDR_011: u8 = 0x23;
161 pub const ADDR_100: u8 = 0x24;
163 pub const ADDR_101: u8 = 0x25;
165 pub const ADDR_110: u8 = 0x26;
167 pub const ADDR_111: u8 = 0x27;
169}