Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eeprom: add support to use CBUS IntEnum in _set_cbus_func #364

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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, 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