From b856b54720bb6749b5d3f895b65be2ecc8f5d965 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Sat, 16 Jan 2016 21:05:03 +0100 Subject: [PATCH] soc/tools/flterm: get rid of serial.tools.miniterm import and fix echo on linux --- litex/soc/tools/flterm.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/litex/soc/tools/flterm.py b/litex/soc/tools/flterm.py index e29a7402..d10f2657 100644 --- a/litex/soc/tools/flterm.py +++ b/litex/soc/tools/flterm.py @@ -7,7 +7,33 @@ import serial import threading import argparse -from serial.tools.miniterm import console, character, LF + +if sys.platform == "win32": + def getkey(): + import msvcrt + return msvcrt.getch() + +else: + def getkey(): + import termios + fd = sys.stdin.fileno() + old = termios.tcgetattr(fd) + new = termios.tcgetattr(fd) + new[3] = new[3] & ~termios.ICANON & ~termios.ECHO + new[6][termios.VMIN] = 1 + new[6][termios.VTIME] = 0 + termios.tcsetattr(fd, termios.TCSANOW, new) + c = None + try: + c = os.read(fd, 1) + finally: + termios.tcsetattr(fd, termios.TCSAFLUSH, old) + return c + + +def character(b): + return b.decode('latin1') + sfl_magic_len = 14 sfl_magic_req = "sL5DdSMmkekro\n" @@ -242,14 +268,14 @@ class Flterm: try: while self.writer_alive: try: - b = console.getkey() + b = getkey() except KeyboardInterrupt: b = serial.to_bytes([3]) c = character(b) if c == chr(0x03): self.stop() elif c == '\n': - self.serial.write(LF) + self.serial.write(serial.to_bytes([10])) else: self.serial.write(b) except: -- 2.30.2