Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pyftdi/eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def set_property(self, name: str, value: Union[str, int, bool],
"""
mobj = match(r'cbus_func_(\d)', name)
if mobj:
if not isinstance(value, str):
if not isinstance(value, str) and not isinstance(value, IntEnum):
raise ValueError("'{name}' should be specified as a string")
self._set_cbus_func(int(mobj.group(1)), value, out)
self._dirty.add(name)
Expand Down Expand Up @@ -871,7 +871,7 @@ def _decode_string(self, offset):
return manufacturer.decode('utf16', errors='ignore')
return ''

def _set_cbus_func(self, cpin: int, value: str,
def _set_cbus_func(self, cpin: int, value: str | IntEnum,
out: Optional[TextIO]) -> None:
cmap = {0x600: (self.CBUS, 5, 0x14, 4), # FT232R
0x900: (self.CBUSH, 10, 0x18, 4), # FT232H
Expand All @@ -893,7 +893,11 @@ def _set_cbus_func(self, cpin: int, value: str,
if not 0 <= cpin < count:
raise ValueError(f"Unsupported CBUS pin '{cpin}'")
try:
code = cbus[value.upper()].value
if isinstance(value, str):
value = value.upper()
elif isinstance(value, IntEnum):
value = value.name
code = cbus[value].value
except KeyError as exc:
raise ValueError(f"CBUS pin '{cpin}'' does not have function "
f"{value}'") from exc
Expand Down