summaryrefslogtreecommitdiffstats
path: root/librazer/razer_private.h
blob: fbcaf72bd1a6eb760da92fc6bab617c62dac76fc (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
121
122
#ifndef RAZER_PRIVATE_H_
#define RAZER_PRIVATE_H_

#include "librazer.h"
#include "util.h"

#include <libusb.h>
#include <stdio.h>
#include <errno.h>


extern razer_logfunc_t razer_logfunc_info;
extern razer_logfunc_t razer_logfunc_error;
extern razer_logfunc_t razer_logfunc_debug;

#define call_razer_logfunc(condition, func, ...) ({			\
		__typeof__(condition) __condition = (condition);	\
		if ((__condition) && (func))				\
			func("librazer: " __VA_ARGS__);			\
		__condition;						\
	})

#define razer_info_on(condition, ...)	call_razer_logfunc(condition, razer_logfunc_info, __VA_ARGS__)
#define razer_error_on(condition, ...)	call_razer_logfunc(condition, razer_logfunc_error, __VA_ARGS__)
#define razer_debug_on(condition, ...)	call_razer_logfunc(condition, razer_logfunc_debug, __VA_ARGS__)

#define razer_info(...)			razer_info_on(1, __VA_ARGS__)
#define razer_error(...)		razer_error_on(1, __VA_ARGS__)
#define razer_debug(...)		razer_debug_on(1, __VA_ARGS__)

#undef WARN_ON
#define WARN_ON(condition)		razer_error_on((condition),		\
						"WARNING at %s/%s():%d\n",	\
						__FILE__, __func__, __LINE__)


/* Default USB timeout */
#define RAZER_USB_TIMEOUT		3000

struct razer_usb_interface {
	uint8_t bInterfaceNumber;
	uint8_t bAlternateSetting;
};

#define RAZER_MAX_NR_INTERFACES		2

struct razer_usb_context {
	/* Device pointer. */
	struct libusb_device *dev;
	/* The handle for all operations. */
	struct libusb_device_handle *h;
	/* The configuration we want to use. Defaults to 1. */
	uint8_t bConfigurationValue;
	/* The interfaces we use. */
	struct razer_usb_interface interfaces[RAZER_MAX_NR_INTERFACES];
	unsigned int nr_interfaces;
};

int razer_usb_add_used_interface(struct razer_usb_context *ctx,
				 int bInterfaceNumber,
				 int bAlternateSetting);

int razer_generic_usb_claim(struct razer_usb_context *ctx);
int razer_generic_usb_claim_refcount(struct razer_usb_context *ctx,
				     unsigned int *refcount);
void razer_generic_usb_release(struct razer_usb_context *ctx);
void razer_generic_usb_release_refcount(struct razer_usb_context *ctx,
					unsigned int *refcount);

struct razer_usb_reconnect_guard {
	struct razer_usb_context *ctx;
	struct libusb_device_descriptor old_desc;
	uint8_t old_busnr;
	uint8_t old_devaddr;
};

int razer_usb_reconnect_guard_init(struct razer_usb_reconnect_guard *guard,
				   struct razer_usb_context *ctx);
int razer_usb_reconnect_guard_wait(struct razer_usb_reconnect_guard *guard, bool hub_reset);

int razer_usb_force_hub_reset(struct razer_usb_context *ctx);

#define BUSTYPESTR_USB		"USB"
#define DEVTYPESTR_MOUSE	"Mouse"
static inline void razer_create_idstr(char *buf,
				      const char *bustype,
				      const char *busposition,
				      const char *devtype,
				      const char *devname,
				      const char *devid)
{
	snprintf(buf, RAZER_IDSTR_MAX_SIZE, "%s:%s:%s-%s:%s",
		 devtype, devname, bustype, busposition, devid);
}

void razer_generic_usb_gen_idstr(struct libusb_device *udev,
				 struct libusb_device_handle *h,
				 const char *devname,
				 bool include_devicenr,
				 const char *serial,
				 char *idstr_buf);

void razer_init_axes(struct razer_axis *axes,
		     const char *name0, unsigned int flags0,
		     const char *name1, unsigned int flags1,
		     const char *name2, unsigned int flags2);

struct razer_mouse_dpimapping * razer_mouse_get_dpimapping_by_res(
		struct razer_mouse_dpimapping *mappings, size_t nr_mappings,
		enum razer_dimension dim, enum razer_mouse_res res);

struct razer_event_spacing {
	unsigned int spacing_msec;
	struct timeval last_event;
};

void razer_event_spacing_init(struct razer_event_spacing *es,
			      unsigned int msec);
void razer_event_spacing_enter(struct razer_event_spacing *es);
void razer_event_spacing_leave(struct razer_event_spacing *es);

#endif /* RAZER_PRIVATE_H_ */
bues.ch cgit interface