|
66 | 66 | _CONFIG_REGISTER = const(3) |
67 | 67 |
|
68 | 68 |
|
69 | | -class RWDependentBit(RWBit): |
70 | | - """A default descriptor """ |
71 | | - dependent_bit: RWBit |
72 | | - |
73 | | - def __init__( |
74 | | - self, |
75 | | - register_address: int, |
76 | | - bit: int, |
77 | | - |
78 | | - flag: bool, |
79 | | - register_width: int = 1, |
80 | | - lsb_first: bool = True |
81 | | - ) -> None: |
82 | | - super(RWDependentBit, self).__init__(register_address, bit, register_width, lsb_first) |
83 | | - # self.__dependent_bit = dependent_bit |
84 | | - self.__flag = flag |
85 | | - |
86 | | - def __set__(self, obj: I2CDeviceDriver, value: bool): |
87 | | - # Pin can be set only when configuration dependent bit is equal to 0. |
88 | | - if self.__flag != self.dependent_bit: # self.__dependent_bit: |
89 | | - raise AttributeError("Pin not configured as output.") |
90 | | - else: |
91 | | - super(RWDependentBit, self).__set__(obj, value) |
92 | | - |
93 | | - |
94 | | -class _I2cGpio: |
95 | | - |
96 | | - def __init__(self, input_reg: ROBit, output_reg: RWDependentBit, polarity_reg: RWBit, cfg_reg: RWBit): |
97 | | - self.__input_reg = input_reg |
98 | | - self.__output_reg = output_reg |
99 | | - self.__polarity_reg = polarity_reg |
100 | | - self.__cfg_reg = cfg_reg |
101 | | - |
102 | | - def _get_value(self) -> bool: |
103 | | - # If a bit in configuration register is set to 1, the corresponding port pin is enabled as an input. |
104 | | - # If a bit in this register is cleared to 0, the corresponding port pin is enabled as an output. |
105 | | - if self.__cfg_reg: |
106 | | - self.value = self.__input_reg |
107 | | - else: |
108 | | - self.value = self.__output_reg |
109 | | - return self.value |
110 | | - |
111 | | -# gpiozero InputDevice and OutputDevice compatible interfaces |
112 | | - @property |
113 | | - def value(self) -> bool: |
114 | | - # The Input Port registers reflect the incoming logic levels of the pins, regardless of whether the pin is |
115 | | - # defined as an input or an output by the Configuration register. |
116 | | - return self.__input_reg |
117 | | - |
118 | | - @value.setter |
119 | | - def value(self, new_val: bool) -> None: |
120 | | - self.__output_reg = new_val |
121 | | - |
122 | | - def is_active(self): |
123 | | - return self.value |
124 | | - |
125 | | - @property |
126 | | - def active_high(self): |
127 | | - pass |
128 | | - |
129 | | - @active_high.setter |
130 | | - def active_high(self, value): |
131 | | - pass |
132 | | - |
133 | | - def on(self): |
134 | | - pass |
135 | | - |
136 | | - def off(self): |
137 | | - pass |
138 | | - |
139 | | - def toggle(self): |
140 | | - pass |
141 | | - |
142 | | - @property |
143 | | - def configure(self) -> bool: |
144 | | - return self.__cfg_reg |
145 | | - |
146 | | - @configure.setter |
147 | | - def configure(self, new_value: bool) -> None: |
148 | | - self.__cfg_reg = new_value |
149 | | - |
150 | | - |
151 | 69 | def _get_registry_params(value, x): |
152 | 70 | _name = "" |
153 | 71 | _reg_address_multiplier = 1 |
@@ -188,14 +106,8 @@ def __new__(mcs, clsname, bases, dct, *args, **kwargs): |
188 | 106 | _cfg_reg = RWBit(_CONFIG_REGISTER * _reg_address_multiplier + _adder, _idx) |
189 | 107 | _input_reg = ROBit(_INPUT_PORT * _reg_address_multiplier + _adder, _idx) |
190 | 108 | _output_reg = RWBit(_OUTPUT_PORT * _reg_address_multiplier + _adder, _idx) |
191 | | - # RWDependentBit(_OUTPUT_PORT * _reg_address_multiplier + _adder, _idx, |
192 | | - # _cfg_reg, False) |
193 | 109 | _polarity_reg = RWBit(_POLARITY_REGISTER * _reg_address_multiplier + _adder, _idx) |
194 | 110 |
|
195 | | - # GPIO object |
196 | | - # prop_name = f"GPIO{x}" |
197 | | - # result_dct[prop_name] = _I2cGpio(_input_reg, _output_reg, _polarity_reg, _cfg_reg) |
198 | | - |
199 | 111 | # REGISTRY 0 and 1 INPUT PORT |
200 | 112 | prop_name = f"I{_name}{_idx}" |
201 | 113 | result_dct[prop_name] = _input_reg |
@@ -223,23 +135,6 @@ def __init__(self, i2c_bus: I2C, address: int, **kwargs) -> None: |
223 | 135 | def max_gpios(self): |
224 | 136 | return getattr(self, '_NUM_GPIO') |
225 | 137 |
|
226 | | -# RPi.GPIO compatible interface |
227 | | - def setmode(self, gpio: int) -> None: |
228 | | - # Does nothing, pin already configured. |
229 | | - pass |
230 | | - |
231 | | - def setup(self, gpio: int, mode: bool) -> None: |
232 | | - _name, _, _, _idx = _get_registry_params(self.max_gpios(), gpio) |
233 | | - setattr(self, f"C{_name}{_idx}", mode) |
234 | | - |
235 | | - def input(self, gpio: int) -> bool: |
236 | | - _name, _, _, _idx = _get_registry_params(self.max_gpios(), gpio) |
237 | | - return getattr(self, f"I{_name}{_idx}") |
238 | | - |
239 | | - def output(self, gpio: int, _value: bool) -> None: |
240 | | - _name, _, _, _idx = _get_registry_params(self.max_gpios(), gpio) |
241 | | - setattr(self, f"O{_name}{_idx}", _value) |
242 | | - |
243 | 138 |
|
244 | 139 | # PCA series |
245 | 140 | class PCA9534(BaseGPIOExpander): |
|
0 commit comments