Tidying WCH-LinkE IAP exit code
This commit is contained in:
@@ -49,7 +49,6 @@ namespace Usb
|
||||
};
|
||||
}
|
||||
|
||||
// For now, just use the first device found.
|
||||
this->libusbDevice.swap(devices.front());
|
||||
::libusb_device_handle* deviceHandle = nullptr;
|
||||
|
||||
@@ -120,6 +119,10 @@ namespace Usb
|
||||
return device;
|
||||
}
|
||||
|
||||
bool UsbDevice::devicePresent(std::uint16_t vendorId, std::uint16_t productId) {
|
||||
return !UsbDevice::findMatchingDevices(vendorId, productId).empty();
|
||||
}
|
||||
|
||||
bool UsbDevice::waitForDevice(std::uint16_t vendorId, std::uint16_t productId, std::chrono::milliseconds timeout) {
|
||||
static constexpr auto DELAY = std::chrono::milliseconds{50};
|
||||
for (auto i = 0; (i * DELAY) <= timeout; ++i){
|
||||
|
||||
@@ -69,6 +69,7 @@ namespace Usb
|
||||
virtual void setConfiguration(std::uint8_t configurationIndex);
|
||||
|
||||
static std::optional<UsbDevice> tryDevice(std::uint16_t vendorId, std::uint16_t productId);
|
||||
static bool devicePresent(std::uint16_t vendorId, std::uint16_t productId);
|
||||
static bool waitForDevice(std::uint16_t vendorId, std::uint16_t productId, std::chrono::milliseconds timeout);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "Protocols/WchLink/WchLinkInterface.hpp"
|
||||
|
||||
#include "src/TargetController/Exceptions/DeviceNotFound.hpp"
|
||||
#include "src/TargetController/Exceptions/DeviceInitializationFailure.hpp"
|
||||
|
||||
#include "src/Logger/Logger.hpp"
|
||||
@@ -31,25 +30,10 @@ namespace DebugToolDrivers::Wch
|
||||
{}
|
||||
|
||||
void WchLinkBase::init() {
|
||||
using Exceptions::DeviceNotFound;
|
||||
|
||||
try {
|
||||
UsbDevice::init();
|
||||
|
||||
} catch (const DeviceNotFound& exception) {
|
||||
if (this->toolConfig.exitIapMode && !UsbDevice::devicePresent(this->vendorId, this->productId)) {
|
||||
auto iapDevice = Usb::UsbDevice::tryDevice(this->iapVendorId, this->iapProductId);
|
||||
|
||||
if (!iapDevice.has_value()) {
|
||||
throw exception;
|
||||
}
|
||||
|
||||
if (!this->toolConfig.exitIapMode) {
|
||||
throw DeviceInitializationFailure{
|
||||
"Device found in IAP mode - Bloom can have the device exit this mode - see the 'exit_iap_mode' "
|
||||
"tool config parameter, for more"
|
||||
};
|
||||
}
|
||||
|
||||
if (iapDevice.has_value()) {
|
||||
Logger::warning("Found device in IAP mode - attempting exit operation");
|
||||
this->exitIapMode(*iapDevice);
|
||||
|
||||
@@ -59,8 +43,10 @@ namespace DebugToolDrivers::Wch
|
||||
}
|
||||
|
||||
Logger::info("Re-enumerated device found - IAP exit operation was successful");
|
||||
UsbDevice::init();
|
||||
}
|
||||
}
|
||||
|
||||
UsbDevice::init();
|
||||
|
||||
this->detachKernelDriverFromInterface(this->wchLinkUsbInterfaceNumber);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user