Monado OpenXR Runtime
u_device.h
Go to the documentation of this file.
1 // Copyright 2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Misc helpers for device drivers.
6  * @author Jakob Bornecrantz <jakob@collabora.com>
7  * @ingroup aux_util
8  */
9 
10 #pragma once
11 
12 #include "xrt/xrt_compiler.h"
13 #include "xrt/xrt_device.h"
14 #include "xrt/xrt_tracking.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 
21 extern const struct xrt_matrix_2x2 u_device_rotation_right;
22 extern const struct xrt_matrix_2x2 u_device_rotation_left;
23 extern const struct xrt_matrix_2x2 u_device_rotation_ident;
24 extern const struct xrt_matrix_2x2 u_device_rotation_180;
25 
26 enum u_device_alloc_flags
27 {
28  // clang-format off
29  U_DEVICE_ALLOC_HMD = 1 << 0,
30  U_DEVICE_ALLOC_TRACKING_NONE = 1 << 1,
31  // clang-format on
32 };
33 
35 {
36  struct
37  {
38  uint32_t w_pixels;
39  uint32_t h_pixels;
40  float w_meters;
41  float h_meters;
42  } display;
43 
44  float lens_horizontal_separation_meters;
45  float lens_vertical_position_meters;
46 
47  struct
48  {
49  float fov;
50  } views[2];
51 };
52 
53 /*!
54  * Setup the device information given a very simple info struct.
55  *
56  * @return true on success.
57  * @ingroup aux_util
58  */
59 bool
61  const struct u_device_simple_info *info);
62 
63 /*!
64  * Dump the device config to stderr.
65  *
66  * @ingroup aux_util
67  */
68 void
69 u_device_dump_config(struct xrt_device *xdev,
70  const char *prefix,
71  const char *prod);
72 
73 #define U_DEVICE_ALLOCATE(type, flags, num_inputs, num_outputs) \
74  ((type *)u_device_allocate(flags, sizeof(type), num_inputs, \
75  num_outputs))
76 
77 
78 /*!
79  * Helper function to allocate a device plus inputs in the same allocation
80  * placed after the device in memory.
81  *
82  * Will setup any pointers and num values.
83  *
84  * @ingroup aux_util
85  */
86 void *
87 u_device_allocate(enum u_device_alloc_flags flags,
88  size_t size,
89  size_t num_inputs,
90  size_t num_outputs);
91 
92 /*!
93  * Helper function to free a device and any data hanging of it.
94  *
95  * @ingroup aux_util
96  */
97 void
98 u_device_free(struct xrt_device *xdev);
99 
100 
101 #ifdef __cplusplus
102 }
103 #endif
Header defining a xrt HMD device.
bool u_device_setup_split_side_by_side(struct xrt_device *xdev, const struct u_device_simple_info *info)
Setup the device information given a very simple info struct.
Definition: u_device.c:142
Definition: u_device.h:34
Header defining the tracking system integration in Monado.
void u_device_dump_config(struct xrt_device *xdev, const char *prefix, const char *prod)
Dump the device config to stderr.
Definition: u_device.c:86
void u_device_free(struct xrt_device *xdev)
Helper function to free a device and any data hanging of it.
Definition: u_device.c:283
void * u_device_allocate(enum u_device_alloc_flags flags, size_t size, size_t num_inputs, size_t num_outputs)
Helper function to allocate a device plus inputs in the same allocation placed after the device in me...
Definition: u_device.c:221
Header holding common defines.
A single HMD or input device.
Definition: xrt_device.h:203
A tightly packed 2x2 matrix of floats.
Definition: xrt_defines.h:253