Skip to content

Commit

Permalink
scons: _check_serial(): refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Obijuan committed Mar 5, 2024
1 parent dc7338c commit f3de45d
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions apio/managers/scons.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ def get_serial_port(self, board, board_data, ext_serial_port):
def _check_serial(
self, board: str, board_data: dict, ext_serial_port: str
) -> str:
"""TODO: Check if the given board is connected or not to the computer
If it is not connected, an exception is raised
"""Check the that the serial port for the given board exists
(board connedted)
* INPUT:
* board: Board name (string)
Expand All @@ -623,6 +623,8 @@ def _check_serial(
* Programmer name
* USB id (vid, pid)
* ext_serial_port: serial port name given by the user (optional)
* OUTPUT: (string) The serial port name
"""

# -- The board is connected by USB
Expand Down Expand Up @@ -650,7 +652,7 @@ def _check_serial(
# Board not available
raise AttributeError("board " + board + " not available")

# --->TODO: Match the discovered serial ports
# -- Match the discovered serial ports
for serial_port_data in serial_ports:

# -- Get the port name of the detected board
Expand All @@ -661,18 +663,21 @@ def _check_serial(
if ext_serial_port and ext_serial_port != port:
continue

# -- TODO
if hwid.lower() in serial_port_data.get("hwid").lower():
if "tinyprog" in board_data and not self._check_tinyprog(
board_data, port
):
# If the board uses tinyprog use its port detection
# to double check the detected port.
# If the port is not detected, skip the port.
# -- Check if the TinyFPGA board is connected
connected = self._check_tinyprog(board_data, port)

# -- If the usb id matches...
if hwid.lower() in serial_port_data["hwid"].lower():

# -- Special case: TinyFPGA. Ignore usb id if
# -- board not detected
if "tinyprog" in board_data and not connected:
continue
# If the hwid and the description pattern matches
# with the detected port return the port.

# -- Return the serial port
return port

# -- No serial port found...
return None

@staticmethod
Expand All @@ -693,9 +698,9 @@ def _check_tinyprog(board_data: dict, port: str) -> bool:
"""

# -- Check that the given board has the property "tinyprog"
# -- If not, it is an error. Raise an exception
# -- If not, return False
if "tinyprog" not in board_data:
raise AttributeError("Missing board configuration: tinyprog")
return False

# -- Get the board description from the the apio database
board_desc = board_data["tinyprog"]["desc"]
Expand Down

0 comments on commit f3de45d

Please sign in to comment.