From 0808303311db3c269ef3082d10915e5ee3f695fc Mon Sep 17 00:00:00 2001 From: Nav Date: Tue, 17 May 2022 19:45:30 +0100 Subject: [PATCH] Moved EdbgAvr8Interface static inline functions to source file --- .../EDBG/AVR/EdbgAvr8Interface.cpp | 87 +++++++++++++++++ .../EDBG/AVR/EdbgAvr8Interface.hpp | 93 +------------------ 2 files changed, 92 insertions(+), 88 deletions(-) diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp index 6e5a8573..462bceb1 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp @@ -696,6 +696,93 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr if (response.getResponseId() == Avr8ResponseId::FAILED) { throw Avr8CommandFailure("Failed to leave programming mode on EDBG debug tool", response); } + + std::map> + EdbgAvr8Interface::getConfigVariantsByFamilyAndPhysicalInterface() { + return std::map>({ + { + Family::MEGA, + { + {PhysicalInterface::JTAG, Avr8ConfigVariant::MEGAJTAG}, + {PhysicalInterface::DEBUG_WIRE, Avr8ConfigVariant::DEBUG_WIRE}, + {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, + } + }, + { + Family::TINY, + { + {PhysicalInterface::JTAG, Avr8ConfigVariant::MEGAJTAG}, + {PhysicalInterface::DEBUG_WIRE, Avr8ConfigVariant::DEBUG_WIRE}, + {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, + } + }, + { + Family::XMEGA, + { + {PhysicalInterface::JTAG, Avr8ConfigVariant::XMEGA}, + {PhysicalInterface::PDI, Avr8ConfigVariant::XMEGA}, + } + }, + { + Family::DA, + { + {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, + } + }, + { + Family::DB, + { + {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, + } + }, + { + Family::DD, + { + {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, + } + }, + }); + } + + std::optional EdbgAvr8Interface::resolveConfigVariant() { + if (this->family.has_value()) { + auto configVariantsByFamily = EdbgAvr8Interface::getConfigVariantsByFamilyAndPhysicalInterface(); + + if (configVariantsByFamily.contains(this->family.value())) { + auto configVariantsByPhysicalInterface = configVariantsByFamily + .at(this->family.value()); + + if (configVariantsByPhysicalInterface.contains(this->targetConfig->physicalInterface)) { + return configVariantsByPhysicalInterface.at(this->targetConfig->physicalInterface); + } + } + + } else { + /* + * If there is no family set, we may be able to resort to a simpler mapping of physical interfaces + * to config variants. But this will only work if the selected physical interface is *NOT* JTAG. + * + * This is because JTAG is the only physical interface that could map to two different config + * variants (MEGAJTAG and XMEGA). The only way we can figure out which config variant to use is if we + * know the target family. + * + * This is why we don't allow users to use ambiguous target names (such as the generic "avr8" target + * name), when using the JTAG physical interface. We won't be able to resolve the correct target + * variant. Users are required to specify the exact target name in their config, when using the JTAG + * physical interface. That way, this->family will be set by the time resolveConfigVariant() is called. + */ + static std::map physicalInterfacesToConfigVariants = { + {PhysicalInterface::DEBUG_WIRE, Avr8ConfigVariant::DEBUG_WIRE}, + {PhysicalInterface::PDI, Avr8ConfigVariant::XMEGA}, + {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, + }; + + if (physicalInterfacesToConfigVariants.contains(this->targetConfig->physicalInterface)) { + return physicalInterfacesToConfigVariants.at(this->targetConfig->physicalInterface); + } + } + + return std::nullopt; } void EdbgAvr8Interface::setParameter(const Avr8EdbgParameter& parameter, const std::vector& value) { diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.hpp index b7bbe525..e7424b1e 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.hpp @@ -340,100 +340,17 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr * This mapping allows us to determine which config variant to select, based on the target family and the * selected physical interface. */ - static inline auto getConfigVariantsByFamilyAndPhysicalInterface() { - using Targets::Microchip::Avr::Avr8Bit::Family; - using Targets::Microchip::Avr::Avr8Bit::PhysicalInterface; - return std::map>({ - { - Family::MEGA, - { - {PhysicalInterface::JTAG, Avr8ConfigVariant::MEGAJTAG}, - {PhysicalInterface::DEBUG_WIRE, Avr8ConfigVariant::DEBUG_WIRE}, - {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, - } - }, - { - Family::TINY, - { - {PhysicalInterface::JTAG, Avr8ConfigVariant::MEGAJTAG}, - {PhysicalInterface::DEBUG_WIRE, Avr8ConfigVariant::DEBUG_WIRE}, - {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, - } - }, - { - Family::XMEGA, - { - {PhysicalInterface::JTAG, Avr8ConfigVariant::XMEGA}, - {PhysicalInterface::PDI, Avr8ConfigVariant::XMEGA}, - } - }, - { - Family::DA, - { - {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, - } - }, - { - Family::DB, - { - {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, - } - }, - { - Family::DD, - { - {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, - } - }, - }); - }; + static std::map< + Targets::Microchip::Avr::Avr8Bit::Family, + std::map + > getConfigVariantsByFamilyAndPhysicalInterface(); /** * Will attempt to resolve the config variant with the information currently held. * * @return */ - std::optional resolveConfigVariant() { - if (this->family.has_value()) { - auto configVariantsByFamily = EdbgAvr8Interface::getConfigVariantsByFamilyAndPhysicalInterface(); - - if (configVariantsByFamily.contains(this->family.value())) { - auto configVariantsByPhysicalInterface = configVariantsByFamily - .at(this->family.value()); - - if (configVariantsByPhysicalInterface.contains(this->targetConfig->physicalInterface)) { - return configVariantsByPhysicalInterface.at(this->targetConfig->physicalInterface); - } - } - - } else { - /* - * If there is no family set, we may be able to resort to a simpler mapping of physical interfaces - * to config variants. But this will only work if the selected physical interface is *NOT* JTAG. - * - * This is because JTAG is the only physical interface that could map to two different config - * variants (MEGAJTAG and XMEGA). The only way we can figure out which config variant to use is if we - * know the target family. - * - * This is why we don't allow users to use ambiguous target names (such as the generic "avr8" target - * name), when using the JTAG physical interface. We won't be able to resolve the correct target - * variant. Users are required to specify the exact target name in their config, when using the JTAG - * physical interface. That way, this->family will be set by the time resolveConfigVariant() is called. - */ - using Targets::Microchip::Avr::Avr8Bit::PhysicalInterface; - static std::map physicalInterfacesToConfigVariants = { - {PhysicalInterface::DEBUG_WIRE, Avr8ConfigVariant::DEBUG_WIRE}, - {PhysicalInterface::PDI, Avr8ConfigVariant::XMEGA}, - {PhysicalInterface::UPDI, Avr8ConfigVariant::UPDI}, - }; - - if (physicalInterfacesToConfigVariants.contains(this->targetConfig->physicalInterface)) { - return physicalInterfacesToConfigVariants.at(this->targetConfig->physicalInterface); - } - } - - return std::nullopt; - } + std::optional resolveConfigVariant(); /** * Sets an AVR8 parameter on the debug tool. See the Avr8EdbgParameters class and protocol documentation