razer_private.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef RAZER_PRIVATE_H_
  2. #define RAZER_PRIVATE_H_
  3. #include "librazer.h"
  4. #include "util.h"
  5. #include <libusb.h>
  6. #include <stdio.h>
  7. #include <errno.h>
  8. extern razer_logfunc_t razer_logfunc_info;
  9. extern razer_logfunc_t razer_logfunc_error;
  10. extern razer_logfunc_t razer_logfunc_debug;
  11. #define call_razer_logfunc(condition, func, ...) ({ \
  12. __typeof__(condition) __condition = (condition); \
  13. if ((__condition) && (func)) \
  14. func("librazer: " __VA_ARGS__); \
  15. __condition; \
  16. })
  17. #define razer_info_on(condition, ...) call_razer_logfunc(condition, razer_logfunc_info, __VA_ARGS__)
  18. #define razer_error_on(condition, ...) call_razer_logfunc(condition, razer_logfunc_error, __VA_ARGS__)
  19. #define razer_debug_on(condition, ...) call_razer_logfunc(condition, razer_logfunc_debug, __VA_ARGS__)
  20. #define razer_info(...) razer_info_on(1, __VA_ARGS__)
  21. #define razer_error(...) razer_error_on(1, __VA_ARGS__)
  22. #define razer_debug(...) razer_debug_on(1, __VA_ARGS__)
  23. #undef WARN_ON
  24. #define WARN_ON(condition) razer_error_on((condition), \
  25. "WARNING at %s/%s():%d\n", \
  26. __FILE__, __func__, __LINE__)
  27. /* Default USB timeout */
  28. #define RAZER_USB_TIMEOUT 3000
  29. struct razer_usb_interface {
  30. uint8_t bInterfaceNumber;
  31. uint8_t bAlternateSetting;
  32. };
  33. #define RAZER_MAX_NR_INTERFACES 2
  34. struct razer_usb_context {
  35. /* Device pointer. */
  36. struct libusb_device *dev;
  37. /* The handle for all operations. */
  38. struct libusb_device_handle *h;
  39. /* The configuration we want to use. Defaults to 1. */
  40. uint8_t bConfigurationValue;
  41. /* The interfaces we use. */
  42. struct razer_usb_interface interfaces[RAZER_MAX_NR_INTERFACES];
  43. unsigned int nr_interfaces;
  44. };
  45. int razer_usb_add_used_interface(struct razer_usb_context *ctx,
  46. int bInterfaceNumber,
  47. int bAlternateSetting);
  48. int razer_generic_usb_claim(struct razer_usb_context *ctx);
  49. int razer_generic_usb_claim_refcount(struct razer_usb_context *ctx,
  50. unsigned int *refcount);
  51. void razer_generic_usb_release(struct razer_usb_context *ctx);
  52. void razer_generic_usb_release_refcount(struct razer_usb_context *ctx,
  53. unsigned int *refcount);
  54. struct razer_usb_reconnect_guard {
  55. struct razer_usb_context *ctx;
  56. struct libusb_device_descriptor old_desc;
  57. uint8_t old_busnr;
  58. uint8_t old_devaddr;
  59. };
  60. int razer_usb_reconnect_guard_init(struct razer_usb_reconnect_guard *guard,
  61. struct razer_usb_context *ctx);
  62. int razer_usb_reconnect_guard_wait(struct razer_usb_reconnect_guard *guard, bool hub_reset);
  63. int razer_usb_force_hub_reset(struct razer_usb_context *ctx);
  64. #define BUSTYPESTR_USB "USB"
  65. #define DEVTYPESTR_MOUSE "Mouse"
  66. static inline void razer_create_idstr(char *buf,
  67. const char *bustype,
  68. const char *busposition,
  69. const char *devtype,
  70. const char *devname,
  71. const char *devid)
  72. {
  73. snprintf(buf, RAZER_IDSTR_MAX_SIZE, "%s:%s:%s-%s:%s",
  74. devtype, devname, bustype, busposition, devid);
  75. }
  76. void razer_generic_usb_gen_idstr(struct libusb_device *udev,
  77. struct libusb_device_handle *h,
  78. const char *devname,
  79. bool include_devicenr,
  80. const char *serial,
  81. char *idstr_buf);
  82. void razer_init_axes(struct razer_axis *axes,
  83. const char *name0, unsigned int flags0,
  84. const char *name1, unsigned int flags1,
  85. const char *name2, unsigned int flags2);
  86. struct razer_mouse_dpimapping * razer_mouse_get_dpimapping_by_res(
  87. struct razer_mouse_dpimapping *mappings, size_t nr_mappings,
  88. enum razer_dimension dim, enum razer_mouse_res res);
  89. struct razer_event_spacing {
  90. unsigned int spacing_msec;
  91. struct timeval last_event;
  92. };
  93. void razer_event_spacing_init(struct razer_event_spacing *es,
  94. unsigned int msec);
  95. void razer_event_spacing_enter(struct razer_event_spacing *es);
  96. void razer_event_spacing_leave(struct razer_event_spacing *es);
  97. #endif /* RAZER_PRIVATE_H_ */