2022-01-19 02:08:56 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#include "core/core_timing.h"
|
|
|
|
#include "core/hle/kernel/k_event.h"
|
|
|
|
#include "core/hle/kernel/k_readable_event.h"
|
|
|
|
#include "core/hle/service/kernel_helpers.h"
|
2024-01-05 02:37:43 +00:00
|
|
|
#include "hid_core/frontend/emulated_controller.h"
|
|
|
|
#include "hid_core/hid_core.h"
|
|
|
|
#include "hid_core/resources/palma/palma.h"
|
2022-01-19 02:08:56 +00:00
|
|
|
|
|
|
|
namespace Service::HID {
|
|
|
|
|
2023-12-14 03:39:38 +00:00
|
|
|
Palma::Palma(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_)
|
2022-01-19 02:08:56 +00:00
|
|
|
: ControllerBase{hid_core_}, service_context{service_context_} {
|
|
|
|
controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Other);
|
|
|
|
operation_complete_event = service_context.CreateEvent("hid:PalmaOperationCompleteEvent");
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Palma::~Palma() {
|
2023-10-29 19:45:53 +00:00
|
|
|
service_context.CloseEvent(operation_complete_event);
|
|
|
|
};
|
2022-01-19 02:08:56 +00:00
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::OnInit() {}
|
2022-01-19 02:08:56 +00:00
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::OnRelease() {}
|
2022-01-19 02:08:56 +00:00
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (!IsControllerActivated()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::GetPalmaConnectionHandle(Core::HID::NpadIdType npad_id,
|
|
|
|
PalmaConnectionHandle& handle) {
|
2022-01-19 02:08:56 +00:00
|
|
|
active_handle.npad_id = npad_id;
|
|
|
|
handle = active_handle;
|
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::InitializePalma(const PalmaConnectionHandle& handle) {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
return InvalidPalmaHandle;
|
|
|
|
}
|
2023-11-16 23:58:05 +00:00
|
|
|
Activate();
|
2022-01-19 02:08:56 +00:00
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Kernel::KReadableEvent& Palma::AcquirePalmaOperationCompleteEvent(
|
2022-01-19 02:08:56 +00:00
|
|
|
const PalmaConnectionHandle& handle) const {
|
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
LOG_ERROR(Service_HID, "Invalid npad id {}", handle.npad_id);
|
|
|
|
}
|
|
|
|
return operation_complete_event->GetReadableEvent();
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::GetPalmaOperationInfo(const PalmaConnectionHandle& handle,
|
|
|
|
PalmaOperationType& operation_type,
|
2024-02-22 23:21:36 +00:00
|
|
|
std::span<u8> out_data) const {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
return InvalidPalmaHandle;
|
|
|
|
}
|
2024-02-22 23:21:36 +00:00
|
|
|
operation_type = static_cast<PalmaOperationType>(operation.operation);
|
|
|
|
std::memcpy(out_data.data(), operation.data.data(),
|
|
|
|
std::min(out_data.size(), operation.data.size()));
|
|
|
|
|
2022-01-19 02:08:56 +00:00
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::PlayPalmaActivity(const PalmaConnectionHandle& handle, u64 palma_activity) {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
return InvalidPalmaHandle;
|
|
|
|
}
|
2024-02-22 23:21:36 +00:00
|
|
|
operation.operation = PackedPalmaOperationType::PlayActivity;
|
2022-01-19 02:08:56 +00:00
|
|
|
operation.result = PalmaResultSuccess;
|
|
|
|
operation.data = {};
|
2022-10-13 00:26:04 +00:00
|
|
|
operation_complete_event->Signal();
|
2022-01-19 02:08:56 +00:00
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::SetPalmaFrModeType(const PalmaConnectionHandle& handle, PalmaFrModeType fr_mode_) {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
return InvalidPalmaHandle;
|
|
|
|
}
|
|
|
|
fr_mode = fr_mode_;
|
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::ReadPalmaStep(const PalmaConnectionHandle& handle) {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
return InvalidPalmaHandle;
|
|
|
|
}
|
2024-02-22 23:21:36 +00:00
|
|
|
operation.operation = PackedPalmaOperationType::ReadStep;
|
2022-01-19 02:08:56 +00:00
|
|
|
operation.result = PalmaResultSuccess;
|
|
|
|
operation.data = {};
|
2022-10-13 00:26:04 +00:00
|
|
|
operation_complete_event->Signal();
|
2022-01-19 02:08:56 +00:00
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::EnablePalmaStep(const PalmaConnectionHandle& handle, bool is_enabled) {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
return InvalidPalmaHandle;
|
|
|
|
}
|
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::ResetPalmaStep(const PalmaConnectionHandle& handle) {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
return InvalidPalmaHandle;
|
|
|
|
}
|
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::ReadPalmaApplicationSection() {}
|
2022-01-19 02:08:56 +00:00
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::WritePalmaApplicationSection() {}
|
2022-01-19 02:08:56 +00:00
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::ReadPalmaUniqueCode(const PalmaConnectionHandle& handle) {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
return InvalidPalmaHandle;
|
|
|
|
}
|
2024-02-22 23:21:36 +00:00
|
|
|
operation.operation = PackedPalmaOperationType::ReadUniqueCode;
|
2022-01-19 02:08:56 +00:00
|
|
|
operation.result = PalmaResultSuccess;
|
|
|
|
operation.data = {};
|
2022-10-13 00:26:04 +00:00
|
|
|
operation_complete_event->Signal();
|
2022-01-19 02:08:56 +00:00
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::SetPalmaUniqueCodeInvalid(const PalmaConnectionHandle& handle) {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
return InvalidPalmaHandle;
|
|
|
|
}
|
2024-02-22 23:21:36 +00:00
|
|
|
operation.operation = PackedPalmaOperationType::SetUniqueCodeInvalid;
|
2022-01-19 02:08:56 +00:00
|
|
|
operation.result = PalmaResultSuccess;
|
|
|
|
operation.data = {};
|
2022-10-13 00:26:04 +00:00
|
|
|
operation_complete_event->Signal();
|
2022-01-19 02:08:56 +00:00
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::WritePalmaActivityEntry() {}
|
2022-01-19 02:08:56 +00:00
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::WritePalmaRgbLedPatternEntry(const PalmaConnectionHandle& handle, u64 unknown) {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
return InvalidPalmaHandle;
|
|
|
|
}
|
2024-02-22 23:21:36 +00:00
|
|
|
operation.operation = PackedPalmaOperationType::WriteRgbLedPatternEntry;
|
2022-01-19 02:08:56 +00:00
|
|
|
operation.result = PalmaResultSuccess;
|
|
|
|
operation.data = {};
|
2022-10-13 00:26:04 +00:00
|
|
|
operation_complete_event->Signal();
|
2022-01-19 02:08:56 +00:00
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::WritePalmaWaveEntry(const PalmaConnectionHandle& handle, PalmaWaveSet wave,
|
|
|
|
Common::ProcessAddress t_mem, u64 size) {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
return InvalidPalmaHandle;
|
|
|
|
}
|
2024-02-22 23:21:36 +00:00
|
|
|
operation.operation = PackedPalmaOperationType::WriteWaveEntry;
|
2022-01-19 02:08:56 +00:00
|
|
|
operation.result = PalmaResultSuccess;
|
|
|
|
operation.data = {};
|
2022-10-13 00:26:04 +00:00
|
|
|
operation_complete_event->Signal();
|
2022-01-19 02:08:56 +00:00
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::SetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle& handle,
|
|
|
|
s32 database_id_version_) {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
return InvalidPalmaHandle;
|
|
|
|
}
|
|
|
|
database_id_version = database_id_version_;
|
2024-02-22 23:21:36 +00:00
|
|
|
operation.operation = PackedPalmaOperationType::ReadDataBaseIdentificationVersion;
|
2022-01-19 02:08:56 +00:00
|
|
|
operation.result = PalmaResultSuccess;
|
|
|
|
operation.data[0] = {};
|
2022-10-13 00:26:04 +00:00
|
|
|
operation_complete_event->Signal();
|
2022-01-19 02:08:56 +00:00
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::GetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle& handle) {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
return InvalidPalmaHandle;
|
|
|
|
}
|
2024-02-22 23:21:36 +00:00
|
|
|
operation.operation = PackedPalmaOperationType::ReadDataBaseIdentificationVersion;
|
2022-01-19 02:08:56 +00:00
|
|
|
operation.result = PalmaResultSuccess;
|
|
|
|
operation.data = {};
|
|
|
|
operation.data[0] = static_cast<u8>(database_id_version);
|
2022-10-13 00:26:04 +00:00
|
|
|
operation_complete_event->Signal();
|
2022-01-19 02:08:56 +00:00
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::SuspendPalmaFeature() {}
|
2022-01-19 02:08:56 +00:00
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::GetPalmaOperationResult(const PalmaConnectionHandle& handle) const {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
return InvalidPalmaHandle;
|
|
|
|
}
|
|
|
|
return operation.result;
|
|
|
|
}
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::ReadPalmaPlayLog() {}
|
2022-01-19 02:08:56 +00:00
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::ResetPalmaPlayLog() {}
|
2022-01-19 02:08:56 +00:00
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::SetIsPalmaAllConnectable(bool is_all_connectable) {
|
2022-01-19 02:08:56 +00:00
|
|
|
// If true controllers are able to be paired
|
|
|
|
is_connectable = is_all_connectable;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::SetIsPalmaPairedConnectable() {}
|
2022-01-19 02:08:56 +00:00
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
Result Palma::PairPalma(const PalmaConnectionHandle& handle) {
|
2022-01-19 02:08:56 +00:00
|
|
|
if (handle.npad_id != active_handle.npad_id) {
|
|
|
|
return InvalidPalmaHandle;
|
|
|
|
}
|
|
|
|
// TODO: Do something
|
|
|
|
return ResultSuccess;
|
|
|
|
}
|
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::SetPalmaBoostMode(bool boost_mode) {}
|
2022-01-19 02:08:56 +00:00
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::CancelWritePalmaWaveEntry() {}
|
2022-01-19 02:08:56 +00:00
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::EnablePalmaBoostMode() {}
|
2022-01-19 02:08:56 +00:00
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::GetPalmaBluetoothAddress() {}
|
2022-01-19 02:08:56 +00:00
|
|
|
|
2023-11-17 17:46:26 +00:00
|
|
|
void Palma::SetDisallowedPalmaConnection() {}
|
2022-01-19 02:08:56 +00:00
|
|
|
|
|
|
|
} // namespace Service::HID
|