Skip to content

Commit 7df9225

Browse files
committed
resource: add FTDI GPIO output resources
Add local and remote resources for FTDI data-bus GPIO lines exposed through asynchronous bit-bang mode. The resource models one output-capable bit on a selected FTDI interface and exports the USB identity, interface, index, and inversion metadata needed by the driver. Signed-off-by: Ozan Durgut <ozan.durgut@analog.com>
1 parent 64723a5 commit 7df9225

4 files changed

Lines changed: 95 additions & 0 deletions

File tree

labgrid/remote/exporter.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,25 @@ def _get_params(self):
549549
}
550550

551551

552+
@attr.s(eq=False)
553+
class USBFTDIGPIOExport(USBGenericExport):
554+
"""ResourceExport for GPIOs on FTDI data-bus bit-bang interfaces"""
555+
556+
def _get_params(self):
557+
"""Helper function to return parameters"""
558+
return {
559+
"host": self.host,
560+
"busnum": self.local.busnum,
561+
"devnum": self.local.devnum,
562+
"path": self.local.path,
563+
"vendor_id": self.local.vendor_id,
564+
"model_id": self.local.model_id,
565+
"index": self.local.index,
566+
"interface": self.local.interface,
567+
"invert": self.local.invert,
568+
}
569+
570+
552571
@attr.s(eq=False)
553572
class USBFlashableExport(USBGenericExport):
554573
"""ResourceExport for Flashable USB devices"""
@@ -591,6 +610,7 @@ def __attrs_post_init__(self):
591610
exports["USBPowerPort"] = USBPowerPortExport
592611
exports["DeditecRelais8"] = USBDeditecRelaisExport
593612
exports["HIDRelay"] = USBHIDRelayExport
613+
exports["FTDIGPIO"] = USBFTDIGPIOExport
594614
exports["USBFlashableDevice"] = USBFlashableExport
595615
exports["LXAUSBMux"] = USBGenericExport
596616

labgrid/resource/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
AndroidUSBFastboot,
1313
DFUDevice,
1414
DeditecRelais8,
15+
FTDIGPIO,
1516
HIDRelay,
1617
IMXUSBLoader,
1718
LXAUSBMux,

labgrid/resource/remote.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,33 @@ def __attrs_post_init__(self):
345345
super().__attrs_post_init__()
346346

347347

348+
@target_factory.reg_resource
349+
@attr.s(eq=False)
350+
class NetworkFTDIGPIO(RemoteUSBResource):
351+
"""The NetworkFTDIGPIO describes a remotely accessible FTDI GPIO line"""
352+
index = attr.ib(
353+
default=0,
354+
converter=int,
355+
validator=attr.validators.and_(
356+
attr.validators.instance_of(int),
357+
attr.validators.ge(0),
358+
attr.validators.le(7),
359+
),
360+
)
361+
interface = attr.ib(
362+
default=1,
363+
converter=int,
364+
validator=attr.validators.and_(
365+
attr.validators.instance_of(int),
366+
attr.validators.ge(1),
367+
),
368+
)
369+
invert = attr.ib(default=False, validator=attr.validators.instance_of(bool))
370+
def __attrs_post_init__(self):
371+
self.timeout = 10.0
372+
super().__attrs_post_init__()
373+
374+
348375
@target_factory.reg_resource
349376
@attr.s(eq=False)
350377
class NetworkSysfsGPIO(NetworkResource, ManagedResource):

labgrid/resource/udev.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,53 @@ def filter_match(self, device):
797797

798798
return super().filter_match(device)
799799

800+
@target_factory.reg_resource
801+
@attr.s(eq=False)
802+
class FTDIGPIO(USBResource):
803+
"""This resource describes a single GPIO line on an FTDI bit-bang interface."""
804+
805+
index = attr.ib(
806+
default=0,
807+
converter=int,
808+
validator=attr.validators.and_(
809+
attr.validators.instance_of(int),
810+
attr.validators.ge(0),
811+
attr.validators.le(7),
812+
),
813+
)
814+
interface = attr.ib(
815+
default=1,
816+
converter=int,
817+
validator=attr.validators.and_(
818+
attr.validators.instance_of(int),
819+
attr.validators.ge(1),
820+
),
821+
)
822+
invert = attr.ib(default=False, validator=attr.validators.instance_of(bool))
823+
824+
def __attrs_post_init__(self):
825+
self.match["DEVTYPE"] = "usb_device"
826+
super().__attrs_post_init__()
827+
828+
def filter_match(self, device):
829+
usb_device = device
830+
if device.device_type != "usb_device":
831+
usb_device = device.find_parent("usb", "usb_device")
832+
if usb_device is None:
833+
return False
834+
835+
match = (
836+
usb_device.properties.get("ID_VENDOR_ID"),
837+
usb_device.properties.get("ID_MODEL_ID"),
838+
)
839+
if match not in [("0403", "6010"), # FT2232C/D/H Dual UART/FIFO IC
840+
("0403", "6011"), # FT4232H Quad UART/MPSSE IC
841+
("0403", "6014"), # FT232HL/Q
842+
]:
843+
return False
844+
845+
return super().filter_match(device)
846+
800847
@target_factory.reg_resource
801848
@attr.s(eq=False)
802849
class USBFlashableDevice(USBResource):

0 commit comments

Comments
 (0)