nfc_device.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "common/common_types.h"
  5. #include "core/hle/service/kernel_helpers.h"
  6. #include "core/hle/service/nfp/nfp_types.h"
  7. #include "core/hle/service/service.h"
  8. namespace Kernel {
  9. class KEvent;
  10. class KReadableEvent;
  11. } // namespace Kernel
  12. namespace Core {
  13. class System;
  14. } // namespace Core
  15. namespace Core::HID {
  16. class EmulatedController;
  17. enum class ControllerTriggerType;
  18. enum class NpadIdType : u32;
  19. } // namespace Core::HID
  20. namespace Service::NFC {
  21. class NfcDevice {
  22. public:
  23. NfcDevice(Core::HID::NpadIdType npad_id_, Core::System& system_,
  24. KernelHelpers::ServiceContext& service_context_,
  25. Kernel::KEvent* availability_change_event_);
  26. ~NfcDevice();
  27. void Initialize();
  28. void Finalize();
  29. Result StartDetection(s32 protocol_);
  30. Result StopDetection();
  31. Result GetTagInfo(NFP::TagInfo& tag_info) const;
  32. u64 GetHandle() const;
  33. NFP::DeviceState GetCurrentState() const;
  34. Core::HID::NpadIdType GetNpadId() const;
  35. Kernel::KReadableEvent& GetActivateEvent() const;
  36. Kernel::KReadableEvent& GetDeactivateEvent() const;
  37. private:
  38. void NpadUpdate(Core::HID::ControllerTriggerType type);
  39. bool LoadNfcTag(std::span<const u8> data);
  40. void CloseNfcTag();
  41. bool is_controller_set{};
  42. int callback_key;
  43. const Core::HID::NpadIdType npad_id;
  44. Core::System& system;
  45. Core::HID::EmulatedController* npad_device = nullptr;
  46. KernelHelpers::ServiceContext& service_context;
  47. Kernel::KEvent* activate_event = nullptr;
  48. Kernel::KEvent* deactivate_event = nullptr;
  49. Kernel::KEvent* availability_change_event = nullptr;
  50. s32 protocol{};
  51. NFP::DeviceState device_state{NFP::DeviceState::Unavailable};
  52. NFP::EncryptedNTAG215File encrypted_tag_data{};
  53. };
  54. } // namespace Service::NFC