ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
keymap.h File Reference
#include "keymap_mac.h"
+ Include dependency graph for keymap.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  key
 

Macros

#define KEY_NONE   -1
 
#define KEY_CORSAIR   -2
 
#define KEY_UNBOUND   -3
 
#define BTN_WHEELUP   0x1f01
 
#define BTN_WHEELDOWN   0x1f02
 
#define KEY_BACKSLASH_ISO   KEY_BACKSLASH
 
#define N_KEYS_HW   152
 
#define N_KEYBYTES_HW   ((N_KEYS_HW + 7) / 8)
 
#define N_KEY_ZONES   22
 
#define N_KEYS_EXTRA   12
 
#define N_BUTTONS_HW   20
 
#define N_BUTTONS_EXTENDED   25
 
#define MOUSE_BUTTON_FIRST   (N_KEYS_HW + N_KEY_ZONES + N_KEYS_EXTRA)
 
#define MOUSE_EXTRA_FIRST   (MOUSE_BUTTON_FIRST + N_BUTTONS_HW)
 
#define N_KEYS_INPUT   (MOUSE_BUTTON_FIRST + N_BUTTONS_EXTENDED)
 
#define N_KEYBYTES_INPUT   ((N_KEYS_INPUT + 7) / 8)
 
#define LED_MOUSE   N_KEYS_HW
 
#define N_MOUSE_ZONES   6
 
#define N_MOUSE_ZONES_EXTENDED   12
 
#define LED_DPI   (LED_MOUSE + 2)
 
#define N_KEYS_EXTENDED   (N_KEYS_INPUT + N_MOUSE_ZONES_EXTENDED)
 
#define N_KEYBYTES_EXTENDED   ((N_KEYS_EXTENDED + 7) / 8)
 
#define SCAN_SILENT   0x8000
 
#define SCAN_KBD   0
 
#define SCAN_MOUSE   0x1000
 

Functions

void hid_kb_translate (unsigned char *kbinput, int endpoint, int length, const unsigned char *urbinput)
 
void hid_mouse_translate (unsigned char *kbinput, short *xaxis, short *yaxis, int endpoint, int length, const unsigned char *urbinput, ushort fwversion)
 
void corsair_kbcopy (unsigned char *kbinput, int endpoint, const unsigned char *urbinput)
 
void corsair_mousecopy (unsigned char *kbinput, int endpoint, const unsigned char *urbinput)
 

Variables

const key keymap [(((152+22+12)+25)+12)]
 

Data Structure Documentation

struct key

Definition at line 49 of file keymap.h.

+ Collaboration diagram for key:
Data Fields
short led
const char * name
short scan

Macro Definition Documentation

#define BTN_WHEELDOWN   0x1f02

Definition at line 13 of file keymap.h.

Referenced by os_keypress().

#define BTN_WHEELUP   0x1f01

Definition at line 12 of file keymap.h.

Referenced by os_keypress().

#define KEY_BACKSLASH_ISO   KEY_BACKSLASH

Definition at line 20 of file keymap.h.

#define KEY_CORSAIR   -2

Definition at line 8 of file keymap.h.

#define KEY_NONE   -1

Definition at line 7 of file keymap.h.

#define KEY_UNBOUND   -3

Definition at line 9 of file keymap.h.

Referenced by cmd_unbind().

#define LED_DPI   (LED_MOUSE + 2)

Definition at line 43 of file keymap.h.

Referenced by loadrgb_mouse(), and savergb_mouse().

#define LED_MOUSE   N_KEYS_HW

Definition at line 39 of file keymap.h.

Referenced by isblack(), loaddpi(), loadrgb_mouse(), rgbcmp(), savedpi(), savergb_mouse(), and updatergb_mouse().

#define MOUSE_BUTTON_FIRST   (N_KEYS_HW + N_KEY_ZONES + N_KEYS_EXTRA)

Definition at line 33 of file keymap.h.

Referenced by corsair_mousecopy(), and hid_mouse_translate().

#define MOUSE_EXTRA_FIRST   (MOUSE_BUTTON_FIRST + N_BUTTONS_HW)

Definition at line 34 of file keymap.h.

Referenced by hid_mouse_translate().

#define N_BUTTONS_EXTENDED   25

Definition at line 32 of file keymap.h.

#define N_BUTTONS_HW   20

Definition at line 31 of file keymap.h.

Referenced by corsair_mousecopy().

#define N_KEY_ZONES   22

Definition at line 27 of file keymap.h.

#define N_KEYBYTES_EXTENDED   ((N_KEYS_EXTENDED + 7) / 8)

Definition at line 46 of file keymap.h.

#define N_KEYBYTES_HW   ((N_KEYS_HW + 7) / 8)

Definition at line 25 of file keymap.h.

Referenced by corsair_kbcopy().

#define N_KEYBYTES_INPUT   ((N_KEYS_INPUT + 7) / 8)

Definition at line 37 of file keymap.h.

Referenced by _cmd_macro(), inputupdate_keys(), and macromask().

#define N_KEYS_EXTENDED   (N_KEYS_INPUT + N_MOUSE_ZONES_EXTENDED)

Definition at line 45 of file keymap.h.

Referenced by printrgb(), and readcmd().

#define N_KEYS_EXTRA   12

Definition at line 29 of file keymap.h.

#define N_KEYS_HW   152

Definition at line 24 of file keymap.h.

Referenced by loadrgb_kb(), makergb_512(), rgbcmp(), and setactive_kb().

#define N_KEYS_INPUT   (MOUSE_BUTTON_FIRST + N_BUTTONS_EXTENDED)
#define N_MOUSE_ZONES   6

Definition at line 40 of file keymap.h.

Referenced by isblack(), loaddpi(), rgbcmp(), savedpi(), and updatergb_mouse().

#define N_MOUSE_ZONES_EXTENDED   12

Definition at line 41 of file keymap.h.

#define SCAN_KBD   0

Definition at line 57 of file keymap.h.

#define SCAN_MOUSE   0x1000

Definition at line 58 of file keymap.h.

Referenced by os_keypress().

#define SCAN_SILENT   0x8000

Definition at line 56 of file keymap.h.

Referenced by inputupdate_keys().

Function Documentation

void corsair_kbcopy ( unsigned char *  kbinput,
int  endpoint,
const unsigned char *  urbinput 
)

Definition at line 420 of file keymap.c.

References N_KEYBYTES_HW.

Referenced by os_inputmain().

420  {
421  if(endpoint == 2 || endpoint == -2){
422  if(urbinput[0] != 3)
423  return;
424  urbinput++;
425  }
426  memcpy(kbinput, urbinput, N_KEYBYTES_HW);
427 }
#define N_KEYBYTES_HW
Definition: keymap.h:25

+ Here is the caller graph for this function:

void corsair_mousecopy ( unsigned char *  kbinput,
int  endpoint,
const unsigned char *  urbinput 
)

Definition at line 429 of file keymap.c.

References BUTTON_HID_COUNT, CLEAR_KEYBIT, MOUSE_BUTTON_FIRST, N_BUTTONS_HW, and SET_KEYBIT.

Referenced by os_inputmain().

429  {
430  if(endpoint == 2 || endpoint == -2){
431  if(urbinput[0] != 3)
432  return;
433  urbinput++;
434  }
435  for(int bit = BUTTON_HID_COUNT; bit < N_BUTTONS_HW; bit++){
436  int byte = bit / 8;
437  uchar test = 1 << (bit % 8);
438  if(urbinput[byte] & test)
439  SET_KEYBIT(kbinput, MOUSE_BUTTON_FIRST + bit);
440  else
441  CLEAR_KEYBIT(kbinput, MOUSE_BUTTON_FIRST + bit);
442  }
443 }
#define MOUSE_BUTTON_FIRST
Definition: keymap.h:33
#define CLEAR_KEYBIT(array, index)
Definition: structures.h:16
#define BUTTON_HID_COUNT
Definition: keymap.c:389
#define SET_KEYBIT(array, index)
Definition: structures.h:15
unsigned char uchar
Definition: includes.h:24
#define N_BUTTONS_HW
Definition: keymap.h:31

+ Here is the caller graph for this function:

void hid_kb_translate ( unsigned char *  kbinput,
int  endpoint,
int  length,
const unsigned char *  urbinput 
)

Definition at line 246 of file keymap.c.

References ckb_warn, CLEAR_KEYBIT, and SET_KEYBIT.

Referenced by os_inputmain().

246  {
247  if(length < 1)
248  return;
249  // LUT for HID -> Corsair scancodes (-1 for no scan code, -2 for currently unsupported)
250  // Modified from Linux drivers/hid/usbhid/usbkbd.c, key codes replaced with keymap array indices and K95 keys added
251  // Make sure the indices match the keyindex as passed to nprintkey() in notify.c
252  static const short hid_codes[256] = {
253  -1, -1, -1, -1, 37, 54, 52, 39, 27, 40, 41, 42, 32, 43, 44, 45,
254  56, 55, 33, 34, 25, 28, 38, 29, 31, 53, 26, 51, 30, 50, 13, 14,
255  15, 16, 17, 18, 19, 20, 21, 22, 82, 0, 86, 24, 64, 23, 84, 35,
256  79, 80, 81, 46, 47, 12, 57, 58, 59, 36, 1, 2, 3, 4, 5, 6,
257  7, 8, 9, 10, 11, 72, 73, 74, 75, 76, 77, 78, 87, 88, 89, 95,
258  93, 94, 92, 102, 103, 104, 105, 106, 107, 115, 116, 117, 112, 113, 114, 108,
259  109, 110, 118, 119, 49, 69, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
260  -2, -2, -2, -2, -2, -2, -2, -2, 98, -2, -2, -2, -2, -2, -2, 97,
261  130, 131, -1, -1, -1, -2, -1, 83, 66, 85, 145, 144, -2, -1, -1, -1,
262  -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
263  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
264  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
265  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -3, -1, -1, -1, // <- -3 = non-RGB program key
266  120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 136, 137, 138, 139, 140, 141,
267  60, 48, 62, 61, 91, 90, 67, 68, 142, 143, 99, 101, -2, 130, 131, 97,
268  -2, 133, 134, 135, -2, 96, -2, 132, -2, -2, 71, 71, 71, 71, -1, -1,
269  };
270  switch(endpoint){
271  case 1:
272  case -1:
273  // EP 1: 6KRO input (RGB and non-RGB)
274  // Clear previous input
275  for(int i = 0; i < 256; i++){
276  if(hid_codes[i] >= 0)
277  CLEAR_KEYBIT(kbinput, hid_codes[i]);
278  }
279  // Set new input
280  for(int i = 0; i < 8; i++){
281  if((urbinput[0] >> i) & 1)
282  SET_KEYBIT(kbinput, hid_codes[i + 224]);
283  }
284  for(int i = 2; i < length; i++){
285  if(urbinput[i] > 3){
286  int scan = hid_codes[urbinput[i]];
287  if(scan >= 0)
288  SET_KEYBIT(kbinput, scan);
289  else
290  ckb_warn("Got unknown key press %d on EP 1\n", urbinput[i]);
291  }
292  }
293  break;
294  case -2:
295  // EP 2 RGB: NKRO input
296  if(urbinput[0] == 1){
297  // Type 1: standard key
298  if(length != 21)
299  return;
300  for(int bit = 0; bit < 8; bit++){
301  if((urbinput[1] >> bit) & 1)
302  SET_KEYBIT(kbinput, hid_codes[bit + 224]);
303  else
304  CLEAR_KEYBIT(kbinput, hid_codes[bit + 224]);
305  }
306  for(int byte = 0; byte < 19; byte++){
307  char input = urbinput[byte + 2];
308  for(int bit = 0; bit < 8; bit++){
309  int keybit = byte * 8 + bit;
310  int scan = hid_codes[keybit];
311  if((input >> bit) & 1){
312  if(scan >= 0)
313  SET_KEYBIT(kbinput, hid_codes[keybit]);
314  else
315  ckb_warn("Got unknown key press %d on EP 2\n", keybit);
316  } else if(scan >= 0)
317  CLEAR_KEYBIT(kbinput, hid_codes[keybit]);
318  }
319  }
320  break;
321  } else if (urbinput[0] == 2)
322  ; // Type 2: media key (implicitly falls through)
323  else
324  break; // No other known types
325  /* FALLTHRU */
326  case 2:
327  // EP 2 Non-RGB: media keys
328  CLEAR_KEYBIT(kbinput, 97); // mute
329  CLEAR_KEYBIT(kbinput, 98); // stop
330  CLEAR_KEYBIT(kbinput, 99); // prev
331  CLEAR_KEYBIT(kbinput, 100); // play
332  CLEAR_KEYBIT(kbinput, 101); // next
333  CLEAR_KEYBIT(kbinput, 130); // volup
334  CLEAR_KEYBIT(kbinput, 131); // voldn
335  for(int i = 0; i < length; i++){
336  switch(urbinput[i]){
337  case 181:
338  SET_KEYBIT(kbinput, 101); // next
339  break;
340  case 182:
341  SET_KEYBIT(kbinput, 99); // prev
342  break;
343  case 183:
344  SET_KEYBIT(kbinput, 98); // stop
345  break;
346  case 205:
347  SET_KEYBIT(kbinput, 100); // play
348  break;
349  case 226:
350  SET_KEYBIT(kbinput, 97); // mute
351  break;
352  case 233:
353  SET_KEYBIT(kbinput, 130); // volup
354  break;
355  case 234:
356  SET_KEYBIT(kbinput, 131); // voldn
357  break;
358  }
359  }
360  break;
361  case 3:
362  // EP 3 non-RGB: NKRO input
363  if(length != 15)
364  return;
365  for(int bit = 0; bit < 8; bit++){
366  if((urbinput[0] >> bit) & 1)
367  SET_KEYBIT(kbinput, hid_codes[bit + 224]);
368  else
369  CLEAR_KEYBIT(kbinput, hid_codes[bit + 224]);
370  }
371  for(int byte = 0; byte < 14; byte++){
372  char input = urbinput[byte + 1];
373  for(int bit = 0; bit < 8; bit++){
374  int keybit = byte * 8 + bit;
375  int scan = hid_codes[keybit];
376  if((input >> bit) & 1){
377  if(scan >= 0)
378  SET_KEYBIT(kbinput, hid_codes[keybit]);
379  else
380  ckb_warn("Got unknown key press %d on EP 3\n", keybit);
381  } else if(scan >= 0)
382  CLEAR_KEYBIT(kbinput, hid_codes[keybit]);
383  }
384  }
385  break;
386  }
387 }
#define CLEAR_KEYBIT(array, index)
Definition: structures.h:16
#define SET_KEYBIT(array, index)
Definition: structures.h:15
#define ckb_warn(fmt, args...)
Definition: includes.h:52

+ Here is the caller graph for this function:

void hid_mouse_translate ( unsigned char *  kbinput,
short *  xaxis,
short *  yaxis,
int  endpoint,
int  length,
const unsigned char *  urbinput,
ushort  fwversion 
)

Definition at line 391 of file keymap.c.

References BUTTON_HID_COUNT, CLEAR_KEYBIT, MOUSE_BUTTON_FIRST, MOUSE_EXTRA_FIRST, and SET_KEYBIT.

Referenced by os_inputmain().

391  {
392  //The HID Input Endpoint on FWv3 is 64 bytes, so we can't check for length.
393  if((endpoint != 2 && endpoint != -2) || (fwversion < 0x300 && length < 10))
394  return;
395  // EP 2: mouse input
396  if(urbinput[0] != 1)
397  return;
398  // Byte 1 = mouse buttons (bitfield)
399  for(int bit = 0; bit < BUTTON_HID_COUNT; bit++){
400  if(urbinput[1] & (1 << bit))
401  SET_KEYBIT(kbinput, MOUSE_BUTTON_FIRST + bit);
402  else
403  CLEAR_KEYBIT(kbinput, MOUSE_BUTTON_FIRST + bit);
404  }
405  // Bytes 5 - 8: movement
406  *xaxis += *(short*)(urbinput + 5);
407  *yaxis += *(short*)(urbinput + 7);
408  // Byte 9: wheel
409  char wheel = urbinput[9];
410  if(wheel > 0)
411  SET_KEYBIT(kbinput, MOUSE_EXTRA_FIRST); // wheelup
412  else
414  if(wheel < 0)
415  SET_KEYBIT(kbinput, MOUSE_EXTRA_FIRST + 1); // wheeldn
416  else
417  CLEAR_KEYBIT(kbinput, MOUSE_EXTRA_FIRST + 1);
418 }
#define MOUSE_BUTTON_FIRST
Definition: keymap.h:33
#define CLEAR_KEYBIT(array, index)
Definition: structures.h:16
#define BUTTON_HID_COUNT
Definition: keymap.c:389
#define SET_KEYBIT(array, index)
Definition: structures.h:15
#define MOUSE_EXTRA_FIRST
Definition: keymap.h:34

+ Here is the caller graph for this function:

Variable Documentation

const key keymap[(((152+22+12)+25)+12)]