Monado OpenXR Runtime
Loading...
Searching...
No Matches
pssense_protocol.h
Go to the documentation of this file.
1// Copyright 2023, Collabora, Ltd.
2// Copyright 2023, Jarett Millard
3// Copyright 2026, Beyley Cardellio
4// SPDX-License-Identifier: BSL-1.0
5/*!
6 * @file
7 * @brief PlayStation Sense controller prober and driver code.
8 * @author Jarett Millard <jarett.millard@gmail.com>
9 * @author Beyley Cardellio <ep1cm1n10n123@gmail.com>
10 * @ingroup drv_pssense
11 */
12
13#pragma once
14
15#include "xrt/xrt_byte_order.h"
16
17#include "math/m_api.h"
18
19
20#pragma pack(push, 1)
21
22const uint8_t INPUT_REPORT_ID = 0x31;
23const uint8_t OUTPUT_REPORT_ID = 0x31;
24const uint8_t OUTPUT_REPORT_TAG = 0x10;
25const uint8_t CALIBRATION_DATA_FEATURE_REPORT_ID = 0x05;
26const uint8_t CALIBRATION_DATA_PART_ID_1 = 0;
27const uint8_t CALIBRATION_DATA_PART_ID_2 = 0x81;
28
29const uint8_t INPUT_REPORT_CRC32_SEED = 0xa1;
30const uint8_t OUTPUT_REPORT_CRC32_SEED = 0xa2;
31const uint8_t FEATURE_REPORT_CRC32_SEED = 0xa3;
32
33//! Gyro read value range is +-32768.
34const double PSSENSE_GYRO_SCALE_DEG = 180.0 / 1024;
35//! Accelerometer read value range is +-32768 and covers +-8 g.
37
38//! Flag bits to enable setting vibration in an output report
39const uint8_t VIBRATE_ENABLE_BITS = 0x03;
40//! Pure 120Hz vibration
41const uint8_t VIBRATE_MODE_HIGH_120HZ = 0x00;
42//! Pure 60Hz vibration
43const uint8_t VIBRATE_MODE_LOW_60HZ = 0x20;
44//! Emulates a legacy vibration motor
45const uint8_t VIBRATE_MODE_CLASSIC_RUMBLE = 0x40;
46//! Softer rumble emulation, like an engine running
47const uint8_t VIBRATE_MODE_DIET_RUMBLE = 0x60;
48
49//! Flag bits to enable setting trigger feedback in an output report
50const uint8_t TRIGGER_FEEDBACK_ENABLE_BITS = 0x04;
51//! Clear the trigger feedback setting
52const uint8_t TRIGGER_FEEDBACK_MODE_NONE = 0x00;
53//! Constant resistance throughout the trigger movement
54const uint8_t TRIGGER_FEEDBACK_MODE_CONSTANT = 0x01;
55//! A single point of resistance at the beginning of the trigger, right before the click flag is activated
56const uint8_t TRIGGER_FEEDBACK_MODE_CATCH = 0x02;
57
58const uint8_t CHARGE_STATE_DISCHARGING = 0x00;
59const uint8_t CHARGE_STATE_CHARGING = 0x01;
60const uint8_t CHARGE_STATE_FULL = 0x02;
61const uint8_t CHARGE_STATE_ABNORMAL_VOLTAGE = 0x0A;
62const uint8_t CHARGE_STATE_ABNORMAL_TEMP = 0x0B;
63const uint8_t CHARGE_STATE_CHARGING_ERROR = 0x0F;
64
65#define INPUT_REPORT_LENGTH 78
66/*!
67 * HID input report data packet.
68 */
70{
71 uint8_t report_id;
72 uint8_t bt_header;
73 uint8_t thumbstick_x;
74 uint8_t thumbstick_y;
75 uint8_t trigger_value;
76 uint8_t trigger_proximity;
77 uint8_t squeeze_proximity;
78 uint8_t unknown1[2]; // Always 0x0001
79 uint8_t buttons[3];
80 uint8_t unknown2; // Always 0x00
81 __le32 seq_no;
82 __le16 gyro[3];
83 __le16 accel[3];
84 __le32 imu_ticks;
85 uint8_t temperature;
86 uint8_t unknown3[9];
87 uint8_t battery_state; // High bits charge level 0x00-0x0a, low bits battery state
88 uint8_t plug_state; // Flags for USB data and/or power connected
89 __le32 host_timestamp;
90 __le32 device_timestamp;
91 uint8_t unknown4[4];
92 uint8_t aes_cmac[8];
93 uint8_t unknown5;
94 uint8_t crc_failure_count;
95 uint8_t padding[7];
96 __le32 crc;
97};
98static_assert(sizeof(struct pssense_input_report) == INPUT_REPORT_LENGTH, "Incorrect input report struct length");
99
100#define OUTPUT_REPORT_LENGTH 78
101/**
102 * HID output report data packet.
103 */
105{
106 uint8_t report_id;
107 uint8_t bt_seq_no; // High bits only; low bits are always 0
108 uint8_t tag; // Needs to be 0x10 for this report
109 uint8_t feedback_flags; // Vibrate mode and enable flags to set vibrate and trigger feedback in this report
110 uint8_t unknown;
111 uint8_t vibration_amplitude; // Vibration amplitude from 0x00-0xff. Sending 0 turns vibration off.
112 uint8_t unknown2;
113 uint8_t trigger_feedback_mode; // Constant or sticky trigger resistance
114 uint8_t ffb[10];
115 __le32 host_timestamp;
116 uint8_t unknown3[19];
117 uint8_t counter;
118 uint8_t haptics[32];
119 __le32 crc;
120};
121static_assert(sizeof(struct pssense_output_report) == OUTPUT_REPORT_LENGTH, "Incorrect output report struct length");
122
123#define FEATURE_REPORT_LENGTH 64
124#define CALIBRATION_DATA_LENGTH 116
125
126/**
127 * HID output report data packet.
128 */
130{
131 uint8_t report_id;
132 uint8_t part_id;
133 uint8_t data[CALIBRATION_DATA_LENGTH / 2];
134 __le32 crc;
135};
136static_assert(sizeof(struct pssense_feature_report) == FEATURE_REPORT_LENGTH, "Incorrect feature report struct length");
137
138#pragma pack(pop)
#define MATH_GRAVITY_M_S2
Standard gravity acceleration constant.
Definition m_api.h:53
C interface to math library.
const uint8_t VIBRATE_MODE_CLASSIC_RUMBLE
Emulates a legacy vibration motor.
Definition pssense_protocol.h:45
const double PSSENSE_ACCEL_SCALE
Accelerometer read value range is +-32768 and covers +-8 g.
Definition pssense_protocol.h:36
const uint8_t TRIGGER_FEEDBACK_MODE_CATCH
A single point of resistance at the beginning of the trigger, right before the click flag is activate...
Definition pssense_protocol.h:56
const uint8_t VIBRATE_ENABLE_BITS
Flag bits to enable setting vibration in an output report.
Definition pssense_protocol.h:39
const uint8_t TRIGGER_FEEDBACK_ENABLE_BITS
Flag bits to enable setting trigger feedback in an output report.
Definition pssense_protocol.h:50
const uint8_t TRIGGER_FEEDBACK_MODE_CONSTANT
Constant resistance throughout the trigger movement.
Definition pssense_protocol.h:54
const double PSSENSE_GYRO_SCALE_DEG
Gyro read value range is +-32768.
Definition pssense_protocol.h:34
const uint8_t VIBRATE_MODE_LOW_60HZ
Pure 60Hz vibration.
Definition pssense_protocol.h:43
const uint8_t VIBRATE_MODE_DIET_RUMBLE
Softer rumble emulation, like an engine running.
Definition pssense_protocol.h:47
const uint8_t TRIGGER_FEEDBACK_MODE_NONE
Clear the trigger feedback setting.
Definition pssense_protocol.h:52
const uint8_t VIBRATE_MODE_HIGH_120HZ
Pure 120Hz vibration.
Definition pssense_protocol.h:41
HID output report data packet.
Definition pssense_protocol.h:130
HID input report data packet.
Definition pssense_protocol.h:70
HID output report data packet.
Definition pssense_protocol.h:105
Endian-specific byte order defines.