In embedded you can spend many lines to configure pin but usually just driving the pin will work because it will write to the register and the the pin.
It's pretty simple. Other phreripherals might override you but that's chip specific.
Now this is modern python example of setting pin value and the fags actually defend the implementation.
The API sucks and maybe they had a point but it doesn't address any problems, it's just verbose because...?
import gpiod
import time
from gpiod.line import Direction, Value
def toggle_value(value):
if value == Value.INACTIVE:
return Value.ACTIVE
return Value.INACTIVE
def toggle_line_value(chip_path, line_offset):
value_str = {Value.ACTIVE: "Active", Value.INACTIVE: "Inactive"}
value = Value.ACTIVE
with gpiod.request_lines(
chip_path,
consumer="toggle-line-value",
config={
line_offset: gpiod.LineSettings(
direction=Direction.OUTPUT, output_value=value
)
},
) as request:
while True:
print("{}={}".format(line_offset, value_str[value]))
time.sleep(1)
value = toggle_value(value)
request.set_value(line_offset, value)
toggle_line_value("/dev/gpiochip0", 5)