palma.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "core/core_timing.h"
  4. #include "core/hle/kernel/k_event.h"
  5. #include "core/hle/kernel/k_readable_event.h"
  6. #include "core/hle/service/kernel_helpers.h"
  7. #include "hid_core/frontend/emulated_controller.h"
  8. #include "hid_core/hid_core.h"
  9. #include "hid_core/resources/palma/palma.h"
  10. namespace Service::HID {
  11. Palma::Palma(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_)
  12. : ControllerBase{hid_core_}, service_context{service_context_} {
  13. controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Other);
  14. operation_complete_event = service_context.CreateEvent("hid:PalmaOperationCompleteEvent");
  15. }
  16. Palma::~Palma() {
  17. service_context.CloseEvent(operation_complete_event);
  18. };
  19. void Palma::OnInit() {}
  20. void Palma::OnRelease() {}
  21. void Palma::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
  22. if (!IsControllerActivated()) {
  23. return;
  24. }
  25. }
  26. Result Palma::GetPalmaConnectionHandle(Core::HID::NpadIdType npad_id,
  27. PalmaConnectionHandle& handle) {
  28. active_handle.npad_id = npad_id;
  29. handle = active_handle;
  30. return ResultSuccess;
  31. }
  32. Result Palma::InitializePalma(const PalmaConnectionHandle& handle) {
  33. if (handle.npad_id != active_handle.npad_id) {
  34. return InvalidPalmaHandle;
  35. }
  36. Activate();
  37. return ResultSuccess;
  38. }
  39. Kernel::KReadableEvent& Palma::AcquirePalmaOperationCompleteEvent(
  40. const PalmaConnectionHandle& handle) const {
  41. if (handle.npad_id != active_handle.npad_id) {
  42. LOG_ERROR(Service_HID, "Invalid npad id {}", handle.npad_id);
  43. }
  44. return operation_complete_event->GetReadableEvent();
  45. }
  46. Result Palma::GetPalmaOperationInfo(const PalmaConnectionHandle& handle,
  47. PalmaOperationType& operation_type,
  48. PalmaOperationData& data) const {
  49. if (handle.npad_id != active_handle.npad_id) {
  50. return InvalidPalmaHandle;
  51. }
  52. operation_type = operation.operation;
  53. data = operation.data;
  54. return ResultSuccess;
  55. }
  56. Result Palma::PlayPalmaActivity(const PalmaConnectionHandle& handle, u64 palma_activity) {
  57. if (handle.npad_id != active_handle.npad_id) {
  58. return InvalidPalmaHandle;
  59. }
  60. operation.operation = PalmaOperationType::PlayActivity;
  61. operation.result = PalmaResultSuccess;
  62. operation.data = {};
  63. operation_complete_event->Signal();
  64. return ResultSuccess;
  65. }
  66. Result Palma::SetPalmaFrModeType(const PalmaConnectionHandle& handle, PalmaFrModeType fr_mode_) {
  67. if (handle.npad_id != active_handle.npad_id) {
  68. return InvalidPalmaHandle;
  69. }
  70. fr_mode = fr_mode_;
  71. return ResultSuccess;
  72. }
  73. Result Palma::ReadPalmaStep(const PalmaConnectionHandle& handle) {
  74. if (handle.npad_id != active_handle.npad_id) {
  75. return InvalidPalmaHandle;
  76. }
  77. operation.operation = PalmaOperationType::ReadStep;
  78. operation.result = PalmaResultSuccess;
  79. operation.data = {};
  80. operation_complete_event->Signal();
  81. return ResultSuccess;
  82. }
  83. Result Palma::EnablePalmaStep(const PalmaConnectionHandle& handle, bool is_enabled) {
  84. if (handle.npad_id != active_handle.npad_id) {
  85. return InvalidPalmaHandle;
  86. }
  87. return ResultSuccess;
  88. }
  89. Result Palma::ResetPalmaStep(const PalmaConnectionHandle& handle) {
  90. if (handle.npad_id != active_handle.npad_id) {
  91. return InvalidPalmaHandle;
  92. }
  93. return ResultSuccess;
  94. }
  95. void Palma::ReadPalmaApplicationSection() {}
  96. void Palma::WritePalmaApplicationSection() {}
  97. Result Palma::ReadPalmaUniqueCode(const PalmaConnectionHandle& handle) {
  98. if (handle.npad_id != active_handle.npad_id) {
  99. return InvalidPalmaHandle;
  100. }
  101. operation.operation = PalmaOperationType::ReadUniqueCode;
  102. operation.result = PalmaResultSuccess;
  103. operation.data = {};
  104. operation_complete_event->Signal();
  105. return ResultSuccess;
  106. }
  107. Result Palma::SetPalmaUniqueCodeInvalid(const PalmaConnectionHandle& handle) {
  108. if (handle.npad_id != active_handle.npad_id) {
  109. return InvalidPalmaHandle;
  110. }
  111. operation.operation = PalmaOperationType::SetUniqueCodeInvalid;
  112. operation.result = PalmaResultSuccess;
  113. operation.data = {};
  114. operation_complete_event->Signal();
  115. return ResultSuccess;
  116. }
  117. void Palma::WritePalmaActivityEntry() {}
  118. Result Palma::WritePalmaRgbLedPatternEntry(const PalmaConnectionHandle& handle, u64 unknown) {
  119. if (handle.npad_id != active_handle.npad_id) {
  120. return InvalidPalmaHandle;
  121. }
  122. operation.operation = PalmaOperationType::WriteRgbLedPatternEntry;
  123. operation.result = PalmaResultSuccess;
  124. operation.data = {};
  125. operation_complete_event->Signal();
  126. return ResultSuccess;
  127. }
  128. Result Palma::WritePalmaWaveEntry(const PalmaConnectionHandle& handle, PalmaWaveSet wave,
  129. Common::ProcessAddress t_mem, u64 size) {
  130. if (handle.npad_id != active_handle.npad_id) {
  131. return InvalidPalmaHandle;
  132. }
  133. operation.operation = PalmaOperationType::WriteWaveEntry;
  134. operation.result = PalmaResultSuccess;
  135. operation.data = {};
  136. operation_complete_event->Signal();
  137. return ResultSuccess;
  138. }
  139. Result Palma::SetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle& handle,
  140. s32 database_id_version_) {
  141. if (handle.npad_id != active_handle.npad_id) {
  142. return InvalidPalmaHandle;
  143. }
  144. database_id_version = database_id_version_;
  145. operation.operation = PalmaOperationType::ReadDataBaseIdentificationVersion;
  146. operation.result = PalmaResultSuccess;
  147. operation.data[0] = {};
  148. operation_complete_event->Signal();
  149. return ResultSuccess;
  150. }
  151. Result Palma::GetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle& handle) {
  152. if (handle.npad_id != active_handle.npad_id) {
  153. return InvalidPalmaHandle;
  154. }
  155. operation.operation = PalmaOperationType::ReadDataBaseIdentificationVersion;
  156. operation.result = PalmaResultSuccess;
  157. operation.data = {};
  158. operation.data[0] = static_cast<u8>(database_id_version);
  159. operation_complete_event->Signal();
  160. return ResultSuccess;
  161. }
  162. void Palma::SuspendPalmaFeature() {}
  163. Result Palma::GetPalmaOperationResult(const PalmaConnectionHandle& handle) const {
  164. if (handle.npad_id != active_handle.npad_id) {
  165. return InvalidPalmaHandle;
  166. }
  167. return operation.result;
  168. }
  169. void Palma::ReadPalmaPlayLog() {}
  170. void Palma::ResetPalmaPlayLog() {}
  171. void Palma::SetIsPalmaAllConnectable(bool is_all_connectable) {
  172. // If true controllers are able to be paired
  173. is_connectable = is_all_connectable;
  174. }
  175. void Palma::SetIsPalmaPairedConnectable() {}
  176. Result Palma::PairPalma(const PalmaConnectionHandle& handle) {
  177. if (handle.npad_id != active_handle.npad_id) {
  178. return InvalidPalmaHandle;
  179. }
  180. // TODO: Do something
  181. return ResultSuccess;
  182. }
  183. void Palma::SetPalmaBoostMode(bool boost_mode) {}
  184. void Palma::CancelWritePalmaWaveEntry() {}
  185. void Palma::EnablePalmaBoostMode() {}
  186. void Palma::GetPalmaBluetoothAddress() {}
  187. void Palma::SetDisallowedPalmaConnection() {}
  188. } // namespace Service::HID