librazer.h 20 KB

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