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
device.h
Go to the documentation of this file.
1 #ifndef DEVICE_H
2 #define DEVICE_H
3 
4 #include "includes.h"
5 #include "keymap.h"
6 
7 // Connected devices
8 #define DEV_MAX 9
10 // Is a device active?
11 #ifdef OS_LINUX
12 #define IS_CONNECTED(kb) ((kb) && (kb)->handle && (kb)->uinput_kb && (kb)->uinput_mouse)
13 #else
14 #define IS_CONNECTED(kb) ((kb) && (kb)->handle && (kb)->event)
15 #endif
16 // A mutex used for USB controls. Needs to be locked before reading or writing the device handle or accessing its profile
17 extern pthread_mutex_t devmutex[DEV_MAX];
18 #define dmutex(kb) (devmutex + INDEX_OF(kb, keyboard))
19 // Similar, but for key input. Also needs to be locked before accessing output FIFOs.
20 // When adding or removing a device you must lock BOTH mutexes, dmutex first.
21 extern pthread_mutex_t inputmutex[DEV_MAX];
22 #define imutex(kb) (inputmutex + INDEX_OF(kb, keyboard))
23 
24 // Needed to synchronize sending macro-keys to the os and sending color info to the device
25 extern pthread_mutex_t macromutex[DEV_MAX];
26 #define mmutex(kb) (macromutex + INDEX_OF(kb, keyboard))
27 extern pthread_mutex_t macromutex2[DEV_MAX];
28 #define mmutex2(kb) (macromutex2 + INDEX_OF(kb, keyboard))
29 extern pthread_cond_t macrovar[DEV_MAX];
30 #define mvar(kb) (macrovar + INDEX_OF(kb, keyboard))
31 
32 // Sets up device hardware, after software initialization is finished. Also used during resets
33 // Should be called only from setupusb/resetusb
34 int start_dev(usbdevice* kb, int makeactive);
35 int start_kb_nrgb(usbdevice* kb, int makeactive);
36 
37 // Activates/deactives software control on a keyboard. Return 0 on success
38 int setactive_kb(usbdevice* kb, int active);
39 int setactive_mouse(usbdevice* kb, int active);
44 #define setactive(kb, makeactive) ((makeactive) ? (kb)->vtable->active((kb), 0, 0, 0, 0) : (kb)->vtable->idle((kb), 0, 0, 0, 0))
45 
46 // Command: Activate a keyboard
47 int cmd_active_kb(usbdevice* kb, usbmode* dummy1, int dummy2, int dummy3, const char* dummy4);
48 int cmd_active_mouse(usbdevice* kb, usbmode* dummy1, int dummy2, int dummy3, const char* dummy4);
49 // Command: Deactivate a keyboard
50 int cmd_idle_kb(usbdevice* kb, usbmode* dummy1, int dummy2, int dummy3, const char* dummy4);
51 int cmd_idle_mouse(usbdevice* kb, usbmode* dummy1, int dummy2, int dummy3, const char* dummy4);
52 
53 // Command: Set poll rate (mouse only)
54 int cmd_pollrate(usbdevice* kb, usbmode* dummy1, int dummy2, int rate, const char* dummy3);
55 
56 // Sets a device's current mode index. This is only used on the non-RGB K95; the RGB keyboards have no gettable HW index.
57 void setmodeindex_nrgb(usbdevice* kb, int index);
58 
59 
60 // Per-key input settings for device setup
61 // The upper nybble controls input mode. 0x80 generates a normal HID interrupt, 0x40 generates a proprietary interrupt. 0xc0 generates both.
62 // The exceptions are the proprietary Corsair keys, which only report HID input in BIOS mode and only report Corsair input in non-BIOS mode.
63 // In BIOS mode, the Corsair input is disabled no matter what.
64 #define IN_HID 0x80
65 #define IN_CORSAIR 0x40
66 
67 // The lower nybble controls various hardware actions
68 #define ACT_LIGHT 1
69 #define ACT_NEXT 3
70 #define ACT_NEXT_NOWRAP 5
71 #define ACT_LOCK 8
72 #define ACT_MR_RING 9
73 #define ACT_M1 10
74 #define ACT_M2 11
75 #define ACT_M3 12
76 
77 #endif // DEVICE_H
pthread_mutex_t devmutex[9]
Mutex for handling the usbdevice structure.
Definition: device.c:12
usbdevice keyboard[9]
remember all usb devices. Needed for closeusb().
Definition: device.c:10
int start_dev(usbdevice *kb, int makeactive)
Definition: device.c:89
int start_kb_nrgb(usbdevice *kb, int makeactive)
pthread_cond_t macrovar[9]
This variable is used to stop and wakeup all macro threads which have to wait.
Definition: device.c:16
int cmd_active_mouse(usbdevice *kb, usbmode *dummy1, int dummy2, int dummy3, const char *dummy4)
Definition: device_mouse.c:44
int setactive_mouse(usbdevice *kb, int active)
Definition: device_mouse.c:9
pthread_mutex_t inputmutex[9]
Mutex for dealing with usb input frames.
Definition: device.c:13
int cmd_idle_kb(usbdevice *kb, usbmode *dummy1, int dummy2, int dummy3, const char *dummy4)
int cmd_idle_mouse(usbdevice *kb, usbmode *dummy1, int dummy2, int dummy3, const char *dummy4)
Definition: device_mouse.c:53
pthread_mutex_t macromutex2[9]
Protecting the single link list of threads and the macrovar.
Definition: device.c:15
void setmodeindex_nrgb(usbdevice *kb, int index)
pthread_mutex_t macromutex[9]
Protecting macros against lightning: Both use usb_send.
Definition: device.c:14
int cmd_active_kb(usbdevice *kb, usbmode *dummy1, int dummy2, int dummy3, const char *dummy4)
#define DEV_MAX
Definition: device.h:8
int setactive_kb(usbdevice *kb, int active)
int cmd_pollrate(usbdevice *kb, usbmode *dummy1, int dummy2, int rate, const char *dummy3)
Definition: device_mouse.c:62