touchscreen.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "common/bit_field.h"
  6. #include "common/common_funcs.h"
  7. #include "common/common_types.h"
  8. #include "common/swap.h"
  9. #include "core/frontend/input.h"
  10. #include "core/hle/service/hid/controllers/controller_base.h"
  11. namespace Service::HID {
  12. class Controller_Touchscreen final : public ControllerBase {
  13. public:
  14. explicit Controller_Touchscreen(Core::System& system);
  15. ~Controller_Touchscreen() override;
  16. // Called when the controller is initialized
  17. void OnInit() override;
  18. // When the controller is released
  19. void OnRelease() override;
  20. // When the controller is requesting an update for the shared memory
  21. void OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, std::size_t size) override;
  22. // Called when input devices should be loaded
  23. void OnLoadInputDevices() override;
  24. private:
  25. struct Attributes {
  26. union {
  27. u32 raw{};
  28. BitField<0, 1, u32> start_touch;
  29. BitField<1, 1, u32> end_touch;
  30. };
  31. };
  32. static_assert(sizeof(Attributes) == 0x4, "Attributes is an invalid size");
  33. struct TouchState {
  34. u64_le delta_time;
  35. Attributes attribute;
  36. u32_le finger;
  37. u32_le x;
  38. u32_le y;
  39. u32_le diameter_x;
  40. u32_le diameter_y;
  41. u32_le rotation_angle;
  42. };
  43. static_assert(sizeof(TouchState) == 0x28, "Touchstate is an invalid size");
  44. struct TouchScreenEntry {
  45. s64_le sampling_number;
  46. s64_le sampling_number2;
  47. s32_le entry_count;
  48. std::array<TouchState, 16> states;
  49. };
  50. static_assert(sizeof(TouchScreenEntry) == 0x298, "TouchScreenEntry is an invalid size");
  51. struct TouchScreenSharedMemory {
  52. CommonHeader header;
  53. std::array<TouchScreenEntry, 17> shared_memory_entries{};
  54. INSERT_PADDING_BYTES(0x3c8);
  55. };
  56. static_assert(sizeof(TouchScreenSharedMemory) == 0x3000,
  57. "TouchScreenSharedMemory is an invalid size");
  58. TouchScreenSharedMemory shared_memory{};
  59. std::unique_ptr<Input::TouchDevice> touch_device;
  60. s64_le last_touch{};
  61. };
  62. } // namespace Service::HID