diff --git a/src/Services/TargetControllerService.cpp b/src/Services/TargetControllerService.cpp index abd75505..023828d0 100644 --- a/src/Services/TargetControllerService.cpp +++ b/src/Services/TargetControllerService.cpp @@ -18,8 +18,8 @@ #include "src/TargetController/Commands/RemoveBreakpoint.hpp" #include "src/TargetController/Commands/SetTargetProgramCounter.hpp" #include "src/TargetController/Commands/SetTargetStackPointer.hpp" -#include "src/TargetController/Commands/GetTargetGpioPinStates.hpp" -#include "src/TargetController/Commands/SetTargetGpioPinState.hpp" +#include "src/TargetController/Commands/GetTargetGpioPadStates.hpp" +#include "src/TargetController/Commands/SetTargetGpioPadState.hpp" #include "src/TargetController/Commands/GetTargetStackPointer.hpp" #include "src/TargetController/Commands/GetTargetProgramCounter.hpp" #include "src/TargetController/Commands/EnableProgrammingMode.hpp" @@ -47,8 +47,8 @@ namespace Services using TargetController::Commands::RemoveBreakpoint; using TargetController::Commands::SetTargetProgramCounter; using TargetController::Commands::SetTargetStackPointer; - using TargetController::Commands::GetTargetGpioPinStates; - using TargetController::Commands::SetTargetGpioPinState; + using TargetController::Commands::GetTargetGpioPadStates; + using TargetController::Commands::SetTargetGpioPadState; using TargetController::Commands::GetTargetStackPointer; using TargetController::Commands::GetTargetProgramCounter; using TargetController::Commands::EnableProgrammingMode; @@ -74,8 +74,8 @@ namespace Services using Targets::TargetPinoutDescriptor; using Targets::TargetPinDescriptor; - using Targets::TargetGpioPinState; - using Targets::TargetGpioPinDescriptorAndStatePairs; + using Targets::TargetGpioPadState; + using Targets::TargetGpioPadDescriptorAndStatePairs; TargetControllerService::AtomicSession::AtomicSession(TargetControllerService& targetControllerService) : targetControllerService(targetControllerService) @@ -270,22 +270,22 @@ namespace Services ); } - TargetGpioPinDescriptorAndStatePairs TargetControllerService::getGpioPinStates( - const TargetPinoutDescriptor& pinoutDescriptor + TargetGpioPadDescriptorAndStatePairs TargetControllerService::getGpioPadStates( + const Targets::TargetPadDescriptors& padDescriptors ) const { return this->commandManager.sendCommandAndWaitForResponse( - std::make_unique(pinoutDescriptor), + std::make_unique(padDescriptors), this->defaultTimeout, this->activeAtomicSessionId - )->gpioPinStates; + )->gpioPadStates; } - void TargetControllerService::setGpioPinState( - const TargetPinDescriptor& pinDescriptor, - const TargetGpioPinState& state + void TargetControllerService::setGpioPadState( + const Targets::TargetPadDescriptor& padDescriptor, + const TargetGpioPadState& state ) const { this->commandManager.sendCommandAndWaitForResponse( - std::make_unique(pinDescriptor, state), + std::make_unique(padDescriptor, state), this->defaultTimeout, this->activeAtomicSessionId ); diff --git a/src/Services/TargetControllerService.hpp b/src/Services/TargetControllerService.hpp index b3996047..6603fa37 100644 --- a/src/Services/TargetControllerService.hpp +++ b/src/Services/TargetControllerService.hpp @@ -16,8 +16,8 @@ #include "src/Targets/TargetRegisterGroupDescriptor.hpp" #include "src/Targets/TargetRegisterDescriptor.hpp" #include "src/Targets/TargetPinoutDescriptor.hpp" -#include "src/Targets/TargetPinDescriptor.hpp" -#include "src/Targets/TargetGpioPinState.hpp" +#include "src/Targets/TargetPadDescriptor.hpp" +#include "src/Targets/TargetGpioPadState.hpp" #include "src/Targets/TargetMemory.hpp" #include "src/Targets/TargetBreakpoint.hpp" @@ -205,23 +205,23 @@ namespace Services void setProgramCounter(Targets::TargetMemoryAddress address) const; /** - * Retrieves the pin states for a particular target variant. + * Retrieves the GPIO states for the given GPIO pads. * - * @param pinoutDescriptor + * @param padDescriptors */ - Targets::TargetGpioPinDescriptorAndStatePairs getGpioPinStates( - const Targets::TargetPinoutDescriptor& pinoutDescriptor + Targets::TargetGpioPadDescriptorAndStatePairs getGpioPadStates( + const Targets::TargetPadDescriptors& padDescriptors ) const; /** * Updates the pin state on the target, for a specific pin. * - * @param pinDescriptor + * @param padDescriptor * @param state */ - void setGpioPinState( - const Targets::TargetPinDescriptor& pinDescriptor, - const Targets::TargetGpioPinState& state + void setGpioPadState( + const Targets::TargetPadDescriptor& padDescriptor, + const Targets::TargetGpioPadState& state ) const; /** diff --git a/src/TargetController/Commands/CommandTypes.hpp b/src/TargetController/Commands/CommandTypes.hpp index 615c52b2..3a8a6bfc 100644 --- a/src/TargetController/Commands/CommandTypes.hpp +++ b/src/TargetController/Commands/CommandTypes.hpp @@ -25,8 +25,8 @@ namespace TargetController::Commands REMOVE_BREAKPOINT, SET_TARGET_PROGRAM_COUNTER, SET_TARGET_STACK_POINTER, - GET_TARGET_GPIO_PIN_STATES, - SET_TARGET_GPIO_PIN_STATE, + GET_TARGET_GPIO_PAD_STATES, + SET_TARGET_GPIO_PAD_STATE, GET_TARGET_STACK_POINTER, GET_TARGET_PROGRAM_COUNTER, ENABLE_PROGRAMMING_MODE, diff --git a/src/TargetController/Commands/GetTargetGpioPadStates.hpp b/src/TargetController/Commands/GetTargetGpioPadStates.hpp new file mode 100644 index 00000000..1d3235d9 --- /dev/null +++ b/src/TargetController/Commands/GetTargetGpioPadStates.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include "Command.hpp" + +#include "src/TargetController/Responses/TargetGpioPadStates.hpp" +#include "src/Targets/TargetPadDescriptor.hpp" + +namespace TargetController::Commands +{ + class GetTargetGpioPadStates: public Command + { + public: + using SuccessResponseType = Responses::TargetGpioPadStates; + + static constexpr CommandType type = CommandType::GET_TARGET_GPIO_PAD_STATES; + static const inline std::string name = "GetTargetGpioPadStates"; + + const Targets::TargetPadDescriptors padDescriptors; + + explicit GetTargetGpioPadStates(const Targets::TargetPadDescriptors& padDescriptors) + : padDescriptors(padDescriptors) + {}; + + [[nodiscard]] CommandType getType() const override { + return GetTargetGpioPadStates::type; + } + + [[nodiscard]] bool requiresStoppedTargetState() const override { + return true; + } + }; +} diff --git a/src/TargetController/Commands/GetTargetGpioPinStates.hpp b/src/TargetController/Commands/GetTargetGpioPinStates.hpp deleted file mode 100644 index 3d04a91f..00000000 --- a/src/TargetController/Commands/GetTargetGpioPinStates.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include "Command.hpp" - -#include "src/TargetController/Responses/TargetGpioPinStates.hpp" - -namespace TargetController::Commands -{ - class GetTargetGpioPinStates: public Command - { - public: - using SuccessResponseType = Responses::TargetGpioPinStates; - - static constexpr CommandType type = CommandType::GET_TARGET_GPIO_PIN_STATES; - static const inline std::string name = "GetTargetGpioPinStates"; - - const Targets::TargetPinoutDescriptor& pinoutDescriptor; - - explicit GetTargetGpioPinStates(const Targets::TargetPinoutDescriptor& pinoutDescriptor) - : pinoutDescriptor(pinoutDescriptor) - {}; - - [[nodiscard]] CommandType getType() const override { - return GetTargetGpioPinStates::type; - } - - [[nodiscard]] bool requiresStoppedTargetState() const override { - return true; - } - }; -} diff --git a/src/TargetController/Commands/SetTargetGpioPadState.hpp b/src/TargetController/Commands/SetTargetGpioPadState.hpp new file mode 100644 index 00000000..684282a2 --- /dev/null +++ b/src/TargetController/Commands/SetTargetGpioPadState.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include "Command.hpp" + +#include "src/Targets/TargetPadDescriptor.hpp" +#include "src/Targets/TargetGpioPadState.hpp" + +namespace TargetController::Commands +{ + class SetTargetGpioPadState: public Command + { + public: + static constexpr CommandType type = CommandType::SET_TARGET_GPIO_PAD_STATE; + static const inline std::string name = "SetTargetGpioPadState"; + + const Targets::TargetPadDescriptor& padDescriptor; + Targets::TargetGpioPadState state; + + SetTargetGpioPadState( + const Targets::TargetPadDescriptor& padDescriptor, + const Targets::TargetGpioPadState& state + ) + : padDescriptor(padDescriptor) + , state(state) + {}; + + [[nodiscard]] CommandType getType() const override { + return SetTargetGpioPadState::type; + } + + [[nodiscard]] bool requiresStoppedTargetState() const override { + return true; + } + }; +} diff --git a/src/TargetController/Commands/SetTargetGpioPinState.hpp b/src/TargetController/Commands/SetTargetGpioPinState.hpp deleted file mode 100644 index 014372fa..00000000 --- a/src/TargetController/Commands/SetTargetGpioPinState.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "Command.hpp" - -#include "src/Targets/TargetPinDescriptor.hpp" -#include "src/Targets/TargetGpioPinState.hpp" - -namespace TargetController::Commands -{ - class SetTargetGpioPinState: public Command - { - public: - static constexpr CommandType type = CommandType::SET_TARGET_GPIO_PIN_STATE; - static const inline std::string name = "SetTargetGpioPinState"; - - const Targets::TargetPinDescriptor& pinDescriptor; - Targets::TargetGpioPinState state; - - SetTargetGpioPinState( - const Targets::TargetPinDescriptor& pinDescriptor, - const Targets::TargetGpioPinState& state - ) - : pinDescriptor(pinDescriptor) - , state(state) - {}; - - [[nodiscard]] CommandType getType() const override { - return SetTargetGpioPinState::type; - } - - [[nodiscard]] bool requiresStoppedTargetState() const override { - return true; - } - }; -} diff --git a/src/TargetController/Responses/ResponseTypes.hpp b/src/TargetController/Responses/ResponseTypes.hpp index bfb1cdb0..06ec44df 100644 --- a/src/TargetController/Responses/ResponseTypes.hpp +++ b/src/TargetController/Responses/ResponseTypes.hpp @@ -13,7 +13,7 @@ namespace TargetController::Responses TARGET_REGISTERS_READ, TARGET_MEMORY_READ, TARGET_STATE, - TARGET_GPIO_PIN_STATES, + TARGET_GPIO_PAD_STATES, TARGET_STACK_POINTER, TARGET_PROGRAM_COUNTER, BREAKPOINT, diff --git a/src/TargetController/Responses/TargetGpioPadStates.hpp b/src/TargetController/Responses/TargetGpioPadStates.hpp new file mode 100644 index 00000000..655a7aae --- /dev/null +++ b/src/TargetController/Responses/TargetGpioPadStates.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include + +#include "Response.hpp" + +#include "src/Targets/TargetPinDescriptor.hpp" +#include "src/Targets/TargetGpioPadState.hpp" + +#include "src/Helpers/Pair.hpp" + +namespace TargetController::Responses +{ + class TargetGpioPadStates: public Response + { + public: + static constexpr ResponseType type = ResponseType::TARGET_GPIO_PAD_STATES; + + Targets::TargetGpioPadDescriptorAndStatePairs gpioPadStates; + + explicit TargetGpioPadStates(const Targets::TargetGpioPadDescriptorAndStatePairs& gpioPadStates) + : gpioPadStates(gpioPadStates) + {} + + [[nodiscard]] ResponseType getType() const override { + return TargetGpioPadStates::type; + } + }; +} diff --git a/src/TargetController/Responses/TargetGpioPinStates.hpp b/src/TargetController/Responses/TargetGpioPinStates.hpp deleted file mode 100644 index e2bd851b..00000000 --- a/src/TargetController/Responses/TargetGpioPinStates.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include - -#include "Response.hpp" - -#include "src/Targets/TargetPinDescriptor.hpp" -#include "src/Targets/TargetGpioPinState.hpp" - -#include "src/Helpers/Pair.hpp" - -namespace TargetController::Responses -{ - class TargetGpioPinStates: public Response - { - public: - static constexpr ResponseType type = ResponseType::TARGET_GPIO_PIN_STATES; - - Targets::TargetGpioPinDescriptorAndStatePairs gpioPinStates; - - explicit TargetGpioPinStates(const Targets::TargetGpioPinDescriptorAndStatePairs& gpioPinStates) - : gpioPinStates(gpioPinStates) - {} - - [[nodiscard]] ResponseType getType() const override { - return TargetGpioPinStates::type; - } - }; -} diff --git a/src/TargetController/TargetControllerComponent.cpp b/src/TargetController/TargetControllerComponent.cpp index 5a7928bb..b9ccea3c 100644 --- a/src/TargetController/TargetControllerComponent.cpp +++ b/src/TargetController/TargetControllerComponent.cpp @@ -44,8 +44,8 @@ namespace TargetController using Commands::RemoveBreakpoint; using Commands::SetTargetProgramCounter; using Commands::SetTargetStackPointer; - using Commands::GetTargetGpioPinStates; - using Commands::SetTargetGpioPinState; + using Commands::GetTargetGpioPadStates; + using Commands::SetTargetGpioPadState; using Commands::GetTargetStackPointer; using Commands::GetTargetProgramCounter; using Commands::EnableProgrammingMode; @@ -55,7 +55,7 @@ namespace TargetController using Responses::AtomicSessionId; using Responses::TargetRegistersRead; using Responses::TargetMemoryRead; - using Responses::TargetGpioPinStates; + using Responses::TargetGpioPadStates; using Responses::TargetStackPointer; using Responses::TargetProgramCounter; using Responses::Breakpoint; @@ -233,12 +233,12 @@ namespace TargetController std::bind(&TargetControllerComponent::handleSetProgramCounter, this, std::placeholders::_1) ); - this->registerCommandHandler( - std::bind(&TargetControllerComponent::handleGetTargetGpioPinStates, this, std::placeholders::_1) + this->registerCommandHandler( + std::bind(&TargetControllerComponent::handleGetTargetGpioPadStates, this, std::placeholders::_1) ); - this->registerCommandHandler( - std::bind(&TargetControllerComponent::handleSetTargetGpioPinState, this, std::placeholders::_1) + this->registerCommandHandler( + std::bind(&TargetControllerComponent::handleSetTargetGpioPadState, this, std::placeholders::_1) ); this->registerCommandHandler( @@ -1007,7 +1007,7 @@ namespace TargetController return std::make_unique(); } - std::unique_ptr TargetControllerComponent::handleStepTargetExecution(StepTargetExecution& command) { + std::unique_ptr TargetControllerComponent::handleStepTargetExecution(StepTargetExecution&) { this->stepTarget(); return std::make_unique(); } @@ -1053,14 +1053,14 @@ namespace TargetController return std::make_unique(); } - std::unique_ptr TargetControllerComponent::handleGetTargetGpioPinStates( - GetTargetGpioPinStates& command + std::unique_ptr TargetControllerComponent::handleGetTargetGpioPadStates( + GetTargetGpioPadStates& command ) { - return std::make_unique(this->target->getGpioPinStates(command.pinoutDescriptor)); + return std::make_unique(this->target->getGpioPadStates(command.padDescriptors)); } - std::unique_ptr TargetControllerComponent::handleSetTargetGpioPinState(SetTargetGpioPinState& command) { - this->target->setGpioPinState(command.pinDescriptor, command.state); + std::unique_ptr TargetControllerComponent::handleSetTargetGpioPadState(SetTargetGpioPadState& command) { + this->target->setGpioPadState(command.padDescriptor, command.state); return std::make_unique(); } @@ -1076,7 +1076,7 @@ namespace TargetController return std::make_unique(this->target->getProgramCounter()); } - std::unique_ptr TargetControllerComponent::handleEnableProgrammingMode(EnableProgrammingMode& command) { + std::unique_ptr TargetControllerComponent::handleEnableProgrammingMode(EnableProgrammingMode&) { if (!this->target->programmingModeEnabled()) { this->enableProgrammingMode(); } @@ -1084,7 +1084,7 @@ namespace TargetController return std::make_unique(); } - std::unique_ptr TargetControllerComponent::handleDisableProgrammingMode(DisableProgrammingMode& command) { + std::unique_ptr TargetControllerComponent::handleDisableProgrammingMode(DisableProgrammingMode&) { if (this->target->programmingModeEnabled()) { this->disableProgrammingMode(); } diff --git a/src/TargetController/TargetControllerComponent.hpp b/src/TargetController/TargetControllerComponent.hpp index 168b2c0b..0020ac98 100644 --- a/src/TargetController/TargetControllerComponent.hpp +++ b/src/TargetController/TargetControllerComponent.hpp @@ -39,8 +39,8 @@ #include "Commands/RemoveBreakpoint.hpp" #include "Commands/SetTargetProgramCounter.hpp" #include "Commands/SetTargetStackPointer.hpp" -#include "Commands/GetTargetGpioPinStates.hpp" -#include "Commands/SetTargetGpioPinState.hpp" +#include "Commands/GetTargetGpioPadStates.hpp" +#include "Commands/SetTargetGpioPadState.hpp" #include "Commands/GetTargetStackPointer.hpp" #include "Commands/GetTargetProgramCounter.hpp" #include "Commands/EnableProgrammingMode.hpp" @@ -53,7 +53,7 @@ #include "Responses/TargetState.hpp" #include "Responses/TargetRegistersRead.hpp" #include "Responses/TargetMemoryRead.hpp" -#include "Responses/TargetGpioPinStates.hpp" +#include "Responses/TargetGpioPadStates.hpp" #include "Responses/TargetStackPointer.hpp" #include "Responses/TargetProgramCounter.hpp" #include "Responses/Breakpoint.hpp" @@ -369,10 +369,10 @@ namespace TargetController std::unique_ptr handleRemoveBreakpoint(Commands::RemoveBreakpoint& command); std::unique_ptr handleSetProgramCounter(Commands::SetTargetProgramCounter& command); std::unique_ptr handleSetStackPointer(Commands::SetTargetStackPointer& command); - std::unique_ptr handleGetTargetGpioPinStates( - Commands::GetTargetGpioPinStates& command + std::unique_ptr handleGetTargetGpioPadStates( + Commands::GetTargetGpioPadStates& command ); - std::unique_ptr handleSetTargetGpioPinState(Commands::SetTargetGpioPinState& command); + std::unique_ptr handleSetTargetGpioPadState(Commands::SetTargetGpioPadState& command); std::unique_ptr handleGetTargetStackPointer( Commands::GetTargetStackPointer& command ); diff --git a/src/Targets/CMakeLists.txt b/src/Targets/CMakeLists.txt index 9cf4dae2..d2ce60dc 100755 --- a/src/Targets/CMakeLists.txt +++ b/src/Targets/CMakeLists.txt @@ -9,6 +9,7 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/TargetRegisterGroupDescriptor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TargetRegisterDescriptor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TargetBitFieldDescriptor.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TargetPadDescriptor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TargetPinoutDescriptor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TargetPinDescriptor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TargetVariantDescriptor.cpp diff --git a/src/Targets/Microchip/AVR8/Avr8.cpp b/src/Targets/Microchip/AVR8/Avr8.cpp index 062571d2..9eb7a9d3 100644 --- a/src/Targets/Microchip/AVR8/Avr8.cpp +++ b/src/Targets/Microchip/AVR8/Avr8.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "IspParameters.hpp" @@ -33,7 +34,7 @@ namespace Targets::Microchip::Avr8 , family(this->targetDescriptionFile.getAvrFamily()) , physicalInterfaces(this->targetDescriptionFile.getPhysicalInterfaces()) , gpioPortPeripheralDescriptors(this->targetDescriptionFile.gpioPortPeripheralDescriptors()) - , gpioPadDescriptorsByPadName(Avr8::generateGpioPadDescriptorMapping(this->gpioPortPeripheralDescriptors)) + , gpioPadDescriptorsByPadId(Avr8::generateGpioPadDescriptorMapping(this->gpioPortPeripheralDescriptors)) , fuseEnableStrategy(this->targetDescriptionFile.getFuseEnableStrategy().value_or(FuseEnableStrategy::CLEAR)) { const auto cpuPeripheralDescriptor = this->targetDescriptionFile.getTargetPeripheralDescriptor("cpu"); @@ -265,6 +266,7 @@ namespace Targets::Microchip::Avr8 this->targetDescriptionFile.tryGetVendorName().value_or("Microchip"), this->targetDescriptionFile.targetAddressSpaceDescriptorsByKey(), this->targetDescriptionFile.targetPeripheralDescriptorsByKey(), + this->targetDescriptionFile.targetPadDescriptorsByKey(), this->targetDescriptionFile.targetPinoutDescriptorsByKey(), this->targetDescriptionFile.targetVariantDescriptors(), this->getBreakpointResources() @@ -558,11 +560,11 @@ namespace Targets::Microchip::Avr8 } } - TargetGpioPinDescriptorAndStatePairs Avr8::getGpioPinStates(const TargetPinoutDescriptor& pinoutDescriptor) { - auto output = TargetGpioPinDescriptorAndStatePairs{}; + TargetGpioPadDescriptorAndStatePairs Avr8::getGpioPadStates(const TargetPadDescriptors& padDescriptors) { + auto output = TargetGpioPadDescriptorAndStatePairs{}; // To reduce the number of memory reads we perform here, we cache the data and map it by start address. - auto cachedRegsByStartAddress = std::map{}; + auto cachedRegsByStartAddress = std::unordered_map{}; const auto readGpioReg = [this, &cachedRegsByStartAddress] (const TargetRegisterDescriptor& descriptor) { assert(descriptor.size == 1); @@ -577,33 +579,32 @@ namespace Targets::Microchip::Avr8 return cachedRegIt->second; }; - for (const auto& pinDescriptor : pinoutDescriptor.pinDescriptors) { - if (pinDescriptor.type != TargetPinType::GPIO) { + for (const auto* padDescriptor : padDescriptors) { + if (padDescriptor->type != TargetPadType::GPIO) { continue; } - const auto padDescriptorIt = this->gpioPadDescriptorsByPadName.find(pinDescriptor.padName); - if (padDescriptorIt == this->gpioPadDescriptorsByPadName.end()) { + const auto gpioPadDescriptorIt = this->gpioPadDescriptorsByPadId.find(padDescriptor->id); + if (gpioPadDescriptorIt == this->gpioPadDescriptorsByPadId.end()) { continue; } - const auto& padDescriptor = padDescriptorIt->second; - + const auto& gpioPadDescriptor = gpioPadDescriptorIt->second; const auto ddrValue = ( - readGpioReg(padDescriptor.dataDirectionRegisterDescriptor) & padDescriptor.registerMask - ) != 0 ? TargetGpioPinState::DataDirection::OUTPUT : TargetGpioPinState::DataDirection::INPUT; + readGpioReg(gpioPadDescriptor.dataDirectionRegisterDescriptor) & gpioPadDescriptor.registerMask + ) != 0 ? TargetGpioPadState::DataDirection::OUTPUT : TargetGpioPadState::DataDirection::INPUT; - const auto& stateRegisterDescriptor = ddrValue == TargetGpioPinState::DataDirection::OUTPUT - ? padDescriptor.outputRegisterDescriptor - : padDescriptor.inputRegisterDescriptor; + const auto& stateRegisterDescriptor = ddrValue == TargetGpioPadState::DataDirection::OUTPUT + ? gpioPadDescriptor.outputRegisterDescriptor + : gpioPadDescriptor.inputRegisterDescriptor; output.emplace_back( - TargetGpioPinDescriptorAndStatePair{ - pinDescriptor, - TargetGpioPinState{ - (readGpioReg(stateRegisterDescriptor) & padDescriptor.registerMask) != 0 - ? TargetGpioPinState::State::HIGH - : TargetGpioPinState::State::LOW, + TargetGpioPadDescriptorAndStatePair{ + *padDescriptor, + TargetGpioPadState{ + (readGpioReg(stateRegisterDescriptor) & gpioPadDescriptor.registerMask) != 0 + ? TargetGpioPadState::State::HIGH + : TargetGpioPadState::State::LOW, ddrValue } } @@ -613,39 +614,38 @@ namespace Targets::Microchip::Avr8 return output; } - void Avr8::setGpioPinState(const TargetPinDescriptor& pinDescriptor, const TargetGpioPinState& state) { - using DataDirection = TargetGpioPinState::DataDirection; - using GpioState = TargetGpioPinState::State; + void Avr8::setGpioPadState(const TargetPadDescriptor& padDescriptor, const TargetGpioPadState& state) { + using DataDirection = TargetGpioPadState::DataDirection; + using GpioState = TargetGpioPadState::State; - const auto padDescriptorIt = this->gpioPadDescriptorsByPadName.find(pinDescriptor.padName); - - if (padDescriptorIt == this->gpioPadDescriptorsByPadName.end()) { + const auto gpioPadDescriptorIt = this->gpioPadDescriptorsByPadId.find(padDescriptor.id); + if (gpioPadDescriptorIt == this->gpioPadDescriptorsByPadId.end()) { throw Exception{"Unknown pad"}; } - const auto& padDescriptor = padDescriptorIt->second; + const auto& gpioPadDescriptor = gpioPadDescriptorIt->second; - const auto currentDdrValue = this->readRegister(padDescriptor.dataDirectionRegisterDescriptor).at(0); + const auto currentDdrValue = this->readRegister(gpioPadDescriptor.dataDirectionRegisterDescriptor).at(0); this->writeRegister( - padDescriptor.dataDirectionRegisterDescriptor, + gpioPadDescriptor.dataDirectionRegisterDescriptor, { static_cast( state.direction == DataDirection::OUTPUT - ? (currentDdrValue | padDescriptor.registerMask) - : (currentDdrValue & ~(padDescriptor.registerMask)) + ? (currentDdrValue | gpioPadDescriptor.registerMask) + : (currentDdrValue & ~(gpioPadDescriptor.registerMask)) ) } ); if (state.direction == DataDirection::OUTPUT) { - const auto currentOutputValue = this->readRegister(padDescriptor.outputRegisterDescriptor).at(0); + const auto currentOutputValue = this->readRegister(gpioPadDescriptor.outputRegisterDescriptor).at(0); this->writeRegister( - padDescriptor.outputRegisterDescriptor, + gpioPadDescriptor.outputRegisterDescriptor, { static_cast( state.value == GpioState::HIGH - ? (currentOutputValue | padDescriptor.registerMask) - : (currentOutputValue & ~(padDescriptor.registerMask)) + ? (currentOutputValue | gpioPadDescriptor.registerMask) + : (currentOutputValue & ~(gpioPadDescriptor.registerMask)) ) } ); @@ -679,22 +679,22 @@ namespace Targets::Microchip::Avr8 return this->activeProgrammingSession.has_value(); } - std::map Avr8::generateGpioPadDescriptorMapping( + std::map Avr8::generateGpioPadDescriptorMapping( const std::vector& portPeripheralDescriptors ) { - auto output = std::map{}; + auto output = std::map{}; for (const auto& peripheralDescriptor : portPeripheralDescriptors) { + if (peripheralDescriptor.registerGroupDescriptorsByKey.empty()) { + continue; + } + for (const auto& signalDescriptor : peripheralDescriptor.signalDescriptors) { if (!signalDescriptor.index.has_value()) { continue; } - if (output.contains(signalDescriptor.padName)) { - continue; - } - - if (peripheralDescriptor.registerGroupDescriptorsByKey.empty()) { + if (output.contains(signalDescriptor.padId)) { continue; } @@ -712,8 +712,9 @@ namespace Targets::Microchip::Avr8 // From a register layout perspective, there are two types of GPIO port modules on AVR8 targets. if (portRegisterGroup.registerDescriptorsByKey.contains("outset")) { output.emplace( - signalDescriptor.padName, + signalDescriptor.padId, GpioPadDescriptor{ + signalDescriptor.padKey, registerMask, portRegisterGroup.getRegisterDescriptor("dir"), portRegisterGroup.getRegisterDescriptor("in"), @@ -752,8 +753,9 @@ namespace Targets::Microchip::Avr8 if (ddrDescriptor.has_value() && inputDescriptor.has_value() && outputDescriptor.has_value()) { output.emplace( - signalDescriptor.padName, + signalDescriptor.padId, GpioPadDescriptor{ + signalDescriptor.padKey, registerMask, ddrDescriptor->get(), inputDescriptor->get(), diff --git a/src/Targets/Microchip/AVR8/Avr8.hpp b/src/Targets/Microchip/AVR8/Avr8.hpp index 7d80a792..5a5668d7 100644 --- a/src/Targets/Microchip/AVR8/Avr8.hpp +++ b/src/Targets/Microchip/AVR8/Avr8.hpp @@ -20,6 +20,7 @@ #include "src/Targets/TargetPhysicalInterface.hpp" #include "src/Targets/TargetRegisterDescriptor.hpp" #include "src/Targets/TargetBitFieldDescriptor.hpp" +#include "src/Targets/TargetPadDescriptor.hpp" #include "src/Targets/TargetBreakpoint.hpp" #include "TargetDescriptionFile.hpp" @@ -104,8 +105,8 @@ namespace Targets::Microchip::Avr8 TargetStackPointer getStackPointer() override; void setStackPointer(TargetStackPointer stackPointer) override; - TargetGpioPinDescriptorAndStatePairs getGpioPinStates(const TargetPinoutDescriptor& pinoutDescriptor) override; - void setGpioPinState(const TargetPinDescriptor& pinDescriptor, const TargetGpioPinState& state) override; + TargetGpioPadDescriptorAndStatePairs getGpioPadStates(const TargetPadDescriptors& padDescriptors) override; + void setGpioPadState(const TargetPadDescriptor& padDescriptor, const TargetGpioPadState& state) override; void enableProgrammingMode() override; @@ -136,7 +137,7 @@ namespace Targets::Microchip::Avr8 std::set physicalInterfaces; std::vector gpioPortPeripheralDescriptors; - std::map gpioPadDescriptorsByPadName; + std::map gpioPadDescriptorsByPadId; /** * The stack pointer register on AVR8 targets can take several forms: @@ -163,7 +164,7 @@ namespace Targets::Microchip::Avr8 std::optional activeProgrammingSession = std::nullopt; - static std::map generateGpioPadDescriptorMapping( + static std::map generateGpioPadDescriptorMapping( const std::vector& portPeripheralDescriptors ); diff --git a/src/Targets/Microchip/AVR8/GpioPadDescriptor.hpp b/src/Targets/Microchip/AVR8/GpioPadDescriptor.hpp index 9761d3da..c4df49fd 100644 --- a/src/Targets/Microchip/AVR8/GpioPadDescriptor.hpp +++ b/src/Targets/Microchip/AVR8/GpioPadDescriptor.hpp @@ -2,6 +2,7 @@ #include +#include "src/Targets/TargetPadDescriptor.hpp" #include "src/Targets/TargetRegisterDescriptor.hpp" namespace Targets::Microchip::Avr8 @@ -13,6 +14,8 @@ namespace Targets::Microchip::Avr8 */ struct GpioPadDescriptor { + const TargetPadId padId; + const std::string padKey; std::uint8_t registerMask; const TargetRegisterDescriptor& dataDirectionRegisterDescriptor; @@ -20,12 +23,15 @@ namespace Targets::Microchip::Avr8 const TargetRegisterDescriptor& outputRegisterDescriptor; GpioPadDescriptor( + const std::string& padKey, std::uint8_t registerMask, const TargetRegisterDescriptor& dataDirectionRegisterDescriptor, const TargetRegisterDescriptor& inputRegisterDescriptor, const TargetRegisterDescriptor& outputRegisterDescriptor ) - : registerMask(registerMask) + : padId(TargetPadDescriptor::generateId(padKey)) + , padKey(padKey) + , registerMask(registerMask) , dataDirectionRegisterDescriptor(dataDirectionRegisterDescriptor) , inputRegisterDescriptor(inputRegisterDescriptor) , outputRegisterDescriptor(outputRegisterDescriptor) diff --git a/src/Targets/RiscV/RiscV.cpp b/src/Targets/RiscV/RiscV.cpp index 91902a79..555f2487 100644 --- a/src/Targets/RiscV/RiscV.cpp +++ b/src/Targets/RiscV/RiscV.cpp @@ -89,6 +89,7 @@ namespace Targets::RiscV this->targetDescriptionFile.getVendorName(), this->targetDescriptionFile.targetAddressSpaceDescriptorsByKey(), this->targetDescriptionFile.targetPeripheralDescriptorsByKey(), + this->targetDescriptionFile.targetPadDescriptorsByKey(), this->targetDescriptionFile.targetPinoutDescriptorsByKey(), this->targetDescriptionFile.targetVariantDescriptors(), {} // TODO: populate this @@ -356,11 +357,11 @@ namespace Targets::RiscV }); } - TargetGpioPinDescriptorAndStatePairs RiscV::getGpioPinStates(const TargetPinoutDescriptor& pinoutDescriptor) { + TargetGpioPadDescriptorAndStatePairs RiscV::getGpioPadStates(const TargetPadDescriptors& padDescriptors) { return {}; } - void RiscV::setGpioPinState(const TargetPinDescriptor& pinDescriptor, const TargetGpioPinState& state) { + void RiscV::setGpioPadState(const TargetPadDescriptor& padDescriptor, const TargetGpioPadState& state) { } diff --git a/src/Targets/RiscV/RiscV.hpp b/src/Targets/RiscV/RiscV.hpp index 8c7d0535..56644e22 100644 --- a/src/Targets/RiscV/RiscV.hpp +++ b/src/Targets/RiscV/RiscV.hpp @@ -85,10 +85,8 @@ namespace Targets::RiscV TargetStackPointer getStackPointer() override; void setStackPointer(TargetStackPointer stackPointer) override; - TargetGpioPinDescriptorAndStatePairs getGpioPinStates( - const TargetPinoutDescriptor& pinoutDescriptor - ) override; - void setGpioPinState(const TargetPinDescriptor& pinDescriptor, const TargetGpioPinState& state) override; + TargetGpioPadDescriptorAndStatePairs getGpioPadStates(const TargetPadDescriptors& padDescriptors) override; + void setGpioPadState(const TargetPadDescriptor& padDescriptor, const TargetGpioPadState& state) override; void enableProgrammingMode() override; diff --git a/src/Targets/Target.hpp b/src/Targets/Target.hpp index d99694ee..27d2a508 100644 --- a/src/Targets/Target.hpp +++ b/src/Targets/Target.hpp @@ -16,9 +16,8 @@ #include "TargetRegisterDescriptor.hpp" #include "TargetMemory.hpp" #include "TargetBreakpoint.hpp" -#include "TargetPinoutDescriptor.hpp" -#include "TargetPinDescriptor.hpp" -#include "TargetGpioPinState.hpp" +#include "TargetPadDescriptor.hpp" +#include "TargetGpioPadState.hpp" #include "src/DebugToolDrivers/DebugTool.hpp" @@ -266,23 +265,19 @@ namespace Targets virtual void setStackPointer(TargetStackPointer stackPointer) = 0; /** - * Should get the current state of each GPIO pin on the target - * - * @param pinoutDescriptor + * Should get the current state of the given GPIO pads. * * @return */ - virtual TargetGpioPinDescriptorAndStatePairs getGpioPinStates( - const TargetPinoutDescriptor& pinoutDescriptor - ) = 0; + virtual TargetGpioPadDescriptorAndStatePairs getGpioPadStates(const TargetPadDescriptors& padDescriptors) = 0; /** - * Should update the pin state for the given GPIO pin, with the given state. + * Should update the state for the given GPIO pad, with the given state. * - * @param pinDescriptor + * @param padDescriptor * @param state */ - virtual void setGpioPinState(const TargetPinDescriptor& pinDescriptor, const TargetGpioPinState& state) = 0; + virtual void setGpioPadState(const TargetPadDescriptor& padDescriptor, const TargetGpioPadState& state) = 0; /** * Should prepare the target for programming. diff --git a/src/Targets/TargetDescription/Pad.hpp b/src/Targets/TargetDescription/Pad.hpp new file mode 100644 index 00000000..6729bb60 --- /dev/null +++ b/src/Targets/TargetDescription/Pad.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include + +namespace Targets::TargetDescription +{ + struct Pad + { + std::string key; + std::string name; + + Pad( + const std::string& key, + const std::string& name + ) + : key(key) + , name(name) + {} + }; +} diff --git a/src/Targets/TargetDescription/Pin.hpp b/src/Targets/TargetDescription/Pin.hpp index 913524f3..91d0c9f1 100644 --- a/src/Targets/TargetDescription/Pin.hpp +++ b/src/Targets/TargetDescription/Pin.hpp @@ -1,20 +1,21 @@ #pragma once #include +#include namespace Targets::TargetDescription { struct Pin { std::string position; - std::string pad; + std::optional padKey; Pin( const std::string& position, - const std::string& pad + const std::optional& padKey ) : position(position) - , pad(pad) + , padKey(padKey) {} }; } diff --git a/src/Targets/TargetDescription/Signal.hpp b/src/Targets/TargetDescription/Signal.hpp index ae68a636..4c5ecc56 100644 --- a/src/Targets/TargetDescription/Signal.hpp +++ b/src/Targets/TargetDescription/Signal.hpp @@ -8,20 +8,20 @@ namespace Targets::TargetDescription { struct Signal { - std::string padId; + std::string padKey; std::optional index; std::optional function; std::optional group; std::optional field; Signal( - const std::string& padId, + const std::string& padKey, const std::optional& index, const std::optional& function, const std::optional& group, const std::optional& field ) - : padId(padId) + : padKey(padKey) , index(index) , function(function) , group(group) diff --git a/src/Targets/TargetDescription/TargetDescriptionFile.cpp b/src/Targets/TargetDescription/TargetDescriptionFile.cpp index f71fb981..192e3017 100644 --- a/src/Targets/TargetDescription/TargetDescriptionFile.cpp +++ b/src/Targets/TargetDescription/TargetDescriptionFile.cpp @@ -219,6 +219,22 @@ namespace Targets::TargetDescription return peripheral->get(); } + std::set TargetDescriptionFile::getModulePeripherals(const std::string& moduleKey) const { + auto output = std::set{}; + + for (const auto& [peripheralKey, peripheral] : this->peripheralsByKey) { + if (peripheral.moduleKey == moduleKey) { + output.insert(&peripheral); + } + } + + return output; + } + + std::set TargetDescriptionFile::getGpioPeripherals() const { + return this->getModulePeripherals("gpio_port"); + } + std::optional TargetDescriptionFile::tryGetTargetMemorySegmentDescriptor( std::string_view addressSpaceKey, std::string_view segmentKey @@ -305,6 +321,20 @@ namespace Targets::TargetDescription return output; } + std::map TargetDescriptionFile::targetPadDescriptorsByKey() const { + auto output = std::map{}; + + const auto gpioPadKeys = this->getGpioPadKeys(); + for (const auto& [key, pad] : this->padsByKey) { + output.emplace( + key, + TargetDescriptionFile::targetPadDescriptorFromPad(pad, gpioPadKeys) + ); + } + + return output; + } + std::map TargetDescriptionFile::targetPinoutDescriptorsByKey() const { auto output = std::map{}; @@ -421,6 +451,15 @@ namespace Targets::TargetDescription this->peripheralsByKey.emplace(peripheral.key, std::move(peripheral)); } + for ( + auto element = deviceElement.firstChildElement("pads").firstChildElement("pad"); + !element.isNull(); + element = element.nextSiblingElement("pad") + ) { + auto pad = TargetDescriptionFile::padFromXml(element); + this->padsByKey.emplace(pad.key, std::move(pad)); + } + for ( auto element = deviceElement.firstChildElement("pinouts").firstChildElement("pinout"); !element.isNull(); @@ -461,6 +500,17 @@ namespace Targets::TargetDescription return attribute->get(); } + std::set TargetDescriptionFile::getGpioPadKeys() const { + auto output = std::set{}; + for (const auto* peripheral : this->getGpioPeripherals()) { + for (const auto& signal : peripheral->sigs) { + output.insert(signal.padKey); + } + } + + return output; + } + std::optional TargetDescriptionFile::tryGetAttribute( const QDomElement& element, const QString& attributeName @@ -806,7 +856,7 @@ namespace Targets::TargetDescription const auto index = TargetDescriptionFile::tryGetAttribute(xmlElement, "index"); return { - TargetDescriptionFile::getAttribute(xmlElement, "pad-id"), + TargetDescriptionFile::getAttribute(xmlElement, "pad-key"), index.has_value() ? std::optional{StringService::toUint64(*index)} : std::nullopt, TargetDescriptionFile::tryGetAttribute(xmlElement, "function"), TargetDescriptionFile::tryGetAttribute(xmlElement, "group"), @@ -814,6 +864,13 @@ namespace Targets::TargetDescription }; } + Pad TargetDescriptionFile::padFromXml(const QDomElement& xmlElement) { + return { + TargetDescriptionFile::getAttribute(xmlElement, "key"), + TargetDescriptionFile::getAttribute(xmlElement, "name") + }; + } + Pinout TargetDescriptionFile::pinoutFromXml(const QDomElement& xmlElement) { static const auto typesByName = BiMap{ {"soic", TargetPinoutType::SOIC}, @@ -857,15 +914,14 @@ namespace Targets::TargetDescription Pin TargetDescriptionFile::pinFromXml(const QDomElement& xmlElement) { return { TargetDescriptionFile::getAttribute(xmlElement, "position"), - TargetDescriptionFile::getAttribute(xmlElement, "pad") + TargetDescriptionFile::tryGetAttribute(xmlElement, "pad-key") }; } Variant TargetDescriptionFile::variantFromXml(const QDomElement& xmlElement) { return { TargetDescriptionFile::getAttribute(xmlElement, "name"), - TargetDescriptionFile::getAttribute(xmlElement, "pinout-key"), - TargetDescriptionFile::getAttribute(xmlElement, "package") + TargetDescriptionFile::getAttribute(xmlElement, "pinout-key") }; } @@ -954,7 +1010,7 @@ namespace Targets::TargetDescription const Signal& signal ) { return { - signal.padId, + signal.padKey, signal.index }; } @@ -1075,6 +1131,41 @@ namespace Targets::TargetDescription }; } + TargetPadDescriptor TargetDescriptionFile::targetPadDescriptorFromPad( + const Pad& pad, + const std::set& gpioPadKeys + ) { + static const auto resolvePadType = [&gpioPadKeys] (const Pad& pad) -> TargetPadType { + if (gpioPadKeys.contains(pad.key)) { + return TargetPadType::GPIO; + } + + const auto padNameLower = StringService::asciiToLower(pad.name); + + if ( + padNameLower.find("vcc") == 0 + || padNameLower.find("avcc") == 0 + || padNameLower.find("aref") == 0 + || padNameLower.find("avdd") == 0 + || padNameLower.find("vdd") == 0 + ) { + return TargetPadType::VCC; + } + + if (padNameLower.find("gnd") == 0 || padNameLower.find("agnd") == 0) { + return TargetPadType::GND; + } + + return TargetPadType::OTHER; + }; + + return { + pad.key, + pad.name, + resolvePadType(pad) + }; + } + TargetPinoutDescriptor TargetDescriptionFile::targetPinoutDescriptorFromPinout(const Pinout& pinout) { auto output = TargetPinoutDescriptor{ pinout.key, @@ -1091,30 +1182,9 @@ namespace Targets::TargetDescription } TargetPinDescriptor TargetDescriptionFile::targetPinDescriptorFromPin(const Pin& pin) { - static const auto resolvePinType = [] (const std::string& pad) -> TargetPinType { - const auto padLower = StringService::asciiToLower(pad); - - if ( - padLower.find("vcc") == 0 - || padLower.find("avcc") == 0 - || padLower.find("aref") == 0 - || padLower.find("avdd") == 0 - || padLower.find("vdd") == 0 - ) { - return TargetPinType::VCC; - } - - if (padLower.find("gnd") == 0) { - return TargetPinType::GND; - } - - return TargetPinType::OTHER; - }; - return { - pin.pad, pin.position, - resolvePinType(pin.pad) + pin.padKey }; } diff --git a/src/Targets/TargetDescription/TargetDescriptionFile.hpp b/src/Targets/TargetDescription/TargetDescriptionFile.hpp index c485daca..6a877bf7 100644 --- a/src/Targets/TargetDescription/TargetDescriptionFile.hpp +++ b/src/Targets/TargetDescription/TargetDescriptionFile.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "PropertyGroup.hpp" #include "AddressSpace.hpp" @@ -19,6 +20,7 @@ #include "RegisterGroupReference.hpp" #include "Peripheral.hpp" #include "RegisterGroupInstance.hpp" +#include "Pad.hpp" #include "Signal.hpp" #include "Pinout.hpp" #include "Pin.hpp" @@ -129,6 +131,9 @@ namespace Targets::TargetDescription std::string_view key ) const; [[nodiscard]] const Peripheral& getPeripheral(std::string_view key) const; + [[nodiscard]] std::set getModulePeripherals(const std::string& moduleKey) const; + [[nodiscard]] std::set getGpioPeripherals() const; + [[nodiscard]] std::optional tryGetTargetMemorySegmentDescriptor( std::string_view addressSpaceKey, @@ -146,6 +151,7 @@ namespace Targets::TargetDescription [[nodiscard]] std::map targetAddressSpaceDescriptorsByKey() const; [[nodiscard]] std::map targetPeripheralDescriptorsByKey() const; + [[nodiscard]] std::map targetPadDescriptorsByKey() const; [[nodiscard]] std::map targetPinoutDescriptorsByKey() const; [[nodiscard]] std::vector targetVariantDescriptors() const; [[nodiscard]] std::vector gpioPortPeripheralDescriptors() const; @@ -157,6 +163,7 @@ namespace Targets::TargetDescription std::vector physicalInterfaces; std::map> modulesByKey; std::map> peripheralsByKey; + std::map> padsByKey; std::map> pinoutsByKey; std::vector variants; @@ -177,6 +184,8 @@ namespace Targets::TargetDescription ) const; const std::string& getDeviceAttribute(const std::string& attributeName) const; + [[nodiscard]] std::set getGpioPadKeys() const; + static std::optional tryGetAttribute(const QDomElement& element, const QString& attributeName); static std::string getAttribute(const QDomElement& element, const QString& attributeName); @@ -194,6 +203,7 @@ namespace Targets::TargetDescription static Peripheral peripheralFromXml(const QDomElement& xmlElement); static RegisterGroupInstance registerGroupInstanceFromXml(const QDomElement& xmlElement); static Signal signalFromXml(const QDomElement& xmlElement); + static Pad padFromXml(const QDomElement& xmlElement); static Pinout pinoutFromXml(const QDomElement& xmlElement); static Pin pinFromXml(const QDomElement& xmlElement); static Variant variantFromXml(const QDomElement& xmlElement); @@ -236,6 +246,11 @@ namespace Targets::TargetDescription static TargetBitFieldDescriptor targetBitFieldDescriptorFromBitField(const BitField& bitField); + static TargetPadDescriptor targetPadDescriptorFromPad( + const Pad& pad, + const std::set& gpioPadKeys + ); + static TargetPinoutDescriptor targetPinoutDescriptorFromPinout(const Pinout& pinout); static TargetPinDescriptor targetPinDescriptorFromPin(const Pin& pin); diff --git a/src/Targets/TargetDescription/Variant.hpp b/src/Targets/TargetDescription/Variant.hpp index 14c7f83c..d2abe2af 100644 --- a/src/Targets/TargetDescription/Variant.hpp +++ b/src/Targets/TargetDescription/Variant.hpp @@ -8,16 +8,13 @@ namespace Targets::TargetDescription { std::string name; std::string pinoutKey; - std::string package; Variant( const std::string& name, - const std::string& pinoutKey, - const std::string& package + const std::string& pinoutKey ) : name(name) , pinoutKey(pinoutKey) - , package(package) {} }; } diff --git a/src/Targets/TargetDescriptor.cpp b/src/Targets/TargetDescriptor.cpp index 119e9cfa..b720e0b3 100644 --- a/src/Targets/TargetDescriptor.cpp +++ b/src/Targets/TargetDescriptor.cpp @@ -13,6 +13,7 @@ namespace Targets const std::string& vendorName, std::map&& addressSpaceDescriptorsByKey, std::map&& peripheralDescriptorsByKey, + std::map&& padDescriptorsByKey, std::map&& pinoutDescriptorsByKey, std::vector&& variantDescriptors, const BreakpointResources& breakpointResources @@ -23,6 +24,7 @@ namespace Targets , vendorName(vendorName) , addressSpaceDescriptorsByKey(std::move(addressSpaceDescriptorsByKey)) , peripheralDescriptorsByKey(std::move(peripheralDescriptorsByKey)) + , padDescriptorsByKey(std::move(padDescriptorsByKey)) , pinoutDescriptorsByKey(std::move(pinoutDescriptorsByKey)) , variantDescriptors(std::move(variantDescriptors)) , breakpointResources(breakpointResources) @@ -92,6 +94,30 @@ namespace Targets return descriptor->get(); } + std::optional< + std::reference_wrapper + > TargetDescriptor::tryGetPadDescriptor(const std::string& key) const { + const auto descriptorIt = this->padDescriptorsByKey.find(key); + + if (descriptorIt == this->padDescriptorsByKey.end()) { + return std::nullopt; + } + + return std::cref(descriptorIt->second); + } + + const TargetPadDescriptor& TargetDescriptor::getPadDescriptor(const std::string& key) const { + const auto descriptor = this->tryGetPadDescriptor(key); + if (!descriptor.has_value()) { + throw Exceptions::InternalFatalErrorException{ + "Failed to get pad descriptor \"" + std::string{key} + + "\" from target descriptor - descriptor not found" + }; + } + + return descriptor->get(); + } + std::optional< std::reference_wrapper > TargetDescriptor::tryGetPinoutDescriptor(const std::string& key) const { diff --git a/src/Targets/TargetDescriptor.hpp b/src/Targets/TargetDescriptor.hpp index eed8fcd6..5e245970 100644 --- a/src/Targets/TargetDescriptor.hpp +++ b/src/Targets/TargetDescriptor.hpp @@ -11,6 +11,7 @@ #include "TargetMemory.hpp" #include "TargetAddressSpaceDescriptor.hpp" #include "TargetPeripheralDescriptor.hpp" +#include "TargetPadDescriptor.hpp" #include "TargetPinoutDescriptor.hpp" #include "TargetVariantDescriptor.hpp" #include "TargetBreakpoint.hpp" @@ -25,6 +26,7 @@ namespace Targets std::string vendorName; std::map addressSpaceDescriptorsByKey; std::map peripheralDescriptorsByKey; + std::map padDescriptorsByKey; std::map pinoutDescriptorsByKey; std::vector variantDescriptors; BreakpointResources breakpointResources; @@ -36,6 +38,7 @@ namespace Targets const std::string& vendorName, std::map&& addressSpaceDescriptorsByKey, std::map&& peripheralDescriptorsByKey, + std::map&& padDescriptorsByKey, std::map&& pinoutDescriptorsByKey, std::vector&& variantDescriptors, const BreakpointResources& breakpointResources @@ -71,6 +74,12 @@ namespace Targets const TargetPeripheralDescriptor& getPeripheralDescriptor(const std::string& key) const; + std::optional> tryGetPadDescriptor( + const std::string& key + ) const; + + const TargetPadDescriptor& getPadDescriptor(const std::string& key) const; + std::optional> tryGetPinoutDescriptor( const std::string& key ) const; diff --git a/src/Targets/TargetGpioPadState.hpp b/src/Targets/TargetGpioPadState.hpp new file mode 100644 index 00000000..b09d6021 --- /dev/null +++ b/src/Targets/TargetGpioPadState.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include +#include + +#include "TargetPadDescriptor.hpp" + +#include "src/Helpers/Pair.hpp" + +namespace Targets +{ + struct TargetGpioPadState + { + enum class State: std::uint8_t + { + HIGH, + LOW, + }; + + enum class DataDirection: std::uint8_t + { + INPUT, + OUTPUT, + }; + + State value; + DataDirection direction; + + TargetGpioPadState( + State value, + DataDirection direction + ) + : value(value) + , direction(direction) + {} + + bool operator == (const TargetGpioPadState& other) const { + return this->value == other.value && this->direction == other.direction; + } + + bool operator != (const TargetGpioPadState& other) const { + return !(*this == other); + } + }; + + using TargetGpioPadDescriptorAndStatePair = Pair; + using TargetGpioPadDescriptorAndStatePairs = std::vector; +} + +Q_DECLARE_METATYPE(Targets::TargetGpioPadState) diff --git a/src/Targets/TargetGpioPinState.hpp b/src/Targets/TargetGpioPinState.hpp deleted file mode 100644 index 9590f342..00000000 --- a/src/Targets/TargetGpioPinState.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include -#include - -#include "TargetPinDescriptor.hpp" - -namespace Targets -{ - struct TargetGpioPinState - { - enum class State: std::uint8_t - { - HIGH, - LOW, - }; - - enum class DataDirection: std::uint8_t - { - INPUT, - OUTPUT, - }; - - State value; - DataDirection direction; - - TargetGpioPinState( - State value, - DataDirection direction - ) - : value(value) - , direction(direction) - {} - }; - - using TargetGpioPinDescriptorAndStatePair = Pair; - using TargetGpioPinDescriptorAndStatePairs = std::vector; -} - -Q_DECLARE_METATYPE(Targets::TargetGpioPinState) diff --git a/src/Targets/TargetPadDescriptor.cpp b/src/Targets/TargetPadDescriptor.cpp new file mode 100644 index 00000000..0f258b52 --- /dev/null +++ b/src/Targets/TargetPadDescriptor.cpp @@ -0,0 +1,29 @@ +#include "TargetPadDescriptor.hpp" + +#include "src/Services/StringService.hpp" + +namespace Targets +{ + TargetPadDescriptor::TargetPadDescriptor( + const std::string& key, + const std::string& name, + TargetPadType type + ) + : id(TargetPadDescriptor::generateId(key)) + , key(key) + , name(name) + , type(type) + {} + + bool TargetPadDescriptor::operator == (const TargetPadDescriptor& other) const { + return this->id == other.id; + } + + bool TargetPadDescriptor::operator != (const TargetPadDescriptor& other) const { + return !(*this == other); + } + + TargetPadId TargetPadDescriptor::generateId(const std::string& padKey) { + return Services::StringService::generateUniqueInteger(padKey); + } +} diff --git a/src/Targets/TargetPadDescriptor.hpp b/src/Targets/TargetPadDescriptor.hpp new file mode 100644 index 00000000..0fbac939 --- /dev/null +++ b/src/Targets/TargetPadDescriptor.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include +#include +#include + +namespace Targets +{ + enum class TargetPadType: std::uint8_t + { + GPIO, + GND, + VCC, + OTHER, + }; + + using TargetPadId = std::size_t; + + struct TargetPadDescriptor + { + public: + const TargetPadId id; + const std::string key; + std::string name; + TargetPadType type = TargetPadType::OTHER; + + TargetPadDescriptor( + const std::string& key, + const std::string& name, + TargetPadType type + ); + + TargetPadDescriptor(const TargetPadDescriptor& other) = delete; + TargetPadDescriptor& operator = (const TargetPadDescriptor& other) = delete; + + TargetPadDescriptor(TargetPadDescriptor&& other) noexcept = default; + + bool operator == (const TargetPadDescriptor& other) const; + bool operator != (const TargetPadDescriptor& other) const; + + static TargetPadId generateId(const std::string& padKey); + }; + + using TargetPadDescriptors = std::vector; +} diff --git a/src/Targets/TargetPeripheralSignalDescriptor.cpp b/src/Targets/TargetPeripheralSignalDescriptor.cpp index 0d7d0246..47dd22b8 100644 --- a/src/Targets/TargetPeripheralSignalDescriptor.cpp +++ b/src/Targets/TargetPeripheralSignalDescriptor.cpp @@ -3,16 +3,17 @@ namespace Targets { TargetPeripheralSignalDescriptor::TargetPeripheralSignalDescriptor( - const std::string& padName, + const std::string& padKey, const std::optional& index ) - : padName(padName) + : padId(TargetPadDescriptor::generateId(padKey)) + , padKey(padKey) , index(index) {} TargetPeripheralSignalDescriptor TargetPeripheralSignalDescriptor::clone() const { return { - this->padName, + this->padKey, this->index }; } diff --git a/src/Targets/TargetPeripheralSignalDescriptor.hpp b/src/Targets/TargetPeripheralSignalDescriptor.hpp index 40c994c8..a221949b 100644 --- a/src/Targets/TargetPeripheralSignalDescriptor.hpp +++ b/src/Targets/TargetPeripheralSignalDescriptor.hpp @@ -4,16 +4,19 @@ #include #include +#include "TargetPadDescriptor.hpp" + namespace Targets { struct TargetPeripheralSignalDescriptor { public: - std::string padName; + const TargetPadId padId; + const std::string padKey; std::optional index; TargetPeripheralSignalDescriptor( - const std::string& padName, + const std::string& padKey, const std::optional& index ); @@ -21,7 +24,6 @@ namespace Targets TargetPeripheralSignalDescriptor& operator = (const TargetPeripheralSignalDescriptor& other) = delete; TargetPeripheralSignalDescriptor(TargetPeripheralSignalDescriptor&& other) noexcept = default; - TargetPeripheralSignalDescriptor& operator = (TargetPeripheralSignalDescriptor&& other) = default; [[nodiscard]] TargetPeripheralSignalDescriptor clone() const; }; diff --git a/src/Targets/TargetPinDescriptor.cpp b/src/Targets/TargetPinDescriptor.cpp index 4922c476..e6556d2c 100644 --- a/src/Targets/TargetPinDescriptor.cpp +++ b/src/Targets/TargetPinDescriptor.cpp @@ -1,14 +1,15 @@ #include "TargetPinDescriptor.hpp" +#include "src/Services/StringService.hpp" + namespace Targets { TargetPinDescriptor::TargetPinDescriptor( - const std::string& padName, const std::string& position, - TargetPinType type + const std::optional& padKey ) - : padName(padName) - , position(position) - , type(type) + : position(position) + , numericPosition(Services::StringService::toUint16(this->position, 10)) + , padKey(padKey) {} } diff --git a/src/Targets/TargetPinDescriptor.hpp b/src/Targets/TargetPinDescriptor.hpp index ae8e9495..16f419ff 100644 --- a/src/Targets/TargetPinDescriptor.hpp +++ b/src/Targets/TargetPinDescriptor.hpp @@ -2,28 +2,20 @@ #include #include +#include namespace Targets { - enum class TargetPinType: std::uint8_t - { - GPIO, - GND, - VCC, - OTHER, - }; - struct TargetPinDescriptor { public: - std::string padName; std::string position; - TargetPinType type = TargetPinType::OTHER; + std::uint16_t numericPosition; + std::optional padKey; TargetPinDescriptor( - const std::string& padName, const std::string& position, - TargetPinType type + const std::optional& padKey ); TargetPinDescriptor(const TargetPinDescriptor& other) = delete;