Updated TDF pinout and pin extraction to align with new TDF format
This commit is contained in:
20
src/Targets/TargetDescription/Pin.hpp
Normal file
20
src/Targets/TargetDescription/Pin.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Targets::TargetDescription
|
||||
{
|
||||
struct Pin
|
||||
{
|
||||
std::string position;
|
||||
std::string pad;
|
||||
|
||||
Pin(
|
||||
const std::string& position,
|
||||
const std::string& pad
|
||||
)
|
||||
: position(position)
|
||||
, pad(pad)
|
||||
{}
|
||||
};
|
||||
}
|
||||
@@ -1,19 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "Pin.hpp"
|
||||
|
||||
#include "src/Targets/TargetPinoutDescriptor.hpp"
|
||||
|
||||
namespace Targets::TargetDescription
|
||||
{
|
||||
struct Pin
|
||||
{
|
||||
std::string pad;
|
||||
int position;
|
||||
};
|
||||
|
||||
struct Pinout
|
||||
{
|
||||
std::string key;
|
||||
std::string name;
|
||||
::Targets::PinoutType type;
|
||||
std::optional<std::string> function;
|
||||
std::vector<Pin> pins;
|
||||
|
||||
Pinout(
|
||||
const std::string& key,
|
||||
const std::string& name,
|
||||
::Targets::PinoutType type,
|
||||
const std::optional<std::string>& function,
|
||||
const std::vector<Pin>& pins
|
||||
)
|
||||
: key(key)
|
||||
, name(name)
|
||||
, type(type)
|
||||
, function(function)
|
||||
, pins(pins)
|
||||
{}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,11 +7,13 @@
|
||||
#include "src/Services/StringService.hpp"
|
||||
|
||||
#include "src/Targets/TargetMemory.hpp"
|
||||
#include "src/Targets/TargetPinoutDescriptor.hpp"
|
||||
#include "src/Helpers/BiMap.hpp"
|
||||
#include "src/Logger/Logger.hpp"
|
||||
|
||||
#include "src/Exceptions/Exception.hpp"
|
||||
#include "Exceptions/TargetDescriptionParsingFailureException.hpp"
|
||||
#include "Exceptions/InvalidTargetDescriptionDataException.hpp"
|
||||
|
||||
namespace Targets::TargetDescription
|
||||
{
|
||||
@@ -247,8 +249,16 @@ namespace Targets::TargetDescription
|
||||
);
|
||||
}
|
||||
|
||||
this->loadVariants(document);
|
||||
this->loadPinouts(document);
|
||||
for (
|
||||
auto element = deviceElement.firstChildElement("pinouts").firstChildElement("pinout");
|
||||
!element.isNull();
|
||||
element = element.nextSiblingElement("pinout")
|
||||
) {
|
||||
auto pinout = TargetDescriptionFile::pinoutFromXml(element);
|
||||
this->pinoutsByKey.insert(
|
||||
std::pair(pinout.key, std::move(pinout))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& TargetDescriptionFile::deviceAttribute(const std::string& attributeName) const {
|
||||
@@ -600,99 +610,50 @@ namespace Targets::TargetDescription
|
||||
);
|
||||
}
|
||||
|
||||
void TargetDescriptionFile::loadVariants(const QDomDocument& document) {
|
||||
const auto deviceElement = document.elementsByTagName("device").item(0).toElement();
|
||||
Pinout TargetDescriptionFile::pinoutFromXml(const QDomElement& xmlElement) {
|
||||
static const auto typesByName = BiMap<std::string, PinoutType>({
|
||||
{"soic", PinoutType::SOIC},
|
||||
{"ssop", PinoutType::SSOP},
|
||||
{"dip", PinoutType::DIP},
|
||||
{"qfn", PinoutType::QFN},
|
||||
{"mlf", PinoutType::MLF},
|
||||
{"drqfn", PinoutType::DUAL_ROW_QFN},
|
||||
{"qfp", PinoutType::QFP},
|
||||
{"bga", PinoutType::BGA},
|
||||
});
|
||||
|
||||
auto variantNodes = document.elementsByTagName("variants").item(0).toElement()
|
||||
.elementsByTagName("variant");
|
||||
const auto typeName = TargetDescriptionFile::getAttribute(xmlElement, "type");
|
||||
|
||||
for (int variantIndex = 0; variantIndex < variantNodes.count(); variantIndex++) {
|
||||
try {
|
||||
auto variantXml = variantNodes.item(variantIndex).toElement();
|
||||
|
||||
if (!variantXml.hasAttribute("name")) {
|
||||
throw Exception("Missing name attribute");
|
||||
}
|
||||
|
||||
if (!variantXml.hasAttribute("package")) {
|
||||
throw Exception("Missing package attribute");
|
||||
}
|
||||
|
||||
if (!variantXml.hasAttribute("pinout")) {
|
||||
throw Exception("Missing pinout attribute");
|
||||
}
|
||||
|
||||
auto variant = Variant();
|
||||
variant.name = variantXml.attribute("name").toStdString();
|
||||
variant.pinoutName = variantXml.attribute("pinout").toLower().toStdString();
|
||||
variant.package = variantXml.attribute("package").toUpper().toStdString();
|
||||
|
||||
if (variantXml.hasAttribute("disabled")) {
|
||||
variant.disabled = (variantXml.attribute("disabled") == "1");
|
||||
}
|
||||
|
||||
this->variants.push_back(variant);
|
||||
|
||||
} catch (const Exception& exception) {
|
||||
Logger::debug(
|
||||
"Failed to extract variant from target description element - " + exception.getMessage()
|
||||
);
|
||||
}
|
||||
const auto type = typesByName.valueAt(typeName);
|
||||
if (!type.has_value()) {
|
||||
throw InvalidTargetDescriptionDataException(
|
||||
"Failed to extract pinout from TDF - invalid pinout type name \"" + typeName + "\""
|
||||
);
|
||||
}
|
||||
|
||||
auto output = Pinout(
|
||||
TargetDescriptionFile::getAttribute(xmlElement, "key"),
|
||||
TargetDescriptionFile::getAttribute(xmlElement, "name"),
|
||||
*type,
|
||||
TargetDescriptionFile::tryGetAttribute(xmlElement, "function"),
|
||||
{}
|
||||
);
|
||||
|
||||
for (
|
||||
auto element = xmlElement.firstChildElement("pin");
|
||||
!element.isNull();
|
||||
element = element.nextSiblingElement("pin")
|
||||
) {
|
||||
output.pins.push_back(TargetDescriptionFile::pinFromXml(element));
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
void TargetDescriptionFile::loadPinouts(const QDomDocument& document) {
|
||||
const auto deviceElement = document.elementsByTagName("device").item(0).toElement();
|
||||
|
||||
auto pinoutNodes = document.elementsByTagName("pinouts").item(0).toElement()
|
||||
.elementsByTagName("pinout");
|
||||
|
||||
for (int pinoutIndex = 0; pinoutIndex < pinoutNodes.count(); pinoutIndex++) {
|
||||
try {
|
||||
auto pinoutXml = pinoutNodes.item(pinoutIndex).toElement();
|
||||
|
||||
if (!pinoutXml.hasAttribute("name")) {
|
||||
throw Exception("Missing name attribute");
|
||||
}
|
||||
|
||||
auto pinout = Pinout();
|
||||
pinout.name = pinoutXml.attribute("name").toLower().toStdString();
|
||||
|
||||
auto pinNodes = pinoutXml.elementsByTagName("pin");
|
||||
|
||||
for (int pinIndex = 0; pinIndex < pinNodes.count(); pinIndex++) {
|
||||
auto pinXml = pinNodes.item(pinIndex).toElement();
|
||||
|
||||
if (!pinXml.hasAttribute("position")) {
|
||||
throw Exception(
|
||||
"Missing position attribute on pin element " + std::to_string(pinIndex)
|
||||
);
|
||||
}
|
||||
|
||||
if (!pinXml.hasAttribute("pad")) {
|
||||
throw Exception("Missing pad attribute on pin element " + std::to_string(pinIndex));
|
||||
}
|
||||
|
||||
auto pin = Pin();
|
||||
bool positionConversionSucceeded = true;
|
||||
pin.position = pinXml.attribute("position").toInt(&positionConversionSucceeded, 10);
|
||||
pin.pad = pinXml.attribute("pad").toLower().toStdString();
|
||||
|
||||
if (!positionConversionSucceeded) {
|
||||
throw Exception("Failed to convert position attribute value to integer on pin element "
|
||||
+ std::to_string(pinIndex));
|
||||
}
|
||||
|
||||
pinout.pins.push_back(pin);
|
||||
}
|
||||
|
||||
this->pinoutsMappedByName.insert(std::pair(pinout.name, pinout));
|
||||
|
||||
} catch (const Exception& exception) {
|
||||
Logger::debug(
|
||||
"Failed to extract pinout from target description element - " + exception.getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
Pin TargetDescriptionFile::pinFromXml(const QDomElement& xmlElement) {
|
||||
return Pin(
|
||||
TargetDescriptionFile::getAttribute(xmlElement, "position"),
|
||||
TargetDescriptionFile::getAttribute(xmlElement, "pad")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "RegisterGroupInstance.hpp"
|
||||
#include "Signal.hpp"
|
||||
#include "Pinout.hpp"
|
||||
#include "Pin.hpp"
|
||||
#include "Variant.hpp"
|
||||
|
||||
#include "src/Targets/TargetFamily.hpp"
|
||||
@@ -109,9 +110,8 @@ namespace Targets::TargetDescription
|
||||
std::vector<PhysicalInterface> physicalInterfaces;
|
||||
std::map<std::string, Module, std::less<void>> modulesByKey;
|
||||
std::map<std::string, Peripheral, std::less<void>> peripheralsByKey;
|
||||
std::map<std::string, Pinout, std::less<void>> pinoutsByKey;
|
||||
std::map<std::string, std::vector<RegisterGroup>> peripheralRegisterGroupsMappedByModuleRegisterGroupName;
|
||||
std::vector<Variant> variants;
|
||||
std::map<std::string, Pinout> pinoutsMappedByName;
|
||||
|
||||
TargetDescriptionFile() = default;
|
||||
virtual ~TargetDescriptionFile() = default;
|
||||
@@ -144,15 +144,7 @@ namespace Targets::TargetDescription
|
||||
static Peripheral peripheralFromXml(const QDomElement& xmlElement);
|
||||
static RegisterGroupInstance registerGroupInstanceFromXml(const QDomElement& xmlElement);
|
||||
static Signal signalFromXml(const QDomElement& xmlElement);
|
||||
|
||||
/**
|
||||
* Extracts all variants and loads them into this->variants.
|
||||
*/
|
||||
void loadVariants(const QDomDocument& document);
|
||||
|
||||
/**
|
||||
* Extracts all pinouts and loads them into this->pinoutsMappedByName.
|
||||
*/
|
||||
void loadPinouts(const QDomDocument& document);
|
||||
static Pinout pinoutFromXml(const QDomElement& xmlElement);
|
||||
static Pin pinFromXml(const QDomElement& xmlElement);
|
||||
};
|
||||
}
|
||||
|
||||
18
src/Targets/TargetPinoutDescriptor.hpp
Normal file
18
src/Targets/TargetPinoutDescriptor.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Targets
|
||||
{
|
||||
enum class PinoutType: std::uint8_t
|
||||
{
|
||||
SOIC,
|
||||
SSOP,
|
||||
DIP,
|
||||
QFN,
|
||||
QFP,
|
||||
DUAL_ROW_QFN,
|
||||
MLF,
|
||||
BGA,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user