Skip to content

Commit 97e7cea

Browse files
Merge pull request #1730 from pmelange/25.0.1-sysfsgpio_active_low
Sysfsgpio invert (active_low)
2 parents 64ef567 + d890309 commit 97e7cea

12 files changed

Lines changed: 35 additions & 19 deletions

File tree

doc/configuration.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,11 @@ A :any:`SysfsGPIO` resource describes a GPIO line.
644644
645645
SysfsGPIO:
646646
index: 12
647+
invert: False
647648
648649
Arguments:
649650
- index (int): index of the GPIO line
651+
- invert (bool, default=False): optional, whether the logic level is inverted (active-low)
650652

651653
Used by:
652654
- `GpioDigitalOutputDriver`_
@@ -670,6 +672,7 @@ USB based gpiochips.
670672
'@SUBSYSTEM': 'usb'
671673
'@ID_SERIAL_SHORT': 'D38EJ8LF'
672674
pin: 0
675+
invert: False
673676
674677
The example would search for a USB gpiochip with the key ``ID_SERIAL_SHORT``
675678
and the value ``D38EJ8LF`` and use the pin 0 of this device.
@@ -678,6 +681,7 @@ The ``ID_SERIAL_SHORT`` property is set by the usb_id builtin helper program.
678681
Arguments:
679682
- match (dict): key and value pairs for a udev match, see `udev Matching`_
680683
- pin (int): gpio pin number within the matched gpiochip.
684+
- invert (bool, default=False): optional, whether the logic level is inverted (active-low)
681685

682686
Used by:
683687
- `GpioDigitalOutputDriver`_
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
desk:
2-
GpioDigitalOutputDriver:
2+
SysfsGPIO:
33
index: 60
4+
invert: False

examples/sysfsgpio/import-gpio.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ targets:
55
name: gpio
66
drivers:
77
GpioDigitalOutputDriver: {}
8-
options:
9-
coordinator_address: 'labgrid:20408'

examples/sysfsgpio/sysfsgpio.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
StepLogger.start()
1414

1515
t = Target("main")
16-
r = SysfsGPIO(t, name=None, index=60)
16+
r = SysfsGPIO(t, name=None, index=60, invert=True)
1717
d = GpioDigitalOutputDriver(t, name=None)
1818

1919
p = t.get_driver("DigitalOutputProtocol")
2020
print(t.resources)
21+
print("Testing IO")
2122
p.set(True)
2223
print(p.get())
2324
time.sleep(2)

examples/sysfsgpio/sysfsgpio_remote.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
p = t.get_driver("DigitalOutputProtocol")
1717
print(t.resources)
18+
print("Testing IO")
1819
p.set(True)
1920
print(p.get())
2021
time.sleep(2)

labgrid/driver/gpiodriver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def on_deactivate(self):
3737
@Driver.check_active
3838
@step(args=['status'])
3939
def set(self, status):
40-
self.proxy.set(self.gpio.index, status)
40+
self.proxy.set(self.gpio.index, self.gpio.invert, status)
4141

4242
@Driver.check_active
4343
@step(result=True)
4444
def get(self):
45-
return self.proxy.get(self.gpio.index)
45+
return self.proxy.get(self.gpio.index, self.gpio.invert)

labgrid/remote/exporter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,16 +666,19 @@ def _get_params(self):
666666
return {
667667
"host": self.host,
668668
"index": self.local.index,
669+
"invert": self.local.invert,
669670
}
670671

671672
def _get_start_params(self):
672673
return {
673674
"index": self.local.index,
675+
"invert": self.local.invert,
674676
}
675677

676678
def _start(self, start_params):
677679
"""Start a GPIO export to userspace"""
678680
index = start_params["index"]
681+
invert = start_params["invert"] # pylint: disable=unused-variable
679682

680683
if self.export_path.exists():
681684
self.system_exported = True

labgrid/resource/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ class SysfsGPIO(Resource):
4242
"""The basic SysfsGPIO contains an index
4343
4444
Args:
45-
index (int): index of target gpio line."""
45+
index (int): index of target gpio line.
46+
invert (bool) : optional, whether the logic level is inverted (active-low)"""
4647
index = attr.ib(default=None, validator=attr.validators.instance_of(int))
48+
invert = attr.ib(default=False, validator=attr.validators.instance_of(bool))

labgrid/resource/remote.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ class NetworkSysfsGPIO(NetworkResource, ManagedResource):
352352

353353
"""The NetworkSysfsGPIO describes a remotely accessible gpio line"""
354354
index = attr.ib(validator=attr.validators.optional(attr.validators.instance_of(int)))
355+
invert = attr.ib(default=False, validator=attr.validators.instance_of(bool))
355356
def __attrs_post_init__(self):
356357
self.timeout = 10.0
357358
super().__attrs_post_init__()

labgrid/resource/udev.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,10 @@ class MatchedSysfsGPIO(USBResource):
929929
"""The MatchedSysfsGPIO described a SysfsGPIO matched by Udev
930930
931931
Args:
932-
pin (int): gpio pin number within the matched gpiochip."""
932+
pin (int): gpio pin number within the matched gpiochip.
933+
invert (bool): optional, whether the logic level is inverted (active-low)"""
933934
pin = attr.ib(default=None, validator=attr.validators.instance_of(int))
935+
invert = attr.ib(default=False, validator=attr.validators.instance_of(bool))
934936
index = None
935937

936938
def __attrs_post_init__(self):

0 commit comments

Comments
 (0)