touchscreen.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "common/common_funcs.h"
  5. #include "common/common_types.h"
  6. #include "core/hid/hid_types.h"
  7. #include "core/hle/service/hid/controllers/controller_base.h"
  8. #include "core/hle/service/hid/ring_lifo.h"
  9. namespace Core::HID {
  10. class EmulatedConsole;
  11. } // namespace Core::HID
  12. namespace Service::HID {
  13. class TouchScreen final : public ControllerBase {
  14. public:
  15. explicit TouchScreen(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_);
  16. ~TouchScreen() override;
  17. // Called when the controller is initialized
  18. void OnInit() override;
  19. // When the controller is released
  20. void OnRelease() override;
  21. // When the controller is requesting an update for the shared memory
  22. void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
  23. void SetTouchscreenDimensions(u32 width, u32 height);
  24. private:
  25. static constexpr std::size_t MAX_FINGERS = 16;
  26. // This is nn::hid::TouchScreenState
  27. struct TouchScreenState {
  28. s64 sampling_number{};
  29. s32 entry_count{};
  30. INSERT_PADDING_BYTES(4); // Reserved
  31. std::array<Core::HID::TouchState, MAX_FINGERS> states{};
  32. };
  33. static_assert(sizeof(TouchScreenState) == 0x290, "TouchScreenState is an invalid size");
  34. struct TouchSharedMemory {
  35. // This is nn::hid::detail::TouchScreenLifo
  36. Lifo<TouchScreenState, hid_entry_count> touch_screen_lifo{};
  37. static_assert(sizeof(touch_screen_lifo) == 0x2C38, "touch_screen_lifo is an invalid size");
  38. INSERT_PADDING_WORDS(0xF2);
  39. };
  40. static_assert(sizeof(TouchSharedMemory) == 0x3000, "TouchSharedMemory is an invalid size");
  41. TouchScreenState next_state{};
  42. TouchSharedMemory* shared_memory = nullptr;
  43. Core::HID::EmulatedConsole* console = nullptr;
  44. std::array<Core::HID::TouchFinger, MAX_FINGERS> fingers{};
  45. u32 touchscreen_width;
  46. u32 touchscreen_height;
  47. };
  48. } // namespace Service::HID