Merge pull request #12933 from german77/irs-interface

service: irs: Migrate service to new interface
This commit is contained in:
liamwhite 2024-02-06 10:24:30 -05:00 committed by GitHub
commit d5fb9fd12c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 260 additions and 407 deletions

View file

@ -9,6 +9,7 @@
#include "core/hle/kernel/k_shared_memory.h" #include "core/hle/kernel/k_shared_memory.h"
#include "core/hle/kernel/k_transfer_memory.h" #include "core/hle/kernel/k_transfer_memory.h"
#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/kernel.h"
#include "core/hle/service/cmif_serialization.h"
#include "core/hle/service/hid/irs.h" #include "core/hle/service/hid/irs.h"
#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/ipc_helpers.h"
#include "core/memory.h" #include "core/memory.h"
@ -28,24 +29,24 @@ namespace Service::IRS {
IRS::IRS(Core::System& system_) : ServiceFramework{system_, "irs"} { IRS::IRS(Core::System& system_) : ServiceFramework{system_, "irs"} {
// clang-format off // clang-format off
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
{302, &IRS::ActivateIrsensor, "ActivateIrsensor"}, {302, C<&IRS::ActivateIrsensor>, "ActivateIrsensor"},
{303, &IRS::DeactivateIrsensor, "DeactivateIrsensor"}, {303, C<&IRS::DeactivateIrsensor>, "DeactivateIrsensor"},
{304, &IRS::GetIrsensorSharedMemoryHandle, "GetIrsensorSharedMemoryHandle"}, {304, C<&IRS::GetIrsensorSharedMemoryHandle>, "GetIrsensorSharedMemoryHandle"},
{305, &IRS::StopImageProcessor, "StopImageProcessor"}, {305, C<&IRS::StopImageProcessor>, "StopImageProcessor"},
{306, &IRS::RunMomentProcessor, "RunMomentProcessor"}, {306, C<&IRS::RunMomentProcessor>, "RunMomentProcessor"},
{307, &IRS::RunClusteringProcessor, "RunClusteringProcessor"}, {307, C<&IRS::RunClusteringProcessor>, "RunClusteringProcessor"},
{308, &IRS::RunImageTransferProcessor, "RunImageTransferProcessor"}, {308, C<&IRS::RunImageTransferProcessor>, "RunImageTransferProcessor"},
{309, &IRS::GetImageTransferProcessorState, "GetImageTransferProcessorState"}, {309, C<&IRS::GetImageTransferProcessorState>, "GetImageTransferProcessorState"},
{310, &IRS::RunTeraPluginProcessor, "RunTeraPluginProcessor"}, {310, C<&IRS::RunTeraPluginProcessor>, "RunTeraPluginProcessor"},
{311, &IRS::GetNpadIrCameraHandle, "GetNpadIrCameraHandle"}, {311, C<&IRS::GetNpadIrCameraHandle>, "GetNpadIrCameraHandle"},
{312, &IRS::RunPointingProcessor, "RunPointingProcessor"}, {312, C<&IRS::RunPointingProcessor>, "RunPointingProcessor"},
{313, &IRS::SuspendImageProcessor, "SuspendImageProcessor"}, {313, C<&IRS::SuspendImageProcessor>, "SuspendImageProcessor"},
{314, &IRS::CheckFirmwareVersion, "CheckFirmwareVersion"}, {314, C<&IRS::CheckFirmwareVersion>, "CheckFirmwareVersion"},
{315, &IRS::SetFunctionLevel, "SetFunctionLevel"}, {315, C<&IRS::SetFunctionLevel>, "SetFunctionLevel"},
{316, &IRS::RunImageTransferExProcessor, "RunImageTransferExProcessor"}, {316, C<&IRS::RunImageTransferExProcessor>, "RunImageTransferExProcessor"},
{317, &IRS::RunIrLedProcessor, "RunIrLedProcessor"}, {317, C<&IRS::RunIrLedProcessor>, "RunIrLedProcessor"},
{318, &IRS::StopImageProcessorAsync, "StopImageProcessorAsync"}, {318, C<&IRS::StopImageProcessorAsync>, "StopImageProcessorAsync"},
{319, &IRS::ActivateIrsensorWithFunctionLevel, "ActivateIrsensorWithFunctionLevel"}, {319, C<&IRS::ActivateIrsensorWithFunctionLevel>, "ActivateIrsensorWithFunctionLevel"},
}; };
// clang-format on // clang-format on
@ -57,489 +58,292 @@ IRS::IRS(Core::System& system_) : ServiceFramework{system_, "irs"} {
} }
IRS::~IRS() = default; IRS::~IRS() = default;
void IRS::ActivateIrsensor(HLERequestContext& ctx) { Result IRS::ActivateIrsensor(ClientAppletResourceUserId aruid) {
IPC::RequestParser rp{ctx}; LOG_WARNING(Service_IRS, "(STUBBED) called, applet_resource_user_id={}", aruid.pid);
const auto applet_resource_user_id{rp.Pop<u64>()}; R_SUCCEED();
LOG_WARNING(Service_IRS, "(STUBBED) called, applet_resource_user_id={}",
applet_resource_user_id);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
} }
void IRS::DeactivateIrsensor(HLERequestContext& ctx) { Result IRS::DeactivateIrsensor(ClientAppletResourceUserId aruid) {
IPC::RequestParser rp{ctx}; LOG_WARNING(Service_IRS, "(STUBBED) called, applet_resource_user_id={}", aruid.pid);
const auto applet_resource_user_id{rp.Pop<u64>()}; R_SUCCEED();
LOG_WARNING(Service_IRS, "(STUBBED) called, applet_resource_user_id={}",
applet_resource_user_id);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
} }
void IRS::GetIrsensorSharedMemoryHandle(HLERequestContext& ctx) { Result IRS::GetIrsensorSharedMemoryHandle(OutCopyHandle<Kernel::KSharedMemory> out_shared_memory,
IPC::RequestParser rp{ctx}; ClientAppletResourceUserId aruid) {
const auto applet_resource_user_id{rp.Pop<u64>()}; LOG_DEBUG(Service_IRS, "called, applet_resource_user_id={}", aruid.pid);
LOG_DEBUG(Service_IRS, "called, applet_resource_user_id={}", applet_resource_user_id); *out_shared_memory = &system.Kernel().GetIrsSharedMem();
R_SUCCEED();
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(ResultSuccess);
rb.PushCopyObjects(&system.Kernel().GetIrsSharedMem());
} }
void IRS::StopImageProcessor(HLERequestContext& ctx) { Result IRS::StopImageProcessor(Core::IrSensor::IrCameraHandle camera_handle,
IPC::RequestParser rp{ctx}; ClientAppletResourceUserId aruid) {
struct Parameters {
Core::IrSensor::IrCameraHandle camera_handle;
INSERT_PADDING_WORDS_NOINIT(1);
u64 applet_resource_user_id;
};
static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
const auto parameters{rp.PopRaw<Parameters>()};
LOG_WARNING(Service_IRS, LOG_WARNING(Service_IRS,
"(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}",
parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, camera_handle.npad_type, camera_handle.npad_id, aruid.pid);
parameters.applet_resource_user_id);
auto result = IsIrCameraHandleValid(parameters.camera_handle); R_TRY(IsIrCameraHandleValid(camera_handle));
if (result.IsSuccess()) {
// TODO: Stop Image processor
npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
Common::Input::PollingMode::Active);
result = ResultSuccess;
}
IPC::ResponseBuilder rb{ctx, 2}; // TODO: Stop Image processor
rb.Push(result); npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
Common::Input::PollingMode::Active);
R_SUCCEED();
} }
void IRS::RunMomentProcessor(HLERequestContext& ctx) { Result IRS::RunMomentProcessor(
IPC::RequestParser rp{ctx}; Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid,
struct Parameters { const Core::IrSensor::PackedMomentProcessorConfig& processor_config) {
Core::IrSensor::IrCameraHandle camera_handle;
INSERT_PADDING_WORDS_NOINIT(1);
u64 applet_resource_user_id;
Core::IrSensor::PackedMomentProcessorConfig processor_config;
};
static_assert(sizeof(Parameters) == 0x30, "Parameters has incorrect size.");
const auto parameters{rp.PopRaw<Parameters>()};
LOG_WARNING(Service_IRS, LOG_WARNING(Service_IRS,
"(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}",
parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, camera_handle.npad_type, camera_handle.npad_id, aruid.pid);
parameters.applet_resource_user_id);
const auto result = IsIrCameraHandleValid(parameters.camera_handle); R_TRY(IsIrCameraHandleValid(camera_handle));
if (result.IsSuccess()) { auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle);
auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); MakeProcessorWithCoreContext<MomentProcessor>(camera_handle, device);
MakeProcessorWithCoreContext<MomentProcessor>(parameters.camera_handle, device); auto& image_transfer_processor = GetProcessor<MomentProcessor>(camera_handle);
auto& image_transfer_processor = GetProcessor<MomentProcessor>(parameters.camera_handle); image_transfer_processor.SetConfig(processor_config);
image_transfer_processor.SetConfig(parameters.processor_config); npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, Common::Input::PollingMode::IR);
Common::Input::PollingMode::IR);
}
IPC::ResponseBuilder rb{ctx, 2}; R_SUCCEED();
rb.Push(result);
} }
void IRS::RunClusteringProcessor(HLERequestContext& ctx) { Result IRS::RunClusteringProcessor(
IPC::RequestParser rp{ctx}; Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid,
struct Parameters { const Core::IrSensor::PackedClusteringProcessorConfig& processor_config) {
Core::IrSensor::IrCameraHandle camera_handle;
INSERT_PADDING_WORDS_NOINIT(1);
u64 applet_resource_user_id;
Core::IrSensor::PackedClusteringProcessorConfig processor_config;
};
static_assert(sizeof(Parameters) == 0x38, "Parameters has incorrect size.");
const auto parameters{rp.PopRaw<Parameters>()};
LOG_WARNING(Service_IRS, LOG_WARNING(Service_IRS,
"(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}",
parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, camera_handle.npad_type, camera_handle.npad_id, aruid.pid);
parameters.applet_resource_user_id);
auto result = IsIrCameraHandleValid(parameters.camera_handle); R_TRY(IsIrCameraHandleValid(camera_handle));
if (result.IsSuccess()) { auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle);
auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); MakeProcessorWithCoreContext<ClusteringProcessor>(camera_handle, device);
MakeProcessorWithCoreContext<ClusteringProcessor>(parameters.camera_handle, device); auto& image_transfer_processor = GetProcessor<ClusteringProcessor>(camera_handle);
auto& image_transfer_processor = image_transfer_processor.SetConfig(processor_config);
GetProcessor<ClusteringProcessor>(parameters.camera_handle); npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
image_transfer_processor.SetConfig(parameters.processor_config); Common::Input::PollingMode::IR);
npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
Common::Input::PollingMode::IR);
}
IPC::ResponseBuilder rb{ctx, 2}; R_SUCCEED();
rb.Push(result);
} }
void IRS::RunImageTransferProcessor(HLERequestContext& ctx) { Result IRS::RunImageTransferProcessor(
IPC::RequestParser rp{ctx}; Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid,
struct Parameters { const Core::IrSensor::PackedImageTransferProcessorConfig& processor_config,
Core::IrSensor::IrCameraHandle camera_handle; u64 transfer_memory_size, InCopyHandle<Kernel::KTransferMemory> t_mem) {
INSERT_PADDING_WORDS_NOINIT(1);
u64 applet_resource_user_id;
Core::IrSensor::PackedImageTransferProcessorConfig processor_config;
u32 transfer_memory_size;
};
static_assert(sizeof(Parameters) == 0x30, "Parameters has incorrect size.");
const auto parameters{rp.PopRaw<Parameters>()}; ASSERT_MSG(t_mem->GetSize() == transfer_memory_size, "t_mem has incorrect size");
const auto t_mem_handle{ctx.GetCopyHandle(0)};
auto t_mem = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(t_mem_handle);
if (t_mem.IsNull()) {
LOG_ERROR(Service_IRS, "t_mem is a nullptr for handle=0x{:08X}", t_mem_handle);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultUnknown);
return;
}
ASSERT_MSG(t_mem->GetSize() == parameters.transfer_memory_size, "t_mem has incorrect size");
LOG_INFO(Service_IRS, LOG_INFO(Service_IRS,
"called, npad_type={}, npad_id={}, transfer_memory_size={}, transfer_memory_size={}, " "called, npad_type={}, npad_id={}, transfer_memory_size={}, transfer_memory_size={}, "
"applet_resource_user_id={}", "applet_resource_user_id={}",
parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, camera_handle.npad_type, camera_handle.npad_id, transfer_memory_size, t_mem->GetSize(),
parameters.transfer_memory_size, t_mem->GetSize(), parameters.applet_resource_user_id); aruid.pid);
const auto result = IsIrCameraHandleValid(parameters.camera_handle); R_TRY(IsIrCameraHandleValid(camera_handle));
if (result.IsSuccess()) { auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle);
auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); MakeProcessorWithCoreContext<ImageTransferProcessor>(camera_handle, device);
MakeProcessorWithCoreContext<ImageTransferProcessor>(parameters.camera_handle, device); auto& image_transfer_processor = GetProcessor<ImageTransferProcessor>(camera_handle);
auto& image_transfer_processor = image_transfer_processor.SetConfig(processor_config);
GetProcessor<ImageTransferProcessor>(parameters.camera_handle); image_transfer_processor.SetTransferMemoryAddress(t_mem->GetSourceAddress());
image_transfer_processor.SetConfig(parameters.processor_config); npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
image_transfer_processor.SetTransferMemoryAddress(t_mem->GetSourceAddress()); Common::Input::PollingMode::IR);
npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
Common::Input::PollingMode::IR);
}
IPC::ResponseBuilder rb{ctx, 2}; R_SUCCEED();
rb.Push(result);
} }
void IRS::GetImageTransferProcessorState(HLERequestContext& ctx) { Result IRS::GetImageTransferProcessorState(
IPC::RequestParser rp{ctx}; Out<Core::IrSensor::ImageTransferProcessorState> out_state,
struct Parameters { Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid,
Core::IrSensor::IrCameraHandle camera_handle; OutBuffer<BufferAttr_HipcMapAlias> out_buffer_data) {
INSERT_PADDING_WORDS_NOINIT(1);
u64 applet_resource_user_id;
};
static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
const auto parameters{rp.PopRaw<Parameters>()};
LOG_DEBUG(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", LOG_DEBUG(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}",
parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, camera_handle.npad_type, camera_handle.npad_id, aruid.pid);
parameters.applet_resource_user_id);
const auto result = IsIrCameraHandleValid(parameters.camera_handle); R_TRY(IsIrCameraHandleValid(camera_handle));
if (result.IsError()) {
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(result);
return;
}
const auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); const auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle);
if (device.mode != Core::IrSensor::IrSensorMode::ImageTransferProcessor) { R_TRY(IsIrCameraHandleValid(camera_handle));
IPC::ResponseBuilder rb{ctx, 2}; R_UNLESS(device.mode == Core::IrSensor::IrSensorMode::ImageTransferProcessor,
rb.Push(InvalidProcessorState); InvalidProcessorState);
return;
}
std::vector<u8> data{}; *out_state = GetProcessor<ImageTransferProcessor>(camera_handle).GetState(out_buffer_data);
const auto& image_transfer_processor =
GetProcessor<ImageTransferProcessor>(parameters.camera_handle);
const auto& state = image_transfer_processor.GetState(data);
ctx.WriteBuffer(data); R_SUCCEED();
IPC::ResponseBuilder rb{ctx, 6};
rb.Push(ResultSuccess);
rb.PushRaw(state);
} }
void IRS::RunTeraPluginProcessor(HLERequestContext& ctx) { Result IRS::RunTeraPluginProcessor(Core::IrSensor::IrCameraHandle camera_handle,
IPC::RequestParser rp{ctx}; Core::IrSensor::PackedTeraPluginProcessorConfig processor_config,
struct Parameters { ClientAppletResourceUserId aruid) {
Core::IrSensor::IrCameraHandle camera_handle; LOG_WARNING(Service_IRS,
Core::IrSensor::PackedTeraPluginProcessorConfig processor_config; "(STUBBED) called, npad_type={}, npad_id={}, mode={}, mcu_version={}.{}, "
INSERT_PADDING_WORDS_NOINIT(1); "applet_resource_user_id={}",
u64 applet_resource_user_id; camera_handle.npad_type, camera_handle.npad_id, processor_config.mode,
}; processor_config.required_mcu_version.major,
static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); processor_config.required_mcu_version.minor, aruid.pid);
const auto parameters{rp.PopRaw<Parameters>()}; R_TRY(IsIrCameraHandleValid(camera_handle));
LOG_WARNING( auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle);
Service_IRS, MakeProcessor<TeraPluginProcessor>(camera_handle, device);
"(STUBBED) called, npad_type={}, npad_id={}, mode={}, mcu_version={}.{}, " auto& image_transfer_processor = GetProcessor<TeraPluginProcessor>(camera_handle);
"applet_resource_user_id={}", image_transfer_processor.SetConfig(processor_config);
parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
parameters.processor_config.mode, parameters.processor_config.required_mcu_version.major, Common::Input::PollingMode::IR);
parameters.processor_config.required_mcu_version.minor, parameters.applet_resource_user_id);
const auto result = IsIrCameraHandleValid(parameters.camera_handle); R_SUCCEED();
if (result.IsSuccess()) {
auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle);
MakeProcessor<TeraPluginProcessor>(parameters.camera_handle, device);
auto& image_transfer_processor =
GetProcessor<TeraPluginProcessor>(parameters.camera_handle);
image_transfer_processor.SetConfig(parameters.processor_config);
npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
Common::Input::PollingMode::IR);
}
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(result);
} }
void IRS::GetNpadIrCameraHandle(HLERequestContext& ctx) { Result IRS::GetNpadIrCameraHandle(Out<Core::IrSensor::IrCameraHandle> out_camera_handle,
IPC::RequestParser rp{ctx}; Core::HID::NpadIdType npad_id) {
const auto npad_id{rp.PopEnum<Core::HID::NpadIdType>()}; R_UNLESS(HID::IsNpadIdValid(npad_id), HID::ResultInvalidNpadId);
if (npad_id > Core::HID::NpadIdType::Player8 && npad_id != Core::HID::NpadIdType::Invalid && *out_camera_handle = {
npad_id != Core::HID::NpadIdType::Handheld) {
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(Service::HID::ResultInvalidNpadId);
return;
}
Core::IrSensor::IrCameraHandle camera_handle{
.npad_id = static_cast<u8>(HID::NpadIdTypeToIndex(npad_id)), .npad_id = static_cast<u8>(HID::NpadIdTypeToIndex(npad_id)),
.npad_type = Core::HID::NpadStyleIndex::None, .npad_type = Core::HID::NpadStyleIndex::None,
}; };
LOG_INFO(Service_IRS, "called, npad_id={}, camera_npad_id={}, camera_npad_type={}", npad_id, LOG_INFO(Service_IRS, "called, npad_id={}, camera_npad_id={}, camera_npad_type={}", npad_id,
camera_handle.npad_id, camera_handle.npad_type); out_camera_handle->npad_id, out_camera_handle->npad_type);
IPC::ResponseBuilder rb{ctx, 3}; R_SUCCEED();
rb.Push(ResultSuccess);
rb.PushRaw(camera_handle);
} }
void IRS::RunPointingProcessor(HLERequestContext& ctx) { Result IRS::RunPointingProcessor(
IPC::RequestParser rp{ctx}; Core::IrSensor::IrCameraHandle camera_handle,
const auto camera_handle{rp.PopRaw<Core::IrSensor::IrCameraHandle>()}; const Core::IrSensor::PackedPointingProcessorConfig& processor_config,
const auto processor_config{rp.PopRaw<Core::IrSensor::PackedPointingProcessorConfig>()}; ClientAppletResourceUserId aruid) {
const auto applet_resource_user_id{rp.Pop<u64>()};
LOG_WARNING( LOG_WARNING(
Service_IRS, Service_IRS,
"(STUBBED) called, npad_type={}, npad_id={}, mcu_version={}.{}, applet_resource_user_id={}", "(STUBBED) called, npad_type={}, npad_id={}, mcu_version={}.{}, applet_resource_user_id={}",
camera_handle.npad_type, camera_handle.npad_id, processor_config.required_mcu_version.major, camera_handle.npad_type, camera_handle.npad_id, processor_config.required_mcu_version.major,
processor_config.required_mcu_version.minor, applet_resource_user_id); processor_config.required_mcu_version.minor, aruid.pid);
auto result = IsIrCameraHandleValid(camera_handle); R_TRY(IsIrCameraHandleValid(camera_handle));
if (result.IsSuccess()) { auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle);
auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); MakeProcessor<PointingProcessor>(camera_handle, device);
MakeProcessor<PointingProcessor>(camera_handle, device); auto& image_transfer_processor = GetProcessor<PointingProcessor>(camera_handle);
auto& image_transfer_processor = GetProcessor<PointingProcessor>(camera_handle); image_transfer_processor.SetConfig(processor_config);
image_transfer_processor.SetConfig(processor_config); npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, Common::Input::PollingMode::IR);
Common::Input::PollingMode::IR);
}
IPC::ResponseBuilder rb{ctx, 2}; R_SUCCEED();
rb.Push(result);
} }
void IRS::SuspendImageProcessor(HLERequestContext& ctx) { Result IRS::SuspendImageProcessor(Core::IrSensor::IrCameraHandle camera_handle,
IPC::RequestParser rp{ctx}; ClientAppletResourceUserId aruid) {
struct Parameters {
Core::IrSensor::IrCameraHandle camera_handle;
INSERT_PADDING_WORDS_NOINIT(1);
u64 applet_resource_user_id;
};
static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
const auto parameters{rp.PopRaw<Parameters>()};
LOG_WARNING(Service_IRS, LOG_WARNING(Service_IRS,
"(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}",
parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, camera_handle.npad_type, camera_handle.npad_id, aruid.pid);
parameters.applet_resource_user_id);
auto result = IsIrCameraHandleValid(parameters.camera_handle); R_TRY(IsIrCameraHandleValid(camera_handle));
if (result.IsSuccess()) {
// TODO: Suspend image processor
result = ResultSuccess;
}
IPC::ResponseBuilder rb{ctx, 2}; // TODO: Suspend image processor
rb.Push(result);
R_SUCCEED();
} }
void IRS::CheckFirmwareVersion(HLERequestContext& ctx) { Result IRS::CheckFirmwareVersion(Core::IrSensor::IrCameraHandle camera_handle,
IPC::RequestParser rp{ctx}; Core::IrSensor::PackedMcuVersion mcu_version,
const auto camera_handle{rp.PopRaw<Core::IrSensor::IrCameraHandle>()}; ClientAppletResourceUserId aruid) {
const auto mcu_version{rp.PopRaw<Core::IrSensor::PackedMcuVersion>()};
const auto applet_resource_user_id{rp.Pop<u64>()};
LOG_WARNING( LOG_WARNING(
Service_IRS, Service_IRS,
"(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}, mcu_version={}.{}", "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}, mcu_version={}.{}",
camera_handle.npad_type, camera_handle.npad_id, applet_resource_user_id, mcu_version.major, camera_handle.npad_type, camera_handle.npad_id, aruid.pid, mcu_version.major,
mcu_version.minor); mcu_version.minor);
auto result = IsIrCameraHandleValid(camera_handle); R_TRY(IsIrCameraHandleValid(camera_handle));
if (result.IsSuccess()) {
// TODO: Check firmware version
result = ResultSuccess;
}
IPC::ResponseBuilder rb{ctx, 2}; // TODO: Check firmware version
rb.Push(result);
R_SUCCEED();
} }
void IRS::SetFunctionLevel(HLERequestContext& ctx) { Result IRS::SetFunctionLevel(Core::IrSensor::IrCameraHandle camera_handle,
IPC::RequestParser rp{ctx}; Core::IrSensor::PackedFunctionLevel function_level,
const auto camera_handle{rp.PopRaw<Core::IrSensor::IrCameraHandle>()}; ClientAppletResourceUserId aruid) {
const auto function_level{rp.PopRaw<Core::IrSensor::PackedFunctionLevel>()};
const auto applet_resource_user_id{rp.Pop<u64>()};
LOG_WARNING( LOG_WARNING(
Service_IRS, Service_IRS,
"(STUBBED) called, npad_type={}, npad_id={}, function_level={}, applet_resource_user_id={}", "(STUBBED) called, npad_type={}, npad_id={}, function_level={}, applet_resource_user_id={}",
camera_handle.npad_type, camera_handle.npad_id, function_level.function_level, camera_handle.npad_type, camera_handle.npad_id, function_level.function_level, aruid.pid);
applet_resource_user_id);
auto result = IsIrCameraHandleValid(camera_handle); R_TRY(IsIrCameraHandleValid(camera_handle));
if (result.IsSuccess()) {
// TODO: Set Function level
result = ResultSuccess;
}
IPC::ResponseBuilder rb{ctx, 2}; // TODO: Set Function level
rb.Push(result);
R_SUCCEED();
} }
void IRS::RunImageTransferExProcessor(HLERequestContext& ctx) { Result IRS::RunImageTransferExProcessor(
IPC::RequestParser rp{ctx}; Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid,
struct Parameters { const Core::IrSensor::PackedImageTransferProcessorExConfig& processor_config,
Core::IrSensor::IrCameraHandle camera_handle; u64 transfer_memory_size, InCopyHandle<Kernel::KTransferMemory> t_mem) {
INSERT_PADDING_WORDS_NOINIT(1);
u64 applet_resource_user_id;
Core::IrSensor::PackedImageTransferProcessorExConfig processor_config;
u64 transfer_memory_size;
};
static_assert(sizeof(Parameters) == 0x38, "Parameters has incorrect size.");
const auto parameters{rp.PopRaw<Parameters>()}; ASSERT_MSG(t_mem->GetSize() == transfer_memory_size, "t_mem has incorrect size");
const auto t_mem_handle{ctx.GetCopyHandle(0)};
auto t_mem = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(t_mem_handle);
LOG_INFO(Service_IRS, LOG_INFO(Service_IRS,
"called, npad_type={}, npad_id={}, transfer_memory_size={}, " "called, npad_type={}, npad_id={}, transfer_memory_size={}, "
"applet_resource_user_id={}", "applet_resource_user_id={}",
parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, camera_handle.npad_type, camera_handle.npad_id, transfer_memory_size, aruid.pid);
parameters.transfer_memory_size, parameters.applet_resource_user_id);
auto result = IsIrCameraHandleValid(parameters.camera_handle); R_TRY(IsIrCameraHandleValid(camera_handle));
if (result.IsSuccess()) { auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle);
auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); MakeProcessorWithCoreContext<ImageTransferProcessor>(camera_handle, device);
MakeProcessorWithCoreContext<ImageTransferProcessor>(parameters.camera_handle, device); auto& image_transfer_processor = GetProcessor<ImageTransferProcessor>(camera_handle);
auto& image_transfer_processor = image_transfer_processor.SetConfig(processor_config);
GetProcessor<ImageTransferProcessor>(parameters.camera_handle); image_transfer_processor.SetTransferMemoryAddress(t_mem->GetSourceAddress());
image_transfer_processor.SetConfig(parameters.processor_config); npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
image_transfer_processor.SetTransferMemoryAddress(t_mem->GetSourceAddress()); Common::Input::PollingMode::IR);
npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
Common::Input::PollingMode::IR);
}
IPC::ResponseBuilder rb{ctx, 2}; R_SUCCEED();
rb.Push(result);
} }
void IRS::RunIrLedProcessor(HLERequestContext& ctx) { Result IRS::RunIrLedProcessor(Core::IrSensor::IrCameraHandle camera_handle,
IPC::RequestParser rp{ctx}; Core::IrSensor::PackedIrLedProcessorConfig processor_config,
const auto camera_handle{rp.PopRaw<Core::IrSensor::IrCameraHandle>()}; ClientAppletResourceUserId aruid) {
const auto processor_config{rp.PopRaw<Core::IrSensor::PackedIrLedProcessorConfig>()};
const auto applet_resource_user_id{rp.Pop<u64>()};
LOG_WARNING(Service_IRS, LOG_WARNING(Service_IRS,
"(STUBBED) called, npad_type={}, npad_id={}, light_target={}, mcu_version={}.{} " "(STUBBED) called, npad_type={}, npad_id={}, light_target={}, mcu_version={}.{} "
"applet_resource_user_id={}", "applet_resource_user_id={}",
camera_handle.npad_type, camera_handle.npad_id, processor_config.light_target, camera_handle.npad_type, camera_handle.npad_id, processor_config.light_target,
processor_config.required_mcu_version.major, processor_config.required_mcu_version.major,
processor_config.required_mcu_version.minor, applet_resource_user_id); processor_config.required_mcu_version.minor, aruid.pid);
auto result = IsIrCameraHandleValid(camera_handle); R_TRY(IsIrCameraHandleValid(camera_handle));
if (result.IsSuccess()) { auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle);
auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); MakeProcessor<IrLedProcessor>(camera_handle, device);
MakeProcessor<IrLedProcessor>(camera_handle, device); auto& image_transfer_processor = GetProcessor<IrLedProcessor>(camera_handle);
auto& image_transfer_processor = GetProcessor<IrLedProcessor>(camera_handle); image_transfer_processor.SetConfig(processor_config);
image_transfer_processor.SetConfig(processor_config); npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, Common::Input::PollingMode::IR);
Common::Input::PollingMode::IR);
}
IPC::ResponseBuilder rb{ctx, 2}; R_SUCCEED();
rb.Push(result);
} }
void IRS::StopImageProcessorAsync(HLERequestContext& ctx) { Result IRS::StopImageProcessorAsync(Core::IrSensor::IrCameraHandle camera_handle,
IPC::RequestParser rp{ctx}; ClientAppletResourceUserId aruid) {
struct Parameters {
Core::IrSensor::IrCameraHandle camera_handle;
INSERT_PADDING_WORDS_NOINIT(1);
u64 applet_resource_user_id;
};
static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
const auto parameters{rp.PopRaw<Parameters>()};
LOG_WARNING(Service_IRS, LOG_WARNING(Service_IRS,
"(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}",
parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, camera_handle.npad_type, camera_handle.npad_id, aruid.pid);
parameters.applet_resource_user_id);
auto result = IsIrCameraHandleValid(parameters.camera_handle); R_TRY(IsIrCameraHandleValid(camera_handle));
if (result.IsSuccess()) {
// TODO: Stop image processor async
npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
Common::Input::PollingMode::Active);
result = ResultSuccess;
}
IPC::ResponseBuilder rb{ctx, 2}; // TODO: Stop image processor async
rb.Push(result); npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
Common::Input::PollingMode::Active);
R_SUCCEED();
} }
void IRS::ActivateIrsensorWithFunctionLevel(HLERequestContext& ctx) { Result IRS::ActivateIrsensorWithFunctionLevel(Core::IrSensor::PackedFunctionLevel function_level,
IPC::RequestParser rp{ctx}; ClientAppletResourceUserId aruid) {
struct Parameters {
Core::IrSensor::PackedFunctionLevel function_level;
INSERT_PADDING_WORDS_NOINIT(1);
u64 applet_resource_user_id;
};
static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
const auto parameters{rp.PopRaw<Parameters>()};
LOG_WARNING(Service_IRS, "(STUBBED) called, function_level={}, applet_resource_user_id={}", LOG_WARNING(Service_IRS, "(STUBBED) called, function_level={}, applet_resource_user_id={}",
parameters.function_level.function_level, parameters.applet_resource_user_id); function_level.function_level, aruid.pid);
R_SUCCEED();
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
} }
Result IRS::IsIrCameraHandleValid(const Core::IrSensor::IrCameraHandle& camera_handle) const { Result IRS::IsIrCameraHandleValid(const Core::IrSensor::IrCameraHandle& camera_handle) const {

View file

@ -4,6 +4,7 @@
#pragma once #pragma once
#include "core/core.h" #include "core/core.h"
#include "core/hle/service/cmif_types.h"
#include "core/hle/service/service.h" #include "core/hle/service/service.h"
#include "hid_core/hid_types.h" #include "hid_core/hid_types.h"
#include "hid_core/irsensor/irs_types.h" #include "hid_core/irsensor/irs_types.h"
@ -35,26 +36,73 @@ private:
}; };
static_assert(sizeof(StatusManager) == 0x8000, "StatusManager is an invalid size"); static_assert(sizeof(StatusManager) == 0x8000, "StatusManager is an invalid size");
void ActivateIrsensor(HLERequestContext& ctx); Result ActivateIrsensor(ClientAppletResourceUserId aruid);
void DeactivateIrsensor(HLERequestContext& ctx);
void GetIrsensorSharedMemoryHandle(HLERequestContext& ctx); Result DeactivateIrsensor(ClientAppletResourceUserId aruid);
void StopImageProcessor(HLERequestContext& ctx);
void RunMomentProcessor(HLERequestContext& ctx); Result GetIrsensorSharedMemoryHandle(OutCopyHandle<Kernel::KSharedMemory> out_shared_memory,
void RunClusteringProcessor(HLERequestContext& ctx); ClientAppletResourceUserId aruid);
void RunImageTransferProcessor(HLERequestContext& ctx); Result StopImageProcessor(Core::IrSensor::IrCameraHandle camera_handle,
void GetImageTransferProcessorState(HLERequestContext& ctx); ClientAppletResourceUserId aruid);
void RunTeraPluginProcessor(HLERequestContext& ctx);
void GetNpadIrCameraHandle(HLERequestContext& ctx); Result RunMomentProcessor(Core::IrSensor::IrCameraHandle camera_handle,
void RunPointingProcessor(HLERequestContext& ctx); ClientAppletResourceUserId aruid,
void SuspendImageProcessor(HLERequestContext& ctx); const Core::IrSensor::PackedMomentProcessorConfig& processor_config);
void CheckFirmwareVersion(HLERequestContext& ctx);
void SetFunctionLevel(HLERequestContext& ctx); Result RunClusteringProcessor(
void RunImageTransferExProcessor(HLERequestContext& ctx); Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid,
void RunIrLedProcessor(HLERequestContext& ctx); const Core::IrSensor::PackedClusteringProcessorConfig& processor_config);
void StopImageProcessorAsync(HLERequestContext& ctx);
void ActivateIrsensorWithFunctionLevel(HLERequestContext& ctx); Result RunImageTransferProcessor(
Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid,
const Core::IrSensor::PackedImageTransferProcessorConfig& processor_config,
u64 transfer_memory_size, InCopyHandle<Kernel::KTransferMemory> t_mem);
Result GetImageTransferProcessorState(
Out<Core::IrSensor::ImageTransferProcessorState> out_state,
Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid,
OutBuffer<BufferAttr_HipcMapAlias> out_buffer_data);
Result RunTeraPluginProcessor(Core::IrSensor::IrCameraHandle camera_handle,
Core::IrSensor::PackedTeraPluginProcessorConfig processor_config,
ClientAppletResourceUserId aruid);
Result GetNpadIrCameraHandle(Out<Core::IrSensor::IrCameraHandle> out_camera_handle,
Core::HID::NpadIdType npad_id);
Result RunPointingProcessor(
Core::IrSensor::IrCameraHandle camera_handle,
const Core::IrSensor::PackedPointingProcessorConfig& processor_config,
ClientAppletResourceUserId aruid);
Result SuspendImageProcessor(Core::IrSensor::IrCameraHandle camera_handle,
ClientAppletResourceUserId aruid);
Result CheckFirmwareVersion(Core::IrSensor::IrCameraHandle camera_handle,
Core::IrSensor::PackedMcuVersion mcu_version,
ClientAppletResourceUserId aruid);
Result SetFunctionLevel(Core::IrSensor::IrCameraHandle camera_handle,
Core::IrSensor::PackedFunctionLevel function_level,
ClientAppletResourceUserId aruid);
Result RunImageTransferExProcessor(
Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid,
const Core::IrSensor::PackedImageTransferProcessorExConfig& processor_config,
u64 transfer_memory_size, InCopyHandle<Kernel::KTransferMemory> t_mem);
Result RunIrLedProcessor(Core::IrSensor::IrCameraHandle camera_handle,
Core::IrSensor::PackedIrLedProcessorConfig processor_config,
ClientAppletResourceUserId aruid);
Result StopImageProcessorAsync(Core::IrSensor::IrCameraHandle camera_handle,
ClientAppletResourceUserId aruid);
Result ActivateIrsensorWithFunctionLevel(Core::IrSensor::PackedFunctionLevel function_level,
ClientAppletResourceUserId aruid);
Result IsIrCameraHandleValid(const Core::IrSensor::IrCameraHandle& camera_handle) const; Result IsIrCameraHandleValid(const Core::IrSensor::IrCameraHandle& camera_handle) const;
Core::IrSensor::DeviceFormat& GetIrCameraSharedMemoryDeviceEntry( Core::IrSensor::DeviceFormat& GetIrCameraSharedMemoryDeviceEntry(
const Core::IrSensor::IrCameraHandle& camera_handle); const Core::IrSensor::IrCameraHandle& camera_handle);

View file

@ -145,9 +145,8 @@ void ImageTransferProcessor::SetTransferMemoryAddress(Common::ProcessAddress t_m
} }
Core::IrSensor::ImageTransferProcessorState ImageTransferProcessor::GetState( Core::IrSensor::ImageTransferProcessorState ImageTransferProcessor::GetState(
std::vector<u8>& data) const { std::span<u8> data) const {
const auto size = GetDataSize(current_config.trimming_format); const auto size = std::min(GetDataSize(current_config.trimming_format), data.size());
data.resize(size);
system.ApplicationMemory().ReadBlock(transfer_memory, data.data(), size); system.ApplicationMemory().ReadBlock(transfer_memory, data.data(), size);
return processor_state; return processor_state;
} }

View file

@ -3,6 +3,8 @@
#pragma once #pragma once
#include <span>
#include "common/typed_address.h" #include "common/typed_address.h"
#include "hid_core/irsensor/irs_types.h" #include "hid_core/irsensor/irs_types.h"
#include "hid_core/irsensor/processor_base.h" #include "hid_core/irsensor/processor_base.h"
@ -39,7 +41,7 @@ public:
// Transfer memory where the image data will be stored // Transfer memory where the image data will be stored
void SetTransferMemoryAddress(Common::ProcessAddress t_mem); void SetTransferMemoryAddress(Common::ProcessAddress t_mem);
Core::IrSensor::ImageTransferProcessorState GetState(std::vector<u8>& data) const; Core::IrSensor::ImageTransferProcessorState GetState(std::span<u8> data) const;
private: private:
// This is nn::irsensor::ImageTransferProcessorConfig // This is nn::irsensor::ImageTransferProcessorConfig