Compare commits
3 Commits
master
...
atmega32u2
Author | SHA1 | Date | |
---|---|---|---|
0fca96f022 | |||
75ef884e4f | |||
b9479b95f0 |
12
Makefile
12
Makefile
|
@ -1,9 +1,9 @@
|
|||
MCU = at90usb1287
|
||||
MCU = atmega32u2
|
||||
ARCH = AVR8
|
||||
BOARD = USER
|
||||
F_CPU = 8000000
|
||||
F_USB = 8000000
|
||||
OPTIMIZATION = 3
|
||||
BOARD = MINIMUS
|
||||
F_CPU = 16000000
|
||||
F_USB = 16000000
|
||||
OPTIMIZATION = s
|
||||
TARGET = main
|
||||
LUFA_PATH = lufa/LUFA
|
||||
CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -Iconfig/ -Wall
|
||||
|
@ -25,7 +25,7 @@ DEVICE = /dev/serial/by-id/usb-LUFA_FT232_*
|
|||
|
||||
# Open terminal on USB port
|
||||
term:
|
||||
terminal.py $(DEVICE)
|
||||
python terminal.py $(DEVICE)
|
||||
.PHONY: term
|
||||
|
||||
# Include LUFA build script makefiles
|
||||
|
|
22
ftdi.h
22
ftdi.h
|
@ -9,11 +9,11 @@
|
|||
|
||||
/* FTDI device-to-host data IN endpoint */
|
||||
#define FTDI_TX_EPADDR (ENDPOINT_DIR_IN | 1)
|
||||
#define FTDI_TX_QUEUE_LEN 256
|
||||
#define FTDI_TX_QUEUE_LEN 32
|
||||
|
||||
/* Endpoint address of FTDI host-to-device data OUT endpoint */
|
||||
#define FTDI_RX_EPADDR (ENDPOINT_DIR_OUT | 2)
|
||||
#define FTDI_RX_QUEUE_LEN 256 /* Must be at least FTDI_TXRX_EPSIZE + 1 */
|
||||
#define FTDI_RX_QUEUE_LEN 32 /* Must be at least FTDI_TXRX_EPSIZE + 1 */
|
||||
|
||||
/* Endpoint size */
|
||||
#define FTDI_TXRX_EPSIZE 16 /* e.g. 16 or 64 */
|
||||
|
@ -63,18 +63,6 @@
|
|||
#define FTDI_BLOCKING_OUT (1 << 2)
|
||||
#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 */
|
||||
void ftdi_init(int flags);
|
||||
|
||||
|
@ -92,9 +80,9 @@ void EVENT_USB_Device_ControlRequest(void);
|
|||
void EVENT_USB_Device_Reset(void);
|
||||
void EVENT_USB_Device_ConfigurationChanged(void);
|
||||
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
|
||||
const uint16_t wIndex,
|
||||
const void** const DescriptorAddress)
|
||||
ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
|
||||
const uint8_t wIndex,
|
||||
const void** const DescriptorAddress)
|
||||
ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
2
lufa
2
lufa
|
@ -1 +1 @@
|
|||
Subproject commit 737382aeda146ca793be452ac5790e12d1ca16ea
|
||||
Subproject commit f59a34370cec33272412d9aee6e68871d7e8b5e0
|
132
terminal.py
Executable file
132
terminal.py
Executable file
|
@ -0,0 +1,132 @@
|
|||
#!/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