hid-roccat-kone.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #ifndef __HID_ROCCAT_KONE_H
  2. #define __HID_ROCCAT_KONE_H
  3. /*
  4. * Copyright (c) 2010 Stefan Achatz <erazor_de@users.sourceforge.net>
  5. */
  6. /*
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. */
  12. #include <linux/types.h>
  13. #define DRIVER_VERSION "v0.3.0"
  14. #define DRIVER_AUTHOR "Stefan Achatz"
  15. #define DRIVER_DESC "USB Roccat Kone driver"
  16. #define DRIVER_LICENSE "GPL v2"
  17. #pragma pack(push)
  18. #pragma pack(1)
  19. struct kone_keystroke {
  20. uint8_t key;
  21. uint8_t action;
  22. uint16_t period; /* in milliseconds */
  23. };
  24. enum kone_keystroke_buttons {
  25. kone_keystroke_button_1 = 0xf0, /* left mouse button */
  26. kone_keystroke_button_2 = 0xf1, /* right mouse button */
  27. kone_keystroke_button_3 = 0xf2, /* wheel */
  28. kone_keystroke_button_9 = 0xf3, /* side button up */
  29. kone_keystroke_button_8 = 0xf4 /* side button down */
  30. };
  31. enum kone_keystroke_actions {
  32. kone_keystroke_action_press = 0,
  33. kone_keystroke_action_release = 1
  34. };
  35. struct kone_button_info {
  36. uint8_t number; /* range 1-8 */
  37. uint8_t type;
  38. uint8_t macro_type; /* 0 = short, 1 = overlong */
  39. uint8_t macro_set_name[16]; /* can be max 15 chars long */
  40. uint8_t macro_name[16]; /* can be max 15 chars long */
  41. uint8_t count;
  42. struct kone_keystroke keystrokes[20];
  43. };
  44. enum kone_button_info_types {
  45. /* valid button types until firmware 1.32 */
  46. kone_button_info_type_button_1 = 0x1, /* click (left mouse button) */
  47. kone_button_info_type_button_2 = 0x2, /* menu (right mouse button)*/
  48. kone_button_info_type_button_3 = 0x3, /* scroll (wheel) */
  49. kone_button_info_type_double_click = 0x4,
  50. kone_button_info_type_key = 0x5,
  51. kone_button_info_type_macro = 0x6,
  52. kone_button_info_type_off = 0x7,
  53. /* TODO clarify function and rename */
  54. kone_button_info_type_osd_xy_prescaling = 0x8,
  55. kone_button_info_type_osd_dpi = 0x9,
  56. kone_button_info_type_osd_profile = 0xa,
  57. kone_button_info_type_button_9 = 0xb, /* ie forward */
  58. kone_button_info_type_button_8 = 0xc, /* ie backward */
  59. kone_button_info_type_dpi_up = 0xd, /* internal */
  60. kone_button_info_type_dpi_down = 0xe, /* internal */
  61. kone_button_info_type_button_7 = 0xf, /* tilt left */
  62. kone_button_info_type_button_6 = 0x10, /* tilt right */
  63. kone_button_info_type_profile_up = 0x11, /* internal */
  64. kone_button_info_type_profile_down = 0x12, /* internal */
  65. /* additional valid button types since firmware 1.38 */
  66. kone_button_info_type_multimedia_open_player = 0x20,
  67. kone_button_info_type_multimedia_next_track = 0x21,
  68. kone_button_info_type_multimedia_prev_track = 0x22,
  69. kone_button_info_type_multimedia_play_pause = 0x23,
  70. kone_button_info_type_multimedia_stop = 0x24,
  71. kone_button_info_type_multimedia_mute = 0x25,
  72. kone_button_info_type_multimedia_volume_up = 0x26,
  73. kone_button_info_type_multimedia_volume_down = 0x27
  74. };
  75. enum kone_button_info_numbers {
  76. kone_button_top = 1,
  77. kone_button_wheel_tilt_left = 2,
  78. kone_button_wheel_tilt_right = 3,
  79. kone_button_forward = 4,
  80. kone_button_backward = 5,
  81. kone_button_middle = 6,
  82. kone_button_plus = 7,
  83. kone_button_minus = 8,
  84. };
  85. struct kone_light_info {
  86. uint8_t number; /* number of light 1-5 */
  87. uint8_t mod; /* 1 = on, 2 = off */
  88. uint8_t red; /* range 0x00-0xff */
  89. uint8_t green; /* range 0x00-0xff */
  90. uint8_t blue; /* range 0x00-0xff */
  91. };
  92. struct kone_profile {
  93. uint16_t size; /* always 975 */
  94. uint16_t unused; /* always 0 */
  95. /*
  96. * range 1-5
  97. * This number does not need to correspond with location where profile
  98. * saved
  99. */
  100. uint8_t profile; /* range 1-5 */
  101. uint16_t main_sensitivity; /* range 100-1000 */
  102. uint8_t xy_sensitivity_enabled; /* 1 = on, 2 = off */
  103. uint16_t x_sensitivity; /* range 100-1000 */
  104. uint16_t y_sensitivity; /* range 100-1000 */
  105. uint8_t dpi_rate; /* bit 1 = 800, ... */
  106. uint8_t startup_dpi; /* range 1-6 */
  107. uint8_t polling_rate; /* 1 = 125Hz, 2 = 500Hz, 3 = 1000Hz */
  108. /* kone has no dcu
  109. * value is always 2 in firmwares <= 1.32 and
  110. * 1 in firmwares > 1.32
  111. */
  112. uint8_t dcu_flag;
  113. uint8_t light_effect_1; /* range 1-3 */
  114. uint8_t light_effect_2; /* range 1-5 */
  115. uint8_t light_effect_3; /* range 1-4 */
  116. uint8_t light_effect_speed; /* range 0-255 */
  117. struct kone_light_info light_infos[5];
  118. /* offset is kone_button_info_numbers - 1 */
  119. struct kone_button_info button_infos[8];
  120. uint16_t checksum; /* \brief holds checksum of struct */
  121. };
  122. enum kone_polling_rates {
  123. kone_polling_rate_125 = 1,
  124. kone_polling_rate_500 = 2,
  125. kone_polling_rate_1000 = 3
  126. };
  127. struct kone_settings {
  128. uint16_t size; /* always 36 */
  129. uint8_t startup_profile; /* 1-5 */
  130. uint8_t unknown1;
  131. uint8_t tcu; /* 0 = off, 1 = on */
  132. uint8_t unknown2[23];
  133. uint8_t calibration_data[4];
  134. uint8_t unknown3[2];
  135. uint16_t checksum;
  136. };
  137. /*
  138. * 12 byte mouse event read by interrupt_read
  139. */
  140. struct kone_mouse_event {
  141. uint8_t report_number; /* always 1 */
  142. uint8_t button;
  143. uint16_t x;
  144. uint16_t y;
  145. uint8_t wheel; /* up = 1, down = -1 */
  146. uint8_t tilt; /* right = 1, left = -1 */
  147. uint8_t unknown;
  148. uint8_t event;
  149. uint8_t value; /* press = 0, release = 1 */
  150. uint8_t macro_key; /* 0 to 8 */
  151. };
  152. enum kone_mouse_events {
  153. /* osd events are thought to be display on screen */
  154. kone_mouse_event_osd_dpi = 0xa0,
  155. kone_mouse_event_osd_profile = 0xb0,
  156. /* TODO clarify meaning and occurence of kone_mouse_event_calibration */
  157. kone_mouse_event_calibration = 0xc0,
  158. kone_mouse_event_call_overlong_macro = 0xe0,
  159. /* switch events notify if user changed values with mousebutton click */
  160. kone_mouse_event_switch_dpi = 0xf0,
  161. kone_mouse_event_switch_profile = 0xf1
  162. };
  163. enum kone_commands {
  164. kone_command_profile = 0x5a,
  165. kone_command_settings = 0x15a,
  166. kone_command_firmware_version = 0x25a,
  167. kone_command_weight = 0x45a,
  168. kone_command_calibrate = 0x55a,
  169. kone_command_confirm_write = 0x65a,
  170. kone_command_firmware = 0xe5a
  171. };
  172. #pragma pack(pop)
  173. struct kone_device {
  174. /*
  175. * Storing actual values when we get informed about changes since there
  176. * is no way of getting this information from the device on demand
  177. */
  178. int actual_profile, actual_dpi;
  179. /* Used for neutralizing abnormal button behaviour */
  180. struct kone_mouse_event last_mouse_event;
  181. /*
  182. * It's unlikely that multiple sysfs attributes are accessed at a time,
  183. * so only one mutex is used to secure hardware access and profiles and
  184. * settings of this struct.
  185. */
  186. struct mutex kone_lock;
  187. /*
  188. * Storing the data here reduces IO and ensures that data is available
  189. * when its needed (E.g. interrupt handler).
  190. */
  191. struct kone_profile profiles[5];
  192. struct kone_settings settings;
  193. /*
  194. * firmware doesn't change unless firmware update is implemented,
  195. * so it's read only once
  196. */
  197. int firmware_version;
  198. };
  199. #endif