From 45d7b284e3e76a11af49d909d4f8a87a9a20cb2a Mon Sep 17 00:00:00 2001 From: lady ada Date: Sat, 15 Jan 2022 20:57:36 -0500 Subject: [PATCH] 1) update CI to add zip on commit for quick testing 2) fix gw readflux command (should be 8 bytes long but was packed as 10) 3) add support for non-gw VID/PID (generic serial port that is gw compatible) 4) manually set/clear DTR on serial port devices - this seems to be essential for tinyusb/arduino CDC not tested with a gw but ought not to have broken anything! --- .github/workflows/ccpp.yml | 9 +++++++++ lib/usb/greaseweazleusb.cc | 2 +- lib/usb/serial.cc | 10 +++++++++- lib/usb/usb.cc | 4 +++- lib/usb/usbfinder.cc | 25 +++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 78543494..08f525f4 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -53,3 +53,12 @@ jobs: run: | make + - name: zip + run: | + zip -9 fluxengine.zip fluxengine.exe brother120tool.exe brother240tool.exe FluxEngine.cydsn/CortexM3/ARM_GCC_541/Release/FluxEngine.hex + + - name: Upload build artifacts + uses: actions/upload-artifact@v2 + with: + name: ${{ github.event.repository.name }}.${{ github.sha }} + path: fluxengine.zip diff --git a/lib/usb/greaseweazleusb.cc b/lib/usb/greaseweazleusb.cc index 5e7ede07..200199a9 100644 --- a/lib/usb/greaseweazleusb.cc +++ b/lib/usb/greaseweazleusb.cc @@ -131,7 +131,7 @@ public: .write_8(CMD_READ_FLUX) .write_8(cmd.size()) .write_le32(0) //ticks default value (guessed) - .write_le32(2);//guessed + .write_le16(2);//revolutions do_command(cmd); } } diff --git a/lib/usb/serial.cc b/lib/usb/serial.cc index 80efa83c..04773071 100644 --- a/lib/usb/serial.cc +++ b/lib/usb/serial.cc @@ -45,8 +45,16 @@ COMMTIMEOUTS commtimeouts = {0}; commtimeouts.ReadIntervalTimeout = 100; SetCommTimeouts(_handle, &commtimeouts); + + if (!EscapeCommFunction(_handle, CLRDTR)) + Error() << fmt::format("Couldn't clear DTR: {}", + get_last_error_string()); + Sleep(200); + if (!EscapeCommFunction(_handle, SETDTR)) + Error() << fmt::format("Couldn't set DTR: {}", + get_last_error_string()); - PurgeComm(_handle, PURGE_RXABORT|PURGE_RXCLEAR|PURGE_TXABORT|PURGE_TXCLEAR); + PurgeComm(_handle, PURGE_RXABORT|PURGE_RXCLEAR|PURGE_TXABORT|PURGE_TXCLEAR); } ~SerialPortImpl() override diff --git a/lib/usb/usb.cc b/lib/usb/usb.cc index 079272c7..2e54e66f 100644 --- a/lib/usb/usb.cc +++ b/lib/usb/usb.cc @@ -69,7 +69,9 @@ USB* get_usb_impl() return createGreaseWeazleUsb(candidate->serialPort, config.usb().greaseweazle()); default: - Error() << "internal"; + std::cerr << fmt::format("Using Unknown GW Compatible {} on {}\n", candidate->serial, candidate->serialPort); + GreaseWeazleProto gwconfig = config.usb().greaseweazle(); + return createGreaseWeazleUsb(candidate->serialPort, gwconfig ); } } diff --git a/lib/usb/usbfinder.cc b/lib/usb/usbfinder.cc index 95b74d76..557a383f 100644 --- a/lib/usb/usbfinder.cc +++ b/lib/usb/usbfinder.cc @@ -45,5 +45,30 @@ std::vector> findUsbDevices(const std::set(); + candidate->device = it; + uint32_t id = (it.get_vendor_id() << 16) | it.get_product_id(); + candidate->id = id; + candidate->serial = get_serial_number(it); + printf("USB ID %04x %04x: ", it.get_vendor_id(), it.get_product_id()); + try + { + libusbp::serial_port port(candidate->device, 0, true); + candidate->serialPort = port.get_name(); + printf("generic serialPort found\n"); + candidates.push_back(std::move(candidate)); + } + catch(const libusbp::error & error) + { + // not a serial port! + printf("not a port!\n"); + continue; + } + + } + } return candidates; }