palma.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <array>
  5. #include "common/common_funcs.h"
  6. #include "common/common_types.h"
  7. #include "core/hle/service/hid/controllers/controller_base.h"
  8. #include "core/hle/service/hid/errors.h"
  9. namespace Kernel {
  10. class KEvent;
  11. class KReadableEvent;
  12. } // namespace Kernel
  13. namespace Service::KernelHelpers {
  14. class ServiceContext;
  15. }
  16. namespace Core::HID {
  17. class EmulatedController;
  18. } // namespace Core::HID
  19. namespace Service::HID {
  20. class Controller_Palma final : public ControllerBase {
  21. public:
  22. using PalmaOperationData = std::array<u8, 0x140>;
  23. // This is nn::hid::PalmaOperationType
  24. enum class PalmaOperationType {
  25. PlayActivity,
  26. SetFrModeType,
  27. ReadStep,
  28. EnableStep,
  29. ResetStep,
  30. ReadApplicationSection,
  31. WriteApplicationSection,
  32. ReadUniqueCode,
  33. SetUniqueCodeInvalid,
  34. WriteActivityEntry,
  35. WriteRgbLedPatternEntry,
  36. WriteWaveEntry,
  37. ReadDataBaseIdentificationVersion,
  38. WriteDataBaseIdentificationVersion,
  39. SuspendFeature,
  40. ReadPlayLog,
  41. ResetPlayLog,
  42. };
  43. // This is nn::hid::PalmaWaveSet
  44. enum class PalmaWaveSet : u64 {
  45. Small,
  46. Medium,
  47. Large,
  48. };
  49. // This is nn::hid::PalmaFrModeType
  50. enum class PalmaFrModeType : u64 {
  51. Off,
  52. B01,
  53. B02,
  54. B03,
  55. Downloaded,
  56. };
  57. // This is nn::hid::PalmaFeature
  58. enum class PalmaFeature : u64 {
  59. FrMode,
  60. RumbleFeedback,
  61. Step,
  62. MuteSwitch,
  63. };
  64. // This is nn::hid::PalmaOperationInfo
  65. struct PalmaOperationInfo {
  66. PalmaOperationType operation{};
  67. Result result{PalmaResultSuccess};
  68. PalmaOperationData data{};
  69. };
  70. static_assert(sizeof(PalmaOperationInfo) == 0x148, "PalmaOperationInfo is an invalid size");
  71. // This is nn::hid::PalmaActivityEntry
  72. struct PalmaActivityEntry {
  73. u32 rgb_led_pattern_index;
  74. INSERT_PADDING_BYTES(2);
  75. PalmaWaveSet wave_set;
  76. u32 wave_index;
  77. INSERT_PADDING_BYTES(12);
  78. };
  79. static_assert(sizeof(PalmaActivityEntry) == 0x20, "PalmaActivityEntry is an invalid size");
  80. struct PalmaConnectionHandle {
  81. Core::HID::NpadIdType npad_id;
  82. INSERT_PADDING_BYTES(4); // Unknown
  83. };
  84. static_assert(sizeof(PalmaConnectionHandle) == 0x8,
  85. "PalmaConnectionHandle has incorrect size.");
  86. explicit Controller_Palma(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_,
  87. KernelHelpers::ServiceContext& service_context_);
  88. ~Controller_Palma() override;
  89. // Called when the controller is initialized
  90. void OnInit() override;
  91. // When the controller is released
  92. void OnRelease() override;
  93. // When the controller is requesting an update for the shared memory
  94. void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
  95. Result GetPalmaConnectionHandle(Core::HID::NpadIdType npad_id, PalmaConnectionHandle& handle);
  96. Result InitializePalma(const PalmaConnectionHandle& handle);
  97. Kernel::KReadableEvent& AcquirePalmaOperationCompleteEvent(
  98. const PalmaConnectionHandle& handle) const;
  99. Result GetPalmaOperationInfo(const PalmaConnectionHandle& handle,
  100. PalmaOperationType& operation_type,
  101. PalmaOperationData& data) const;
  102. Result PlayPalmaActivity(const PalmaConnectionHandle& handle, u64 palma_activity);
  103. Result SetPalmaFrModeType(const PalmaConnectionHandle& handle, PalmaFrModeType fr_mode_);
  104. Result ReadPalmaStep(const PalmaConnectionHandle& handle);
  105. Result EnablePalmaStep(const PalmaConnectionHandle& handle, bool is_enabled);
  106. Result ResetPalmaStep(const PalmaConnectionHandle& handle);
  107. Result ReadPalmaUniqueCode(const PalmaConnectionHandle& handle);
  108. Result SetPalmaUniqueCodeInvalid(const PalmaConnectionHandle& handle);
  109. Result WritePalmaRgbLedPatternEntry(const PalmaConnectionHandle& handle, u64 unknown);
  110. Result WritePalmaWaveEntry(const PalmaConnectionHandle& handle, PalmaWaveSet wave, VAddr t_mem,
  111. u64 size);
  112. Result SetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle& handle,
  113. s32 database_id_version_);
  114. Result GetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle& handle);
  115. Result GetPalmaOperationResult(const PalmaConnectionHandle& handle) const;
  116. void SetIsPalmaAllConnectable(bool is_all_connectable);
  117. Result PairPalma(const PalmaConnectionHandle& handle);
  118. void SetPalmaBoostMode(bool boost_mode);
  119. private:
  120. void ReadPalmaApplicationSection();
  121. void WritePalmaApplicationSection();
  122. void WritePalmaActivityEntry();
  123. void SuspendPalmaFeature();
  124. void ReadPalmaPlayLog();
  125. void ResetPalmaPlayLog();
  126. void SetIsPalmaPairedConnectable();
  127. void CancelWritePalmaWaveEntry();
  128. void EnablePalmaBoostMode();
  129. void GetPalmaBluetoothAddress();
  130. void SetDisallowedPalmaConnection();
  131. bool is_connectable{};
  132. s32 database_id_version{};
  133. PalmaOperationInfo operation{};
  134. PalmaFrModeType fr_mode{};
  135. PalmaConnectionHandle active_handle{};
  136. Core::HID::EmulatedController* controller;
  137. Kernel::KEvent* operation_complete_event;
  138. KernelHelpers::ServiceContext& service_context;
  139. };
  140. } // namespace Service::HID