summaryrefslogtreecommitdiff
path: root/src/device.h
blob: b8458909c06c4fa9db45e3639b2f53479ef8095f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright (c) 2012
 * 	Lars-Dominik Braun <lars@6xq.net>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#ifndef _DEVICE_H
#define _DEVICE_H

#include <stdbool.h>

#include <libusb.h>

typedef enum {
	HIDPP_DEVID_ROOT = 0xff,
} hidppDeviceId_t;

/* HID++ version */
typedef struct {
	uint8_t major, minor;
} hidppVersion_t;

/* firmware type */
typedef enum {
	HIDPP_FW_TYPE_MAIN = 0,
	HIDPP_FW_TYPE_BOOT = 1,
	HIDPP_FW_TYPE_HARDWARE = 2,
	/* _OTHER >= 3 */
} hidppFirmwareType_t;

/* firmware version object */
typedef struct {
	char prefix[4];
	uint16_t version;
	uint16_t build;
} hidppFirmware_t;

/* device types */
typedef enum {
	HIDPP_DEV_KEYBOARD = 0,
	HIDPP_DEV_REMOTE_CONTROL = 1,
	HIDPP_DEV_NUMPAD = 2,
	HIDPP_DEV_MOUSE = 3,
	HIDPP_DEV_TOUCHPAD = 4,
	HIDPP_DEV_TRACKBALL = 5,
	HIDPP_DEV_PRESENTER = 6,
	HIDPP_DEV_RECEIVER = 7,
} hidppDeviceType_t;

/* feature id’s */
typedef enum {
	HIDPP_FEATURE_ROOT = 0x0000,
	HIDPP_FEATURE_SET = 0x0001,
	HIDPP_FEATURE_FIRMWARE_INFO = 0x0003,
	HIDPP_FEATURE_DEVICE_INFO = 0x0005,
	HIDPP_FEATURE_BATTERY_STATUS = 0x1000,
	HIDPP_FEATURE_PROGRAMMABLE_KEYS = 0x1b00,
	HIDPP_FEATURE_WIRELESS_STATUS = 0x1d4b,
} hidppFeatureId_t;

/* feature flags (bitfield) */
typedef enum {
	HIDPP_FF_OBSOLETE = (1 << 7),
	HIDPP_FF_HIDDEN = (1 << 6),
	HIDPP_FF_LOGITECH = (1 << 5),
} hidppFeatureFlags_t;

typedef struct {
	hidppFeatureId_t id;
	hidppFeatureFlags_t flags;
} hidppFeature_t;

struct hidppDevice {
	libusb_device_handle *usbDev;

	/* general */
	hidppDeviceId_t id;
	hidppDeviceType_t type;
	hidppVersion_t hidVersion;
	char *name;

	/* feature index table */
	size_t featuresCount;
	hidppFeature_t *features;
	/* firmware versions */
	size_t firmwareCount;
	hidppFirmware_t *firmware;

	/* children (if any) */
	size_t childrenCount;
	struct hidppDevice *children;
} hidppDevice;
typedef struct hidppDevice hidppDevice_t;

void hidppDeviceDestroy (hidppDevice_t * const d);
void hidppDeviceInit (hidppDevice_t * const d,
		libusb_device_handle * const usbDev, const hidppDeviceId_t id);
void hidppDevicePrint (const hidppDevice_t * const d);
bool hidppFeatureIdToIdx (const hidppDevice_t * const d,
		const hidppFeatureId_t id, uint8_t * const retIdx);

#endif /* _DEVICE_H */