Skip to content

Commit

Permalink
allowing passing the iodevice
Browse files Browse the repository at this point in the history
  • Loading branch information
snhobbs committed Jun 22, 2024
1 parent d1fc0d0 commit e894dd0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/isp_programmer/IODevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ def __init__(
port: str = "/dev/ttyUSB0",
baudrate: int = 9600,
timeout: float = kTimeout,
device: serial.Serial | None
):
self.uart = Serial(port, baudrate, xonxoff=False, timeout=timeout)
if device:
self.uart = device
else:
self.uart = Serial(port, baudrate, xonxoff=False, timeout=timeout)

def read(self, *args, **kwargs):
return self.uart.read(*args, **kwargs)
Expand Down
8 changes: 5 additions & 3 deletions src/isp_programmer/ISPConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,17 +892,17 @@ def MassErase(isp: ISPConnection, chip: ChipDescription):


def SetupChip(
baudrate: int,
device: str,
baudrate: int,
crystal_frequency: int,
chip_file: str,
no_sync: bool = False,
sleep_time: float = 1,
serial_sleep: float = 0,
iodevice: IODevice = None
):
"""
:param int baudrate: The baudrate to set or use. If no_sync is True this baudrate is assumed to already be set
:param str device: Serial port
:param float crystal_frequency: On board oscillator
:param str chip_file: Alternate file to find chip settings
:param bool no_sync: Whether or not to synchronize the channel on start
Expand All @@ -924,7 +924,9 @@ def SetupChip(
kStartingBaudRate = BAUDRATES[0]

_log.debug("Using baud rate %d", kStartingBaudRate)
iodevice: UartDevice = UartDevice(device, baudrate=kStartingBaudRate)
if not iodevice:
iodevice=UartDevice(device, baudrate=kStartingBaudRate)
iodevice.SetBaudrate(kStartingBaudRate)
isp = ISPConnection(iodevice)
isp.serial_sleep = serial_sleep
isp.return_code_sleep = sleep_time
Expand Down

0 comments on commit e894dd0

Please sign in to comment.