palma.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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() = default;
  19. void Controller_Palma::OnInit() {}
  20. void Controller_Palma::OnRelease() {}
  21. void Controller_Palma::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
  22. if (!IsControllerActivated()) {
  23. return;
  24. }
  25. }
  26. Result Controller_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 Controller_Palma::InitializePalma(const PalmaConnectionHandle& handle) {
  33. if (handle.npad_id != active_handle.npad_id) {
  34. return InvalidPalmaHandle;
  35. }
  36. ActivateController();
  37. return ResultSuccess;
  38. }
  39. Kernel::KReadableEvent& Controller_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 Controller_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 Controller_Palma::PlayPalmaActivity(const PalmaConnectionHandle& handle,
  57. u64 palma_activity) {
  58. if (handle.npad_id != active_handle.npad_id) {
  59. return InvalidPalmaHandle;
  60. }
  61. operation.operation = PalmaOperationType::PlayActivity;
  62. operation.result = PalmaResultSuccess;
  63. operation.data = {};
  64. operation_complete_event->GetWritableEvent().Signal();
  65. return ResultSuccess;
  66. }
  67. Result Controller_Palma::SetPalmaFrModeType(const PalmaConnectionHandle& handle,
  68. 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 Controller_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->GetWritableEvent().Signal();
  83. return ResultSuccess;
  84. }
  85. Result Controller_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 Controller_Palma::ResetPalmaStep(const PalmaConnectionHandle& handle) {
  92. if (handle.npad_id != active_handle.npad_id) {
  93. return InvalidPalmaHandle;
  94. }
  95. return ResultSuccess;
  96. }
  97. void Controller_Palma::ReadPalmaApplicationSection() {}
  98. void Controller_Palma::WritePalmaApplicationSection() {}
  99. Result Controller_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->GetWritableEvent().Signal();
  107. return ResultSuccess;
  108. }
  109. Result Controller_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->GetWritableEvent().Signal();
  117. return ResultSuccess;
  118. }
  119. void Controller_Palma::WritePalmaActivityEntry() {}
  120. Result Controller_Palma::WritePalmaRgbLedPatternEntry(const PalmaConnectionHandle& handle,
  121. u64 unknown) {
  122. if (handle.npad_id != active_handle.npad_id) {
  123. return InvalidPalmaHandle;
  124. }
  125. operation.operation = PalmaOperationType::WriteRgbLedPatternEntry;
  126. operation.result = PalmaResultSuccess;
  127. operation.data = {};
  128. operation_complete_event->GetWritableEvent().Signal();
  129. return ResultSuccess;
  130. }
  131. Result Controller_Palma::WritePalmaWaveEntry(const PalmaConnectionHandle& handle, PalmaWaveSet wave,
  132. u8* t_mem, u64 size) {
  133. if (handle.npad_id != active_handle.npad_id) {
  134. return InvalidPalmaHandle;
  135. }
  136. operation.operation = PalmaOperationType::WriteWaveEntry;
  137. operation.result = PalmaResultSuccess;
  138. operation.data = {};
  139. operation_complete_event->GetWritableEvent().Signal();
  140. return ResultSuccess;
  141. }
  142. Result Controller_Palma::SetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle& handle,
  143. s32 database_id_version_) {
  144. if (handle.npad_id != active_handle.npad_id) {
  145. return InvalidPalmaHandle;
  146. }
  147. database_id_version = database_id_version_;
  148. operation.operation = PalmaOperationType::ReadDataBaseIdentificationVersion;
  149. operation.result = PalmaResultSuccess;
  150. operation.data[0] = {};
  151. operation_complete_event->GetWritableEvent().Signal();
  152. return ResultSuccess;
  153. }
  154. Result Controller_Palma::GetPalmaDataBaseIdentificationVersion(
  155. const PalmaConnectionHandle& handle) {
  156. if (handle.npad_id != active_handle.npad_id) {
  157. return InvalidPalmaHandle;
  158. }
  159. operation.operation = PalmaOperationType::ReadDataBaseIdentificationVersion;
  160. operation.result = PalmaResultSuccess;
  161. operation.data = {};
  162. operation.data[0] = static_cast<u8>(database_id_version);
  163. operation_complete_event->GetWritableEvent().Signal();
  164. return ResultSuccess;
  165. }
  166. void Controller_Palma::SuspendPalmaFeature() {}
  167. Result Controller_Palma::GetPalmaOperationResult(const PalmaConnectionHandle& handle) const {
  168. if (handle.npad_id != active_handle.npad_id) {
  169. return InvalidPalmaHandle;
  170. }
  171. return operation.result;
  172. }
  173. void Controller_Palma::ReadPalmaPlayLog() {}
  174. void Controller_Palma::ResetPalmaPlayLog() {}
  175. void Controller_Palma::SetIsPalmaAllConnectable(bool is_all_connectable) {
  176. // If true controllers are able to be paired
  177. is_connectable = is_all_connectable;
  178. }
  179. void Controller_Palma::SetIsPalmaPairedConnectable() {}
  180. Result Controller_Palma::PairPalma(const PalmaConnectionHandle& handle) {
  181. if (handle.npad_id != active_handle.npad_id) {
  182. return InvalidPalmaHandle;
  183. }
  184. // TODO: Do something
  185. return ResultSuccess;
  186. }
  187. void Controller_Palma::SetPalmaBoostMode(bool boost_mode) {}
  188. void Controller_Palma::CancelWritePalmaWaveEntry() {}
  189. void Controller_Palma::EnablePalmaBoostMode() {}
  190. void Controller_Palma::GetPalmaBluetoothAddress() {}
  191. void Controller_Palma::SetDisallowedPalmaConnection() {}
  192. } // namespace Service::HID