Check if Microchip hybrid devices (Snap and PICkit 4) are not in AVR mode and report back to the user.

This commit is contained in:
Nav
2023-05-07 16:44:15 +01:00
parent 7bdc03116e
commit adcca0079d
7 changed files with 99 additions and 12 deletions

View File

@@ -1,5 +1,8 @@
#include "MplabPickit4.hpp"
#include "src/TargetController/Exceptions/DeviceNotFound.hpp"
#include "src/Services/PathService.hpp"
namespace Bloom::DebugToolDrivers
{
MplabPickit4::MplabPickit4()
@@ -9,4 +12,31 @@ namespace Bloom::DebugToolDrivers
MplabPickit4::CMSIS_HID_INTERFACE_NUMBER
)
{}
void MplabPickit4::init() {
using Exceptions::DeviceNotFound;
try {
EdbgDevice::init();
} catch (const DeviceNotFound& exception) {
/*
* The MPLAB PICkit 4 could be connected but not in AVR mode - if this is the case, inform the user and
* direct them to the AVR mode article.
*/
const auto nonEdbgDevices = this->findMatchingDevices(
MplabPickit4::NON_EDBG_USB_VENDOR_ID,
MplabPickit4::NON_EDBG_USB_PRODUCT_ID
);
if (!nonEdbgDevices.empty()) {
throw DeviceNotFound(
"The connected MPLAB PICkit 4 device is not in \"AVR mode\". Please follow the instructions at "
+ Services::PathService::homeDomainName() + "/docs/avr-mode"
);
}
throw exception;
}
}
}

View File

@@ -26,10 +26,15 @@ namespace Bloom::DebugToolDrivers
static const inline std::uint16_t USB_PRODUCT_ID = 0x2177;
static const inline std::uint8_t CMSIS_HID_INTERFACE_NUMBER = 0;
static const inline std::uint16_t NON_EDBG_USB_VENDOR_ID = 0x04d8;
static const inline std::uint16_t NON_EDBG_USB_PRODUCT_ID = 0x9012;
MplabPickit4();
std::string getName() override {
return "MPLAB PICkit 4";
}
void init() override;
};
}

View File

@@ -1,5 +1,8 @@
#include "MplabSnap.hpp"
#include "src/TargetController/Exceptions/DeviceNotFound.hpp"
#include "src/Services/PathService.hpp"
namespace Bloom::DebugToolDrivers
{
MplabSnap::MplabSnap()
@@ -9,4 +12,39 @@ namespace Bloom::DebugToolDrivers
MplabSnap::CMSIS_HID_INTERFACE_NUMBER
)
{}
void MplabSnap::init() {
using Exceptions::DeviceNotFound;
try {
EdbgDevice::init();
} catch (const DeviceNotFound& exception) {
/*
* The MPLAB Snap could be connected but not in AVR mode - if this is the case, inform the user and direct
* them to the AVR mode article.
*/
auto nonEdbgDevices = this->findMatchingDevices(
MplabSnap::NON_EDBG_USB_VENDOR_ID,
MplabSnap::NON_EDBG_USB_PRODUCT_ID
);
if (nonEdbgDevices.empty()) {
// The MPLAB Snap sometimes uses another product ID when not in AVR mode.
nonEdbgDevices = this->findMatchingDevices(
MplabSnap::NON_EDBG_USB_VENDOR_ID,
MplabSnap::NON_EDBG_USB_PRODUCT_ID_ALTERNATIVE
);
}
if (!nonEdbgDevices.empty()) {
throw DeviceNotFound(
"The connected MPLAB Snap device is not in \"AVR mode\". Please follow the instructions at "
+ Services::PathService::homeDomainName() + "/docs/avr-mode"
);
}
throw exception;
}
}
}

View File

@@ -28,10 +28,16 @@ namespace Bloom::DebugToolDrivers
static const inline std::uint16_t USB_PRODUCT_ID = 0x2180;
static const inline std::uint8_t CMSIS_HID_INTERFACE_NUMBER = 0;
static const inline std::uint16_t NON_EDBG_USB_VENDOR_ID = 0x04d8;
static const inline std::uint16_t NON_EDBG_USB_PRODUCT_ID = 0x9018;
static const inline std::uint16_t NON_EDBG_USB_PRODUCT_ID_ALTERNATIVE = 0x9017;
MplabSnap();
std::string getName() override {
return "MPLAB Snap";
}
void init() override;
};
}