From ee847f8ff0b1b0aec39c1b78c010bc0c08a0a613 Mon Sep 17 00:00:00 2001 From: Narr the Reg Date: Thu, 4 Jan 2024 20:37:43 -0600 Subject: hid_core: Move hid to it's own subproject --- .../service/hid/irsensor/clustering_processor.cpp | 267 --------------------- .../service/hid/irsensor/clustering_processor.h | 115 --------- .../hid/irsensor/image_transfer_processor.cpp | 155 ------------ .../hid/irsensor/image_transfer_processor.h | 77 ------ .../hle/service/hid/irsensor/ir_led_processor.cpp | 27 --- .../hle/service/hid/irsensor/ir_led_processor.h | 47 ---- .../hle/service/hid/irsensor/moment_processor.cpp | 149 ------------ .../hle/service/hid/irsensor/moment_processor.h | 91 ------- .../service/hid/irsensor/pointing_processor.cpp | 26 -- .../hle/service/hid/irsensor/pointing_processor.h | 61 ----- .../hle/service/hid/irsensor/processor_base.cpp | 67 ------ src/core/hle/service/hid/irsensor/processor_base.h | 33 --- .../service/hid/irsensor/tera_plugin_processor.cpp | 29 --- .../service/hid/irsensor/tera_plugin_processor.h | 53 ---- 14 files changed, 1197 deletions(-) delete mode 100644 src/core/hle/service/hid/irsensor/clustering_processor.cpp delete mode 100644 src/core/hle/service/hid/irsensor/clustering_processor.h delete mode 100644 src/core/hle/service/hid/irsensor/image_transfer_processor.cpp delete mode 100644 src/core/hle/service/hid/irsensor/image_transfer_processor.h delete mode 100644 src/core/hle/service/hid/irsensor/ir_led_processor.cpp delete mode 100644 src/core/hle/service/hid/irsensor/ir_led_processor.h delete mode 100644 src/core/hle/service/hid/irsensor/moment_processor.cpp delete mode 100644 src/core/hle/service/hid/irsensor/moment_processor.h delete mode 100644 src/core/hle/service/hid/irsensor/pointing_processor.cpp delete mode 100644 src/core/hle/service/hid/irsensor/pointing_processor.h delete mode 100644 src/core/hle/service/hid/irsensor/processor_base.cpp delete mode 100644 src/core/hle/service/hid/irsensor/processor_base.h delete mode 100644 src/core/hle/service/hid/irsensor/tera_plugin_processor.cpp delete mode 100644 src/core/hle/service/hid/irsensor/tera_plugin_processor.h (limited to 'src/core/hle/service/hid/irsensor') diff --git a/src/core/hle/service/hid/irsensor/clustering_processor.cpp b/src/core/hle/service/hid/irsensor/clustering_processor.cpp deleted file mode 100644 index c559eb0d5..000000000 --- a/src/core/hle/service/hid/irsensor/clustering_processor.cpp +++ /dev/null @@ -1,267 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#include - -#include "core/core.h" -#include "core/core_timing.h" -#include "core/hid/emulated_controller.h" -#include "core/hid/hid_core.h" -#include "core/hle/service/hid/irsensor/clustering_processor.h" - -namespace Service::IRS { -ClusteringProcessor::ClusteringProcessor(Core::System& system_, - Core::IrSensor::DeviceFormat& device_format, - std::size_t npad_index) - : device{device_format}, system{system_} { - npad_device = system.HIDCore().GetEmulatedControllerByIndex(npad_index); - - device.mode = Core::IrSensor::IrSensorMode::ClusteringProcessor; - device.camera_status = Core::IrSensor::IrCameraStatus::Unconnected; - device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Stopped; - SetDefaultConfig(); - - shared_memory = std::construct_at( - reinterpret_cast(&device_format.state.processor_raw_data)); - - Core::HID::ControllerUpdateCallback engine_callback{ - .on_change = [this](Core::HID::ControllerTriggerType type) { OnControllerUpdate(type); }, - .is_npad_service = true, - }; - callback_key = npad_device->SetCallback(engine_callback); -} - -ClusteringProcessor::~ClusteringProcessor() { - npad_device->DeleteCallback(callback_key); -}; - -void ClusteringProcessor::StartProcessor() { - device.camera_status = Core::IrSensor::IrCameraStatus::Available; - device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Ready; -} - -void ClusteringProcessor::SuspendProcessor() {} - -void ClusteringProcessor::StopProcessor() {} - -void ClusteringProcessor::OnControllerUpdate(Core::HID::ControllerTriggerType type) { - if (type != Core::HID::ControllerTriggerType::IrSensor) { - return; - } - - next_state = {}; - const auto& camera_data = npad_device->GetCamera(); - auto filtered_image = camera_data.data; - - RemoveLowIntensityData(filtered_image); - - const auto window_start_x = static_cast(current_config.window_of_interest.x); - const auto window_start_y = static_cast(current_config.window_of_interest.y); - const auto window_end_x = - window_start_x + static_cast(current_config.window_of_interest.width); - const auto window_end_y = - window_start_y + static_cast(current_config.window_of_interest.height); - - for (std::size_t y = window_start_y; y < window_end_y; y++) { - for (std::size_t x = window_start_x; x < window_end_x; x++) { - u8 pixel = GetPixel(filtered_image, x, y); - if (pixel == 0) { - continue; - } - const auto cluster = GetClusterProperties(filtered_image, x, y); - if (cluster.pixel_count > current_config.pixel_count_max) { - continue; - } - if (cluster.pixel_count < current_config.pixel_count_min) { - continue; - } - // Cluster object limit reached - if (next_state.object_count >= next_state.data.size()) { - continue; - } - next_state.data[next_state.object_count] = cluster; - next_state.object_count++; - } - } - - next_state.sampling_number = camera_data.sample; - next_state.timestamp = system.CoreTiming().GetGlobalTimeNs().count(); - next_state.ambient_noise_level = Core::IrSensor::CameraAmbientNoiseLevel::Low; - shared_memory->clustering_lifo.WriteNextEntry(next_state); - - if (!IsProcessorActive()) { - StartProcessor(); - } -} - -void ClusteringProcessor::RemoveLowIntensityData(std::vector& data) { - for (u8& pixel : data) { - if (pixel < current_config.pixel_count_min) { - pixel = 0; - } - } -} - -ClusteringProcessor::ClusteringData ClusteringProcessor::GetClusterProperties(std::vector& data, - std::size_t x, - std::size_t y) { - using DataPoint = Common::Point; - std::queue search_points{}; - ClusteringData current_cluster = GetPixelProperties(data, x, y); - SetPixel(data, x, y, 0); - search_points.emplace({x, y}); - - while (!search_points.empty()) { - const auto point = search_points.front(); - search_points.pop(); - - // Avoid negative numbers - if (point.x == 0 || point.y == 0) { - continue; - } - - std::array new_points{ - DataPoint{point.x - 1, point.y}, - {point.x, point.y - 1}, - {point.x + 1, point.y}, - {point.x, point.y + 1}, - }; - - for (const auto new_point : new_points) { - if (new_point.x >= width) { - continue; - } - if (new_point.y >= height) { - continue; - } - if (GetPixel(data, new_point.x, new_point.y) < current_config.object_intensity_min) { - continue; - } - const ClusteringData cluster = GetPixelProperties(data, new_point.x, new_point.y); - current_cluster = MergeCluster(current_cluster, cluster); - SetPixel(data, new_point.x, new_point.y, 0); - search_points.emplace({new_point.x, new_point.y}); - } - } - - return current_cluster; -} - -ClusteringProcessor::ClusteringData ClusteringProcessor::GetPixelProperties( - const std::vector& data, std::size_t x, std::size_t y) const { - return { - .average_intensity = GetPixel(data, x, y) / 255.0f, - .centroid = - { - .x = static_cast(x), - .y = static_cast(y), - - }, - .pixel_count = 1, - .bound = - { - .x = static_cast(x), - .y = static_cast(y), - .width = 1, - .height = 1, - }, - }; -} - -ClusteringProcessor::ClusteringData ClusteringProcessor::MergeCluster( - const ClusteringData a, const ClusteringData b) const { - const f32 a_pixel_count = static_cast(a.pixel_count); - const f32 b_pixel_count = static_cast(b.pixel_count); - const f32 pixel_count = a_pixel_count + b_pixel_count; - const f32 average_intensity = - (a.average_intensity * a_pixel_count + b.average_intensity * b_pixel_count) / pixel_count; - const Core::IrSensor::IrsCentroid centroid = { - .x = (a.centroid.x * a_pixel_count + b.centroid.x * b_pixel_count) / pixel_count, - .y = (a.centroid.y * a_pixel_count + b.centroid.y * b_pixel_count) / pixel_count, - }; - s16 bound_start_x = a.bound.x < b.bound.x ? a.bound.x : b.bound.x; - s16 bound_start_y = a.bound.y < b.bound.y ? a.bound.y : b.bound.y; - s16 a_bound_end_x = a.bound.x + a.bound.width; - s16 a_bound_end_y = a.bound.y + a.bound.height; - s16 b_bound_end_x = b.bound.x + b.bound.width; - s16 b_bound_end_y = b.bound.y + b.bound.height; - - const Core::IrSensor::IrsRect bound = { - .x = bound_start_x, - .y = bound_start_y, - .width = a_bound_end_x > b_bound_end_x ? static_cast(a_bound_end_x - bound_start_x) - : static_cast(b_bound_end_x - bound_start_x), - .height = a_bound_end_y > b_bound_end_y ? static_cast(a_bound_end_y - bound_start_y) - : static_cast(b_bound_end_y - bound_start_y), - }; - - return { - .average_intensity = average_intensity, - .centroid = centroid, - .pixel_count = static_cast(pixel_count), - .bound = bound, - }; -} - -u8 ClusteringProcessor::GetPixel(const std::vector& data, std::size_t x, std::size_t y) const { - if ((y * width) + x >= data.size()) { - return 0; - } - return data[(y * width) + x]; -} - -void ClusteringProcessor::SetPixel(std::vector& data, std::size_t x, std::size_t y, u8 value) { - if ((y * width) + x >= data.size()) { - return; - } - data[(y * width) + x] = value; -} - -void ClusteringProcessor::SetDefaultConfig() { - using namespace std::literals::chrono_literals; - current_config.camera_config.exposure_time = std::chrono::microseconds(200ms).count(); - current_config.camera_config.gain = 2; - current_config.camera_config.is_negative_used = false; - current_config.camera_config.light_target = Core::IrSensor::CameraLightTarget::BrightLeds; - current_config.window_of_interest = { - .x = 0, - .y = 0, - .width = width, - .height = height, - }; - current_config.pixel_count_min = 3; - current_config.pixel_count_max = static_cast(GetDataSize(format)); - current_config.is_external_light_filter_enabled = true; - current_config.object_intensity_min = 150; - - npad_device->SetCameraFormat(format); -} - -void ClusteringProcessor::SetConfig(Core::IrSensor::PackedClusteringProcessorConfig config) { - current_config.camera_config.exposure_time = config.camera_config.exposure_time; - current_config.camera_config.gain = config.camera_config.gain; - current_config.camera_config.is_negative_used = config.camera_config.is_negative_used; - current_config.camera_config.light_target = - static_cast(config.camera_config.light_target); - current_config.window_of_interest = config.window_of_interest; - current_config.pixel_count_min = config.pixel_count_min; - current_config.pixel_count_max = config.pixel_count_max; - current_config.is_external_light_filter_enabled = config.is_external_light_filter_enabled; - current_config.object_intensity_min = config.object_intensity_min; - - LOG_INFO(Service_IRS, - "Processor config, exposure_time={}, gain={}, is_negative_used={}, " - "light_target={}, window_of_interest=({}, {}, {}, {}), pixel_count_min={}, " - "pixel_count_max={}, is_external_light_filter_enabled={}, object_intensity_min={}", - current_config.camera_config.exposure_time, current_config.camera_config.gain, - current_config.camera_config.is_negative_used, - current_config.camera_config.light_target, current_config.window_of_interest.x, - current_config.window_of_interest.y, current_config.window_of_interest.width, - current_config.window_of_interest.height, current_config.pixel_count_min, - current_config.pixel_count_max, current_config.is_external_light_filter_enabled, - current_config.object_intensity_min); - - npad_device->SetCameraFormat(format); -} - -} // namespace Service::IRS diff --git a/src/core/hle/service/hid/irsensor/clustering_processor.h b/src/core/hle/service/hid/irsensor/clustering_processor.h deleted file mode 100644 index 83f34734a..000000000 --- a/src/core/hle/service/hid/irsensor/clustering_processor.h +++ /dev/null @@ -1,115 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#pragma once - -#include "common/common_types.h" -#include "core/hid/irs_types.h" -#include "core/hle/service/hid/irs_ring_lifo.h" -#include "core/hle/service/hid/irsensor/processor_base.h" - -namespace Core { -class System; -} - -namespace Core::HID { -class EmulatedController; -} // namespace Core::HID - -namespace Service::IRS { -class ClusteringProcessor final : public ProcessorBase { -public: - explicit ClusteringProcessor(Core::System& system_, Core::IrSensor::DeviceFormat& device_format, - std::size_t npad_index); - ~ClusteringProcessor() override; - - // Called when the processor is initialized - void StartProcessor() override; - - // Called when the processor is suspended - void SuspendProcessor() override; - - // Called when the processor is stopped - void StopProcessor() override; - - // Sets config parameters of the camera - void SetConfig(Core::IrSensor::PackedClusteringProcessorConfig config); - -private: - static constexpr auto format = Core::IrSensor::ImageTransferProcessorFormat::Size320x240; - static constexpr std::size_t width = 320; - static constexpr std::size_t height = 240; - - // This is nn::irsensor::ClusteringProcessorConfig - struct ClusteringProcessorConfig { - Core::IrSensor::CameraConfig camera_config; - Core::IrSensor::IrsRect window_of_interest; - u32 pixel_count_min; - u32 pixel_count_max; - u32 object_intensity_min; - bool is_external_light_filter_enabled; - INSERT_PADDING_BYTES(3); - }; - static_assert(sizeof(ClusteringProcessorConfig) == 0x30, - "ClusteringProcessorConfig is an invalid size"); - - // This is nn::irsensor::AdaptiveClusteringProcessorConfig - struct AdaptiveClusteringProcessorConfig { - Core::IrSensor::AdaptiveClusteringMode mode; - Core::IrSensor::AdaptiveClusteringTargetDistance target_distance; - }; - static_assert(sizeof(AdaptiveClusteringProcessorConfig) == 0x8, - "AdaptiveClusteringProcessorConfig is an invalid size"); - - // This is nn::irsensor::ClusteringData - struct ClusteringData { - f32 average_intensity; - Core::IrSensor::IrsCentroid centroid; - u32 pixel_count; - Core::IrSensor::IrsRect bound; - }; - static_assert(sizeof(ClusteringData) == 0x18, "ClusteringData is an invalid size"); - - // This is nn::irsensor::ClusteringProcessorState - struct ClusteringProcessorState { - s64 sampling_number; - u64 timestamp; - u8 object_count; - INSERT_PADDING_BYTES(3); - Core::IrSensor::CameraAmbientNoiseLevel ambient_noise_level; - std::array data; - }; - static_assert(sizeof(ClusteringProcessorState) == 0x198, - "ClusteringProcessorState is an invalid size"); - - struct ClusteringSharedMemory { - Service::IRS::Lifo clustering_lifo; - static_assert(sizeof(clustering_lifo) == 0x9A0, "clustering_lifo is an invalid size"); - INSERT_PADDING_WORDS(0x11F); - }; - static_assert(sizeof(ClusteringSharedMemory) == 0xE20, - "ClusteringSharedMemory is an invalid size"); - - void OnControllerUpdate(Core::HID::ControllerTriggerType type); - void RemoveLowIntensityData(std::vector& data); - ClusteringData GetClusterProperties(std::vector& data, std::size_t x, std::size_t y); - ClusteringData GetPixelProperties(const std::vector& data, std::size_t x, - std::size_t y) const; - ClusteringData MergeCluster(const ClusteringData a, const ClusteringData b) const; - u8 GetPixel(const std::vector& data, std::size_t x, std::size_t y) const; - void SetPixel(std::vector& data, std::size_t x, std::size_t y, u8 value); - - // Sets config parameters of the camera - void SetDefaultConfig(); - - ClusteringSharedMemory* shared_memory = nullptr; - ClusteringProcessorState next_state{}; - - ClusteringProcessorConfig current_config{}; - Core::IrSensor::DeviceFormat& device; - Core::HID::EmulatedController* npad_device; - int callback_key{}; - - Core::System& system; -}; -} // namespace Service::IRS diff --git a/src/core/hle/service/hid/irsensor/image_transfer_processor.cpp b/src/core/hle/service/hid/irsensor/image_transfer_processor.cpp deleted file mode 100644 index 22067a591..000000000 --- a/src/core/hle/service/hid/irsensor/image_transfer_processor.cpp +++ /dev/null @@ -1,155 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "core/core.h" -#include "core/hid/emulated_controller.h" -#include "core/hid/hid_core.h" -#include "core/hle/service/hid/irsensor/image_transfer_processor.h" -#include "core/memory.h" - -namespace Service::IRS { -ImageTransferProcessor::ImageTransferProcessor(Core::System& system_, - Core::IrSensor::DeviceFormat& device_format, - std::size_t npad_index) - : device{device_format}, system{system_} { - npad_device = system.HIDCore().GetEmulatedControllerByIndex(npad_index); - - Core::HID::ControllerUpdateCallback engine_callback{ - .on_change = [this](Core::HID::ControllerTriggerType type) { OnControllerUpdate(type); }, - .is_npad_service = true, - }; - callback_key = npad_device->SetCallback(engine_callback); - - device.mode = Core::IrSensor::IrSensorMode::ImageTransferProcessor; - device.camera_status = Core::IrSensor::IrCameraStatus::Unconnected; - device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Stopped; -} - -ImageTransferProcessor::~ImageTransferProcessor() { - npad_device->DeleteCallback(callback_key); -}; - -void ImageTransferProcessor::StartProcessor() { - is_active = true; - device.camera_status = Core::IrSensor::IrCameraStatus::Available; - device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Ready; - processor_state.sampling_number = 0; - processor_state.ambient_noise_level = Core::IrSensor::CameraAmbientNoiseLevel::Low; -} - -void ImageTransferProcessor::SuspendProcessor() {} - -void ImageTransferProcessor::StopProcessor() {} - -void ImageTransferProcessor::OnControllerUpdate(Core::HID::ControllerTriggerType type) { - if (type != Core::HID::ControllerTriggerType::IrSensor) { - return; - } - if (transfer_memory == 0) { - return; - } - - const auto& camera_data = npad_device->GetCamera(); - - // This indicates how much ambient light is present - processor_state.ambient_noise_level = Core::IrSensor::CameraAmbientNoiseLevel::Low; - processor_state.sampling_number = camera_data.sample; - - if (camera_data.format != current_config.origin_format) { - LOG_WARNING(Service_IRS, "Wrong Input format {} expected {}", camera_data.format, - current_config.origin_format); - system.ApplicationMemory().ZeroBlock(transfer_memory, - GetDataSize(current_config.trimming_format)); - return; - } - - if (current_config.origin_format > current_config.trimming_format) { - LOG_WARNING(Service_IRS, "Origin format {} is smaller than trimming format {}", - current_config.origin_format, current_config.trimming_format); - system.ApplicationMemory().ZeroBlock(transfer_memory, - GetDataSize(current_config.trimming_format)); - return; - } - - std::vector window_data{}; - const auto origin_width = GetDataWidth(current_config.origin_format); - const auto origin_height = GetDataHeight(current_config.origin_format); - const auto trimming_width = GetDataWidth(current_config.trimming_format); - const auto trimming_height = GetDataHeight(current_config.trimming_format); - window_data.resize(GetDataSize(current_config.trimming_format)); - - if (trimming_width + current_config.trimming_start_x > origin_width || - trimming_height + current_config.trimming_start_y > origin_height) { - LOG_WARNING(Service_IRS, - "Trimming area ({}, {}, {}, {}) is outside of origin area ({}, {})", - current_config.trimming_start_x, current_config.trimming_start_y, - trimming_width, trimming_height, origin_width, origin_height); - system.ApplicationMemory().ZeroBlock(transfer_memory, - GetDataSize(current_config.trimming_format)); - return; - } - - for (std::size_t y = 0; y < trimming_height; y++) { - for (std::size_t x = 0; x < trimming_width; x++) { - const std::size_t window_index = (y * trimming_width) + x; - const std::size_t origin_index = - ((y + current_config.trimming_start_y) * origin_width) + x + - current_config.trimming_start_x; - window_data[window_index] = camera_data.data[origin_index]; - } - } - - system.ApplicationMemory().WriteBlock(transfer_memory, window_data.data(), - GetDataSize(current_config.trimming_format)); - - if (!IsProcessorActive()) { - StartProcessor(); - } -} - -void ImageTransferProcessor::SetConfig(Core::IrSensor::PackedImageTransferProcessorConfig config) { - current_config.camera_config.exposure_time = config.camera_config.exposure_time; - current_config.camera_config.gain = config.camera_config.gain; - current_config.camera_config.is_negative_used = config.camera_config.is_negative_used; - current_config.camera_config.light_target = - static_cast(config.camera_config.light_target); - current_config.origin_format = - static_cast(config.format); - current_config.trimming_format = - static_cast(config.format); - current_config.trimming_start_x = 0; - current_config.trimming_start_y = 0; - - npad_device->SetCameraFormat(current_config.origin_format); -} - -void ImageTransferProcessor::SetConfig( - Core::IrSensor::PackedImageTransferProcessorExConfig config) { - current_config.camera_config.exposure_time = config.camera_config.exposure_time; - current_config.camera_config.gain = config.camera_config.gain; - current_config.camera_config.is_negative_used = config.camera_config.is_negative_used; - current_config.camera_config.light_target = - static_cast(config.camera_config.light_target); - current_config.origin_format = - static_cast(config.origin_format); - current_config.trimming_format = - static_cast(config.trimming_format); - current_config.trimming_start_x = config.trimming_start_x; - current_config.trimming_start_y = config.trimming_start_y; - - npad_device->SetCameraFormat(current_config.origin_format); -} - -void ImageTransferProcessor::SetTransferMemoryAddress(Common::ProcessAddress t_mem) { - transfer_memory = t_mem; -} - -Core::IrSensor::ImageTransferProcessorState ImageTransferProcessor::GetState( - std::vector& data) const { - const auto size = GetDataSize(current_config.trimming_format); - data.resize(size); - system.ApplicationMemory().ReadBlock(transfer_memory, data.data(), size); - return processor_state; -} - -} // namespace Service::IRS diff --git a/src/core/hle/service/hid/irsensor/image_transfer_processor.h b/src/core/hle/service/hid/irsensor/image_transfer_processor.h deleted file mode 100644 index 7f42d8453..000000000 --- a/src/core/hle/service/hid/irsensor/image_transfer_processor.h +++ /dev/null @@ -1,77 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#pragma once - -#include "common/typed_address.h" -#include "core/hid/irs_types.h" -#include "core/hle/service/hid/irsensor/processor_base.h" - -namespace Core { -class System; -} - -namespace Core::HID { -class EmulatedController; -} // namespace Core::HID - -namespace Service::IRS { -class ImageTransferProcessor final : public ProcessorBase { -public: - explicit ImageTransferProcessor(Core::System& system_, - Core::IrSensor::DeviceFormat& device_format, - std::size_t npad_index); - ~ImageTransferProcessor() override; - - // Called when the processor is initialized - void StartProcessor() override; - - // Called when the processor is suspended - void SuspendProcessor() override; - - // Called when the processor is stopped - void StopProcessor() override; - - // Sets config parameters of the camera - void SetConfig(Core::IrSensor::PackedImageTransferProcessorConfig config); - void SetConfig(Core::IrSensor::PackedImageTransferProcessorExConfig config); - - // Transfer memory where the image data will be stored - void SetTransferMemoryAddress(Common::ProcessAddress t_mem); - - Core::IrSensor::ImageTransferProcessorState GetState(std::vector& data) const; - -private: - // This is nn::irsensor::ImageTransferProcessorConfig - struct ImageTransferProcessorConfig { - Core::IrSensor::CameraConfig camera_config; - Core::IrSensor::ImageTransferProcessorFormat format; - }; - static_assert(sizeof(ImageTransferProcessorConfig) == 0x20, - "ImageTransferProcessorConfig is an invalid size"); - - // This is nn::irsensor::ImageTransferProcessorExConfig - struct ImageTransferProcessorExConfig { - Core::IrSensor::CameraConfig camera_config; - Core::IrSensor::ImageTransferProcessorFormat origin_format; - Core::IrSensor::ImageTransferProcessorFormat trimming_format; - u16 trimming_start_x; - u16 trimming_start_y; - bool is_external_light_filter_enabled; - INSERT_PADDING_BYTES(3); - }; - static_assert(sizeof(ImageTransferProcessorExConfig) == 0x28, - "ImageTransferProcessorExConfig is an invalid size"); - - void OnControllerUpdate(Core::HID::ControllerTriggerType type); - - ImageTransferProcessorExConfig current_config{}; - Core::IrSensor::ImageTransferProcessorState processor_state{}; - Core::IrSensor::DeviceFormat& device; - Core::HID::EmulatedController* npad_device; - int callback_key{}; - - Core::System& system; - Common::ProcessAddress transfer_memory{}; -}; -} // namespace Service::IRS diff --git a/src/core/hle/service/hid/irsensor/ir_led_processor.cpp b/src/core/hle/service/hid/irsensor/ir_led_processor.cpp deleted file mode 100644 index 8e6dd99e4..000000000 --- a/src/core/hle/service/hid/irsensor/ir_led_processor.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "core/hle/service/hid/irsensor/ir_led_processor.h" - -namespace Service::IRS { -IrLedProcessor::IrLedProcessor(Core::IrSensor::DeviceFormat& device_format) - : device(device_format) { - device.mode = Core::IrSensor::IrSensorMode::IrLedProcessor; - device.camera_status = Core::IrSensor::IrCameraStatus::Unconnected; - device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Stopped; -} - -IrLedProcessor::~IrLedProcessor() = default; - -void IrLedProcessor::StartProcessor() {} - -void IrLedProcessor::SuspendProcessor() {} - -void IrLedProcessor::StopProcessor() {} - -void IrLedProcessor::SetConfig(Core::IrSensor::PackedIrLedProcessorConfig config) { - current_config.light_target = - static_cast(config.light_target); -} - -} // namespace Service::IRS diff --git a/src/core/hle/service/hid/irsensor/ir_led_processor.h b/src/core/hle/service/hid/irsensor/ir_led_processor.h deleted file mode 100644 index c3d8693c9..000000000 --- a/src/core/hle/service/hid/irsensor/ir_led_processor.h +++ /dev/null @@ -1,47 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#pragma once - -#include "common/bit_field.h" -#include "common/common_types.h" -#include "core/hid/irs_types.h" -#include "core/hle/service/hid/irsensor/processor_base.h" - -namespace Service::IRS { -class IrLedProcessor final : public ProcessorBase { -public: - explicit IrLedProcessor(Core::IrSensor::DeviceFormat& device_format); - ~IrLedProcessor() override; - - // Called when the processor is initialized - void StartProcessor() override; - - // Called when the processor is suspended - void SuspendProcessor() override; - - // Called when the processor is stopped - void StopProcessor() override; - - // Sets config parameters of the camera - void SetConfig(Core::IrSensor::PackedIrLedProcessorConfig config); - -private: - // This is nn::irsensor::IrLedProcessorConfig - struct IrLedProcessorConfig { - Core::IrSensor::CameraLightTarget light_target; - }; - static_assert(sizeof(IrLedProcessorConfig) == 0x4, "IrLedProcessorConfig is an invalid size"); - - struct IrLedProcessorState { - s64 sampling_number; - u64 timestamp; - std::array data; - }; - static_assert(sizeof(IrLedProcessorState) == 0x18, "IrLedProcessorState is an invalid size"); - - IrLedProcessorConfig current_config{}; - Core::IrSensor::DeviceFormat& device; -}; - -} // namespace Service::IRS diff --git a/src/core/hle/service/hid/irsensor/moment_processor.cpp b/src/core/hle/service/hid/irsensor/moment_processor.cpp deleted file mode 100644 index cf045bda7..000000000 --- a/src/core/hle/service/hid/irsensor/moment_processor.cpp +++ /dev/null @@ -1,149 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "core/core.h" -#include "core/core_timing.h" -#include "core/hid/emulated_controller.h" -#include "core/hid/hid_core.h" -#include "core/hle/service/hid/irsensor/moment_processor.h" - -namespace Service::IRS { -static constexpr auto format = Core::IrSensor::ImageTransferProcessorFormat::Size40x30; -static constexpr std::size_t ImageWidth = 40; -static constexpr std::size_t ImageHeight = 30; - -MomentProcessor::MomentProcessor(Core::System& system_, Core::IrSensor::DeviceFormat& device_format, - std::size_t npad_index) - : device(device_format), system{system_} { - npad_device = system.HIDCore().GetEmulatedControllerByIndex(npad_index); - - device.mode = Core::IrSensor::IrSensorMode::MomentProcessor; - device.camera_status = Core::IrSensor::IrCameraStatus::Unconnected; - device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Stopped; - - shared_memory = std::construct_at( - reinterpret_cast(&device_format.state.processor_raw_data)); - - Core::HID::ControllerUpdateCallback engine_callback{ - .on_change = [this](Core::HID::ControllerTriggerType type) { OnControllerUpdate(type); }, - .is_npad_service = true, - }; - callback_key = npad_device->SetCallback(engine_callback); -} - -MomentProcessor::~MomentProcessor() { - npad_device->DeleteCallback(callback_key); -}; - -void MomentProcessor::StartProcessor() { - device.camera_status = Core::IrSensor::IrCameraStatus::Available; - device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Ready; -} - -void MomentProcessor::SuspendProcessor() {} - -void MomentProcessor::StopProcessor() {} - -void MomentProcessor::OnControllerUpdate(Core::HID::ControllerTriggerType type) { - if (type != Core::HID::ControllerTriggerType::IrSensor) { - return; - } - - next_state = {}; - const auto& camera_data = npad_device->GetCamera(); - - const auto window_width = static_cast(current_config.window_of_interest.width); - const auto window_height = static_cast(current_config.window_of_interest.height); - const auto window_start_x = static_cast(current_config.window_of_interest.x); - const auto window_start_y = static_cast(current_config.window_of_interest.y); - - const std::size_t block_width = window_width / Columns; - const std::size_t block_height = window_height / Rows; - - for (std::size_t row = 0; row < Rows; row++) { - for (std::size_t column = 0; column < Columns; column++) { - const size_t x_pos = (column * block_width) + window_start_x; - const size_t y_pos = (row * block_height) + window_start_y; - auto& statistic = next_state.statistic[column + (row * Columns)]; - statistic = GetStatistic(camera_data.data, x_pos, y_pos, block_width, block_height); - } - } - - next_state.sampling_number = camera_data.sample; - next_state.timestamp = system.CoreTiming().GetGlobalTimeNs().count(); - next_state.ambient_noise_level = Core::IrSensor::CameraAmbientNoiseLevel::Low; - shared_memory->moment_lifo.WriteNextEntry(next_state); - - if (!IsProcessorActive()) { - StartProcessor(); - } -} - -u8 MomentProcessor::GetPixel(const std::vector& data, std::size_t x, std::size_t y) const { - if ((y * ImageWidth) + x >= data.size()) { - return 0; - } - return data[(y * ImageWidth) + x]; -} - -MomentProcessor::MomentStatistic MomentProcessor::GetStatistic(const std::vector& data, - std::size_t start_x, - std::size_t start_y, - std::size_t width, - std::size_t height) const { - // The actual implementation is always 320x240 - static constexpr std::size_t RealWidth = 320; - static constexpr std::size_t RealHeight = 240; - static constexpr std::size_t Threshold = 30; - MomentStatistic statistic{}; - std::size_t active_points{}; - - // Sum all data points on the block that meet with the threshold - for (std::size_t y = 0; y < width; y++) { - for (std::size_t x = 0; x < height; x++) { - const size_t x_pos = x + start_x; - const size_t y_pos = y + start_y; - const auto pixel = - GetPixel(data, x_pos * ImageWidth / RealWidth, y_pos * ImageHeight / RealHeight); - - if (pixel < Threshold) { - continue; - } - - statistic.average_intensity += pixel; - - statistic.centroid.x += static_cast(x_pos); - statistic.centroid.y += static_cast(y_pos); - - active_points++; - } - } - - // Return an empty field if no points were available - if (active_points == 0) { - return {}; - } - - // Finally calculate the actual centroid and average intensity - statistic.centroid.x /= static_cast(active_points); - statistic.centroid.y /= static_cast(active_points); - statistic.average_intensity /= static_cast(width * height); - - return statistic; -} - -void MomentProcessor::SetConfig(Core::IrSensor::PackedMomentProcessorConfig config) { - current_config.camera_config.exposure_time = config.camera_config.exposure_time; - current_config.camera_config.gain = config.camera_config.gain; - current_config.camera_config.is_negative_used = config.camera_config.is_negative_used; - current_config.camera_config.light_target = - static_cast(config.camera_config.light_target); - current_config.window_of_interest = config.window_of_interest; - current_config.preprocess = - static_cast(config.preprocess); - current_config.preprocess_intensity_threshold = config.preprocess_intensity_threshold; - - npad_device->SetCameraFormat(format); -} - -} // namespace Service::IRS diff --git a/src/core/hle/service/hid/irsensor/moment_processor.h b/src/core/hle/service/hid/irsensor/moment_processor.h deleted file mode 100644 index 398cfbdc1..000000000 --- a/src/core/hle/service/hid/irsensor/moment_processor.h +++ /dev/null @@ -1,91 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#pragma once - -#include "common/bit_field.h" -#include "common/common_types.h" -#include "core/hid/irs_types.h" -#include "core/hle/service/hid/irs_ring_lifo.h" -#include "core/hle/service/hid/irsensor/processor_base.h" - -namespace Core { -class System; -} - -namespace Core::HID { -class EmulatedController; -} // namespace Core::HID - -namespace Service::IRS { -class MomentProcessor final : public ProcessorBase { -public: - explicit MomentProcessor(Core::System& system_, Core::IrSensor::DeviceFormat& device_format, - std::size_t npad_index); - ~MomentProcessor() override; - - // Called when the processor is initialized - void StartProcessor() override; - - // Called when the processor is suspended - void SuspendProcessor() override; - - // Called when the processor is stopped - void StopProcessor() override; - - // Sets config parameters of the camera - void SetConfig(Core::IrSensor::PackedMomentProcessorConfig config); - -private: - static constexpr std::size_t Columns = 8; - static constexpr std::size_t Rows = 6; - - // This is nn::irsensor::MomentProcessorConfig - struct MomentProcessorConfig { - Core::IrSensor::CameraConfig camera_config; - Core::IrSensor::IrsRect window_of_interest; - Core::IrSensor::MomentProcessorPreprocess preprocess; - u32 preprocess_intensity_threshold; - }; - static_assert(sizeof(MomentProcessorConfig) == 0x28, - "MomentProcessorConfig is an invalid size"); - - // This is nn::irsensor::MomentStatistic - struct MomentStatistic { - f32 average_intensity; - Core::IrSensor::IrsCentroid centroid; - }; - static_assert(sizeof(MomentStatistic) == 0xC, "MomentStatistic is an invalid size"); - - // This is nn::irsensor::MomentProcessorState - struct MomentProcessorState { - s64 sampling_number; - u64 timestamp; - Core::IrSensor::CameraAmbientNoiseLevel ambient_noise_level; - INSERT_PADDING_BYTES(4); - std::array statistic; - }; - static_assert(sizeof(MomentProcessorState) == 0x258, "MomentProcessorState is an invalid size"); - - struct MomentSharedMemory { - Service::IRS::Lifo moment_lifo; - }; - static_assert(sizeof(MomentSharedMemory) == 0xE20, "MomentSharedMemory is an invalid size"); - - void OnControllerUpdate(Core::HID::ControllerTriggerType type); - u8 GetPixel(const std::vector& data, std::size_t x, std::size_t y) const; - MomentStatistic GetStatistic(const std::vector& data, std::size_t start_x, - std::size_t start_y, std::size_t width, std::size_t height) const; - - MomentSharedMemory* shared_memory = nullptr; - MomentProcessorState next_state{}; - - MomentProcessorConfig current_config{}; - Core::IrSensor::DeviceFormat& device; - Core::HID::EmulatedController* npad_device; - int callback_key{}; - - Core::System& system; -}; - -} // namespace Service::IRS diff --git a/src/core/hle/service/hid/irsensor/pointing_processor.cpp b/src/core/hle/service/hid/irsensor/pointing_processor.cpp deleted file mode 100644 index 929f177fc..000000000 --- a/src/core/hle/service/hid/irsensor/pointing_processor.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "core/hle/service/hid/irsensor/pointing_processor.h" - -namespace Service::IRS { -PointingProcessor::PointingProcessor(Core::IrSensor::DeviceFormat& device_format) - : device(device_format) { - device.mode = Core::IrSensor::IrSensorMode::PointingProcessorMarker; - device.camera_status = Core::IrSensor::IrCameraStatus::Unconnected; - device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Stopped; -} - -PointingProcessor::~PointingProcessor() = default; - -void PointingProcessor::StartProcessor() {} - -void PointingProcessor::SuspendProcessor() {} - -void PointingProcessor::StopProcessor() {} - -void PointingProcessor::SetConfig(Core::IrSensor::PackedPointingProcessorConfig config) { - current_config.window_of_interest = config.window_of_interest; -} - -} // namespace Service::IRS diff --git a/src/core/hle/service/hid/irsensor/pointing_processor.h b/src/core/hle/service/hid/irsensor/pointing_processor.h deleted file mode 100644 index d63423aff..000000000 --- a/src/core/hle/service/hid/irsensor/pointing_processor.h +++ /dev/null @@ -1,61 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#pragma once - -#include "common/common_types.h" -#include "core/hid/irs_types.h" -#include "core/hle/service/hid/irsensor/processor_base.h" - -namespace Service::IRS { -class PointingProcessor final : public ProcessorBase { -public: - explicit PointingProcessor(Core::IrSensor::DeviceFormat& device_format); - ~PointingProcessor() override; - - // Called when the processor is initialized - void StartProcessor() override; - - // Called when the processor is suspended - void SuspendProcessor() override; - - // Called when the processor is stopped - void StopProcessor() override; - - // Sets config parameters of the camera - void SetConfig(Core::IrSensor::PackedPointingProcessorConfig config); - -private: - // This is nn::irsensor::PointingProcessorConfig - struct PointingProcessorConfig { - Core::IrSensor::IrsRect window_of_interest; - }; - static_assert(sizeof(PointingProcessorConfig) == 0x8, - "PointingProcessorConfig is an invalid size"); - - struct PointingProcessorMarkerData { - u8 pointing_status; - INSERT_PADDING_BYTES(3); - u32 unknown; - float unknown_float1; - float position_x; - float position_y; - float unknown_float2; - Core::IrSensor::IrsRect window_of_interest; - }; - static_assert(sizeof(PointingProcessorMarkerData) == 0x20, - "PointingProcessorMarkerData is an invalid size"); - - struct PointingProcessorMarkerState { - s64 sampling_number; - u64 timestamp; - std::array data; - }; - static_assert(sizeof(PointingProcessorMarkerState) == 0x70, - "PointingProcessorMarkerState is an invalid size"); - - PointingProcessorConfig current_config{}; - Core::IrSensor::DeviceFormat& device; -}; - -} // namespace Service::IRS diff --git a/src/core/hle/service/hid/irsensor/processor_base.cpp b/src/core/hle/service/hid/irsensor/processor_base.cpp deleted file mode 100644 index 4d43ca17a..000000000 --- a/src/core/hle/service/hid/irsensor/processor_base.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "core/hle/service/hid/irsensor/processor_base.h" - -namespace Service::IRS { - -ProcessorBase::ProcessorBase() {} -ProcessorBase::~ProcessorBase() = default; - -bool ProcessorBase::IsProcessorActive() const { - return is_active; -} - -std::size_t ProcessorBase::GetDataSize(Core::IrSensor::ImageTransferProcessorFormat format) const { - switch (format) { - case Core::IrSensor::ImageTransferProcessorFormat::Size320x240: - return 320 * 240; - case Core::IrSensor::ImageTransferProcessorFormat::Size160x120: - return 160 * 120; - case Core::IrSensor::ImageTransferProcessorFormat::Size80x60: - return 80 * 60; - case Core::IrSensor::ImageTransferProcessorFormat::Size40x30: - return 40 * 30; - case Core::IrSensor::ImageTransferProcessorFormat::Size20x15: - return 20 * 15; - default: - return 0; - } -} - -std::size_t ProcessorBase::GetDataWidth(Core::IrSensor::ImageTransferProcessorFormat format) const { - switch (format) { - case Core::IrSensor::ImageTransferProcessorFormat::Size320x240: - return 320; - case Core::IrSensor::ImageTransferProcessorFormat::Size160x120: - return 160; - case Core::IrSensor::ImageTransferProcessorFormat::Size80x60: - return 80; - case Core::IrSensor::ImageTransferProcessorFormat::Size40x30: - return 40; - case Core::IrSensor::ImageTransferProcessorFormat::Size20x15: - return 20; - default: - return 0; - } -} - -std::size_t ProcessorBase::GetDataHeight( - Core::IrSensor::ImageTransferProcessorFormat format) const { - switch (format) { - case Core::IrSensor::ImageTransferProcessorFormat::Size320x240: - return 240; - case Core::IrSensor::ImageTransferProcessorFormat::Size160x120: - return 120; - case Core::IrSensor::ImageTransferProcessorFormat::Size80x60: - return 60; - case Core::IrSensor::ImageTransferProcessorFormat::Size40x30: - return 30; - case Core::IrSensor::ImageTransferProcessorFormat::Size20x15: - return 15; - default: - return 0; - } -} - -} // namespace Service::IRS diff --git a/src/core/hle/service/hid/irsensor/processor_base.h b/src/core/hle/service/hid/irsensor/processor_base.h deleted file mode 100644 index bc0d2977b..000000000 --- a/src/core/hle/service/hid/irsensor/processor_base.h +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#pragma once - -#include "common/common_types.h" -#include "core/hid/irs_types.h" - -namespace Service::IRS { -class ProcessorBase { -public: - explicit ProcessorBase(); - virtual ~ProcessorBase(); - - virtual void StartProcessor() = 0; - virtual void SuspendProcessor() = 0; - virtual void StopProcessor() = 0; - - bool IsProcessorActive() const; - -protected: - /// Returns the number of bytes the image uses - std::size_t GetDataSize(Core::IrSensor::ImageTransferProcessorFormat format) const; - - /// Returns the width of the image - std::size_t GetDataWidth(Core::IrSensor::ImageTransferProcessorFormat format) const; - - /// Returns the height of the image - std::size_t GetDataHeight(Core::IrSensor::ImageTransferProcessorFormat format) const; - - bool is_active{false}; -}; -} // namespace Service::IRS diff --git a/src/core/hle/service/hid/irsensor/tera_plugin_processor.cpp b/src/core/hle/service/hid/irsensor/tera_plugin_processor.cpp deleted file mode 100644 index e691c840a..000000000 --- a/src/core/hle/service/hid/irsensor/tera_plugin_processor.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "core/hle/service/hid/irsensor/tera_plugin_processor.h" - -namespace Service::IRS { -TeraPluginProcessor::TeraPluginProcessor(Core::IrSensor::DeviceFormat& device_format) - : device(device_format) { - device.mode = Core::IrSensor::IrSensorMode::TeraPluginProcessor; - device.camera_status = Core::IrSensor::IrCameraStatus::Unconnected; - device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Stopped; -} - -TeraPluginProcessor::~TeraPluginProcessor() = default; - -void TeraPluginProcessor::StartProcessor() {} - -void TeraPluginProcessor::SuspendProcessor() {} - -void TeraPluginProcessor::StopProcessor() {} - -void TeraPluginProcessor::SetConfig(Core::IrSensor::PackedTeraPluginProcessorConfig config) { - current_config.mode = config.mode; - current_config.unknown_1 = config.unknown_1; - current_config.unknown_2 = config.unknown_2; - current_config.unknown_3 = config.unknown_3; -} - -} // namespace Service::IRS diff --git a/src/core/hle/service/hid/irsensor/tera_plugin_processor.h b/src/core/hle/service/hid/irsensor/tera_plugin_processor.h deleted file mode 100644 index bbea7ed0b..000000000 --- a/src/core/hle/service/hid/irsensor/tera_plugin_processor.h +++ /dev/null @@ -1,53 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-3.0-or-later - -#pragma once - -#include "common/bit_field.h" -#include "common/common_types.h" -#include "core/hid/irs_types.h" -#include "core/hle/service/hid/irsensor/processor_base.h" - -namespace Service::IRS { -class TeraPluginProcessor final : public ProcessorBase { -public: - explicit TeraPluginProcessor(Core::IrSensor::DeviceFormat& device_format); - ~TeraPluginProcessor() override; - - // Called when the processor is initialized - void StartProcessor() override; - - // Called when the processor is suspended - void SuspendProcessor() override; - - // Called when the processor is stopped - void StopProcessor() override; - - // Sets config parameters of the camera - void SetConfig(Core::IrSensor::PackedTeraPluginProcessorConfig config); - -private: - // This is nn::irsensor::TeraPluginProcessorConfig - struct TeraPluginProcessorConfig { - u8 mode; - u8 unknown_1; - u8 unknown_2; - u8 unknown_3; - }; - static_assert(sizeof(TeraPluginProcessorConfig) == 0x4, - "TeraPluginProcessorConfig is an invalid size"); - - struct TeraPluginProcessorState { - s64 sampling_number; - u64 timestamp; - Core::IrSensor::CameraAmbientNoiseLevel ambient_noise_level; - std::array data; - }; - static_assert(sizeof(TeraPluginProcessorState) == 0x140, - "TeraPluginProcessorState is an invalid size"); - - TeraPluginProcessorConfig current_config{}; - Core::IrSensor::DeviceFormat& device; -}; - -} // namespace Service::IRS -- cgit v1.2.3