mirror of
https://github.com/AsahiLinux/m1n1
synced 2024-11-14 03:17:05 +00:00
proxy.py: Move M1N1DEVICE/UART port open logic into UartInterface
Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
parent
82978081f8
commit
80f73926e8
3 changed files with 20 additions and 13 deletions
|
@ -3,10 +3,7 @@
|
|||
import serial, os
|
||||
from proxy import *
|
||||
|
||||
uartdev = os.environ.get("M1N1DEVICE", "/dev/ttyUSB0")
|
||||
usbuart = serial.Serial(uartdev, 115200)
|
||||
|
||||
iface = UartInterface(usbuart, debug=False)
|
||||
iface = UartInterface()
|
||||
proxy = M1N1Proxy(iface, debug=False)
|
||||
|
||||
SCRATCH = 0x24F00000
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import os, sys, struct
|
||||
import os, sys, struct, serial
|
||||
from serial.tools.miniterm import Miniterm
|
||||
|
||||
def hexdump(s, sep=" "):
|
||||
|
@ -80,8 +80,21 @@ class UartInterface:
|
|||
CMD_LEN = 56
|
||||
REPLY_LEN = 36
|
||||
|
||||
def __init__(self, device, debug=False):
|
||||
def __init__(self, device=None, debug=False):
|
||||
self.debug = debug
|
||||
self.devpath = None
|
||||
if device is None:
|
||||
device = os.environ.get("M1N1DEVICE", "/dev/ttyUSB0:115200")
|
||||
if isinstance(device, str):
|
||||
baud = 115200
|
||||
if ":" in device:
|
||||
device, baud = device.rsplit(":", 1)
|
||||
baud = int(baud)
|
||||
self.devpath = device
|
||||
self.baudrate = baud
|
||||
|
||||
device = serial.Serial(self.devpath, baud)
|
||||
|
||||
self.dev = device
|
||||
self.dev.timeout = 0
|
||||
self.dev.flushOutput()
|
||||
|
|
|
@ -3,21 +3,18 @@ from proxy import *
|
|||
from tgtypes import *
|
||||
from utils import *
|
||||
|
||||
uartdev = os.environ.get("M1N1DEVICE", "/dev/ttyUSB0")
|
||||
uart = serial.Serial(uartdev, 115200)
|
||||
|
||||
iface = UartInterface(uart, debug=False)
|
||||
iface = UartInterface()
|
||||
p = M1N1Proxy(iface, debug=False)
|
||||
|
||||
try:
|
||||
uart.timeout = 0.15
|
||||
iface.dev.timeout = 0.15
|
||||
iface.nop()
|
||||
p.set_baud(1500000)
|
||||
except UartTimeout:
|
||||
uart.baudrate = 1500000
|
||||
iface.dev.baudrate = 1500000
|
||||
iface.nop()
|
||||
|
||||
uart.timeout = 3
|
||||
iface.dev.timeout = 3
|
||||
|
||||
u = ProxyUtils(p)
|
||||
mon = RegMonitor(u)
|
||||
|
|
Loading…
Reference in a new issue