librazer.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. /*
  2. * Razer lowlevel device access library.
  3. * Applications do NOT want to use this.
  4. * Applications should use pyrazer or librazerd instead.
  5. *
  6. * Copyright (C) 2007-2011 Michael Buesch <m@bues.ch>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #ifndef LIB_RAZER_H_
  19. #define LIB_RAZER_H_
  20. #ifndef RAZERCFG_BUILD
  21. # error "librazer.h is a razercfg internal library!"
  22. # error "Do not include this file into your application!"
  23. #endif
  24. #include <stdlib.h>
  25. #include <stdint.h>
  26. #include <stddef.h>
  27. #define RAZER_IDSTR_MAX_SIZE 128
  28. #define RAZER_LEDNAME_MAX_SIZE 64
  29. #define RAZER_DEFAULT_CONFIG "/etc/razer.conf"
  30. /* Opaque internal data structures */
  31. struct razer_usb_context;
  32. struct razer_mouse_base_ops;
  33. struct razer_mouse_profile_emu;
  34. struct razer_mouse;
  35. /** razer_utf16_t - UTF-16 type */
  36. typedef uint16_t razer_utf16_t;
  37. /** razer_ascii_to_utf16 - Convert ASCII to UTF16.
  38. * @dest: Destination buffer.
  39. * @dest_max_chars: Maximum number of characters in dest.
  40. * @src: NUL terminated ASCII source buffer.
  41. */
  42. void razer_ascii_to_utf16(razer_utf16_t *dest, size_t dest_max_chars,
  43. const char *src);
  44. /** razer_utf16_cpy - Copy an UTF16 string.
  45. * @dest: Destination buffer.
  46. * @src: Source buffer.
  47. * @max_chars: Maximum number of characters to copy.
  48. */
  49. int razer_utf16_cpy(razer_utf16_t *dest, const razer_utf16_t *src,
  50. size_t max_chars);
  51. /** razer_utf16_strlen - Return the length of an UTF16 string.
  52. * @str: An UTF16 string.
  53. */
  54. size_t razer_utf16_strlen(const razer_utf16_t *str);
  55. /** enum razer_led_state - The LED state value
  56. * @RAZER_LED_OFF: The LED is turned off
  57. * @RAZER_LED_ON: The LED is turned on
  58. * @RAZER_LED_UNKNOWN: The LED is in an unknown state (on or off)
  59. */
  60. enum razer_led_state {
  61. RAZER_LED_OFF = 0,
  62. RAZER_LED_ON = 1,
  63. RAZER_LED_UNKNOWN,
  64. };
  65. /** enum razer_led_mode - The LED working mode
  66. * @RAZER_LED_MODE_STATIC: The LED has a static color
  67. * @RAZER_LED_MODE_SPECTRUM: The LED color goes through a spectrum of colors
  68. * @RAZER_LED_MODE_BREATHING: The LED has a static color and pulsates from off to on
  69. */
  70. enum razer_led_mode {
  71. RAZER_LED_MODE_STATIC = 0,
  72. RAZER_LED_MODE_SPECTRUM = 1,
  73. RAZER_LED_MODE_BREATHING = 2
  74. };
  75. /** struct razer_rgb_color - An RGB color
  76. * @r: Red value.
  77. * @g: Green value.
  78. * @b: Blue value.
  79. * @valid: 1 if this color is valid. 0 otherise.
  80. */
  81. struct razer_rgb_color {
  82. uint8_t r;
  83. uint8_t g;
  84. uint8_t b;
  85. uint8_t valid;
  86. };
  87. /** struct razer_led - A LED on a razer device.
  88. *
  89. * @next: The next LED device in the linked list.
  90. *
  91. * @name: The human readable name string for the LED.
  92. * @id: A unique ID cookie
  93. * @state: The state of the LED (on, off, unknown)
  94. * @mode: The mode of the LED (static, spectrum, breathing)
  95. * @supported_modes_mask: A mask of supported LED modes.
  96. * The RAZER_LED_MODE_STATIC is assumed as the only supported mode if 0.
  97. * @color: The color of the LED.
  98. *
  99. * @toggle_state: Toggle the state. Note that a new_state of
  100. * RAZER_LED_UNKNOWN result is an error.
  101. *
  102. * @change_color: Change the color of the LED.
  103. * May be NULL, if the color cannot be changed.
  104. *
  105. * @set_mode: Set the mode of the LED.
  106. * May be NULL if the mode cannot be changed.
  107. *
  108. * @u: This union contains a pointer to the parent device.
  109. */
  110. struct razer_led {
  111. struct razer_led *next;
  112. const char *name;
  113. unsigned int id;
  114. enum razer_led_state state;
  115. enum razer_led_mode mode;
  116. unsigned int supported_modes_mask;
  117. struct razer_rgb_color color;
  118. int (*toggle_state)(struct razer_led *led,
  119. enum razer_led_state new_state);
  120. int (*change_color)(struct razer_led *led,
  121. const struct razer_rgb_color *new_color);
  122. int (*set_mode)(struct razer_led *led,
  123. enum razer_led_mode new_mode);
  124. union {
  125. struct razer_mouse *mouse;
  126. struct razer_mouse_profile *mouse_prof;
  127. } u;
  128. };
  129. /** enum razer_mouse_freq - Mouse scan frequency
  130. * @RAZER_MOUSE_FREQ_UNKNOWN: Unknown scan frequency
  131. */
  132. enum razer_mouse_freq {
  133. RAZER_MOUSE_FREQ_UNKNOWN = 0,
  134. RAZER_MOUSE_FREQ_125HZ = 125,
  135. RAZER_MOUSE_FREQ_500HZ = 500,
  136. RAZER_MOUSE_FREQ_1000HZ = 1000,
  137. };
  138. /** enum razer_mouse_res - Mouse scan resolutions
  139. * @RAZER_MOUSE_RES_UNKNOWN: Unknown scan resolution
  140. */
  141. enum razer_mouse_res {
  142. RAZER_MOUSE_RES_UNKNOWN = 0,
  143. RAZER_MOUSE_RES_100DPI = 100,
  144. RAZER_MOUSE_RES_125DPI = 125,
  145. RAZER_MOUSE_RES_250DPI = 250,
  146. RAZER_MOUSE_RES_400DPI = 400,
  147. RAZER_MOUSE_RES_450DPI = 450,
  148. RAZER_MOUSE_RES_500DPI = 500,
  149. RAZER_MOUSE_RES_800DPI = 800,
  150. RAZER_MOUSE_RES_900DPI = 900,
  151. RAZER_MOUSE_RES_1000DPI = 1000,
  152. RAZER_MOUSE_RES_1600DPI = 1600,
  153. RAZER_MOUSE_RES_1800DPI = 1800,
  154. RAZER_MOUSE_RES_2000DPI = 2000,
  155. RAZER_MOUSE_RES_3500DPI = 3500,
  156. RAZER_MOUSE_RES_4000DPI = 4000,
  157. RAZER_MOUSE_RES_5600DPI = 5600,
  158. RAZER_MOUSE_RES_6000DPI = 6000,
  159. RAZER_MOUSE_RES_6400DPI = 6400,
  160. RAZER_MOUSE_RES_7000DPI = 7000,
  161. RAZER_MOUSE_RES_7600DPI = 7600,
  162. RAZER_MOUSE_RES_8200DPI = 8200,
  163. RAZER_MOUSE_RES_8800DPI = 8800,
  164. RAZER_MOUSE_RES_9400DPI = 9400,
  165. RAZER_MOUSE_RES_10000DPI = 10000
  166. };
  167. /** enum razer_mouse_type
  168. * @RAZER_MOUSETYPE_DEATHADDER: A "DeathAdder" mouse
  169. * @RAZER_MOUSETYPE_KRAIT: A "Krait" mouse
  170. * @RAZER_MOUSETYPE_LACHESIS: A "Lachesis" mouse
  171. * @RAZER_MOUSETYPE_COPPERHEAD: A "Copperhead" mouse
  172. * @RAZER_MOUSETYPE_NAGA: A "Naga" mouse
  173. * @RAZER_MOUSETYPE_BOOMSLANGCE: A "Boomslang Collector's Edition" mouse
  174. * @RAZER_MOUSETYPE_IMPERATOR: An "Imperator" mouse
  175. * @RAZER_MOUSETYPE_TAIPAN: A "Taipan" mouse
  176. */
  177. enum razer_mouse_type {
  178. RAZER_MOUSETYPE_DEATHADDER,
  179. RAZER_MOUSETYPE_KRAIT,
  180. RAZER_MOUSETYPE_LACHESIS,
  181. RAZER_MOUSETYPE_COPPERHEAD,
  182. RAZER_MOUSETYPE_NAGA,
  183. RAZER_MOUSETYPE_BOOMSLANGCE,
  184. RAZER_MOUSETYPE_IMPERATOR,
  185. RAZER_MOUSETYPE_TAIPAN,
  186. };
  187. /** struct razer_button_function - A logical button function
  188. *
  189. * @id: A unique ID number for the function.
  190. *
  191. * @name: A unique and human readable name string for the function.
  192. */
  193. struct razer_button_function {
  194. unsigned int id;
  195. const char *name;
  196. };
  197. /** struct razer_button - A physical button (physical = piece of hardware)
  198. *
  199. * @id: A unique ID number for this button.
  200. *
  201. * @name: A unique and human readable name string for the button.
  202. */
  203. struct razer_button {
  204. unsigned int id;
  205. const char *name;
  206. };
  207. /** enum razer_axis_flags - Usage flags for an axis.
  208. * @RAZER_AXIS_INDEPENDENT_DPIMAPPING: Supports independent DPI mappings.
  209. */
  210. enum razer_axis_flags {
  211. RAZER_AXIS_INDEPENDENT_DPIMAPPING = (1 << 0),
  212. };
  213. /** struct razer_axis - A device axis.
  214. *
  215. * @id: A unique ID number for this axis.
  216. *
  217. * @name: A unique and human readable name string for this axis.
  218. *
  219. * @flags: Usage flags.
  220. */
  221. struct razer_axis {
  222. unsigned int id;
  223. const char *name;
  224. unsigned int flags;
  225. };
  226. /** razer_id_mask_t - ID mask type */
  227. typedef uint64_t razer_id_mask_t;
  228. /** razer_id_mask_set - Set a bit in an ID mask.
  229. *
  230. * @mask: Pointer to the mask.
  231. *
  232. * @nr: The ID number.
  233. */
  234. static inline void razer_id_mask_set(razer_id_mask_t *mask, unsigned int id)
  235. {
  236. *mask |= ((razer_id_mask_t)1ull << id);
  237. }
  238. /** razer_id_mask_clear - Clear a bit in an ID mask.
  239. *
  240. * @mask: Pointer to the mask.
  241. *
  242. * @nr: The ID number.
  243. */
  244. static inline void razer_id_mask_clear(razer_id_mask_t *mask, unsigned int id)
  245. {
  246. *mask &= ~((razer_id_mask_t)1ull << id);
  247. }
  248. /** razer_id_mask_zero - Initialize an ID mask to "all unset".
  249. *
  250. * @mask: Pointer to the mask.
  251. */
  252. static inline void razer_id_mask_zero(razer_id_mask_t *mask)
  253. {
  254. *mask = (razer_id_mask_t)0ull;
  255. }
  256. /** enum razer_dimension - Dimension IDs
  257. * @RAZER_DIM_X: X dimension
  258. * @RAZER_DIM_Y: Y dimension
  259. * @RAZER_DIM_Z: Z dimension
  260. * @RAZER_NR_DIMS: 3 dimensions ought to be enough in this universe.
  261. * @RAZER_DIM_0: First dimension. X alias.
  262. * @RAZER_DIM_1: Second dimension. Y alias.
  263. * @RAZER_DIM_2: Third dimension. Z alias.
  264. */
  265. enum razer_dimension {
  266. RAZER_DIM_X,
  267. RAZER_DIM_Y,
  268. RAZER_DIM_Z,
  269. RAZER_NR_DIMS,
  270. RAZER_DIM_0 = RAZER_DIM_X,
  271. RAZER_DIM_1 = RAZER_DIM_Y,
  272. RAZER_DIM_2 = RAZER_DIM_Z,
  273. };
  274. /** struct razer_mouse_dpimapping - Mouse scan resolution mapping.
  275. *
  276. * @nr: The ID number.
  277. *
  278. * @res: The resolution values. One per dimension.
  279. *
  280. * @dimension_mask: Mask of used dimensions.
  281. *
  282. * @profile_mask: A bitmask of which profile this dpimapping is valid for.
  283. * A value of 0 indicates "any profile".
  284. * If bit0 is set, this means profile 0.
  285. * If bit1 is set, this means profile 1. etc...
  286. *
  287. * @change: Change this mapping to another resolution value.
  288. * May be NULL, if the mapping cannot be changed.
  289. */
  290. struct razer_mouse_dpimapping {
  291. unsigned int nr;
  292. enum razer_mouse_res res[RAZER_NR_DIMS];
  293. unsigned int dimension_mask;
  294. razer_id_mask_t profile_mask;
  295. int (*change)(struct razer_mouse_dpimapping *d,
  296. enum razer_dimension dim,
  297. enum razer_mouse_res res);
  298. struct razer_mouse *mouse;
  299. };
  300. /** struct razer_mouse_profile - A mouse profile
  301. *
  302. * @nr: The profile ID.
  303. *
  304. * @get_name: Get the profile name.
  305. * May be NULL.
  306. *
  307. * @set_name: Set the profile name.
  308. * May be NULL.
  309. *
  310. * @get_leds: Get a linked list of per-profile LEDs.
  311. * Returns the number of LEDs or a negative error code.
  312. * leds_list points to the first LED in the list.
  313. * The caller is responsible to free every item in leds_list.
  314. * May be NULL.
  315. *
  316. * @get_freq: Get the currently used scan frequency.
  317. * May be NULL, if the scan frequency is not managed per profile.
  318. *
  319. * @set_freq: Change the mouse scan frequency.
  320. * May be NULL, if the scan frequency is not managed per profile.
  321. *
  322. * @get_dpimapping: Returns the active scan resolution mapping.
  323. * If axis is NULL, returns the mapping of the first axis.
  324. *
  325. * @set_dpimapping: Sets the active scan resolution mapping.
  326. * If axis is NULL, sets the mapping of all axes.
  327. *
  328. * @get_button_function: Get the currently assigned function for a button.
  329. * May be NULL.
  330. *
  331. * @set_button_function: Assign a new function to a button.
  332. * May be NULL.
  333. */
  334. struct razer_mouse_profile {
  335. unsigned int nr;
  336. const razer_utf16_t * (*get_name)(struct razer_mouse_profile *p);
  337. int (*set_name)(struct razer_mouse_profile *p,
  338. const razer_utf16_t *new_name);
  339. int (*get_leds)(struct razer_mouse_profile *p,
  340. struct razer_led **leds_list);
  341. enum razer_mouse_freq (*get_freq)(struct razer_mouse_profile *p);
  342. int (*set_freq)(struct razer_mouse_profile *p, enum razer_mouse_freq freq);
  343. struct razer_mouse_dpimapping * (*get_dpimapping)(struct razer_mouse_profile *p,
  344. struct razer_axis *axis);
  345. int (*set_dpimapping)(struct razer_mouse_profile *p,
  346. struct razer_axis *axis,
  347. struct razer_mouse_dpimapping *d);
  348. struct razer_button_function * (*get_button_function)(struct razer_mouse_profile *p,
  349. struct razer_button *b);
  350. int (*set_button_function)(struct razer_mouse_profile *p,
  351. struct razer_button *b,
  352. struct razer_button_function *f);
  353. struct razer_mouse *mouse;
  354. };
  355. /** enum razer_mouse_flags - Flags for a mouse
  356. *
  357. * @RAZER_MOUSEFLG_PROFEMU: Profiles are emulated in software. The device
  358. * does only support one profile in hardware.
  359. *
  360. * @RAZER_MOUSEFLG_SUGGESTFWUP: A firmware update for this device is suggested.
  361. *
  362. * @RAZER_MOUSEFLG_MASK: A mask of all public flags.
  363. */
  364. enum razer_mouse_flags {
  365. RAZER_MOUSEFLG_PROFEMU = (1 << 0),
  366. RAZER_MOUSEFLG_SUGGESTFWUP = (1 << 1),
  367. RAZER_MOUSEFLG_MASK = 0x0000FFFF,
  368. /* Internal flags */
  369. RAZER_MOUSEFLG_PRESENT = (1 << 15),
  370. };
  371. /** enum - Various constants
  372. *
  373. * @RAZER_FW_FLASH_MAGIC: Magic parameter to flash_firmware callback.
  374. *
  375. * @RAZER_NR_EMULATED_PROFILES: Default number of emulated profiles.
  376. */
  377. enum {
  378. RAZER_FW_FLASH_MAGIC = 0xB00B135,
  379. RAZER_NR_EMULATED_PROFILES = 20,
  380. };
  381. /** struct razer_mouse - Representation of a mouse device
  382. *
  383. * @next: Linked list to the next mouse.
  384. *
  385. * @idstr: A system wide unique ID string for the device.
  386. *
  387. * @type: The mouse type
  388. *
  389. * @flags: Various ORed enum razer_mouse_flags.
  390. *
  391. * @claim: Claim and open the backend device (USB).
  392. * As long as the device is claimed, it is not operable by the user!
  393. * Claim can be called multiple times before release, but it must always
  394. * pair up with the corresponding number of release calls.
  395. *
  396. * @release: Release a claimed backend device.
  397. * Implicitely commits the config, if the last claim is released.
  398. * Returns 0 on success or an error code.
  399. * An error is a commit error. The mouse is always released properly.
  400. *
  401. * @commit: Commit the current settings.
  402. * This usually doesn't have to be called explicitly.
  403. * May be NULL.
  404. *
  405. * @get_fw_version: Read the firmware version from the device.
  406. * Returns the firmware version or a negative error code.
  407. *
  408. * @flash_firmware: Upload a firmware image to the device and
  409. * flash it to the PROM. &magic_number is &RAZER_FW_FLASH_MAGIC.
  410. * The magic is used to project against accidental calls.
  411. *
  412. * @global_get_leds: Get a linked list of globally managed LEDs.
  413. * Returns the number of LEDs or a negative error code.
  414. * leds_list points to the first LED in the list.
  415. * The caller is responsible to free every item in leds_list.
  416. * May be NULL.
  417. *
  418. * @global_get_freq: Get the current globally used scan frequency.
  419. * May be NULL, if the scan frequency is not managed globally.
  420. *
  421. * @global_set_freq: Change the global mouse scan frequency.
  422. * May be NULL, if the scan frequency is not managed globally.
  423. *
  424. * @nr_profiles: The number of profiles supported by this device.
  425. * Defaults to 1.
  426. *
  427. * @get_profiles: Returns an array of supported profiles.
  428. * Array length is nr_profiles.
  429. *
  430. * @get_active_profile: Returns the currently active profile.
  431. * May be NULL, if nr_profiles is 1.
  432. *
  433. * @set_active_profile: Selects the active profile.
  434. * May be NULL, if nr_profiles is 1.
  435. *
  436. * @supported_axes: Returns a list of supported device axes
  437. * for this mouse in res_ptr.
  438. * The return value is a positive list length or a negative error code.
  439. *
  440. * @supported_resolutions: Returns a list of supported scan resolutions
  441. * for this mouse in res_ptr.
  442. * The return value is a positive list length or a negative error code.
  443. * The caller is responsible to free res_ptr.
  444. *
  445. * @supported_freqs: Get an array of supported scan frequencies.
  446. * Returns the array size or a negative error code.
  447. * freq_ptr points to the array.
  448. * The caller is responsible to free freq_ptr.
  449. *
  450. * @supported_dpimappings: Returns a list of supported scan resolution
  451. * mappings in res_ptr.
  452. * The function return value is the positive list size or a negative
  453. * error code.
  454. *
  455. * @supported_buttons: Returns a list of physical buttons on the device
  456. * in res_ptr.
  457. * The function return value is the positive list size or a negative
  458. * error code.
  459. * May be NULL.
  460. *
  461. * @supported_button_functions: Returns a list of possible function assignments
  462. * for the physical buttons in res_ptr.
  463. * The function return value is the positive list size or a negative
  464. * error code.
  465. * May be NULL.
  466. */
  467. struct razer_mouse {
  468. struct razer_mouse *next;
  469. char idstr[RAZER_IDSTR_MAX_SIZE + 1];
  470. enum razer_mouse_type type;
  471. unsigned int flags;
  472. int (*claim)(struct razer_mouse *m);
  473. int (*release)(struct razer_mouse *m);
  474. int (*commit)(struct razer_mouse *m, int force);
  475. int (*get_fw_version)(struct razer_mouse *m);
  476. int (*flash_firmware)(struct razer_mouse *m,
  477. const char *data, size_t len,
  478. unsigned int magic_number);
  479. int (*global_get_leds)(struct razer_mouse *m,
  480. struct razer_led **leds_list);
  481. enum razer_mouse_freq (*global_get_freq)(struct razer_mouse *m);
  482. int (*global_set_freq)(struct razer_mouse *m, enum razer_mouse_freq freq);
  483. unsigned int nr_profiles;
  484. struct razer_mouse_profile * (*get_profiles)(struct razer_mouse *m);
  485. struct razer_mouse_profile * (*get_active_profile)(struct razer_mouse *m);
  486. int (*set_active_profile)(struct razer_mouse *m,
  487. struct razer_mouse_profile *p);
  488. int (*supported_axes)(struct razer_mouse *m,
  489. struct razer_axis **res_ptr);
  490. int (*supported_resolutions)(struct razer_mouse *m,
  491. enum razer_mouse_res **res_ptr);
  492. int (*supported_freqs)(struct razer_mouse *m,
  493. enum razer_mouse_freq **freq_ptr);
  494. int (*supported_dpimappings)(struct razer_mouse *m,
  495. struct razer_mouse_dpimapping **res_ptr);
  496. int (*supported_buttons)(struct razer_mouse *m,
  497. struct razer_button **res_ptr);
  498. int (*supported_button_functions)(struct razer_mouse *m,
  499. struct razer_button_function **res_ptr);
  500. /* Do not touch these pointers. */
  501. const struct razer_mouse_base_ops *base_ops;
  502. struct razer_usb_context *usb_ctx;
  503. unsigned int claim_count;
  504. struct razer_mouse_profile_emu *profemu;
  505. void *drv_data; /* For use by the hardware driver */
  506. };
  507. /** razer_msleep - Delay.
  508. * msecs: Number of milliseconds to delay.
  509. */
  510. void razer_msleep(unsigned int msecs);
  511. /** razer_strlcpy - Copy a string into a sized buffer.
  512. * @dst: Destination buffer.
  513. * @src: Source string.
  514. * @dst_size: Destination buffer size.
  515. */
  516. void razer_strlcpy(char *dst, const char *src, size_t dst_size);
  517. /** razer_free_freq_list - Free an array of frequencies.
  518. * This function frees a whole array of frequencies as returned
  519. * by the device methods.
  520. */
  521. void razer_free_freq_list(enum razer_mouse_freq *freq_list, int count);
  522. /** razer_free_resolution_list - Free an array of resolutions.
  523. * This function frees a whole array of resolutions as returned
  524. * by the device methods.
  525. */
  526. void razer_free_resolution_list(enum razer_mouse_res *res_list, int count);
  527. /** razer_free_leds - Free a linked list of struct razer_led.
  528. * This function frees a whole linked list of struct razer_led,
  529. * as returned by the device methods. Note that you can
  530. * also free a single struct razer_led with this function, if
  531. * you assign a NULL pointer to led_list->next before calling this.
  532. */
  533. void razer_free_leds(struct razer_led *led_list);
  534. /** razer_rescan_mice - Rescan for connected razer mice.
  535. * Returns a pointer to the linked list of mice, or a NULL pointer
  536. * in case of an error.
  537. */
  538. struct razer_mouse * razer_rescan_mice(void);
  539. /** razer_reconfig_mice - Reconfigure all detected razer mice.
  540. * Returns 0 on success or an error code.
  541. */
  542. int razer_reconfig_mice(void);
  543. /** razer_for_each_mouse - Convenience helper for traversing a mouse list
  544. *
  545. * @mouse: 'struct razer_mouse' pointer used as a list pointer.
  546. * @next: 'struct razer_mouse' pointer used as temporary 'next' pointer.
  547. * @mice_list: Pointer to the base of the linked list.
  548. *
  549. * Use razer_for_each_mouse like a normal C 'for' loop.
  550. */
  551. #define razer_for_each_mouse(mouse, next, mice_list) \
  552. for (mouse = mice_list, next = (mice_list) ? (mice_list)->next : NULL; \
  553. mouse; \
  554. mouse = next, next = (mouse) ? (mouse)->next : NULL)
  555. /** enum razer_event - The type of an event.
  556. */
  557. enum razer_event {
  558. RAZER_EV_MOUSE_ADD,
  559. RAZER_EV_MOUSE_REMOVE,
  560. };
  561. /** struct razer_event_data - Context data for an event.
  562. */
  563. struct razer_event_data {
  564. union {
  565. struct razer_mouse *mouse;
  566. } u;
  567. };
  568. /** razer_event_handler_t - The type of an event handler.
  569. */
  570. typedef void (*razer_event_handler_t)(enum razer_event event,
  571. const struct razer_event_data *data);
  572. /** razer_register_event_handler - Register an event handler.
  573. */
  574. int razer_register_event_handler(razer_event_handler_t handler);
  575. /** razer_unregister_event_handler - Unregister an event handler.
  576. */
  577. void razer_unregister_event_handler(razer_event_handler_t handler);
  578. /** razer_load_config - Load a configuration file.
  579. * If path is NULL, the default config is loaded.
  580. * If path is an empty string, the current config (if any) will be
  581. * discarded and no config will be loaded.
  582. */
  583. int razer_load_config(const char *path);
  584. typedef void (*razer_logfunc_t)(const char *fmt, ...);
  585. /** razer_set_logging - Set log callbacks.
  586. * Callbacks may be NULL to suppress messages.
  587. */
  588. void razer_set_logging(razer_logfunc_t info_callback,
  589. razer_logfunc_t error_callback,
  590. razer_logfunc_t debug_callback);
  591. /** razer_init - LibRazer initialization
  592. * Call this before any other library function.
  593. */
  594. int razer_init(int enable_profile_emu);
  595. /** razer_exit - LibRazer cleanup
  596. * Call this after any operation with the library.
  597. */
  598. void razer_exit(void);
  599. #endif /* LIB_RAZER_H_ */