palma.cpp 7.8 KB

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