From a32ea6e5f8d7e0bd9e93e110e098b52ea7e205db Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 1 Jan 2022 22:45:27 +0100 Subject: [PATCH] Add support for selecting the Shugart or IBMPC GreaseWeazle bus types. --- doc/greaseweazle.md | 2 ++ lib/usb/greaseweazleusb.cc | 13 ++++++++----- lib/usb/usb.cc | 2 +- lib/usb/usb.h | 3 ++- lib/usb/usb.proto | 13 +++++++++++++ 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/doc/greaseweazle.md b/doc/greaseweazle.md index 753dcbda..b1ba8f02 100644 --- a/doc/greaseweazle.md +++ b/doc/greaseweazle.md @@ -30,6 +30,8 @@ Supported features with the GreaseWeazle include: - simple reading and writing of disks, seeking etc - erasing disks - determining disk rotation speed + - both Shugart and normal IBM buses (via + `--usb.greaseweazle.bus_type=SHUGART` or `IBMPC`; the default is `IBMPC`) What doesn't work ----------------- diff --git a/lib/usb/greaseweazleusb.cc b/lib/usb/greaseweazleusb.cc index 9d3efe07..5e7ede07 100644 --- a/lib/usb/greaseweazleusb.cc +++ b/lib/usb/greaseweazleusb.cc @@ -4,6 +4,7 @@ #include "fluxmap.h" #include "bytes.h" #include "fmt/format.h" +#include "lib/usb/usb.pb.h" #include "greaseweazle.h" #include "serial.h" @@ -61,8 +62,9 @@ private: } public: - GreaseWeazleUsb(const std::string& port): - _serial(SerialPort::openSerialPort(port)) + GreaseWeazleUsb(const std::string& port, const GreaseWeazleProto& config): + _serial(SerialPort::openSerialPort(port)), + _config(config) { int version = getVersion(); if (version >= 29) @@ -79,7 +81,7 @@ public: /* Configure the hardware. */ - do_command({ CMD_SET_BUS_TYPE, 3, BUS_IBMPC }); + do_command({ CMD_SET_BUS_TYPE, 3, (uint8_t)config.bus_type() }); } int getVersion() @@ -384,14 +386,15 @@ private: }; std::unique_ptr _serial; + const GreaseWeazleProto& _config; int _version; nanoseconds_t _clock; nanoseconds_t _revolutions; }; -USB* createGreaseWeazleUsb(const std::string& port) +USB* createGreaseWeazleUsb(const std::string& port, const GreaseWeazleProto& config) { - return new GreaseWeazleUsb(port); + return new GreaseWeazleUsb(port, config); } // vim: sw=4 ts=4 et diff --git a/lib/usb/usb.cc b/lib/usb/usb.cc index 32e6acae..079272c7 100644 --- a/lib/usb/usb.cc +++ b/lib/usb/usb.cc @@ -66,7 +66,7 @@ USB* get_usb_impl() case GREASEWEAZLE_ID: std::cerr << fmt::format("Using GreaseWeazle {} on {}\n", candidate->serial, candidate->serialPort); - return createGreaseWeazleUsb(candidate->serialPort); + return createGreaseWeazleUsb(candidate->serialPort, config.usb().greaseweazle()); default: Error() << "internal"; diff --git a/lib/usb/usb.h b/lib/usb/usb.h index 28605770..f76baad8 100644 --- a/lib/usb/usb.h +++ b/lib/usb/usb.h @@ -5,6 +5,7 @@ #include "flags.h" class Fluxmap; +class GreaseWeazleProto; namespace libusbp { class device; } class USB @@ -33,7 +34,7 @@ protected: extern USB& getUsb(); extern USB* createFluxengineUsb(libusbp::device& device); -extern USB* createGreaseWeazleUsb(const std::string& serialPort); +extern USB* createGreaseWeazleUsb(const std::string& serialPort, const GreaseWeazleProto& config); static inline int usbGetVersion() { return getUsb().getVersion(); } static inline void usbRecalibrate() { getUsb().recalibrate(); } diff --git a/lib/usb/usb.proto b/lib/usb/usb.proto index f78f5fd2..f3d7c4b7 100644 --- a/lib/usb/usb.proto +++ b/lib/usb/usb.proto @@ -2,9 +2,22 @@ syntax = "proto2"; import "lib/common.proto"; +message GreaseWeazleProto { + enum BusType { + BUSTYPE_INVALID = 0; + IBMPC = 1; + SHUGART = 2; + }; + + optional BusType bus_type = 1 + [(help) = "which FDD bus type is in use", default = IBMPC]; +} + message UsbProto { oneof device { string serial = 1 [(help) = "serial number of FluxEngine or GreaseWeazle device to use"]; } + + optional GreaseWeazleProto greaseweazle = 2 [(help) = "GreaseWeazle-specific options"]; }