From e894dd00f26f9ee8a6d5d8da408176dacce29627 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 22 Jun 2024 09:25:59 -0400 Subject: [PATCH] allowing passing the iodevice --- src/isp_programmer/IODevices.py | 6 +++++- src/isp_programmer/ISPConnection.py | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/isp_programmer/IODevices.py b/src/isp_programmer/IODevices.py index d2bed0f..290e9f7 100644 --- a/src/isp_programmer/IODevices.py +++ b/src/isp_programmer/IODevices.py @@ -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) diff --git a/src/isp_programmer/ISPConnection.py b/src/isp_programmer/ISPConnection.py index e67af9b..473e91f 100644 --- a/src/isp_programmer/ISPConnection.py +++ b/src/isp_programmer/ISPConnection.py @@ -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 @@ -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