Began implementation of WCH-Link protocol, for the WCH-LinkE debug tool.

Foundations have been laid.
This commit is contained in:
Nav
2023-11-18 22:58:48 +00:00
parent 210552de4f
commit 221d931add
15 changed files with 445 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
#include "WchLinkBase.hpp"
#include "Protocols/WchLink/Commands/Control/GetDeviceInfo.hpp"
#include "src/TargetController/Exceptions/DeviceFailure.hpp"
#include "src/TargetController/Exceptions/DeviceInitializationFailure.hpp"
#include "src/Logger/Logger.hpp"
namespace DebugToolDrivers::Wch
{
using Exceptions::DeviceFailure;
using Exceptions::DeviceInitializationFailure;
WchLinkBase::WchLinkBase(
WchLinkVariant variant,
std::uint16_t vendorId,
std::uint16_t productId,
std::uint8_t wchLinkUsbInterfaceNumber
)
: UsbDevice(vendorId, productId)
, variant(variant)
, wchLinkUsbInterfaceNumber(wchLinkUsbInterfaceNumber)
{}
void WchLinkBase::init() {
UsbDevice::init();
this->detachKernelDriverFromInterface(this->wchLinkUsbInterfaceNumber);
this->wchLinkUsbInterface = std::make_unique<Usb::UsbInterface>(
this->wchLinkUsbInterfaceNumber,
this->libusbDeviceHandle.get()
);
this->wchLinkUsbInterface->init();
this->wchLinkInterface = std::make_unique<Protocols::WchLink::WchLinkInterface>(
*(this->wchLinkUsbInterface.get())
);
if (this->getDeviceInfo().variant != this->variant) {
throw DeviceInitializationFailure(
"WCH-Link variant mismatch - device returned variant ID that doesn't match the " + this->getName()
+ " variant ID"
);
}
this->setInitialised(true);
}
void WchLinkBase::close() {
if (this->wchLinkUsbInterface) {
this->wchLinkUsbInterface->close();
}
}
std::string WchLinkBase::getSerialNumber() {
return UsbDevice::getSerialNumber();
}
const DeviceInfo& WchLinkBase::getDeviceInfo() const {
if (!this->cachedDeviceInfo.has_value()) {
this->cachedDeviceInfo = this->wchLinkInterface->getDeviceInfo();
}
return *(this->cachedDeviceInfo);
}
}