Target driver passthrough commands

Added `pm` commands to manage the program mode of WCH targets
This commit is contained in:
Nav
2024-12-15 17:32:58 +00:00
parent 1392cda74f
commit 40859201e4
16 changed files with 243 additions and 3 deletions

View File

@@ -31,5 +31,6 @@ namespace TargetController::Commands
GET_TARGET_PROGRAM_COUNTER,
ENABLE_PROGRAMMING_MODE,
DISABLE_PROGRAMMING_MODE,
INVOKE_TARGET_PASSTHROUGH_COMMAND,
};
}

View File

@@ -0,0 +1,31 @@
#pragma once
#include "Command.hpp"
#include "src/TargetController/Responses/TargetPassthroughResponse.hpp"
#include "src/Targets/PassthroughCommand.hpp"
namespace TargetController::Commands
{
class InvokeTargetPassthroughCommand: public Command
{
public:
using SuccessResponseType = Responses::TargetPassthroughResponse;
static constexpr CommandType type = CommandType::INVOKE_TARGET_PASSTHROUGH_COMMAND;
static const inline std::string name = "InvokeTargetPassthroughCommand";
Targets::PassthroughCommand command;
explicit InvokeTargetPassthroughCommand(Targets::PassthroughCommand&& command)
: command(std::move(command))
{};
[[nodiscard]] CommandType getType() const override {
return InvokeTargetPassthroughCommand::type;
}
[[nodiscard]] bool requiresStoppedTargetState() const override {
return true;
}
};
}

View File

@@ -17,5 +17,6 @@ namespace TargetController::Responses
TARGET_STACK_POINTER,
TARGET_PROGRAM_COUNTER,
PROGRAM_BREAKPOINT,
TARGET_PASSTHROUGH_RESPONSE,
};
}

View File

@@ -0,0 +1,26 @@
#pragma once
#include <optional>
#include "Response.hpp"
#include "src/Targets/PassthroughResponse.hpp"
namespace TargetController::Responses
{
class TargetPassthroughResponse: public Response
{
public:
static constexpr ResponseType type = ResponseType::TARGET_PASSTHROUGH_RESPONSE;
std::optional<Targets::PassthroughResponse> response;
explicit TargetPassthroughResponse(std::optional<Targets::PassthroughResponse>&& response)
: response(std::move(response))
{}
[[nodiscard]] ResponseType getType() const override {
return TargetPassthroughResponse::type;
}
};
}

View File

@@ -51,6 +51,7 @@ namespace TargetController
using Commands::GetTargetProgramCounter;
using Commands::EnableProgrammingMode;
using Commands::DisableProgrammingMode;
using Commands::InvokeTargetPassthroughCommand;
using Responses::Response;
using Responses::AtomicSessionId;
@@ -60,6 +61,7 @@ namespace TargetController
using Responses::TargetStackPointer;
using Responses::TargetProgramCounter;
using Responses::ProgramBreakpoint;
using Responses::TargetPassthroughResponse;
TargetControllerComponent::TargetControllerComponent(
const ProjectConfig& projectConfig,
@@ -262,6 +264,10 @@ namespace TargetController
std::bind(&TargetControllerComponent::handleDisableProgrammingMode, this, std::placeholders::_1)
);
this->registerCommandHandler<InvokeTargetPassthroughCommand>(
std::bind(&TargetControllerComponent::handleTargetPassthroughCommand, this, std::placeholders::_1)
);
// Register event handlers
this->eventListener->registerCallbackForEventType<Events::ShutdownTargetController>(
std::bind(&TargetControllerComponent::onShutdownTargetControllerEvent, this, std::placeholders::_1)
@@ -1173,4 +1179,10 @@ namespace TargetController
return std::make_unique<Response>();
}
std::unique_ptr<TargetPassthroughResponse> TargetControllerComponent::handleTargetPassthroughCommand(
InvokeTargetPassthroughCommand& command
) {
return std::make_unique<TargetPassthroughResponse>(this->target->invokePassthroughCommand(command.command));
}
}

View File

@@ -45,6 +45,7 @@
#include "Commands/GetTargetProgramCounter.hpp"
#include "Commands/EnableProgrammingMode.hpp"
#include "Commands/DisableProgrammingMode.hpp"
#include "Commands/InvokeTargetPassthroughCommand.hpp"
// Responses
#include "Responses/Response.hpp"
@@ -57,6 +58,7 @@
#include "Responses/TargetStackPointer.hpp"
#include "Responses/TargetProgramCounter.hpp"
#include "Responses/ProgramBreakpoint.hpp"
#include "Responses/TargetPassthroughResponse.hpp"
#include "src/DebugToolDrivers/DebugTools.hpp"
#include "src/Targets/BriefTargetDescriptor.hpp"
@@ -379,5 +381,8 @@ namespace TargetController
);
std::unique_ptr<Responses::Response> handleEnableProgrammingMode(Commands::EnableProgrammingMode& command);
std::unique_ptr<Responses::Response> handleDisableProgrammingMode(Commands::DisableProgrammingMode& command);
std::unique_ptr<Responses::TargetPassthroughResponse> handleTargetPassthroughCommand(
Commands::InvokeTargetPassthroughCommand& command
);
};
}