palma.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. Palma::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. Palma::~Palma() {
  19. service_context.CloseEvent(operation_complete_event);
  20. };
  21. void Palma::OnInit() {}
  22. void Palma::OnRelease() {}
  23. void Palma::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
  24. if (!IsControllerActivated()) {
  25. return;
  26. }
  27. }
  28. Result 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 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& 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 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 Palma::PlayPalmaActivity(const PalmaConnectionHandle& handle, u64 palma_activity) {
  59. if (handle.npad_id != active_handle.npad_id) {
  60. return InvalidPalmaHandle;
  61. }
  62. operation.operation = PalmaOperationType::PlayActivity;
  63. operation.result = PalmaResultSuccess;
  64. operation.data = {};
  65. operation_complete_event->Signal();
  66. return ResultSuccess;
  67. }
  68. Result Palma::SetPalmaFrModeType(const PalmaConnectionHandle& handle, PalmaFrModeType fr_mode_) {
  69. if (handle.npad_id != active_handle.npad_id) {
  70. return InvalidPalmaHandle;
  71. }
  72. fr_mode = fr_mode_;
  73. return ResultSuccess;
  74. }
  75. Result Palma::ReadPalmaStep(const PalmaConnectionHandle& handle) {
  76. if (handle.npad_id != active_handle.npad_id) {
  77. return InvalidPalmaHandle;
  78. }
  79. operation.operation = PalmaOperationType::ReadStep;
  80. operation.result = PalmaResultSuccess;
  81. operation.data = {};
  82. operation_complete_event->Signal();
  83. return ResultSuccess;
  84. }
  85. Result Palma::EnablePalmaStep(const PalmaConnectionHandle& handle, bool is_enabled) {
  86. if (handle.npad_id != active_handle.npad_id) {
  87. return InvalidPalmaHandle;
  88. }
  89. return ResultSuccess;
  90. }
  91. Result Palma::ResetPalmaStep(const PalmaConnectionHandle& handle) {
  92. if (handle.npad_id != active_handle.npad_id) {
  93. return InvalidPalmaHandle;
  94. }
  95. return ResultSuccess;
  96. }
  97. void Palma::ReadPalmaApplicationSection() {}
  98. void Palma::WritePalmaApplicationSection() {}
  99. Result Palma::ReadPalmaUniqueCode(const PalmaConnectionHandle& handle) {
  100. if (handle.npad_id != active_handle.npad_id) {
  101. return InvalidPalmaHandle;
  102. }
  103. operation.operation = PalmaOperationType::ReadUniqueCode;
  104. operation.result = PalmaResultSuccess;
  105. operation.data = {};
  106. operation_complete_event->Signal();
  107. return ResultSuccess;
  108. }
  109. Result Palma::SetPalmaUniqueCodeInvalid(const PalmaConnectionHandle& handle) {
  110. if (handle.npad_id != active_handle.npad_id) {
  111. return InvalidPalmaHandle;
  112. }
  113. operation.operation = PalmaOperationType::SetUniqueCodeInvalid;
  114. operation.result = PalmaResultSuccess;
  115. operation.data = {};
  116. operation_complete_event->Signal();
  117. return ResultSuccess;
  118. }
  119. void Palma::WritePalmaActivityEntry() {}
  120. Result Palma::WritePalmaRgbLedPatternEntry(const PalmaConnectionHandle& handle, u64 unknown) {
  121. if (handle.npad_id != active_handle.npad_id) {
  122. return InvalidPalmaHandle;
  123. }
  124. operation.operation = PalmaOperationType::WriteRgbLedPatternEntry;
  125. operation.result = PalmaResultSuccess;
  126. operation.data = {};
  127. operation_complete_event->Signal();
  128. return ResultSuccess;
  129. }
  130. Result Palma::WritePalmaWaveEntry(const PalmaConnectionHandle& handle, PalmaWaveSet wave,
  131. Common::ProcessAddress t_mem, u64 size) {
  132. if (handle.npad_id != active_handle.npad_id) {
  133. return InvalidPalmaHandle;
  134. }
  135. operation.operation = PalmaOperationType::WriteWaveEntry;
  136. operation.result = PalmaResultSuccess;
  137. operation.data = {};
  138. operation_complete_event->Signal();
  139. return ResultSuccess;
  140. }
  141. Result Palma::SetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle& handle,
  142. s32 database_id_version_) {
  143. if (handle.npad_id != active_handle.npad_id) {
  144. return InvalidPalmaHandle;
  145. }
  146. database_id_version = database_id_version_;
  147. operation.operation = PalmaOperationType::ReadDataBaseIdentificationVersion;
  148. operation.result = PalmaResultSuccess;
  149. operation.data[0] = {};
  150. operation_complete_event->Signal();
  151. return ResultSuccess;
  152. }
  153. Result Palma::GetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle& handle) {
  154. if (handle.npad_id != active_handle.npad_id) {
  155. return InvalidPalmaHandle;
  156. }
  157. operation.operation = PalmaOperationType::ReadDataBaseIdentificationVersion;
  158. operation.result = PalmaResultSuccess;
  159. operation.data = {};
  160. operation.data[0] = static_cast<u8>(database_id_version);
  161. operation_complete_event->Signal();
  162. return ResultSuccess;
  163. }
  164. void Palma::SuspendPalmaFeature() {}
  165. Result Palma::GetPalmaOperationResult(const PalmaConnectionHandle& handle) const {
  166. if (handle.npad_id != active_handle.npad_id) {
  167. return InvalidPalmaHandle;
  168. }
  169. return operation.result;
  170. }
  171. void Palma::ReadPalmaPlayLog() {}
  172. void Palma::ResetPalmaPlayLog() {}
  173. void Palma::SetIsPalmaAllConnectable(bool is_all_connectable) {
  174. // If true controllers are able to be paired
  175. is_connectable = is_all_connectable;
  176. }
  177. void Palma::SetIsPalmaPairedConnectable() {}
  178. Result Palma::PairPalma(const PalmaConnectionHandle& handle) {
  179. if (handle.npad_id != active_handle.npad_id) {
  180. return InvalidPalmaHandle;
  181. }
  182. // TODO: Do something
  183. return ResultSuccess;
  184. }
  185. void Palma::SetPalmaBoostMode(bool boost_mode) {}
  186. void Palma::CancelWritePalmaWaveEntry() {}
  187. void Palma::EnablePalmaBoostMode() {}
  188. void Palma::GetPalmaBluetoothAddress() {}
  189. void Palma::SetDisallowedPalmaConnection() {}
  190. } // namespace Service::HID