summaryrefslogtreecommitdiffstats
path: root/librazer/librazer.h
blob: 8ebf573ba7e8949e6a36bb0af38667a6e36ab65b (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
/*
 *   Razer lowlevel device access library.
 *   Applications do NOT want to use this.
 *   Applications should use pyrazer or librazerd instead.
 *
 *   Copyright (C) 2007-2011 Michael Buesch <m@bues.ch>
 *
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU General Public License
 *   as published by the Free Software Foundation; either version 2
 *   of the License, or (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 */

#ifndef LIB_RAZER_H_
#define LIB_RAZER_H_

#ifndef RAZERCFG_BUILD
# error "librazer.h is a razercfg internal library!"
# error "Do not include this file into your application!"
#endif

#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>


#define RAZER_IDSTR_MAX_SIZE	128
#define RAZER_LEDNAME_MAX_SIZE	64
#define RAZER_DEFAULT_CONFIG	"/etc/razer.conf"

/* Opaque internal data structures */
struct razer_usb_context;
struct razer_mouse_base_ops;
struct razer_mouse_profile_emu;

struct razer_mouse;


/** razer_utf16_t - UTF-16 type */
typedef uint16_t razer_utf16_t;

/** razer_ascii_to_utf16 - Convert ASCII to UTF16.
 * @dest: Destination buffer.
 * @dest_max_chars: Maximum number of characters in dest.
 * @src: NUL terminated ASCII source buffer.
 */
void razer_ascii_to_utf16(razer_utf16_t *dest, size_t dest_max_chars,
			  const char *src);

/** razer_utf16_cpy - Copy an UTF16 string.
 * @dest: Destination buffer.
 * @src: Source buffer.
 * @max_chars: Maximum number of characters to copy.
 */
int razer_utf16_cpy(razer_utf16_t *dest, const razer_utf16_t *src,
		    size_t max_chars);

/** razer_utf16_strlen - Return the length of an UTF16 string.
 * @str: An UTF16 string.
 */
size_t razer_utf16_strlen(const razer_utf16_t *str);

/** enum razer_led_state - The LED state value
  * @RAZER_LED_OFF: The LED is turned off
  * @RAZER_LED_ON: The LED is turned on
  * @RAZER_LED_UNKNOWN: The LED is in an unknown state (on or off)
  */
enum razer_led_state {
	RAZER_LED_OFF		= 0,
	RAZER_LED_ON		= 1,
	RAZER_LED_UNKNOWN,
};

/** enum razer_led_mode - The LED working mode
 * @RAZER_LED_MODE_STATIC: The LED has a static color
 * @RAZER_LED_MODE_SPECTRUM: The LED color goes through a spectrum of colors
 * @RAZER_LED_MODE_BREATHING: The LED has a static color and pulsates from off to on
 */
enum razer_led_mode {
	RAZER_LED_MODE_STATIC    = 0,
	RAZER_LED_MODE_SPECTRUM  = 1,
	RAZER_LED_MODE_BREATHING = 2,
	RAZER_LED_MODE_WAVE      = 3,
	RAZER_LED_MODE_REACTION  = 4,
};

/** struct razer_rgb_color - An RGB color
 * @r: Red value.
 * @g: Green value.
 * @b: Blue value.
 * @valid: 1 if this color is valid. 0 otherise.
 */
struct razer_rgb_color {
	uint8_t r;
	uint8_t g;
	uint8_t b;
	uint8_t valid;
};

/** struct razer_led - A LED on a razer device.
  *
  * @next: The next LED device in the linked list.
  *
  * @name: The human readable name string for the LED.
  * @id: A unique ID cookie
  * @state: The state of the LED (on, off, unknown)
  * @mode: The mode of the LED (static, spectrum, breathing)
  * @supported_modes_mask: A mask of supported LED modes.
  * The RAZER_LED_MODE_STATIC is assumed as the only supported mode if 0.
  * @color: The color of the LED.
  *
  * @toggle_state: Toggle the state. Note that a new_state of
  * 	RAZER_LED_UNKNOWN result is an error.
  *
  * @change_color: Change the color of the LED.
  *	May be NULL, if the color cannot be changed.
  *
  * @set_mode: Set the mode of the LED.
  * May be NULL if the mode cannot be changed.
  *
  * @u: This union contains a pointer to the parent device.
  */
struct razer_led {
	struct razer_led *next;

	const char *name;
	unsigned int id;
	enum razer_led_state state;
	enum razer_led_mode mode;
	unsigned int supported_modes_mask;
	struct razer_rgb_color color;

	int (*toggle_state)(struct razer_led *led,
			    enum razer_led_state new_state);

	int (*change_color)(struct razer_led *led,
			    const struct razer_rgb_color *new_color);

	int (*set_mode)(struct razer_led *led,
			    enum razer_led_mode new_mode);

	union {
		struct razer_mouse *mouse;
		struct razer_mouse_profile *mouse_prof;
	} u;
};

/** enum razer_mouse_freq - Mouse scan frequency
  * @RAZER_MOUSE_FREQ_UNKNOWN: Unknown scan frequency
  */
enum razer_mouse_freq {
	RAZER_MOUSE_FREQ_UNKNOWN	= 0,
	RAZER_MOUSE_FREQ_125HZ		= 125,
	RAZER_MOUSE_FREQ_500HZ		= 500,
	RAZER_MOUSE_FREQ_1000HZ		= 1000,
};

/** enum razer_mouse_res - Mouse scan resolutions
  * @RAZER_MOUSE_RES_UNKNOWN: Unknown scan resolution
  */
enum razer_mouse_res {
	RAZER_MOUSE_RES_UNKNOWN		= 0,
	RAZER_MOUSE_RES_100DPI		= 100,
	RAZER_MOUSE_RES_125DPI		= 125,
	RAZER_MOUSE_RES_250DPI		= 250,
	RAZER_MOUSE_RES_400DPI		= 400,
	RAZER_MOUSE_RES_450DPI		= 450,
	RAZER_MOUSE_RES_500DPI		= 500,
	RAZER_MOUSE_RES_800DPI		= 800,
	RAZER_MOUSE_RES_900DPI		= 900,
	RAZER_MOUSE_RES_1000DPI		= 1000,
	RAZER_MOUSE_RES_1600DPI		= 1600,
	RAZER_MOUSE_RES_1800DPI		= 1800,
	RAZER_MOUSE_RES_2000DPI		= 2000,
	RAZER_MOUSE_RES_3500DPI		= 3500,
	RAZER_MOUSE_RES_4000DPI		= 4000,
	RAZER_MOUSE_RES_5600DPI		= 5600,
	RAZER_MOUSE_RES_6000DPI		= 6000,
	RAZER_MOUSE_RES_6400DPI		= 6400,
	RAZER_MOUSE_RES_7000DPI		= 7000,
	RAZER_MOUSE_RES_7600DPI		= 7600,
	RAZER_MOUSE_RES_8200DPI		= 8200,
	RAZER_MOUSE_RES_8800DPI		= 8800,
	RAZER_MOUSE_RES_9400DPI		= 9400,
	RAZER_MOUSE_RES_10000DPI	= 10000
};

/** enum razer_mouse_type
  * @RAZER_MOUSETYPE_DEATHADDER: A "DeathAdder" mouse
  * @RAZER_MOUSETYPE_KRAIT: A "Krait" mouse
  * @RAZER_MOUSETYPE_LACHESIS: A "Lachesis" mouse
  * @RAZER_MOUSETYPE_COPPERHEAD: A "Copperhead" mouse
  * @RAZER_MOUSETYPE_NAGA: A "Naga" mouse
  * @RAZER_MOUSETYPE_BOOMSLANGCE: A "Boomslang Collector's Edition" mouse
  * @RAZER_MOUSETYPE_IMPERATOR: An "Imperator" mouse
  * @RAZER_MOUSETYPE_TAIPAN: A "Taipan" mouse
  * @RAZER_MOUSETYPE_MAMBA_TE: A "Mamba Tournament Edition" mouse
  */

enum razer_mouse_type {
	RAZER_MOUSETYPE_DEATHADDER,
	RAZER_MOUSETYPE_KRAIT,
	RAZER_MOUSETYPE_LACHESIS,
	RAZER_MOUSETYPE_COPPERHEAD,
	RAZER_MOUSETYPE_NAGA,
	RAZER_MOUSETYPE_BOOMSLANGCE,
	RAZER_MOUSETYPE_IMPERATOR,
	RAZER_MOUSETYPE_TAIPAN,
	RAZER_MOUSETYPE_MAMBA_TE,
};

/** struct razer_button_function - A logical button function
 *
 * @id: A unique ID number for the function.
 *
 * @name: A unique and human readable name string for the function.
 */
struct razer_button_function {
	unsigned int id;
	const char *name;
};

/** struct razer_button - A physical button (physical = piece of hardware)
 *
 * @id: A unique ID number for this button.
 *
 * @name: A unique and human readable name string for the button.
 */
struct razer_button {
	unsigned int id;
	const char *name;
};

/** enum razer_axis_flags - Usage flags for an axis.
 * @RAZER_AXIS_INDEPENDENT_DPIMAPPING: Supports independent DPI mappings.
 */
enum razer_axis_flags {
	RAZER_AXIS_INDEPENDENT_DPIMAPPING	= (1 << 0),
};

/** struct razer_axis - A device axis.
 *
 * @id: A unique ID number for this axis.
 *
 * @name: A unique and human readable name string for this axis.
 *
 * @flags: Usage flags.
 */
struct razer_axis {
	unsigned int id;
	const char *name;
	unsigned int flags;
};

/** razer_id_mask_t - ID mask type */
typedef uint64_t razer_id_mask_t;

/** razer_id_mask_set - Set a bit in an ID mask.
 *
 * @mask: Pointer to the mask.
 *
 * @nr: The ID number.
 */
static inline void razer_id_mask_set(razer_id_mask_t *mask, unsigned int id)
{
	*mask |= ((razer_id_mask_t)1ull << id);
}

/** razer_id_mask_clear - Clear a bit in an ID mask.
 *
 * @mask: Pointer to the mask.
 *
 * @nr: The ID number.
 */
static inline void razer_id_mask_clear(razer_id_mask_t *mask, unsigned int id)
{
	*mask &= ~((razer_id_mask_t)1ull << id);
}

/** razer_id_mask_zero - Initialize an ID mask to "all unset".
 *
 * @mask: Pointer to the mask.
 */
static inline void razer_id_mask_zero(razer_id_mask_t *mask)
{
	*mask = (razer_id_mask_t)0ull;
}

/** enum razer_dimension - Dimension IDs
 * @RAZER_DIM_X: X dimension
 * @RAZER_DIM_Y: Y dimension
 * @RAZER_DIM_Z: Z dimension
 * @RAZER_NR_DIMS: 3 dimensions ought to be enough in this universe.
 * @RAZER_DIM_0: First dimension. X alias.
 * @RAZER_DIM_1: Second dimension. Y alias.
 * @RAZER_DIM_2: Third dimension. Z alias.
 */
enum razer_dimension {
	RAZER_DIM_X,
	RAZER_DIM_Y,
	RAZER_DIM_Z,

	RAZER_NR_DIMS,

	RAZER_DIM_0	= RAZER_DIM_X,
	RAZER_DIM_1	= RAZER_DIM_Y,
	RAZER_DIM_2	= RAZER_DIM_Z,
};

/** struct razer_mouse_dpimapping - Mouse scan resolution mapping.
 *
 * @nr: The ID number.
 *
 * @res: The resolution values. One per dimension.
 *
 * @dimension_mask: Mask of used dimensions.
 *
 * @profile_mask: A bitmask of which profile this dpimapping is valid for.
 *	A value of 0 indicates "any profile".
 *	If bit0 is set, this means profile 0.
 *	If bit1 is set, this means profile 1. etc...
 *
 * @change: Change this mapping to another resolution value.
 *	May be NULL, if the mapping cannot be changed.
 */
struct razer_mouse_dpimapping {
	unsigned int nr;
	enum razer_mouse_res res[RAZER_NR_DIMS];
	unsigned int dimension_mask;
	razer_id_mask_t profile_mask;

	int (*change)(struct razer_mouse_dpimapping *d,
		      enum razer_dimension dim,
		      enum razer_mouse_res res);

	struct razer_mouse *mouse;
};

/** struct razer_mouse_profile - A mouse profile
 *
 * @nr: The profile ID.
 *
 * @get_name: Get the profile name.
 *	May be NULL.
 *
 * @set_name: Set the profile name.
 *	May be NULL.
 *
 * @get_leds: Get a linked list of per-profile LEDs.
 * 	Returns the number of LEDs or a negative error code.
 * 	leds_list points to the first LED in the list.
 * 	The caller is responsible to free every item in leds_list.
 *	May be NULL.
 *
 * @get_freq: Get the currently used scan frequency.
 *	May be NULL, if the scan frequency is not managed per profile.
 *
 * @set_freq: Change the mouse scan frequency.
 *	May be NULL, if the scan frequency is not managed per profile.
 *
 * @get_dpimapping: Returns the active scan resolution mapping.
 *	If axis is NULL, returns the mapping of the first axis.
 *
 * @set_dpimapping: Sets the active scan resolution mapping.
 *	If axis is NULL, sets the mapping of all axes.
 *
 * @get_button_function: Get the currently assigned function for a button.
 *  May be NULL.
 *
 * @set_button_function: Assign a new function to a button.
 *  May be NULL.
 */
struct razer_mouse_profile {
	unsigned int nr;

	const razer_utf16_t * (*get_name)(struct razer_mouse_profile *p);
	int (*set_name)(struct razer_mouse_profile *p,
			const razer_utf16_t *new_name);

	int (*get_leds)(struct razer_mouse_profile *p,
			struct razer_led **leds_list);

	enum razer_mouse_freq (*get_freq)(struct razer_mouse_profile *p);
	int (*set_freq)(struct razer_mouse_profile *p, enum razer_mouse_freq freq);

	struct razer_mouse_dpimapping * (*get_dpimapping)(struct razer_mouse_profile *p,
							  struct razer_axis *axis);
	int (*set_dpimapping)(struct razer_mouse_profile *p,
			      struct razer_axis *axis,
			      struct razer_mouse_dpimapping *d);

	struct razer_button_function * (*get_button_function)(struct razer_mouse_profile *p,
							      struct razer_button *b);
	int (*set_button_function)(struct razer_mouse_profile *p,
				   struct razer_button *b,
				   struct razer_button_function *f);

	struct razer_mouse *mouse;
};

/** enum razer_mouse_flags - Flags for a mouse
 *
 * @RAZER_MOUSEFLG_PROFEMU: Profiles are emulated in software. The device
 *	does only support one profile in hardware.
 *
 * @RAZER_MOUSEFLG_SUGGESTFWUP: A firmware update for this device is suggested.
 *
 * @RAZER_MOUSEFLG_MASK: A mask of all public flags.
 */
enum razer_mouse_flags {
	RAZER_MOUSEFLG_PROFEMU		= (1 << 0),
	RAZER_MOUSEFLG_SUGGESTFWUP	= (1 << 1),

	RAZER_MOUSEFLG_MASK		= 0x0000FFFF,

	/* Internal flags */
	RAZER_MOUSEFLG_PRESENT		= (1 << 15),
};

/** enum - Various constants
 *
 * @RAZER_FW_FLASH_MAGIC: Magic parameter to flash_firmware callback.
 *
 * @RAZER_NR_EMULATED_PROFILES: Default number of emulated profiles.
 */
enum {
	RAZER_FW_FLASH_MAGIC		= 0xB00B135,
	RAZER_NR_EMULATED_PROFILES	= 20,
};

/** struct razer_mouse - Representation of a mouse device
  *
  * @next: Linked list to the next mouse.
  *
  * @idstr: A system wide unique ID string for the device.
  *
  * @type: The mouse type
  *
  * @flags: Various ORed enum razer_mouse_flags.
  *
  * @claim: Claim and open the backend device (USB).
  * 	As long as the device is claimed, it is not operable by the user!
  *	Claim can be called multiple times before release, but it must always
  *	pair up with the corresponding number of release calls.
  *
  * @release: Release a claimed backend device.
  *	Implicitely commits the config, if the last claim is released.
  *	Returns 0 on success or an error code.
  *	An error is a commit error. The mouse is always released properly.
  *
  * @commit: Commit the current settings.
  *	This usually doesn't have to be called explicitly.
  *	May be NULL.
  *
  * @get_fw_version: Read the firmware version from the device.
  *     Returns the firmware version or a negative error code.
  *
  * @flash_firmware: Upload a firmware image to the device and
  *     flash it to the PROM. &magic_number is &RAZER_FW_FLASH_MAGIC.
  *     The magic is used to project against accidental calls.
  *
  * @global_get_leds: Get a linked list of globally managed LEDs.
  * 	Returns the number of LEDs or a negative error code.
  * 	leds_list points to the first LED in the list.
  * 	The caller is responsible to free every item in leds_list.
  *	May be NULL.
  *
  * @global_get_freq: Get the current globally used scan frequency.
  *	May be NULL, if the scan frequency is not managed globally.
  *
  * @global_set_freq: Change the global mouse scan frequency.
  *	May be NULL, if the scan frequency is not managed globally.
  *
  * @nr_profiles: The number of profiles supported by this device.
  *	Defaults to 1.
  *
  * @get_profiles: Returns an array of supported profiles.
  *	Array length is nr_profiles.
  *
  * @get_active_profile: Returns the currently active profile.
  *	May be NULL, if nr_profiles is 1.
  *
  * @set_active_profile: Selects the active profile.
  *	May be NULL, if nr_profiles is 1.
  *
  * @supported_axes: Returns a list of supported device axes
  *	for this mouse in res_ptr.
  *	The return value is a positive list length or a negative error code.
  *
  * @supported_resolutions: Returns a list of supported scan resolutions
  *	for this mouse in res_ptr.
  *	The return value is a positive list length or a negative error code.
  *	The caller is responsible to free res_ptr.
  *
  * @supported_freqs: Get an array of supported scan frequencies.
  * 	Returns the array size or a negative error code.
  * 	freq_ptr points to the array.
  * 	The caller is responsible to free freq_ptr.
  *
  * @supported_dpimappings: Returns a list of supported scan resolution
  *	mappings in res_ptr.
  *	The function return value is the positive list size or a negative
  *	error code.
  *
  * @supported_buttons: Returns a list of physical buttons on the device
  *	in res_ptr.
  *	The function return value is the positive list size or a negative
  *	error code.
  *	May be NULL.
  *
  * @supported_button_functions: Returns a list of possible function assignments
  *	for the physical buttons in res_ptr.
  *	The function return value is the positive list size or a negative
  *	error code.
  *	May be NULL.
  */
struct razer_mouse {
	struct razer_mouse *next;

	char idstr[RAZER_IDSTR_MAX_SIZE + 1];

	enum razer_mouse_type type;
	unsigned int flags;

	int (*claim)(struct razer_mouse *m);
	int (*release)(struct razer_mouse *m);

	int (*commit)(struct razer_mouse *m, int force);

	int (*get_fw_version)(struct razer_mouse *m);

	int (*flash_firmware)(struct razer_mouse *m,
			      const char *data, size_t len,
			      unsigned int magic_number);

	int (*global_get_leds)(struct razer_mouse *m,
			       struct razer_led **leds_list);

	enum razer_mouse_freq (*global_get_freq)(struct razer_mouse *m);
	int (*global_set_freq)(struct razer_mouse *m, enum razer_mouse_freq freq);

	unsigned int nr_profiles;
	struct razer_mouse_profile * (*get_profiles)(struct razer_mouse *m);
	struct razer_mouse_profile * (*get_active_profile)(struct razer_mouse *m);
	int (*set_active_profile)(struct razer_mouse *m,
				  struct razer_mouse_profile *p);

	int (*supported_axes)(struct razer_mouse *m,
			      struct razer_axis **res_ptr);
	int (*supported_resolutions)(struct razer_mouse *m,
				     enum razer_mouse_res **res_ptr);
	int (*supported_freqs)(struct razer_mouse *m,
			       enum razer_mouse_freq **freq_ptr);
	int (*supported_dpimappings)(struct razer_mouse *m,
				     struct razer_mouse_dpimapping **res_ptr);
	int (*supported_buttons)(struct razer_mouse *m,
				 struct razer_button **res_ptr);
	int (*supported_button_functions)(struct razer_mouse *m,
					  struct razer_button_function **res_ptr);

	/* Do not touch these pointers. */
	const struct razer_mouse_base_ops *base_ops;
	struct razer_usb_context *usb_ctx;
	unsigned int claim_count;
	struct razer_mouse_profile_emu *profemu;
	void *drv_data; /* For use by the hardware driver */
};

/** razer_msleep - Delay.
 * msecs: Number of milliseconds to delay.
 */
void razer_msleep(unsigned int msecs);

/** razer_strlcpy - Copy a string into a sized buffer.
 * @dst: Destination buffer.
 * @src: Source string.
 * @dst_size: Destination buffer size.
 */
void razer_strlcpy(char *dst, const char *src, size_t dst_size);

/** razer_free_freq_list - Free an array of frequencies.
  * This function frees a whole array of frequencies as returned
  * by the device methods.
  */
void razer_free_freq_list(enum razer_mouse_freq *freq_list, int count);

/** razer_free_resolution_list - Free an array of resolutions.
  * This function frees a whole array of resolutions as returned
  * by the device methods.
  */
void razer_free_resolution_list(enum razer_mouse_res *res_list, int count);

/** razer_free_leds - Free a linked list of struct razer_led.
  * This function frees a whole linked list of struct razer_led,
  * as returned by the device methods. Note that you can
  * also free a single struct razer_led with this function, if
  * you assign a NULL pointer to led_list->next before calling this.
  */
void razer_free_leds(struct razer_led *led_list);

/** razer_rescan_mice - Rescan for connected razer mice.
  * Returns a pointer to the linked list of mice, or a NULL pointer
  * in case of an error.
  */
struct razer_mouse * razer_rescan_mice(void);

/** razer_reconfig_mice - Reconfigure all detected razer mice.
  * Returns 0 on success or an error code.
  */
int razer_reconfig_mice(void);

/** razer_for_each_mouse - Convenience helper for traversing a mouse list
 *
 * @mouse: 'struct razer_mouse' pointer used as a list pointer.
 * @next: 'struct razer_mouse' pointer used as temporary 'next' pointer.
 * @mice_list: Pointer to the base of the linked list.
 *
 * Use razer_for_each_mouse like a normal C 'for' loop.
 */
#define razer_for_each_mouse(mouse, next, mice_list) \
	for (mouse = mice_list, next = (mice_list) ? (mice_list)->next : NULL; \
	     mouse; \
	     mouse = next, next = (mouse) ? (mouse)->next : NULL)

/** enum razer_event - The type of an event.
 */
enum razer_event {
	RAZER_EV_MOUSE_ADD,
	RAZER_EV_MOUSE_REMOVE,
};

/** struct razer_event_data - Context data for an event.
 */
struct razer_event_data {
	union {
		struct razer_mouse *mouse;
	} u;
};

/** razer_event_handler_t - The type of an event handler.
 */
typedef void (*razer_event_handler_t)(enum razer_event event,
				      const struct razer_event_data *data);

/** razer_register_event_handler - Register an event handler.
 */
int razer_register_event_handler(razer_event_handler_t handler);

/** razer_unregister_event_handler - Unregister an event handler.
 */
void razer_unregister_event_handler(razer_event_handler_t handler);

/** razer_load_config - Load a configuration file.
 * If path is NULL, the default config is loaded.
 * If path is an empty string, the current config (if any) will be
 * discarded and no config will be loaded.
 */
int razer_load_config(const char *path);

typedef void (*razer_logfunc_t)(const char *fmt, ...);

/** razer_set_logging - Set log callbacks.
 * Callbacks may be NULL to suppress messages.
 */
void razer_set_logging(razer_logfunc_t info_callback,
		       razer_logfunc_t error_callback,
		       razer_logfunc_t debug_callback);

/** razer_init - LibRazer initialization
  * Call this before any other library function.
  */
int razer_init(int enable_profile_emu);

/** razer_exit - LibRazer cleanup
  * Call this after any operation with the library.
  */
void razer_exit(void);

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