Monado OpenXR Runtime
rift_s_protocol.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 Lucas Teske <lucas@teske.com.br>
3 * Copyright 2019-2020 Jan Schmidt
4 * SPDX-License-Identifier: BSL-1.0
5 *
6 * OpenHMD - Free and Open Source API and drivers for immersive technology.
7 */
8
9/*!
10 * @file
11 * @brief Oculus Rift S USB protocol implementation interface.
12 *
13 * Functions for interpreting the USB protocol to the
14 * headset and Touch Controllers (via the headset's radio link)
15 *
16 * Ported from OpenHMD
17 *
18 * @author Jan Schmidt <jan@centricular.com>
19 */
20#ifndef __RIFT_S_PROTOCOL__
21#define __RIFT_S_PROTOCOL__
22
23#include <stdlib.h>
24#include "os/os_hid.h"
25#include "xrt/xrt_defines.h"
26
27#define FEATURE_BUFFER_SIZE 256
28
29#define KEEPALIVE_INTERVAL_MS 1000
30#define CAMERA_REPORT_INTERVAL_MS 1000
31
32#define RIFT_S_BUTTON_A_X 0x01
33#define RIFT_S_BUTTON_B_Y 0x02
34#define RIFT_S_BUTTON_STICK 0x04
35#define RIFT_S_BUTTON_MENU_OCULUS 0x08
36
37#define RIFT_S_BUTTON_UNKNOWN 0x10 // Unknown mask value seen sometimes. Low battery?
38
39#define RIFT_S_FINGER_A_X_STRONG 0x01
40#define RIFT_S_FINGER_B_Y_STRONG 0x02
41#define RIFT_S_FINGER_STICK_STRONG 0x04
42#define RIFT_S_FINGER_TRIGGER_STRONG 0x08
43#define RIFT_S_FINGER_A_X_WEAK 0x10
44#define RIFT_S_FINGER_B_Y_WEAK 0x20
45#define RIFT_S_FINGER_STICK_WEAK 0x40
46#define RIFT_S_FINGER_TRIGGER_WEAK 0x80
47
48typedef enum
49{
50 RIFT_S_CTRL_MASK08 = 0x08, /* Unknown. Vals seen 0x28, 0x0a, 0x32, 0x46, 0x00... */
51 RIFT_S_CTRL_BUTTONS = 0x0c, /* Button states */
52 RIFT_S_CTRL_FINGERS = 0x0d, /* Finger positions */
53 RIFT_S_CTRL_MASK0e = 0x0e, /* Unknown. Only seen 0x00 */
54 RIFT_S_CTRL_TRIGGRIP = 0x1b, /* Trigger + Grip */
55 RIFT_S_CTRL_JOYSTICK = 0x22, /* Joystick X/Y */
56 RIFT_S_CTRL_CAPSENSE = 0x27, /* Capsense */
57 RIFT_S_CTRL_IMU = 0x91
58} rift_s_controller_block_id_t;
59
60typedef enum
61{
62 RIFT_S_DEVICE_TYPE_UNKNOWN = 0,
63 RIFT_S_DEVICE_LEFT_CONTROLLER = 0x13001101,
64 RIFT_S_DEVICE_RIGHT_CONTROLLER = 0x13011101,
65} rift_s_device_type;
66
67#pragma pack(push, 1)
68typedef struct
69{
70 uint8_t id;
71
72 uint32_t timestamp;
73 uint16_t unknown_varying2;
74
75 int16_t accel[3];
76 int16_t gyro[3];
78
79typedef struct
80{
81 /* 0x08, 0x0c, 0x0d or 0x0e block */
82 uint8_t id;
83
84 uint8_t val;
86
87typedef struct
88{
89 /* 0x1b trigger/grip block */
90 uint8_t id;
91 uint8_t vals[3];
93
94typedef struct
95{
96 /* 0x22 joystick axes block */
97 uint8_t id;
98 uint32_t val;
100
101typedef struct
102{
103 /* 0x27 - capsense block */
104 uint8_t id;
105
106 uint8_t a_x;
107 uint8_t b_y;
108 uint8_t joystick;
109 uint8_t trigger;
111
112typedef struct
113{
114 uint8_t data[19];
116
117typedef union {
118 uint8_t block_id;
126#pragma pack(pop)
127
128typedef struct
129{
130 uint8_t id;
131
132 uint64_t device_id;
133
134 /* Length of the data block, which contains variable length entries
135 * If this is < 4, then the flags and log aren't valid. */
136 uint8_t data_len;
137
138 /* 0x04 = new log line
139 * 0x02 = parity bit, toggles each line when receiving log chars
140 * other bits, unknown */
141 uint8_t flags;
142 // Contains up to 3 bytes of debug log chars
143 uint8_t log[3];
144
145 uint8_t num_info;
147
148 uint8_t extra_bytes_len;
149 uint8_t extra_bytes[48];
151
152#pragma pack(push, 1)
153typedef struct
154{
155 uint8_t marker;
156
157 int16_t accel[3];
158 int16_t gyro[3];
159 int16_t temperature;
161
162typedef struct
163{
164 uint8_t id;
165 uint16_t unknown_const1;
166
167 uint32_t timestamp;
168
169 rift_s_hmd_imu_sample_t samples[3];
170
171 uint8_t marker;
172 uint8_t unknown2;
173
174 /* Frame timestamp and ID increment when the screen is running,
175 * every 12.5 ms (80Hz) */
176 uint32_t frame_timestamp;
177 int16_t unknown_zero1;
178 int16_t frame_id;
179 int16_t unknown_zero2;
181
182/* Read/Write using report 5 */
183/*
184 * 05 O1 O2 P1 P1 P2 P2 P3 P3 P4 P4 P5 P5 E1 E1 E3
185 * E4 E5 U1 U2 U3 A1 A1 A1 A1 A2 A2 A2 A2 A3 A3 A3
186 * A3 A4 A4 A4 A4 A5 A5 A5 A5
187 *
188 * O1 = Camera stream on (0x00 = off, 0x1 = on)
189 * O2 = Radio Sync? (Usage not clear, but seems to sometimes affect sync)
190 * Px = Exposure *and* Vertical offset / position of camera x passthrough view
191 * Seems to take values from 0x1db7-0x36b3. Values above 0x36c6 are ignored.
192 * Ex = Gain of camera x passthrough view
193 * U1U2U3 = 26 00 40 always?
194 * Ax = ? of camera x. 4 byte LE, Always seems to take values 0x3b0-0x4ff
195 * but I can't see the effect on the images, either controller or passthrough
196 */
197typedef struct
198{
199 uint8_t id;
200 uint8_t uvc_enable;
201 uint8_t radio_sync_flag;
202 /* One slot per camera: */
203 uint16_t slam_frame_exposures[5];
204 uint8_t slam_frame_gains[5];
205
206 uint8_t marker[3]; // 0x26 0x00 0x40
207
208 uint32_t unknown32[5];
210
211/* Read using report 6 */
212typedef struct
213{
214 uint8_t cmd;
215 uint16_t v_resolution;
216 uint16_t h_resolution;
217 uint16_t unknown1;
218 uint8_t refresh_rate;
219 uint8_t unknown2[14];
221
222/* Read using report 9 */
224{
225 uint8_t cmd;
226 uint32_t imu_hz;
227 float gyro_scale; /* Gyro = reading / gyro_scale - in degrees */
228 float accel_scale; /* Accel = reading * g / accel_scale */
229 float temperature_scale; /* Temperature = reading / scale + offset */
230 float temperature_offset;
231};
232
233/* Packet read from endpoint 11 (0x0b) */
234typedef struct
235{
236 uint8_t cmd;
237 uint8_t seqnum;
238 uint8_t busy_flag;
239 uint8_t response_bytes[197];
241
242/* Struct for sending radio commands to 0x12 / 0x13 */
243typedef struct
244{
245 uint8_t cmd;
246 uint64_t device_id;
247 uint8_t cmd_bytes[52];
249
250typedef struct
251{
252 uint64_t device_id;
253 uint32_t device_type;
254 uint64_t empty[2];
256#pragma pack(pop)
257
258/* The maximum number that can fit in a 200 byte report */
259#define DEVICES_LIST_MAX_DEVICES 7
260
261typedef struct
262{
263 uint8_t num_devices;
264
265 rift_s_device_type_record_t devices[DEVICES_LIST_MAX_DEVICES];
267
268int
269rift_s_read_firmware_version(struct os_hid_device *hid);
270int
271rift_s_read_panel_info(struct os_hid_device *hid, rift_s_panel_info_t *panel_info);
272int
273rift_s_read_imu_config_info(struct os_hid_device *hid, struct rift_s_imu_config_info_t *imu_config);
274int
275rift_s_read_fw_proximity_threshold(struct os_hid_device *hid, int *proximity_threshold);
276int
277rift_s_protocol_set_proximity_threshold(struct os_hid_device *hid, uint16_t threshold);
278int
279rift_s_hmd_enable(struct os_hid_device *hid, bool enable);
280int
281rift_s_set_screen_enable(struct os_hid_device *hid, bool enable);
282
283void
284rift_s_send_keepalive(struct os_hid_device *hid);
285
286void
287rift_s_protocol_camera_report_init(rift_s_camera_report_t *camera_report);
288int
289rift_s_protocol_send_camera_report(struct os_hid_device *hid, rift_s_camera_report_t *camera_report);
290
291bool
292rift_s_parse_hmd_report(rift_s_hmd_report_t *report, const unsigned char *buf, int size);
293bool
294rift_s_parse_controller_report(rift_s_controller_report_t *report, const unsigned char *buf, int size);
295int
296rift_s_read_firmware_block(struct os_hid_device *handle, uint8_t block_id, char **data_out, int *len_out);
297
298int
299rift_s_read_devices_list(struct os_hid_device *handle, rift_s_devices_list_t *dev_list);
300
301void
302rift_s_hexdump_buffer(const char *label, const unsigned char *buf, int length); // Debugging
303int
304rift_s_snprintf_hexdump_buffer(
305 char *outbuf, size_t outbufsize, const char *label, const unsigned char *buf, int length); // Debugging
306#endif
Wrapper around OS native hid functions.
Definition: m_space.cpp:87
Representing a single hid interface on a device.
Definition: os_hid.h:29
Definition: rift_s_protocol.h:198
Definition: rift_s_protocol.h:102
Definition: rift_s_protocol.h:69
Definition: rift_s_protocol.h:95
Definition: rift_s_protocol.h:80
Definition: rift_s_protocol.h:113
Definition: rift_s_protocol.h:129
Definition: rift_s_protocol.h:88
Definition: rift_s_protocol.h:251
Definition: rift_s_protocol.h:262
Definition: rift_s_protocol.h:154
Definition: rift_s_protocol.h:244
Definition: rift_s_protocol.h:235
Definition: rift_s_protocol.h:163
Definition: rift_s_protocol.h:224
Definition: rift_s_protocol.h:213
Definition: rift_s_protocol.h:117
Common defines and enums for XRT.