gpio: fix initial state for inverted gpios

The python-periphery library XORs the initial value based on
whether or not its inverted.  This requires consumers to set
the direction to "high" for inverted pins that are off, and
"low" otherwise.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2024-01-10 05:59:21 -05:00
parent 27a0295218
commit ea6df41f05
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 3 additions and 2 deletions

View File

@ -121,6 +121,7 @@ class GpioFactory:
"documentation for details on the pin format." "documentation for details on the pin format."
) )
bias_flag: Optional[str] = pin_match.group("bias") bias_flag: Optional[str] = pin_match.group("bias")
params["inverted"] = pin_match.group("inverted") is not None
if req_type == "event": if req_type == "event":
params["direction"] = "in" params["direction"] = "in"
params["edge"] = "both" params["edge"] = "both"
@ -131,8 +132,8 @@ class GpioFactory:
f"Invalid pin format {pin_desc}. Bias flag {bias_flag} " f"Invalid pin format {pin_desc}. Bias flag {bias_flag} "
"not available for output pins." "not available for output pins."
) )
params["direction"] = "out" if not initial_value else "high" initial_state = bool(initial_value) ^ params["inverted"]
params["inverted"] = pin_match.group("inverted") is not None params["direction"] = "low" if not initial_state else "high"
chip_id: str = pin_match.group("chip_id") or "gpiochip0" chip_id: str = pin_match.group("chip_id") or "gpiochip0"
pin_name: str = pin_match.group("pin_name") pin_name: str = pin_match.group("pin_name")
params["pin_id"] = int(pin_match.group("pin_id")) params["pin_id"] = int(pin_match.group("pin_id"))