hid-roccat-kone.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. struct kone_light_info {
  76. uint8_t number; /* number of light 1-5 */
  77. uint8_t mod; /* 1 = on, 2 = off */
  78. uint8_t red; /* range 0x00-0xff */
  79. uint8_t green; /* range 0x00-0xff */
  80. uint8_t blue; /* range 0x00-0xff */
  81. };
  82. struct kone_profile {
  83. uint16_t size; /* always 975 */
  84. uint16_t unused; /* always 0 */
  85. /*
  86. * range 1-5
  87. * This number does not need to correspond with location where profile
  88. * saved
  89. */
  90. uint8_t profile; /* range 1-5 */
  91. uint16_t main_sensitivity; /* range 100-1000 */
  92. uint8_t xy_sensitivity_enabled; /* 1 = on, 2 = off */
  93. uint16_t x_sensitivity; /* range 100-1000 */
  94. uint16_t y_sensitivity; /* range 100-1000 */
  95. uint8_t dpi_rate; /* bit 1 = 800, ... */
  96. uint8_t startup_dpi; /* range 1-6 */
  97. uint8_t polling_rate; /* 1 = 125Hz, 2 = 500Hz, 3 = 1000Hz */
  98. /* kone has no dcu
  99. * value is always 2 in firmwares <= 1.32 and
  100. * 1 in firmwares > 1.32
  101. */
  102. uint8_t dcu_flag;
  103. uint8_t light_effect_1; /* range 1-3 */
  104. uint8_t light_effect_2; /* range 1-5 */
  105. uint8_t light_effect_3; /* range 1-4 */
  106. uint8_t light_effect_speed; /* range 0-255 */
  107. struct kone_light_info light_infos[5];
  108. struct kone_button_info button_infos[8];
  109. uint16_t checksum; /* \brief holds checksum of struct */
  110. };
  111. enum kone_polling_rates {
  112. kone_polling_rate_125 = 1,
  113. kone_polling_rate_500 = 2,
  114. kone_polling_rate_1000 = 3
  115. };
  116. struct kone_settings {
  117. uint16_t size; /* always 36 */
  118. uint8_t startup_profile; /* 1-5 */
  119. uint8_t unknown1;
  120. uint8_t tcu; /* 0 = off, 1 = on */
  121. uint8_t unknown2[23];
  122. uint8_t calibration_data[4];
  123. uint8_t unknown3[2];
  124. uint16_t checksum;
  125. };
  126. /*
  127. * 12 byte mouse event read by interrupt_read
  128. */
  129. struct kone_mouse_event {
  130. uint8_t report_number; /* always 1 */
  131. uint8_t button;
  132. uint16_t x;
  133. uint16_t y;
  134. uint8_t wheel; /* up = 1, down = -1 */
  135. uint8_t tilt; /* right = 1, left = -1 */
  136. uint8_t unknown;
  137. uint8_t event;
  138. uint8_t value; /* press = 0, release = 1 */
  139. uint8_t macro_key; /* 0 to 8 */
  140. };
  141. enum kone_mouse_events {
  142. /* osd events are thought to be display on screen */
  143. kone_mouse_event_osd_dpi = 0xa0,
  144. kone_mouse_event_osd_profile = 0xb0,
  145. /* TODO clarify meaning and occurence of kone_mouse_event_calibration */
  146. kone_mouse_event_calibration = 0xc0,
  147. kone_mouse_event_call_overlong_macro = 0xe0,
  148. /* switch events notify if user changed values wiht mousebutton click */
  149. kone_mouse_event_switch_dpi = 0xf0,
  150. kone_mouse_event_switch_profile = 0xf1
  151. };
  152. enum kone_commands {
  153. kone_command_profile = 0x5a,
  154. kone_command_settings = 0x15a,
  155. kone_command_firmware_version = 0x25a,
  156. kone_command_weight = 0x45a,
  157. kone_command_calibrate = 0x55a,
  158. kone_command_confirm_write = 0x65a,
  159. kone_command_firmware = 0xe5a
  160. };
  161. #pragma pack(pop)
  162. struct kone_device {
  163. /*
  164. * Storing actual values when we get informed about changes since there
  165. * is no way of getting this information from the device on demand
  166. */
  167. int actual_profile, actual_dpi;
  168. /* Used for neutralizing abnormal tilt button behaviour */
  169. int last_tilt_state;
  170. /*
  171. * It's unlikely that multiple sysfs attributes are accessed at a time,
  172. * so only one mutex is used to secure hardware access and profiles and
  173. * settings of this struct.
  174. */
  175. struct mutex kone_lock;
  176. /*
  177. * Storing the data here reduces IO and ensures that data is available
  178. * when its needed (E.g. interrupt handler).
  179. */
  180. struct kone_profile profiles[5];
  181. struct kone_settings settings;
  182. /*
  183. * firmware doesn't change unless firmware update is implemented,
  184. * so it's read only once
  185. */
  186. int firmware_version;
  187. };
  188. #endif