Skip to content

Commit 1024f1d

Browse files
authored
feat(hid): Improve docstrings for playstation hid reports (#521)
1 parent d9b1aec commit 1024f1d

File tree

1 file changed

+46
-27
lines changed

1 file changed

+46
-27
lines changed

components/hid-rp/include/hid-rp-playstation.hpp

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ namespace espp {
3434

3535
#pragma pack(push, 1)
3636

37-
/// Playstation DualSense Touchpad Data
37+
/// Playstation DualSense Touchpad Data Used in the vendor defined data for
38+
/// input report ID 0x31 (49) when used over BLE.
3839
struct PlaystationTouchpadData {
3940
union {
4041
std::uint8_t raw[9]; ///< Raw data array
@@ -45,7 +46,8 @@ struct PlaystationTouchpadData {
4546
};
4647
};
4748

48-
/// Playstation DualSense Gamepad Buttons
49+
/// Playstation DualSense Gamepad Buttons Used in input reports (0x01, 0x31)
50+
/// when used over BLE.
4951
union PlaystationDualsenseGamepadButtons {
5052
std::array<std::uint8_t, 3> raw; ///< Buttons as bytes
5153
struct {
@@ -72,7 +74,8 @@ union PlaystationDualsenseGamepadButtons {
7274
}; // struct
7375
}; // union PlaystationDualsenseGamepadButtons
7476

75-
/// Playstation DualSense Vendor Defined Data
77+
/// Playstation DualSense Vendor Defined Data. Used for IMU, touchpad, battery,
78+
/// etc. in input report 0x31 (49) over Bluetooth.
7679
union PlaystationDualsenseVendorDefinedData {
7780
using Accelerometer = espp::gamepad::Accelerometer; ///< Accelerometer type
7881
using Gyroscope = espp::gamepad::Gyroscope; ///< Gyroscope type
@@ -114,27 +117,30 @@ union PlaystationDualsenseVendorDefinedData {
114117

115118
/// Button Struct concept for the Playstation controller
116119
/// This concept defines the requirements for a struct that contains the
117-
/// button values for the Playstation controller.
120+
/// button values for the Playstation controller. Any struct which meets these
121+
/// requirements can be used with the PlaystationDualsenseBLESimpleInputReport
122+
/// and PlaystationDualsenseBLEComplexInputReport classes.
118123
template <typename T>
119124
concept PlaystationDualsenseButtonStruct = requires(T t) {
120-
{ auto(t.cross) } -> std::integral; // xbox a
121-
{ auto(t.circle) } -> std::integral; // xbox b
122-
{ auto(t.square) } -> std::integral; // xbox x
123-
{ auto(t.triangle) } -> std::integral; // xbox y
124-
{ auto(t.l1) } -> std::integral;
125-
{ auto(t.r1) } -> std::integral;
126-
{ auto(t.l2) } -> std::integral;
127-
{ auto(t.r2) } -> std::integral;
128-
{ auto(t.l3) } -> std::integral;
129-
{ auto(t.r3) } -> std::integral;
130-
{ auto(t.home) } -> std::integral; // ps button
131-
{ auto(t.capture) } -> std::integral; // create button
132-
{ auto(t.menu) } -> std::integral; // touchpad button
133-
{ auto(t.options) } -> std::integral; // options button
134-
{ auto(t.microphone_mute) } -> std::integral; // microphone mute button
125+
{ auto(t.cross) } -> std::integral; ///< Cross button, same as xbox a
126+
{ auto(t.circle) } -> std::integral; ///< Circle button, same as xbox b
127+
{ auto(t.square) } -> std::integral; ///< Square button, same as xbox x
128+
{ auto(t.triangle) } -> std::integral; ///< Triangle button, same as xbox y
129+
{ auto(t.l1) } -> std::integral; ///< L1 (left shoulder) button
130+
{ auto(t.r1) } -> std::integral; ///< R1 (right shoulder) button
131+
{ auto(t.l2) } -> std::integral; ///< L2 (left trigger, digital representation) button
132+
{ auto(t.r2) } -> std::integral; ///< R2 (right trigger, digital representation) button
133+
{ auto(t.l3) } -> std::integral; ///< L3 (left joystick) button
134+
{ auto(t.r3) } -> std::integral; ///< R3 (left joystick) button
135+
{ auto(t.home) } -> std::integral; ///< Playstation button
136+
{ auto(t.capture) } -> std::integral; ///< Create button
137+
{ auto(t.menu) } -> std::integral; ///< Touchpad button
138+
{ auto(t.options) } -> std::integral; ///< Options button
139+
{ auto(t.microphone_mute) } -> std::integral; ///< Microphone mute button
135140
};
136141

137-
/// Possible Hat switch directions for Playstation controller
142+
/// Possible Hat switch directions for Playstation controller. Uses different
143+
/// values than espp::gamepad::Hat
138144
enum class PlaystationHat {
139145
CENTERED = 0x08, ///< Centered, no direction pressed.
140146
UP = 0,
@@ -147,11 +153,11 @@ enum class PlaystationHat {
147153
UP_LEFT = 7
148154
};
149155

150-
/// Convert from espp::gamepad::Hat to Hat
156+
/// Convert from espp::gamepad::Hat to PlaystationHat
151157
/// \param hat The espp::gamepad::Hat value to convert
152-
/// \return The corresponding Hat value
158+
/// \return The corresponding PlaystationHat value
153159
/// \note This is a constexpr function, so it can be used in compile-time
154-
/// expressions.
160+
/// expressions, as well as at runtime.
155161
[[maybe_unused]] static constexpr PlaystationHat from_gamepad_hat(espp::gamepad::Hat hat) {
156162
if (hat == espp::gamepad::Hat::CENTERED) {
157163
return PlaystationHat::CENTERED;
@@ -164,10 +170,16 @@ enum class PlaystationHat {
164170
/// This class implements a HID Playstation DualSense Bluetooth Gamepad Report.
165171
/// It supports 14 buttons, a d-pad, 4 joystick axes, and 2 trigger axes.
166172
///
167-
/// This matches the information found here:
168-
/// https://github.com/nondebug/dualsense
173+
/// This is the simple report which is used by default when connecting the
174+
/// controller over bluetooth and matches report ID 0x01.
169175
///
170-
/// which provides a bluetooth VID/PID of 054C:0CE6
176+
/// \note I have tested the playstation dualsense report descriptor and input
177+
/// reports over BLE with iOS, MacOS, Windows, and Android and found that:
178+
/// - iOS, MacOS, and Windows only parse the complex report (0x31) and ignore
179+
/// the simple report (0x01). This means that the simple report is effectively
180+
/// unused fields in the report descriptor.
181+
/// - Android seems to require Audio support, which it cannot find over BLE, so
182+
/// it does not work at all.
171183
///
172184
/// \section hid_rp_playstation_ex1 HID-RP Playstation Gamepad Example
173185
/// \snippet hid_rp_example.cpp hid rp example
@@ -667,9 +679,16 @@ class PlaystationDualsenseBLESimpleInputReport
667679
///
668680
/// This matches the information found here:
669681
/// https://github.com/nondebug/dualsense
670-
///
671682
/// which provides a bluetooth VID/PID of 054C:0CE6
672683
///
684+
/// \note I have tested the playstation dualsense report descriptor and input
685+
/// reports over BLE with iOS, MacOS, Windows, and Android and found that:
686+
/// - iOS, MacOS, and Windows only parse the complex report (0x31) and ignore
687+
/// the simple report (0x01). This means that the simple report is effectively
688+
/// unused fields in the report descriptor.
689+
/// - Android seems to require Audio support, which it cannot find over BLE, so
690+
/// it does not work at all.
691+
///
673692
/// \section hid_rp_playstation_ex1 HID-RP Playstation Gamepad Example
674693
/// \snippet hid_rp_example.cpp hid rp example
675694
template <uint8_t REPORT_ID = 49>

0 commit comments

Comments
 (0)