Skip to content

Commit c944ce6

Browse files
committed
SysfsGpio: add invert attribute (active-low) to the SysfsGPIO resources
The resources SysfsGPIO, NetworkSysfsGPIO and MatchedSysfsGPIO and the GPIOSysFSExport have been modified to have an additional optional invert (active-low) attribute (default False) which can be used to invert the logical value used on the gpio line. Signed-off-by: Perry Melange <[email protected]>
1 parent 02fa1ef commit c944ce6

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

labgrid/remote/exporter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,16 +642,19 @@ def _get_params(self):
642642
return {
643643
"host": self.host,
644644
"index": self.local.index,
645+
"invert": self.local.invert,
645646
}
646647

647648
def _get_start_params(self):
648649
return {
649650
"index": self.local.index,
651+
"invert": self.local.invert,
650652
}
651653

652654
def _start(self, start_params):
653655
"""Start a GPIO export to userspace"""
654656
index = start_params["index"]
657+
invert = start_params["invert"]
655658

656659
if self.export_path.exists():
657660
self.system_exported = True
@@ -672,7 +675,6 @@ def _stop(self, start_params):
672675
with open(export_sysfs_path, mode="wb") as unexport:
673676
unexport.write(str(index).encode("utf-8"))
674677

675-
676678
exports["SysfsGPIO"] = GPIOSysFSExport
677679
exports["MatchedSysfsGPIO"] = GPIOSysFSExport
678680

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ class NetworkSysfsGPIO(NetworkResource, ManagedResource):
339339
manager_cls = RemotePlaceManager
340340

341341
"""The NetworkSysfsGPIO describes a remotely accessible gpio line"""
342+
342343
index = attr.ib(validator=attr.validators.optional(attr.validators.instance_of(int)))
344+
invert = attr.ib(default=False, validator=attr.validators.instance_of(bool))
343345
def __attrs_post_init__(self):
344346
self.timeout = 10.0
345347
super().__attrs_post_init__()

labgrid/resource/udev.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,10 @@ class MatchedSysfsGPIO(USBResource):
758758
"""The MatchedSysfsGPIO described a SysfsGPIO matched by Udev
759759
760760
Args:
761-
pin (int): gpio pin number within the matched gpiochip."""
761+
pin (int): gpio pin number within the matched gpiochip.
762+
invert (bool): optional, whether the logic level is inverted (active-low)"""
762763
pin = attr.ib(default=None, validator=attr.validators.instance_of(int))
764+
invert = attr.ib(default=False, validator=attr.validators.instance_of(bool))
763765
index = None
764766

765767
def __attrs_post_init__(self):

0 commit comments

Comments
 (0)