Skip to content

Commit

Permalink
Preliminary Windows compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Aug 15, 2018
1 parent c96b3ef commit d2ae0e4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
6 changes: 3 additions & 3 deletions software/glasgow/applet/uart.py
@@ -1,7 +1,5 @@
import os
import sys
import atexit
import termios
import logging
import asyncio
from migen import *
Expand Down Expand Up @@ -84,6 +82,8 @@ def add_interact_arguments(cls, parser):

async def interact(self, device, args, uart):
if sys.stdin.isatty():
import atexit, termios

old_stdin_attrs = termios.tcgetattr(sys.stdin)
[iflag, oflag, cflag, lflag, ispeed, ospeed, cc] = old_stdin_attrs
lflag &= ~(termios.ECHO | termios.ICANON | termios.ISIG)
Expand All @@ -95,7 +95,7 @@ async def interact(self, device, args, uart):
def restore_stdin_attrs():
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_stdin_attrs)

self.logger.info("running on a TTY; enter `Ctrl+\\ q` to quit")
self.logger.info("running on a TTY; enter `Ctrl+\\ q` to quit")

quit = 0
stdin_fut = None
Expand Down
2 changes: 1 addition & 1 deletion software/glasgow/cli.py
Expand Up @@ -271,7 +271,7 @@ async def _main():
root_logger.setLevel(logging.INFO + args.quiet * 10 - args.verbose * 10)
handler = logging.StreamHandler()
formatter_args = {"fmt": "[{levelname:>8s}] {name:s}: {message:s}", "style": "{"}
if sys.stderr.isatty():
if sys.stderr.isatty() and sys.platform != 'win32'::
handler.setFormatter(ANSIColorFormatter(**formatter_args))
else:
handler.setFormatter(logging.Formatter(**formatter_args))
Expand Down
13 changes: 10 additions & 3 deletions software/glasgow/device/hardware.py
Expand Up @@ -60,7 +60,11 @@ def _open_device(self, vendor_id, product_id):
if self.usb is None:
raise GlasgowDeviceError("device {:04x}:{:04x} not found"
.format(vendor_id, product_id))
self.usb.setAutoDetachKernelDriver(True)

try:
self.usb.setAutoDetachKernelDriver(True)
except usb1.USBErrorNotSupported:
pass

def _write_ram(self, addr, data):
self.usb.controlWrite(usb1.REQUEST_TYPE_VENDOR, REQ_RAM, addr, 0, data)
Expand Down Expand Up @@ -101,8 +105,11 @@ def __init__(self, firmware_file=None, vendor_id=VID_QIHW, product_id=PID_GLASGO
if self.usb.getDevice().getbcdDevice() & 0xFF00 in (0x0000, 0xA000):
raise GlasgowDeviceError("firmware upload failed")

logger.debug("found device with serial %s",
self.usb.getDevice().getSerialNumber())
# https://github.com/vpelletier/python-libusb1/issues/39
# serial = self.usb.getDevice().getSerialNumber()
serial = self.usb.getASCIIStringDescriptor(
self.usb.getDevice().device_descriptor.iSerialNumber)
logger.debug("found device with serial %s", serial)

async def _do_transfer(self, is_read, setup):
transfer = self.usb.getTransfer()
Expand Down
22 changes: 17 additions & 5 deletions software/setup.py
@@ -1,20 +1,29 @@
import os
from os import path

from setuptools import setup, find_packages
from setuptools.command.build_ext import build_ext
from setuptools.command.bdist_egg import bdist_egg

from distutils import log
from distutils.spawn import spawn
from distutils.dir_util import mkpath
from distutils.errors import DistutilsExecError


class GlasgowBuildExt(build_ext):
def run(self):
firmware_dir = path.join("..", "firmware")
spawn(["make", "-C", path.join(firmware_dir)], dry_run=self.dry_run)
try:
firmware_dir = path.join("..", "firmware")
spawn(["make", "-C", path.join(firmware_dir)], dry_run=self.dry_run)

bootloader_ihex = path.join(firmware_dir, "glasgow.ihex")
self.copy_file(bootloader_ihex, "glasgow")
glasgow_ihex = path.join(firmware_dir, "glasgow.ihex")
self.copy_file(glasgow_ihex, "glasgow")
except DistutilsExecError as e:
if os.access(path.join("glasgow", "glasgow.ihex"), os.R_OK):
log.info("using prebuilt firmware")
else:
raise


class GlasgowBdistEgg(bdist_egg):
Expand All @@ -32,7 +41,10 @@ def run(self):
#description="TODO",
#long_description="""TODO""",
license="0-clause BSD License",
install_requires=["migen", "fx2"],
install_requires=["migen", "fx2>=0.6"],
depndency_links=[
"git+https://github.com/m-labs/migen.git#egg=migen",
],
packages=find_packages(),
package_data={"": ["*.ihex"]},
entry_points={
Expand Down
2 changes: 1 addition & 1 deletion vendor/libfx2

0 comments on commit d2ae0e4

Please sign in to comment.