Compare commits
7 Commits
stack-debu
...
master
Author | SHA1 | Date | |
---|---|---|---|
1e59f6ab19 | |||
cf1459f3b9 | |||
868e6c6827 | |||
20935ae354 | |||
f097a20fc4 | |||
806b7670f7 | |||
7bfeaae7b1 |
2
Makefile
2
Makefile
|
@ -25,7 +25,7 @@ DEVICE = /dev/serial/by-id/usb-LUFA_FT232_*
|
||||||
|
|
||||||
# Open terminal on USB port
|
# Open terminal on USB port
|
||||||
term:
|
term:
|
||||||
python terminal.py $(DEVICE)
|
terminal.py $(DEVICE)
|
||||||
.PHONY: term
|
.PHONY: term
|
||||||
|
|
||||||
# Include LUFA build script makefiles
|
# Include LUFA build script makefiles
|
||||||
|
|
18
ftdi.h
18
ftdi.h
|
@ -63,6 +63,18 @@
|
||||||
#define FTDI_BLOCKING_OUT (1 << 2)
|
#define FTDI_BLOCKING_OUT (1 << 2)
|
||||||
#define FTDI_BLOCKING (FTDI_BLOCKING_IN | FTDI_BLOCKING_OUT)
|
#define FTDI_BLOCKING (FTDI_BLOCKING_IN | FTDI_BLOCKING_OUT)
|
||||||
|
|
||||||
|
/* Whether to translate \n to \r\n on output, like stty's onlcr flag */
|
||||||
|
#define FTDI_ONLCR (1 << 3)
|
||||||
|
|
||||||
|
/* Whether to delay the initial TX after USB configuration.
|
||||||
|
If set, wait for either:
|
||||||
|
- 250ms to pass after a SET_BAUDRATE command
|
||||||
|
- input to be received
|
||||||
|
before sending any data. This is to work around issues where
|
||||||
|
some hsots will discard (or even echo) input while the port
|
||||||
|
is still being opened. */
|
||||||
|
#define FTDI_DELAY_INIT_TX (1 << 4)
|
||||||
|
|
||||||
/* Initialize FTDI routines, with flags above */
|
/* Initialize FTDI routines, with flags above */
|
||||||
void ftdi_init(int flags);
|
void ftdi_init(int flags);
|
||||||
|
|
||||||
|
@ -80,9 +92,9 @@ void EVENT_USB_Device_ControlRequest(void);
|
||||||
void EVENT_USB_Device_Reset(void);
|
void EVENT_USB_Device_Reset(void);
|
||||||
void EVENT_USB_Device_ConfigurationChanged(void);
|
void EVENT_USB_Device_ConfigurationChanged(void);
|
||||||
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
|
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
|
||||||
const uint8_t wIndex,
|
const uint16_t wIndex,
|
||||||
const void** const DescriptorAddress)
|
const void** const DescriptorAddress)
|
||||||
ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
|
ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
2
lufa
2
lufa
|
@ -1 +1 @@
|
||||||
Subproject commit f59a34370cec33272412d9aee6e68871d7e8b5e0
|
Subproject commit 737382aeda146ca793be452ac5790e12d1ca16ea
|
132
terminal.py
132
terminal.py
|
@ -1,132 +0,0 @@
|
||||||
#!/usr/bin/python
|
|
||||||
# Based on miniterm sample in pyserial
|
|
||||||
|
|
||||||
import sys, os, serial, threading, traceback, time
|
|
||||||
|
|
||||||
if os.name == 'nt':
|
|
||||||
import msvcrt
|
|
||||||
class Console:
|
|
||||||
def __init__(self):
|
|
||||||
pass
|
|
||||||
def cleanup(self):
|
|
||||||
pass
|
|
||||||
def getkey(self):
|
|
||||||
while 1:
|
|
||||||
z = msvcrt.getch()
|
|
||||||
if z == '\0' or z == '\xe0': # function keys
|
|
||||||
msvcrt.getch()
|
|
||||||
else:
|
|
||||||
if z == '\r':
|
|
||||||
return '\n'
|
|
||||||
return z
|
|
||||||
elif os.name == 'posix':
|
|
||||||
import termios, sys, os
|
|
||||||
class Console:
|
|
||||||
def __init__(self):
|
|
||||||
self.fd = sys.stdin.fileno()
|
|
||||||
try:
|
|
||||||
self.old = termios.tcgetattr(self.fd)
|
|
||||||
new = termios.tcgetattr(self.fd)
|
|
||||||
new[3] = new[3] & ~termios.ICANON & ~termios.ECHO & ~termios.ISIG
|
|
||||||
new[6][termios.VMIN] = 1
|
|
||||||
new[6][termios.VTIME] = 0
|
|
||||||
termios.tcsetattr(self.fd, termios.TCSANOW, new)
|
|
||||||
except termios.error:
|
|
||||||
# ignore errors, so we can pipe stuff to this script
|
|
||||||
pass
|
|
||||||
def cleanup(self):
|
|
||||||
try:
|
|
||||||
termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
|
|
||||||
except:
|
|
||||||
# ignore errors, so we can pipe stuff to this script
|
|
||||||
pass
|
|
||||||
def getkey(self):
|
|
||||||
c = os.read(self.fd, 1)
|
|
||||||
return c
|
|
||||||
else:
|
|
||||||
raise ("Sorry, no terminal implementation for your platform (%s) "
|
|
||||||
"available." % sys.platform)
|
|
||||||
|
|
||||||
class Miniterm:
|
|
||||||
def __init__(self, serial):
|
|
||||||
self.serial = serial
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
self.alive = True
|
|
||||||
#start serial->console thread
|
|
||||||
self.receiver_thread = threading.Thread(target=self.reader)
|
|
||||||
self.receiver_thread.daemon = True
|
|
||||||
self.receiver_thread.start()
|
|
||||||
#enter console->serial loop
|
|
||||||
self.console = Console()
|
|
||||||
self.transmitter_thread = threading.Thread(target=self.writer)
|
|
||||||
self.transmitter_thread.daemon = True
|
|
||||||
self.transmitter_thread.start()
|
|
||||||
|
|
||||||
def stop(self):
|
|
||||||
self.alive = False
|
|
||||||
|
|
||||||
def join(self, transmit_only=False):
|
|
||||||
self.receiver_thread.join()
|
|
||||||
self.transmitter_thread.join()
|
|
||||||
|
|
||||||
def reader(self):
|
|
||||||
"""loop and copy serial->console"""
|
|
||||||
try:
|
|
||||||
while self.alive:
|
|
||||||
data = self.serial.read(1)
|
|
||||||
sys.stdout.write(data)
|
|
||||||
sys.stdout.flush()
|
|
||||||
except Exception as e:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.console.cleanup()
|
|
||||||
os._exit(1)
|
|
||||||
|
|
||||||
def writer(self):
|
|
||||||
"""loop and copy console->serial until ^C"""
|
|
||||||
try:
|
|
||||||
while self.alive:
|
|
||||||
try:
|
|
||||||
c = self.console.getkey()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
c = '\x03'
|
|
||||||
if c == '\x03':
|
|
||||||
self.stop()
|
|
||||||
return
|
|
||||||
elif c == '':
|
|
||||||
# EOF on input. Wait a tiny bit so we can
|
|
||||||
# flush the remaining input, then stop.
|
|
||||||
time.sleep(0.25)
|
|
||||||
self.stop()
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
self.serial.write(c) # send character
|
|
||||||
except Exception as e:
|
|
||||||
traceback.print_exc()
|
|
||||||
self.console.cleanup()
|
|
||||||
os._exit(1)
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
self.serial.timeout = 0.1
|
|
||||||
self.start()
|
|
||||||
self.join()
|
|
||||||
print ""
|
|
||||||
self.console.cleanup()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Simple serial terminal")
|
|
||||||
parser.add_argument('device', metavar='DEVICE',
|
|
||||||
help='serial device')
|
|
||||||
parser.add_argument('baudrate', metavar='BAUDRATE', type=int, nargs='?',
|
|
||||||
help='baud rate', default=115200)
|
|
||||||
args = parser.parse_args()
|
|
||||||
try:
|
|
||||||
dev = serial.Serial(args.device, args.baudrate)
|
|
||||||
except serial.serialutil.SerialException:
|
|
||||||
sys.stderr.write("error opening %s\n" % args.device)
|
|
||||||
raise SystemExit(1)
|
|
||||||
term = Miniterm(dev)
|
|
||||||
term.run()
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user