librazer.h 21 KB

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