monado/src/xrt/auxiliary/os/os_hid.h

149 lines
3.5 KiB
C
Raw Normal View History

2019-05-03 14:47:45 +00:00
// Copyright 2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Wrapper around OS native hid functions.
* @author Jakob Bornecrantz <jakob@collabora.com>
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
2019-05-03 14:47:45 +00:00
*
* @ingroup aux_os
*/
#pragma once
#include "xrt/xrt_config_os.h"
#include <stdint.h>
#include <stddef.h>
2019-05-03 14:47:45 +00:00
2019-06-18 18:22:30 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2019-05-03 14:47:45 +00:00
/*!
2020-06-03 16:43:30 +00:00
* @interface os_hid_device
*
2019-05-03 14:47:45 +00:00
* Representing a single hid interface on a device.
*/
struct os_hid_device
{
2021-01-14 14:13:48 +00:00
int (*read)(struct os_hid_device *hid_dev, uint8_t *data, size_t size, int milliseconds);
2019-05-03 14:47:45 +00:00
2021-01-14 14:13:48 +00:00
int (*write)(struct os_hid_device *hid_dev, const uint8_t *data, size_t size);
2019-05-03 14:47:45 +00:00
2021-01-14 14:13:48 +00:00
int (*get_feature)(struct os_hid_device *hid_dev, uint8_t report_num, uint8_t *data, size_t size);
2021-01-14 14:13:48 +00:00
int (*get_feature_timeout)(struct os_hid_device *hid_dev, void *data, size_t size, uint32_t timeout);
2021-01-14 14:13:48 +00:00
int (*set_feature)(struct os_hid_device *hid_dev, const uint8_t *data, size_t size);
2021-02-12 01:44:00 +00:00
int (*get_physical_address)(struct os_hid_device *hid_dev, uint8_t *data, size_t size);
2019-05-03 14:47:45 +00:00
void (*destroy)(struct os_hid_device *hid_dev);
};
/*!
* Read the next input report, if any, from the given hid device.
*
* If milliseconds are negative, this call blocks indefinitely, 0 polls,
* and positive will block for that amount of milliseconds.
2020-06-03 16:43:30 +00:00
*
* @public @memberof os_hid_device
2019-05-03 14:47:45 +00:00
*/
static inline int
2021-01-14 14:13:48 +00:00
os_hid_read(struct os_hid_device *hid_dev, uint8_t *data, size_t size, int milliseconds)
2019-05-03 14:47:45 +00:00
{
return hid_dev->read(hid_dev, data, size, milliseconds);
}
/*!
* Write an output report to the given device.
2020-06-03 16:43:30 +00:00
*
* @public @memberof os_hid_device
2019-05-03 14:47:45 +00:00
*/
static inline int
2019-05-03 14:47:45 +00:00
os_hid_write(struct os_hid_device *hid_dev, const uint8_t *data, size_t size)
{
return hid_dev->write(hid_dev, data, size);
}
/*!
* Get a numbered feature report.
*
* If the device doesn't have more than one feature report, just request
* report 0.
2020-06-03 16:43:30 +00:00
*
* @public @memberof os_hid_device
*/
static inline int
2021-01-14 14:13:48 +00:00
os_hid_get_feature(struct os_hid_device *hid_dev, uint8_t report_num, uint8_t *data, size_t size)
{
return hid_dev->get_feature(hid_dev, report_num, data, size);
}
/*!
* Get a feature report with a timeout.
2020-06-03 16:43:30 +00:00
*
* @public @memberof os_hid_device
*/
static inline int
2021-01-14 14:13:48 +00:00
os_hid_get_feature_timeout(struct os_hid_device *hid_dev, void *data, size_t size, uint32_t timeout)
{
return hid_dev->get_feature_timeout(hid_dev, data, size, timeout);
}
/*!
* Set a feature report.
*
* The first byte of the buffer is the report number, to be followed by
* the data of the report.
2020-06-03 16:43:30 +00:00
*
* @public @memberof os_hid_device
*/
static inline int
2021-01-14 14:13:48 +00:00
os_hid_set_feature(struct os_hid_device *hid_dev, const uint8_t *data, size_t size)
{
return hid_dev->set_feature(hid_dev, data, size);
}
2021-02-12 01:44:00 +00:00
/*!
* Get the physical address.
*
* For USB devices, the string contains the physical path to the device (the
* USB controller, hubs, ports, etc). For Bluetooth *devices, the string
* contains the hardware (MAC) address of the device.
*
* @public @memberof os_hid_device
*/
static inline int
os_hid_get_physical_address(struct os_hid_device *hid_dev, uint8_t *data, size_t size)
{
return hid_dev->get_physical_address(hid_dev, data, size);
}
2019-05-03 14:47:45 +00:00
/*!
* Close and free the given device.
2020-06-03 16:43:30 +00:00
*
* @public @memberof os_hid_device
2019-05-03 14:47:45 +00:00
*/
static inline void
2019-05-03 14:47:45 +00:00
os_hid_destroy(struct os_hid_device *hid_dev)
{
hid_dev->destroy(hid_dev);
}
#ifdef XRT_OS_LINUX
/*!
* Open the given path as a hidraw device.
2020-06-03 16:43:30 +00:00
*
2021-03-26 16:21:00 +00:00
* @see hid_hidraw
* @public @memberof os_hid_device
2019-05-03 14:47:45 +00:00
*/
int
os_hid_open_hidraw(const char *path, struct os_hid_device **out_hid);
#endif
2019-06-18 18:22:30 +00:00
#ifdef __cplusplus
} // extern "C"
#endif