ckb-next  beta-v0.2.8 at branch testing
ckb-next driver for corsair devices
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator 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   3
 
#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   5
 
#define N_MOUSE_ZONES_EXTENDED   11
 
#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)
 
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+3+12)+25)+11)]
 

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   3

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   5

Definition at line 40 of file keymap.h.

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

#define N_MOUSE_ZONES_EXTENDED   11

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 394 of file keymap.c.

References N_KEYBYTES_HW.

Referenced by os_inputmain().

394  {
395  if(endpoint == 2 || endpoint == -2){
396  if(urbinput[0] != 3)
397  return;
398  urbinput++;
399  }
400  memcpy(kbinput, urbinput, N_KEYBYTES_HW);
401 }
#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 403 of file keymap.c.

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

Referenced by os_inputmain().

403  {
404  if(endpoint == 2 || endpoint == -2){
405  if(urbinput[0] != 3)
406  return;
407  urbinput++;
408  }
409  for(int bit = BUTTON_HID_COUNT; bit < N_BUTTONS_HW; bit++){
410  int byte = bit / 8;
411  uchar test = 1 << (bit % 8);
412  if(urbinput[byte] & test)
413  SET_KEYBIT(kbinput, MOUSE_BUTTON_FIRST + bit);
414  else
415  CLEAR_KEYBIT(kbinput, MOUSE_BUTTON_FIRST + bit);
416  }
417 }
#define CLEAR_KEYBIT(array, index)
Definition: structures.h:16
#define MOUSE_BUTTON_FIRST
Definition: keymap.h:33
#define BUTTON_HID_COUNT
Definition: keymap.c:364
#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 223 of file keymap.c.

References ckb_warn, CLEAR_KEYBIT, and SET_KEYBIT.

Referenced by os_inputmain().

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

Definition at line 366 of file keymap.c.

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

Referenced by os_inputmain().

366  {
367  if((endpoint != 2 && endpoint != -2) || length < 10)
368  return;
369  // EP 2: mouse input
370  if(urbinput[0] != 1)
371  return;
372  // Byte 1 = mouse buttons (bitfield)
373  for(int bit = 0; bit < BUTTON_HID_COUNT; bit++){
374  if(urbinput[1] & (1 << bit))
375  SET_KEYBIT(kbinput, MOUSE_BUTTON_FIRST + bit);
376  else
377  CLEAR_KEYBIT(kbinput, MOUSE_BUTTON_FIRST + bit);
378  }
379  // Bytes 5 - 8: movement
380  *xaxis += *(short*)(urbinput + 5);
381  *yaxis += *(short*)(urbinput + 7);
382  // Byte 9: wheel
383  char wheel = urbinput[9];
384  if(wheel > 0)
385  SET_KEYBIT(kbinput, MOUSE_EXTRA_FIRST); // wheelup
386  else
388  if(wheel < 0)
389  SET_KEYBIT(kbinput, MOUSE_EXTRA_FIRST + 1); // wheeldn
390  else
391  CLEAR_KEYBIT(kbinput, MOUSE_EXTRA_FIRST + 1);
392 }
#define CLEAR_KEYBIT(array, index)
Definition: structures.h:16
#define MOUSE_BUTTON_FIRST
Definition: keymap.h:33
#define BUTTON_HID_COUNT
Definition: keymap.c:364
#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+3+12)+25)+11)]