Lots of tidying
This commit is contained in:
@@ -454,12 +454,14 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
||||
}
|
||||
|
||||
std::map<int, TargetPinState> Avr8::getPinStates(int variantId) {
|
||||
if (!this->targetVariantsById.contains(variantId)) {
|
||||
const auto targetVariantIt = this->targetVariantsById.find(variantId);
|
||||
|
||||
if (targetVariantIt == this->targetVariantsById.end()) {
|
||||
throw Exception("Invalid target variant ID");
|
||||
}
|
||||
|
||||
std::map<int, TargetPinState> output;
|
||||
auto& variant = this->targetVariantsById.at(variantId);
|
||||
const auto& variant = targetVariantIt->second;
|
||||
|
||||
/*
|
||||
* To prevent the number of memory reads we perform here, we cache the data and map it by start address.
|
||||
@@ -471,24 +473,28 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
||||
* will be considered when the need for it becomes apparent.
|
||||
*/
|
||||
std::map<std::uint16_t, TargetMemoryBuffer> cachedMemoryByStartAddress;
|
||||
auto readMemoryBitset = [this, &cachedMemoryByStartAddress] (std::uint16_t startAddress) {
|
||||
if (!cachedMemoryByStartAddress.contains(startAddress)) {
|
||||
cachedMemoryByStartAddress.insert(
|
||||
const auto readMemoryBitset = [this, &cachedMemoryByStartAddress] (std::uint16_t startAddress) {
|
||||
auto cachedByteIt = cachedMemoryByStartAddress.find(startAddress);
|
||||
|
||||
if (cachedByteIt == cachedMemoryByStartAddress.end()) {
|
||||
cachedByteIt = cachedMemoryByStartAddress.insert(
|
||||
std::pair(
|
||||
startAddress,
|
||||
this->readMemory(TargetMemoryType::RAM, startAddress, 1)
|
||||
)
|
||||
);
|
||||
).first;
|
||||
}
|
||||
|
||||
return std::bitset<std::numeric_limits<unsigned char>::digits>(
|
||||
cachedMemoryByStartAddress.at(startAddress).at(0)
|
||||
cachedByteIt->second.at(0)
|
||||
);
|
||||
};
|
||||
|
||||
for (const auto& [pinNumber, pinDescriptor] : variant.pinDescriptorsByNumber) {
|
||||
if (this->padDescriptorsByName.contains(pinDescriptor.padName)) {
|
||||
auto& pad = this->padDescriptorsByName.at(pinDescriptor.padName);
|
||||
const auto padIt = this->padDescriptorsByName.find(pinDescriptor.padName);
|
||||
|
||||
if (padIt != this->padDescriptorsByName.end()) {
|
||||
const auto& pad = padIt->second;
|
||||
|
||||
if (!pad.gpioPinNumber.has_value()) {
|
||||
continue;
|
||||
@@ -526,12 +532,15 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
||||
}
|
||||
|
||||
void Avr8::setPinState(const TargetPinDescriptor& pinDescriptor, const TargetPinState& state) {
|
||||
auto variantId = pinDescriptor.variantId;
|
||||
if (!this->targetVariantsById.contains(variantId)) {
|
||||
const auto targetVariantIt = this->targetVariantsById.find(pinDescriptor.variantId);
|
||||
|
||||
if (targetVariantIt == this->targetVariantsById.end()) {
|
||||
throw Exception("Invalid target variant ID");
|
||||
}
|
||||
|
||||
if (!this->padDescriptorsByName.contains(pinDescriptor.padName)) {
|
||||
const auto padDescriptorIt = this->padDescriptorsByName.find(pinDescriptor.padName);
|
||||
|
||||
if (padDescriptorIt == this->padDescriptorsByName.end()) {
|
||||
throw Exception("Unknown pad");
|
||||
}
|
||||
|
||||
@@ -539,8 +548,8 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
||||
throw Exception("Missing IO direction state");
|
||||
}
|
||||
|
||||
const auto& variant = this->targetVariantsById.at(variantId);
|
||||
const auto& padDescriptor = this->padDescriptorsByName.at(pinDescriptor.padName);
|
||||
const auto& variant = targetVariantIt->second;
|
||||
const auto& padDescriptor = padDescriptorIt->second;
|
||||
auto ioState = state.ioState;
|
||||
|
||||
if (state.ioDirection == TargetPinState::IoDirection::INPUT) {
|
||||
|
||||
@@ -28,8 +28,10 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
||||
{
|
||||
public:
|
||||
explicit Avr8() = default;
|
||||
Avr8(std::string name, const TargetSignature& signature): name(std::move(name)) {
|
||||
this->id = signature;
|
||||
Avr8(std::string name, const TargetSignature& signature)
|
||||
: name(std::move(name))
|
||||
, Target(signature)
|
||||
{
|
||||
this->initFromTargetDescriptionFile();
|
||||
};
|
||||
|
||||
|
||||
@@ -18,8 +18,11 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
||||
}
|
||||
|
||||
const auto physicalInterfaceName = String::asciiToLower(targetNode["physicalInterface"].as<std::string>());
|
||||
const auto physicalInterfaceIt = Avr8TargetConfig::debugPhysicalInterfacesByConfigName.find(
|
||||
physicalInterfaceName
|
||||
);
|
||||
|
||||
if (!Avr8TargetConfig::debugPhysicalInterfacesByConfigName.contains(physicalInterfaceName)) {
|
||||
if (physicalInterfaceIt == Avr8TargetConfig::debugPhysicalInterfacesByConfigName.end()) {
|
||||
throw InvalidConfig(
|
||||
"Invalid physical interface provided (\"" + physicalInterfaceName + "\") for AVR8 target. "
|
||||
"See " + Paths::homeDomainName() + "/docs/configuration/avr8-physical-interfaces for valid physical "
|
||||
@@ -27,7 +30,7 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit
|
||||
);
|
||||
}
|
||||
|
||||
this->physicalInterface = Avr8TargetConfig::debugPhysicalInterfacesByConfigName.at(physicalInterfaceName);
|
||||
this->physicalInterface = physicalInterfaceIt->second;
|
||||
|
||||
// The 'manageDwenFuseBit' param used to be 'updateDwenFuseBit' - we still support the old, for now.
|
||||
if (targetNode["updateDwenFuseBit"]) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,9 @@ namespace Bloom::Targets::Microchip::Avr
|
||||
class Target: public ::Bloom::Targets::Target
|
||||
{
|
||||
public:
|
||||
explicit Target() = default;
|
||||
explicit Target(std::optional<TargetSignature> id = std::nullopt)
|
||||
: id(id)
|
||||
{};
|
||||
|
||||
std::string getHumanReadableId() override {
|
||||
return this->getId().toHex();
|
||||
@@ -21,10 +23,6 @@ namespace Bloom::Targets::Microchip::Avr
|
||||
protected:
|
||||
std::optional<TargetSignature> id;
|
||||
|
||||
virtual void setId(const TargetSignature& id) {
|
||||
this->id = id;
|
||||
}
|
||||
|
||||
virtual TargetSignature getId() = 0;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user