@desklink/host 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +44 -0
  3. package/README.md +266 -0
  4. package/bin/desklink-host.mjs +113 -0
  5. package/dist/bridge.d.ts +57 -0
  6. package/dist/bridge.d.ts.map +1 -0
  7. package/dist/bridge.js +208 -0
  8. package/dist/bridge.js.map +1 -0
  9. package/dist/engineProcess.d.ts +82 -0
  10. package/dist/engineProcess.d.ts.map +1 -0
  11. package/dist/engineProcess.js +243 -0
  12. package/dist/engineProcess.js.map +1 -0
  13. package/dist/index.d.ts +12 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +12 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/protocol.d.ts +169 -0
  18. package/dist/protocol.d.ts.map +1 -0
  19. package/dist/protocol.js +18 -0
  20. package/dist/protocol.js.map +1 -0
  21. package/dist/resolveEngine.d.ts +34 -0
  22. package/dist/resolveEngine.d.ts.map +1 -0
  23. package/dist/resolveEngine.js +103 -0
  24. package/dist/resolveEngine.js.map +1 -0
  25. package/docs/BOUNDARY.md +145 -0
  26. package/docs/PROTOCOL.md +363 -0
  27. package/engine/Cargo.lock +3077 -0
  28. package/engine/Cargo.toml +37 -0
  29. package/engine/build.rs +107 -0
  30. package/engine/native/inputtino_shim.cpp +11 -0
  31. package/engine/native/vpx_shim.c +184 -0
  32. package/engine/native/wrapper.h +7 -0
  33. package/engine/src/capture.rs +510 -0
  34. package/engine/src/clipboard.rs +132 -0
  35. package/engine/src/convert.rs +299 -0
  36. package/engine/src/encoder.rs +204 -0
  37. package/engine/src/input.rs +355 -0
  38. package/engine/src/keymap.rs +338 -0
  39. package/engine/src/main.rs +614 -0
  40. package/engine/src/peer.rs +775 -0
  41. package/engine/src/portal.rs +115 -0
  42. package/engine/src/protocol.rs +331 -0
  43. package/engine/src/session.rs +2159 -0
  44. package/engine/src/x11.rs +244 -0
  45. package/engine/vendor/inputtino/.clang-format +166 -0
  46. package/engine/vendor/inputtino/.clang-tidy +30 -0
  47. package/engine/vendor/inputtino/.dockerignore +11 -0
  48. package/engine/vendor/inputtino/.github/workflows/mirror-repo.yml +14 -0
  49. package/engine/vendor/inputtino/.github/workflows/python-lint-format-test-typecheck.yml +124 -0
  50. package/engine/vendor/inputtino/.github/workflows/python-test-install.yaml +49 -0
  51. package/engine/vendor/inputtino/.github/workflows/rust.yml +40 -0
  52. package/engine/vendor/inputtino/CMakeLists.txt +187 -0
  53. package/engine/vendor/inputtino/LICENSE +21 -0
  54. package/engine/vendor/inputtino/README.md +110 -0
  55. package/engine/vendor/inputtino/bindings/python/.devcontainer/Dockerfile +23 -0
  56. package/engine/vendor/inputtino/bindings/python/.devcontainer/devcontainer.json +28 -0
  57. package/engine/vendor/inputtino/bindings/python/.python-version +1 -0
  58. package/engine/vendor/inputtino/bindings/python/CMakeLists.txt +23 -0
  59. package/engine/vendor/inputtino/bindings/python/CPPLINT.cfg +2 -0
  60. package/engine/vendor/inputtino/bindings/python/Makefile +49 -0
  61. package/engine/vendor/inputtino/bindings/python/README.md +215 -0
  62. package/engine/vendor/inputtino/bindings/python/pyproject.toml +178 -0
  63. package/engine/vendor/inputtino/bindings/python/src/inputtino/__init__.py +43 -0
  64. package/engine/vendor/inputtino/bindings/python/src/inputtino/_core.pyi +533 -0
  65. package/engine/vendor/inputtino/bindings/python/src/inputtino/base.py +63 -0
  66. package/engine/vendor/inputtino/bindings/python/src/inputtino/joypad.py +248 -0
  67. package/engine/vendor/inputtino/bindings/python/src/inputtino/keyboard.py +256 -0
  68. package/engine/vendor/inputtino/bindings/python/src/inputtino/mouse.py +106 -0
  69. package/engine/vendor/inputtino/bindings/python/src/inputtino/pentablet.py +73 -0
  70. package/engine/vendor/inputtino/bindings/python/src/inputtino/py.typed +0 -0
  71. package/engine/vendor/inputtino/bindings/python/src/inputtino/touchscreen.py +61 -0
  72. package/engine/vendor/inputtino/bindings/python/src/inputtino/trackpad.py +74 -0
  73. package/engine/vendor/inputtino/bindings/python/src/main.cpp +217 -0
  74. package/engine/vendor/inputtino/bindings/python/tests/__init__.py +0 -0
  75. package/engine/vendor/inputtino/bindings/python/tests/helpers.py +3 -0
  76. package/engine/vendor/inputtino/bindings/python/tests/test_base.py +60 -0
  77. package/engine/vendor/inputtino/bindings/python/tests/test_inputtino.py +5 -0
  78. package/engine/vendor/inputtino/bindings/python/tests/test_joypad.py +332 -0
  79. package/engine/vendor/inputtino/bindings/python/tests/test_keyboard.py +164 -0
  80. package/engine/vendor/inputtino/bindings/python/tests/test_mouse.py +185 -0
  81. package/engine/vendor/inputtino/bindings/python/tests/test_pentablet.py +198 -0
  82. package/engine/vendor/inputtino/bindings/python/tests/test_touchscreen.py +144 -0
  83. package/engine/vendor/inputtino/bindings/python/tests/test_trackpad.py +146 -0
  84. package/engine/vendor/inputtino/bindings/python/uv.lock +390 -0
  85. package/engine/vendor/inputtino/bindings/rust/Cargo.toml +6 -0
  86. package/engine/vendor/inputtino/bindings/rust/inputtino/.dockerignore +1 -0
  87. package/engine/vendor/inputtino/bindings/rust/inputtino/Cargo.toml +18 -0
  88. package/engine/vendor/inputtino/bindings/rust/inputtino/examples/keyboard.rs +33 -0
  89. package/engine/vendor/inputtino/bindings/rust/inputtino/examples/mouse.rs +17 -0
  90. package/engine/vendor/inputtino/bindings/rust/inputtino/src/common.rs +116 -0
  91. package/engine/vendor/inputtino/bindings/rust/inputtino/src/error.rs +17 -0
  92. package/engine/vendor/inputtino/bindings/rust/inputtino/src/joypad.rs +74 -0
  93. package/engine/vendor/inputtino/bindings/rust/inputtino/src/joypad_nintendo.rs +135 -0
  94. package/engine/vendor/inputtino/bindings/rust/inputtino/src/joypad_ps5.rs +280 -0
  95. package/engine/vendor/inputtino/bindings/rust/inputtino/src/joypad_xbox.rs +134 -0
  96. package/engine/vendor/inputtino/bindings/rust/inputtino/src/keyboard.rs +76 -0
  97. package/engine/vendor/inputtino/bindings/rust/inputtino/src/lib.rs +32 -0
  98. package/engine/vendor/inputtino/bindings/rust/inputtino/src/mouse.rs +178 -0
  99. package/engine/vendor/inputtino/bindings/rust/inputtino/tests/common.rs +38 -0
  100. package/engine/vendor/inputtino/bindings/rust/inputtino/tests/joypads.rs +150 -0
  101. package/engine/vendor/inputtino/bindings/rust/inputtino/tests/keyboard.rs +73 -0
  102. package/engine/vendor/inputtino/bindings/rust/inputtino/tests/mouse.rs +139 -0
  103. package/engine/vendor/inputtino/bindings/rust/inputtino-sys/.dockerignore +1 -0
  104. package/engine/vendor/inputtino/bindings/rust/inputtino-sys/Cargo.toml +12 -0
  105. package/engine/vendor/inputtino/bindings/rust/inputtino-sys/build.rs +48 -0
  106. package/engine/vendor/inputtino/bindings/rust/inputtino-sys/src/lib.rs +5 -0
  107. package/engine/vendor/inputtino/bindings/rust/inputtino-sys/wrapper.h +1 -0
  108. package/engine/vendor/inputtino/cmake/utils.cmake +9 -0
  109. package/engine/vendor/inputtino/docker/Dockerfile +70 -0
  110. package/engine/vendor/inputtino/include/inputtino/input.h +324 -0
  111. package/engine/vendor/inputtino/include/inputtino/input.hpp +466 -0
  112. package/engine/vendor/inputtino/include/inputtino/result.hpp +37 -0
  113. package/engine/vendor/inputtino/share/pkgconfig/libinputtino.pc.in +17 -0
  114. package/engine/vendor/inputtino/src/c-bindings/helpers.hpp +19 -0
  115. package/engine/vendor/inputtino/src/c-bindings/joypad_ps5.cpp +115 -0
  116. package/engine/vendor/inputtino/src/c-bindings/joypad_switch.cpp +63 -0
  117. package/engine/vendor/inputtino/src/c-bindings/joypad_xone.cpp +62 -0
  118. package/engine/vendor/inputtino/src/c-bindings/keyboard.cpp +42 -0
  119. package/engine/vendor/inputtino/src/c-bindings/mouse.cpp +67 -0
  120. package/engine/vendor/inputtino/src/c-bindings/pen_tablet.cpp +50 -0
  121. package/engine/vendor/inputtino/src/c-bindings/touchscreen.cpp +43 -0
  122. package/engine/vendor/inputtino/src/c-bindings/trackpad.cpp +49 -0
  123. package/engine/vendor/inputtino/src/uhid/README.adoc +63 -0
  124. package/engine/vendor/inputtino/src/uhid/include/crc32.hpp +38 -0
  125. package/engine/vendor/inputtino/src/uhid/include/uhid/protected_types.hpp +36 -0
  126. package/engine/vendor/inputtino/src/uhid/include/uhid/ps5.hpp +550 -0
  127. package/engine/vendor/inputtino/src/uhid/include/uhid/uhid.hpp +168 -0
  128. package/engine/vendor/inputtino/src/uhid/joypad_ps5.cpp +580 -0
  129. package/engine/vendor/inputtino/src/uinput/include/inputtino/keyboard.hpp +84 -0
  130. package/engine/vendor/inputtino/src/uinput/include/inputtino/protected_ps5_types.hpp +7 -0
  131. package/engine/vendor/inputtino/src/uinput/include/inputtino/protected_types.hpp +110 -0
  132. package/engine/vendor/inputtino/src/uinput/joypad_nintendo.cpp +190 -0
  133. package/engine/vendor/inputtino/src/uinput/joypad_ps.cpp +203 -0
  134. package/engine/vendor/inputtino/src/uinput/joypad_utils.hpp +246 -0
  135. package/engine/vendor/inputtino/src/uinput/joypad_xbox.cpp +190 -0
  136. package/engine/vendor/inputtino/src/uinput/keyboard.cpp +120 -0
  137. package/engine/vendor/inputtino/src/uinput/mouse.cpp +199 -0
  138. package/engine/vendor/inputtino/src/uinput/pentablet.cpp +162 -0
  139. package/engine/vendor/inputtino/src/uinput/touchscreen.cpp +140 -0
  140. package/engine/vendor/inputtino/src/uinput/trackpad.cpp +192 -0
  141. package/examples/reference-client.html +428 -0
  142. package/package.json +38 -0
@@ -0,0 +1,550 @@
1
+ #pragma once
2
+
3
+ #include <crc32.hpp>
4
+ #include <linux/uhid.h>
5
+ #include <vector>
6
+
7
+ namespace uhid {
8
+
9
+ /*
10
+ * Ranges taken from https://github.com/nondebug/dualsense
11
+ */
12
+ static constexpr int PS5_AXIS_MIN = 0;
13
+ static constexpr int PS5_AXIS_MAX = 0xFF;
14
+ static constexpr int PS5_AXIS_NEUTRAL = 0x80;
15
+
16
+ /*
17
+ * DualSense hardware limits
18
+ */
19
+ static constexpr int PS5_ACC_RES_PER_G = 8192;
20
+ static constexpr int PS5_ACC_RANGE = (4 * PS5_ACC_RES_PER_G);
21
+ static constexpr int PS5_GYRO_RES_PER_DEG_S = 1024;
22
+ static constexpr int PS5_GYRO_RANGE = (2048 * PS5_GYRO_RES_PER_DEG_S);
23
+ static constexpr int PS5_TOUCHPAD_WIDTH = 1920;
24
+ static constexpr int PS5_TOUCHPAD_HEIGHT = 1080;
25
+ static constexpr float SDL_STANDARD_GRAVITY_CONST = 9.80665f;
26
+
27
+ /*
28
+ * Bluetooth constants,
29
+ * https://github.com/torvalds/linux/blob/305230142ae0637213bf6e04f6d9f10bbcb74af8/drivers/hid/hid-playstation.c#L70-L72
30
+ */
31
+ static constexpr unsigned char PS_INPUT_CRC32_SEED = 0xA1;
32
+ static constexpr auto PS_INPUT_CRC32 = CRC32(&PS_INPUT_CRC32_SEED, 1);
33
+ static constexpr unsigned char PS_OUTPUT_CRC32_SEED = 0xA2;
34
+ static constexpr auto PS_OUTPUT_CRC32 = CRC32(&PS_OUTPUT_CRC32_SEED, 1);
35
+ static constexpr unsigned char PS_FEATURE_CRC32_SEED = 0xA3;
36
+ static constexpr auto PS_FEATURE_CRC32 = CRC32(&PS_FEATURE_CRC32_SEED, 1);
37
+
38
+ /**
39
+ * Taken from: https://github.com/nondebug/dualsense/blob/main/report-descriptor-usb.txt
40
+ * and verified manually using hid-decode
41
+ */
42
+ static constexpr unsigned char ps5_rdesc[] = {
43
+ 0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
44
+ 0x09, 0x05, // Usage (Game Pad)
45
+ 0xA1, 0x01, // Collection (Application)
46
+ 0x85, 0x01, // Report ID (1)
47
+ 0x09, 0x30, // Usage (X)
48
+ 0x09, 0x31, // Usage (Y)
49
+ 0x09, 0x32, // Usage (Z)
50
+ 0x09, 0x35, // Usage (Rz)
51
+ 0x09, 0x33, // Usage (Rx)
52
+ 0x09, 0x34, // Usage (Ry)
53
+ 0x15, 0x00, // Logical Minimum (0)
54
+ 0x26, 0xFF, 0x00, // Logical Maximum (255)
55
+ 0x75, 0x08, // Report Size (8)
56
+ 0x95, 0x06, // Report Count (6)
57
+ 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
58
+ 0x06, 0x00, 0xFF, // Usage Page (Vendor Defined 0xFF00)
59
+ 0x09, 0x20, // Usage (0x20)
60
+ 0x95, 0x01, // Report Count (1)
61
+ 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
62
+ 0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
63
+ 0x09, 0x39, // Usage (Hat switch)
64
+ 0x15, 0x00, // Logical Minimum (0)
65
+ 0x25, 0x07, // Logical Maximum (7)
66
+ 0x35, 0x00, // Physical Minimum (0)
67
+ 0x46, 0x3B, 0x01, // Physical Maximum (315)
68
+ 0x65, 0x14, // Unit (System: English Rotation, Length: Centimeter)
69
+ 0x75, 0x04, // Report Size (4)
70
+ 0x95, 0x01, // Report Count (1)
71
+ 0x81, 0x42, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,Null State)
72
+ 0x65, 0x00, // Unit (None)
73
+ 0x05, 0x09, // Usage Page (Button)
74
+ 0x19, 0x01, // Usage Minimum (0x01)
75
+ 0x29, 0x0F, // Usage Maximum (0x0F)
76
+ 0x15, 0x00, // Logical Minimum (0)
77
+ 0x25, 0x01, // Logical Maximum (1)
78
+ 0x75, 0x01, // Report Size (1)
79
+ 0x95, 0x0F, // Report Count (15)
80
+ 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
81
+ 0x06, 0x00, 0xFF, // Usage Page (Vendor Defined 0xFF00)
82
+ 0x09, 0x21, // Usage (0x21)
83
+ 0x95, 0x0D, // Report Count (13)
84
+ 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
85
+ 0x06, 0x00, 0xFF, // Usage Page (Vendor Defined 0xFF00)
86
+ 0x09, 0x22, // Usage (0x22)
87
+ 0x15, 0x00, // Logical Minimum (0)
88
+ 0x26, 0xFF, 0x00, // Logical Maximum (255)
89
+ 0x75, 0x08, // Report Size (8)
90
+ 0x95, 0x34, // Report Count (52)
91
+ 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
92
+ 0x85, 0x02, // Report ID (2)
93
+ 0x09, 0x23, // Usage (0x23)
94
+ 0x95, 0x2F, // Report Count (47)
95
+ 0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
96
+ 0x85, 0x05, // Report ID (5)
97
+ 0x09, 0x33, // Usage (0x33)
98
+ 0x95, 0x28, // Report Count (40)
99
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
100
+ 0x85, 0x08, // Report ID (8)
101
+ 0x09, 0x34, // Usage (0x34)
102
+ 0x95, 0x2F, // Report Count (47)
103
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
104
+ 0x85, 0x09, // Report ID (9)
105
+ 0x09, 0x24, // Usage (0x24)
106
+ 0x95, 0x13, // Report Count (19)
107
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
108
+ 0x85, 0x0A, // Report ID (10)
109
+ 0x09, 0x25, // Usage (0x25)
110
+ 0x95, 0x1A, // Report Count (26)
111
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
112
+ 0x85, 0x20, // Report ID (32)
113
+ 0x09, 0x26, // Usage (0x26)
114
+ 0x95, 0x3F, // Report Count (63)
115
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
116
+ 0x85, 0x21, // Report ID (33)
117
+ 0x09, 0x27, // Usage (0x27)
118
+ 0x95, 0x04, // Report Count (4)
119
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
120
+ 0x85, 0x22, // Report ID (34)
121
+ 0x09, 0x40, // Usage (0x40)
122
+ 0x95, 0x3F, // Report Count (63)
123
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
124
+ 0x85, 0x80, // Report ID (-128)
125
+ 0x09, 0x28, // Usage (0x28)
126
+ 0x95, 0x3F, // Report Count (63)
127
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
128
+ 0x85, 0x81, // Report ID (-127)
129
+ 0x09, 0x29, // Usage (0x29)
130
+ 0x95, 0x3F, // Report Count (63)
131
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
132
+ 0x85, 0x82, // Report ID (-126)
133
+ 0x09, 0x2A, // Usage (0x2A)
134
+ 0x95, 0x09, // Report Count (9)
135
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
136
+ 0x85, 0x83, // Report ID (-125)
137
+ 0x09, 0x2B, // Usage (0x2B)
138
+ 0x95, 0x3F, // Report Count (63)
139
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
140
+ 0x85, 0x84, // Report ID (-124)
141
+ 0x09, 0x2C, // Usage (0x2C)
142
+ 0x95, 0x3F, // Report Count (63)
143
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
144
+ 0x85, 0x85, // Report ID (-123)
145
+ 0x09, 0x2D, // Usage (0x2D)
146
+ 0x95, 0x02, // Report Count (2)
147
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
148
+ 0x85, 0xA0, // Report ID (-96)
149
+ 0x09, 0x2E, // Usage (0x2E)
150
+ 0x95, 0x01, // Report Count (1)
151
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
152
+ 0x85, 0xE0, // Report ID (-32)
153
+ 0x09, 0x2F, // Usage (0x2F)
154
+ 0x95, 0x3F, // Report Count (63)
155
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
156
+ 0x85, 0xF0, // Report ID (-16)
157
+ 0x09, 0x30, // Usage (0x30)
158
+ 0x95, 0x3F, // Report Count (63)
159
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
160
+ 0x85, 0xF1, // Report ID (-15)
161
+ 0x09, 0x31, // Usage (0x31)
162
+ 0x95, 0x3F, // Report Count (63)
163
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
164
+ 0x85, 0xF2, // Report ID (-14)
165
+ 0x09, 0x32, // Usage (0x32)
166
+ 0x95, 0x0F, // Report Count (15)
167
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
168
+ 0x85, 0xF4, // Report ID (-12)
169
+ 0x09, 0x35, // Usage (0x35)
170
+ 0x95, 0x3F, // Report Count (63)
171
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
172
+ 0x85, 0xF5, // Report ID (-11)
173
+ 0x09, 0x36, // Usage (0x36)
174
+ 0x95, 0x03, // Report Count (3)
175
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
176
+ 0xC0, // End Collection
177
+ };
178
+
179
+ /**
180
+ * Taken from https://github.com/nondebug/dualsense/blob/main/report-descriptor-bluetooth.txt
181
+ */
182
+ static constexpr unsigned char ps5_rdesc_bt[] = {
183
+ 0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
184
+ 0x09, 0x05, // Usage (Game Pad)
185
+ 0xA1, 0x01, // Collection (Application)
186
+ 0x85, 0x01, // Report ID (1)
187
+ 0x09, 0x30, // Usage (X)
188
+ 0x09, 0x31, // Usage (Y)
189
+ 0x09, 0x32, // Usage (Z)
190
+ 0x09, 0x35, // Usage (Rz)
191
+ 0x15, 0x00, // Logical Minimum (0)
192
+ 0x26, 0xFF, 0x00, // Logical Maximum (255)
193
+ 0x75, 0x08, // Report Size (8)
194
+ 0x95, 0x04, // Report Count (4)
195
+ 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
196
+ 0x09, 0x39, // Usage (Hat switch)
197
+ 0x15, 0x00, // Logical Minimum (0)
198
+ 0x25, 0x07, // Logical Maximum (7)
199
+ 0x35, 0x00, // Physical Minimum (0)
200
+ 0x46, 0x3B, 0x01, // Physical Maximum (315)
201
+ 0x65, 0x14, // Unit (System: English Rotation, Length: Centimeter)
202
+ 0x75, 0x04, // Report Size (4)
203
+ 0x95, 0x01, // Report Count (1)
204
+ 0x81, 0x42, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,Null State)
205
+ 0x65, 0x00, // Unit (None)
206
+ 0x05, 0x09, // Usage Page (Button)
207
+ 0x19, 0x01, // Usage Minimum (0x01)
208
+ 0x29, 0x0E, // Usage Maximum (0x0E)
209
+ 0x15, 0x00, // Logical Minimum (0)
210
+ 0x25, 0x01, // Logical Maximum (1)
211
+ 0x75, 0x01, // Report Size (1)
212
+ 0x95, 0x0E, // Report Count (14)
213
+ 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
214
+ 0x75, 0x06, // Report Size (6)
215
+ 0x95, 0x01, // Report Count (1)
216
+ 0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
217
+ 0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
218
+ 0x09, 0x33, // Usage (Rx)
219
+ 0x09, 0x34, // Usage (Ry)
220
+ 0x15, 0x00, // Logical Minimum (0)
221
+ 0x26, 0xFF, 0x00, // Logical Maximum (255)
222
+ 0x75, 0x08, // Report Size (8)
223
+ 0x95, 0x02, // Report Count (2)
224
+ 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
225
+ 0x06, 0x00, 0xFF, // Usage Page (Vendor Defined 0xFF00)
226
+ 0x15, 0x00, // Logical Minimum (0)
227
+ 0x26, 0xFF, 0x00, // Logical Maximum (255)
228
+ 0x75, 0x08, // Report Size (8)
229
+ 0x95, 0x4D, // Report Count (77)
230
+ 0x85, 0x31, // Report ID (49)
231
+ 0x09, 0x31, // Usage (0x31)
232
+ 0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
233
+ 0x09, 0x3B, // Usage (0x3B)
234
+ 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
235
+ 0x85, 0x32, // Report ID (50)
236
+ 0x09, 0x32, // Usage (0x32)
237
+ 0x95, 0x8D, // Report Count (-115)
238
+ 0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
239
+ 0x85, 0x33, // Report ID (51)
240
+ 0x09, 0x33, // Usage (0x33)
241
+ 0x95, 0xCD, // Report Count (-51)
242
+ 0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
243
+ 0x85, 0x34, // Report ID (52)
244
+ 0x09, 0x34, // Usage (0x34)
245
+ 0x96, 0x0D, 0x01, // Report Count (269)
246
+ 0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
247
+ 0x85, 0x35, // Report ID (53)
248
+ 0x09, 0x35, // Usage (0x35)
249
+ 0x96, 0x4D, 0x01, // Report Count (333)
250
+ 0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
251
+ 0x85, 0x36, // Report ID (54)
252
+ 0x09, 0x36, // Usage (0x36)
253
+ 0x96, 0x8D, 0x01, // Report Count (397)
254
+ 0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
255
+ 0x85, 0x37, // Report ID (55)
256
+ 0x09, 0x37, // Usage (0x37)
257
+ 0x96, 0xCD, 0x01, // Report Count (461)
258
+ 0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
259
+ 0x85, 0x38, // Report ID (56)
260
+ 0x09, 0x38, // Usage (0x38)
261
+ 0x96, 0x0D, 0x02, // Report Count (525)
262
+ 0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
263
+ 0x85, 0x39, // Report ID (57)
264
+ 0x09, 0x39, // Usage (0x39)
265
+ 0x96, 0x22, 0x02, // Report Count (546)
266
+ 0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
267
+ 0x06, 0x80, 0xFF, // Usage Page (Vendor Defined 0xFF80)
268
+ 0x85, 0x05, // Report ID (5)
269
+ 0x09, 0x33, // Usage (0x33)
270
+ 0x95, 0x28, // Report Count (40)
271
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
272
+ 0x85, 0x08, // Report ID (8)
273
+ 0x09, 0x34, // Usage (0x34)
274
+ 0x95, 0x2F, // Report Count (47)
275
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
276
+ 0x85, 0x09, // Report ID (9)
277
+ 0x09, 0x24, // Usage (0x24)
278
+ 0x95, 0x13, // Report Count (19)
279
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
280
+ 0x85, 0x20, // Report ID (32)
281
+ 0x09, 0x26, // Usage (0x26)
282
+ 0x95, 0x3F, // Report Count (63)
283
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
284
+ 0x85, 0x22, // Report ID (34)
285
+ 0x09, 0x40, // Usage (0x40)
286
+ 0x95, 0x3F, // Report Count (63)
287
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
288
+ 0x85, 0x80, // Report ID (-128)
289
+ 0x09, 0x28, // Usage (0x28)
290
+ 0x95, 0x3F, // Report Count (63)
291
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
292
+ 0x85, 0x81, // Report ID (-127)
293
+ 0x09, 0x29, // Usage (0x29)
294
+ 0x95, 0x3F, // Report Count (63)
295
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
296
+ 0x85, 0x82, // Report ID (-126)
297
+ 0x09, 0x2A, // Usage (0x2A)
298
+ 0x95, 0x09, // Report Count (9)
299
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
300
+ 0x85, 0x83, // Report ID (-125)
301
+ 0x09, 0x2B, // Usage (0x2B)
302
+ 0x95, 0x3F, // Report Count (63)
303
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
304
+ 0x85, 0xF1, // Report ID (-15)
305
+ 0x09, 0x31, // Usage (0x31)
306
+ 0x95, 0x3F, // Report Count (63)
307
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
308
+ 0x85, 0xF2, // Report ID (-14)
309
+ 0x09, 0x32, // Usage (0x32)
310
+ 0x95, 0x0F, // Report Count (15)
311
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
312
+ 0x85, 0xF0, // Report ID (-16)
313
+ 0x09, 0x30, // Usage (0x30)
314
+ 0x95, 0x3F, // Report Count (63)
315
+ 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
316
+ 0xC0, // End Collection
317
+ };
318
+
319
+ enum PS5_REPORT_TYPES : unsigned int {
320
+ CALIBRATION = 0x05,
321
+ PAIRING_INFO = 0x09,
322
+ FIRMWARE_INFO = 0x20
323
+ };
324
+
325
+ static constexpr unsigned char ps5_calibration_info[] = {
326
+ 0x05,
327
+ 0x00, // gyro_pitch_bias
328
+ 0x00,
329
+ 0x00, // gyro_yaw_bias
330
+ 0x00,
331
+ 0x00, // gyro_roll_bias
332
+ 0x00,
333
+ 0x10, // gyro_pitch_plus
334
+ 0x27,
335
+ 0xF0, // gyro_pitch_minus
336
+ 0xD8,
337
+ 0x10, // gyro_yaw_plus
338
+ 0x27,
339
+ 0xF0, // gyro_yaw_minus
340
+ 0xD8,
341
+ 0x10, // gyro_roll_plus
342
+ 0x27,
343
+ 0xF0, // gyro_roll_minus
344
+ 0xD8,
345
+ 0xF4, // gyro_speed_plus
346
+ 0x01,
347
+ 0xF4, // gyro_speed_minus
348
+ 0x01,
349
+ 0x10, // acc_x_plus
350
+ 0x27,
351
+ 0xF0, // acc_x_minus
352
+ 0xD8,
353
+ 0x10, // acc_y_plus
354
+ 0x27,
355
+ 0xF0, // acc_y_minus
356
+ 0xD8,
357
+ 0x10, // acc_z_plus
358
+ 0x27,
359
+ 0xF0, // acc_z_minus
360
+ 0xD8, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00,
361
+ };
362
+
363
+ static constexpr int gyro_resolution = 1145;
364
+
365
+ static constexpr unsigned char ps5_firmware_info[] = {
366
+ 0x20, 0x4A, 0x75, 0x6E, 0x20, 0x31, 0x39, 0x20, 0x32, 0x30, 0x32, 0x33, 0x31, 0x34, 0x3A, 0x34,
367
+ 0x37, 0x3A, 0x33, 0x34, 0x03, 0x00, 0x44, 0x00, 0x08, 0x02, 0x00, 0x01, 0x36, 0x00, 0x00, 0x01,
368
+ 0xC1, 0xC8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00,
369
+ 0x14, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x01, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
370
+ };
371
+
372
+ static constexpr unsigned char ps5_pairing_info[] = {
373
+ 0x09, 0x74, 0xE7, 0xD6, 0x3A, 0x53, 0x35, 0x08, 0x25, 0x00,
374
+ 0x1E, 0x00, 0xEE, 0x74, 0xD0, 0xBC, 0x00, 0x00, 0x00, 0x00,
375
+ };
376
+
377
+ #pragma pack(push, 1)
378
+ struct dualsense_touch_point {
379
+ /*
380
+ * Status of a DualShock4 touch point contact.
381
+ * Contact IDs, with highest bit set are 'inactive'
382
+ * and any associated data is then invalid.
383
+ */
384
+ uint8_t id : 7;
385
+ uint8_t contact : 1;
386
+ uint8_t x_lo;
387
+ uint8_t x_hi : 4, y_lo : 4;
388
+ uint8_t y_hi;
389
+ };
390
+
391
+ /*
392
+ * Button masks for DualSense input report.
393
+ * see:
394
+ * https://github.com/torvalds/linux/blob/005f6f34bd47eaa61d939a2727fc648e687b84c1/drivers/hid/hid-playstation.c#L90-L106
395
+ */
396
+ enum DS_BUTTONS0 : uint8_t {
397
+ HAT_SWITCH = 0x07, // First 3 bits are HAT
398
+ SQUARE = 0x10,
399
+ CROSS = 0x20,
400
+ CIRCLE = 0x40,
401
+ TRIANGLE = 0x80
402
+ };
403
+
404
+ enum DS_BUTTONS1 : uint8_t {
405
+ L1 = 0x01,
406
+ R1 = 0x02,
407
+ L2 = 0x04,
408
+ R2 = 0x08,
409
+ CREATE = 0x10,
410
+ OPTIONS = 0x20,
411
+ L3 = 0x40,
412
+ R3 = 0x80
413
+ };
414
+
415
+ enum DS_BUTTONS2 : uint8_t {
416
+ PS_HOME = 0x01,
417
+ TOUCHPAD = 0x02,
418
+ MIC_MUTE = 0x04
419
+ };
420
+
421
+ enum HAT_STATES : uint8_t {
422
+ HAT_NEUTRAL = 0x8,
423
+ HAT_N = 0x0,
424
+ HAT_NE = 0x1,
425
+ HAT_E = 0x2,
426
+ HAT_SE = 0x3,
427
+ HAT_S = 0x4,
428
+ HAT_SW = 0x5,
429
+ HAT_W = 0x6,
430
+ HAT_NW = 0x7
431
+ };
432
+
433
+ struct dualsense_input_report_usb_header {
434
+ uint8_t report_id = 0x01;
435
+ };
436
+
437
+ struct dualsense_input_report_bt_header {
438
+ uint8_t report_id = 0x31;
439
+ uint8_t reserved;
440
+ };
441
+
442
+ constexpr size_t PS_INPUT_REPORT_BT_OFFSET = 13;
443
+
444
+ struct dualsense_input_report {
445
+ uint8_t x, y = PS5_AXIS_NEUTRAL; // LS
446
+ uint8_t rx, ry = PS5_AXIS_NEUTRAL; // RS
447
+ uint8_t z, rz = PS5_AXIS_NEUTRAL; // L2, R2
448
+ uint8_t seq_number = 0;
449
+ // HAT_SWITCH is neutral when 0x8 is reported
450
+ uint8_t buttons[4] = {HAT_NEUTRAL, 0, 0, 0};
451
+ uint8_t reserved[4] = {0, 0, 0, 0};
452
+
453
+ /* Motion sensors */
454
+ __le16 gyro[3] = {0, 0, 0}; /* x, y, z */
455
+ __le16 accel[3] = {0, 0, 0}; /* x, y, z */
456
+ __le32 sensor_timestamp = 0;
457
+ uint8_t reserved2 = 0;
458
+
459
+ /* Touchpad */
460
+ struct dualsense_touch_point points[2] = {};
461
+
462
+ uint8_t reserved3 = 0;
463
+ uint8_t r2_adaptive_trigger = 0;
464
+ uint8_t l2_adaptive_trigger = 0;
465
+ uint8_t reserved4[9] = {};
466
+
467
+ uint8_t battery_charge : 4;
468
+ uint8_t battery_status : 4;
469
+ uint8_t battery2 = 0x0c;
470
+ uint8_t reserved6[9] = {};
471
+ };
472
+
473
+ enum FLAG0 : uint8_t {
474
+ MOTOR_OR_COMPATIBLE_VIBRATION = 0x01,
475
+ USE_RUMBLE_NOT_HAPTICS = 0x02,
476
+ RIGHT_TRIGGER_EFFECT = 0x04,
477
+ LEFT_TRIGGER_EFFECT = 0x08,
478
+ };
479
+
480
+ enum FLAG1 : uint8_t {
481
+ MIC_MUTE_LED_ENABLE = 0x01,
482
+ POWER_SAVE_ENABLE = 0x02,
483
+ LIGHTBAR_ENABLE = 0x04,
484
+ RELEASE_LEDS = 0x08,
485
+ PLAYER_INDICATOR_ENABLE = 0x10
486
+ };
487
+
488
+ enum FLAG2 : uint8_t {
489
+ LIGHTBAR_SETUP_ENABLE = 0x02,
490
+ COMPATIBLE_VIBRATION = 0x04
491
+ };
492
+
493
+ /* Common data between DualSense BT/USB main output report. */
494
+ struct dualsense_output_report_common {
495
+ uint8_t valid_flag0;
496
+ uint8_t valid_flag1;
497
+
498
+ /* For DualShock 4 compatibility mode. */
499
+ uint8_t motor_right;
500
+ uint8_t motor_left;
501
+
502
+ /* Audio controls */
503
+ uint8_t reserved[4];
504
+ uint8_t mute_button_led;
505
+
506
+ uint8_t power_save_control;
507
+ uint8_t right_trigger_effect_type;
508
+ uint8_t right_trigger_effect[10];
509
+ uint8_t left_trigger_effect_type;
510
+ uint8_t left_trigger_effect[10];
511
+ uint8_t reserved2[6];
512
+
513
+ /* LEDs and lightbar */
514
+ uint8_t valid_flag2;
515
+ uint8_t reserved3[2];
516
+ uint8_t lightbar_setup;
517
+ uint8_t led_brightness;
518
+ uint8_t player_leds;
519
+ uint8_t lightbar_red;
520
+ uint8_t lightbar_green;
521
+ uint8_t lightbar_blue;
522
+ };
523
+
524
+ static constexpr uint8_t DS_OUTPUT_REPORT_USB = 0x02;
525
+
526
+ struct dualsense_output_report_usb {
527
+ uint8_t report_id; /* 0x02 */
528
+ struct dualsense_output_report_common common;
529
+ uint8_t reserved[15];
530
+ };
531
+
532
+ static constexpr uint8_t DS_OUTPUT_REPORT_BT = 0x31;
533
+
534
+ struct dualsense_output_report_bt {
535
+ uint8_t report_id; /* 0x31 */
536
+
537
+ /* Following has been taken from https://controllers.fandom.com/wiki/Sony_DualSense#Output_Reports */
538
+ uint8_t UNK1 : 1; // -+
539
+ uint8_t EnableHID : 1; // | - these 3 bits seem to act as an enum
540
+ uint8_t UNK2 : 1; // -+
541
+ uint8_t UNK3 : 1;
542
+ uint8_t SeqNo : 4; // increment for every write
543
+
544
+ struct dualsense_output_report_common common;
545
+ uint8_t reserved[24];
546
+ __le32 crc32;
547
+ };
548
+ #pragma pack(pop)
549
+
550
+ } // namespace uhid