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
usb.h
Go to the documentation of this file.
1 #ifndef USB_H
2 #define USB_H
3 
4 #include "includes.h"
5 #include "keymap.h"
6 
30 
38 #define V_CORSAIR 0x1b1c
39 #define V_CORSAIR_STR "1b1c"
40 
41 #define P_K65 0x1b17
42 #define P_K65_STR "1b17"
43 #define P_K65_NRGB 0x1b07
44 #define P_K65_NRGB_STR "1b07"
45 #define P_K65_LUX 0x1b37
46 #define P_K65_LUX_STR "1b37"
47 #define P_K65_RFIRE 0x1b39
48 #define P_K65_RFIRE_STR "1b39"
49 #define IS_K65(kb) ((kb)->vendor == V_CORSAIR && ((kb)->product == P_K65 || (kb)->product == P_K65_NRGB || (kb)->product == P_K65_LUX || (kb)->product == P_K65_RFIRE))
50 
51 #define P_K70 0x1b13
52 #define P_K70_STR "1b13"
53 #define P_K70_NRGB 0x1b09
54 #define P_K70_NRGB_STR "1b09"
55 #define P_K70_LUX 0x1b33
56 #define P_K70_LUX_STR "1b33"
57 #define P_K70_LUX_NRGB 0x1b36
58 #define P_K70_LUX_NRGB_STR "1b36"
59 #define P_K70_RFIRE 0x1b38
60 #define P_K70_RFIRE_STR "1b38"
61 #define P_K70_RFIRE_NRGB 0x1b3a
62 #define P_K70_RFIRE_NRGB_STR "1b3a"
63 #define IS_K70(kb) ((kb)->vendor == V_CORSAIR && ((kb)->product == P_K70 || (kb)->product == P_K70_NRGB || (kb)->product == P_K70_RFIRE || (kb)->product == P_K70_RFIRE_NRGB || (kb)->product == P_K70_LUX || (kb)->product == P_K70_LUX_NRGB))
64 
65 #define P_K95 0x1b11
66 #define P_K95_STR "1b11"
67 #define P_K95_NRGB 0x1b08
68 #define P_K95_NRGB_STR "1b08"
69 #define P_K95_PLATINUM 0x1b2d
70 #define P_K95_PLATINUM_STR "1b2d"
71 #define IS_K95(kb) ((kb)->vendor == V_CORSAIR && ((kb)->product == P_K95 || (kb)->product == P_K95_NRGB || (kb)->product == P_K95_PLATINUM))
72 
73 #define P_STRAFE 0x1b20
74 #define P_STRAFE_STR "1b20"
75 #define P_STRAFE_NRGB 0x1b15
76 #define P_STRAFE_NRGB_STR "1b15"
77 #define IS_STRAFE(kb) ((kb)->vendor == V_CORSAIR && ((kb)->product == P_STRAFE || (kb)->product == P_STRAFE_NRGB))
78 
79 #define P_M65 0x1b12
80 #define P_M65_STR "1b12"
81 #define P_M65_PRO 0x1b2e
82 #define P_M65_PRO_STR "1b2e"
83 #define IS_M65(kb) ((kb)->vendor == V_CORSAIR && ((kb)->product == P_M65 || (kb)->product == P_M65_PRO))
84 
85 #define P_SABRE_O 0x1b14 /* optical */
86 #define P_SABRE_O_STR "1b14"
87 #define P_SABRE_L 0x1b19 /* laser */
88 #define P_SABRE_L_STR "1b19"
89 #define P_SABRE_N 0x1b2f /* new? */
90 #define P_SABRE_N_STR "1b2f"
91 #define P_SABRE_O2 0x1b32 /* Observed on a CH-9000111-EU model SABRE */
92 #define P_SABRE_O2_STR "1b32"
93 #define IS_SABRE(kb) ((kb)->vendor == V_CORSAIR && ((kb)->product == P_SABRE_O || (kb)->product == P_SABRE_L || (kb)->product == P_SABRE_N || (kb)->product == P_SABRE_O2))
94 
95 #define P_SCIMITAR 0x1b1e
96 #define P_SCIMITAR_STR "1b1e"
97 #define P_SCIMITAR_PRO 0x1b3e
98 #define P_SCIMITAR_PRO_STR "1b3e"
99 #define IS_SCIMITAR(kb) ((kb)->vendor == V_CORSAIR && ((kb)->product == P_SCIMITAR || (kb)->product == P_SCIMITAR_PRO))
100 
103 // #define DEBUG_USB
104 
107 // #define DEBUG_USB_RECV
108 
113 const char* vendor_str(short vendor);
114 
119 const char* product_str(short product);
120 
124 #define IS_RGB(vendor, product) ((vendor) == (V_CORSAIR) && (product) != (P_K65_NRGB) && (product) != (P_K70_NRGB) && (product) != (P_K95_NRGB))
125 
129 #define IS_MONOCHROME(vendor, product) ((vendor) == (V_CORSAIR) && (product) == (P_STRAFE_NRGB))
130 
132 #define IS_RGB_DEV(kb) IS_RGB((kb)->vendor, (kb)->product)
133 
135 #define IS_MONOCHROME_DEV(kb) IS_MONOCHROME((kb)->vendor, (kb)->product)
136 
138 #define IS_FULLRANGE(kb) (IS_RGB((kb)->vendor, (kb)->product) && (kb)->product != P_K65 && (kb)->product != P_K70 && (kb)->product != P_K95)
139 
141 #define IS_MOUSE(vendor, product) ((vendor) == (V_CORSAIR) && ((product) == (P_M65) || (product) == (P_M65_PRO) || (product) == (P_SABRE_O) || (product) == (P_SABRE_L) || (product) == (P_SABRE_N) || (product) == (P_SCIMITAR) || (product) == (P_SCIMITAR_PRO) || (product) == (P_SABRE_O2)))
142 
144 #define IS_MOUSE_DEV(kb) IS_MOUSE((kb)->vendor, (kb)->product)
145 
149 #define DELAY_SHORT(kb) usleep((int)(kb)->usbdelay * 1000) // base (default: 5ms)
150 
152 #define DELAY_MEDIUM(kb) usleep((int)(kb)->usbdelay * 10000) // x10 (default: 50ms)
153 
155 #define DELAY_LONG(kb) usleep(100000) // long, fixed 100ms
156 
160 #define USB_DELAY_DEFAULT 5
161 
163 int usbmain();
164 
166 void usbkill();
167 
173 void setupusb(usbdevice* kb);
174 
179 int os_setupusb(usbdevice* kb);
180 
186 void* os_inputmain(void* context);
187 
191 int revertusb(usbdevice* kb);
192 
197 int closeusb(usbdevice* kb);
198 
203 void os_closeusb(usbdevice* kb);
204 
211 int _resetusb(usbdevice* kb, const char* file, int line);
212 
214 #define resetusb(kb) _resetusb(kb, __FILE_NOPATH__, __LINE__)
215 
222 int os_resetusb(usbdevice* kb, const char* file, int line);
223 
233 int _usbsend(usbdevice* kb, const uchar* messages, int count, const char* file, int line);
234 
239 #define usbsend(kb, messages, count) _usbsend(kb, messages, count, __FILE_NOPATH__, __LINE__)
240 
250 int _usbrecv(usbdevice* kb, const uchar* out_msg, uchar* in_msg, const char* file, int line);
251 
256 #define usbrecv(kb, out_msg, in_msg) _usbrecv(kb, out_msg, in_msg, __FILE_NOPATH__, __LINE__)
257 
266 int os_usbsend(usbdevice* kb, const uchar* out_msg, int is_recv, const char* file, int line);
267 
275 int os_usbrecv(usbdevice* kb, uchar* in_msg, const char* file, int line);
276 
280 void os_sendindicators(usbdevice* kb);
281 
290 int _nk95cmd(usbdevice* kb, uchar bRequest, ushort wValue, const char* file, int line);
291 
296 #define nk95cmd(kb, command) _nk95cmd(kb, (command) >> 16 & 0xFF, (command) & 0xFFFF, __FILE_NOPATH__, __LINE__)
297 
301 #define NK95_HWOFF 0x020030
302 
304 #define NK95_HWON 0x020001
305 
307 #define NK95_M1 0x140001
308 
310 #define NK95_M2 0x140002
311 
313 #define NK95_M3 0x140003
314 
320 int usb_tryreset(usbdevice* kb);
321 
322 #endif // USB_H
int usbmain()
Start the USB main loop. Returns program exit code when finished.
Definition: usb_linux.c:775
int os_resetusb(usbdevice *kb, const char *file, int line)
os_resetusb is the os specific implementation for resetting usb
Definition: usb_linux.c:497
void * os_inputmain(void *context)
os_inputmain is run in a separate thread and will be detached from the main thread, so it needs to clean up its own resources.
Definition: usb_linux.c:238
void os_closeusb(usbdevice *kb)
os_closeusb unclaim it, destroy the udev device and clear data structures at kb
Definition: usb_linux.c:435
const char * vendor_str(short vendor)
uncomment the following Define to see USB packets sent to the device
Definition: usb.c:43
int os_usbrecv(usbdevice *kb, uchar *in_msg, const char *file, int line)
os_usbrecv receives a max MSGSIZE long buffer from usb device
Definition: usb_linux.c:129
int os_setupusb(usbdevice *kb)
os_setupusb OS-specific setup for a specific usb device.
Definition: usb_linux.c:535
unsigned char uchar
Definition: includes.h:24
int usb_tryreset(usbdevice *kb)
usb_tryreset does what the name means: Try to reset the usb via resetusb()
Definition: usb.c:465
unsigned short ushort
Definition: includes.h:25
int closeusb(usbdevice *kb)
closeusb Close a USB device and remove device entry.
Definition: usb.c:677
int _usbsend(usbdevice *kb, const uchar *messages, int count, const char *file, int line)
_usbsend send a logical message completely to the given device
Definition: usb.c:532
const char * product_str(short product)
product_str returns a condensed view on what type of device we have.
Definition: usb.c:70
int revertusb(usbdevice *kb)
revertusb sets a given device to inactive (hardware controlled) mode if not a fw-ugrade is indicated ...
Definition: usb.c:407
void setupusb(usbdevice *kb)
setupusb starts a thread with kb as parameter and _setupusb() as entrypoint.
Definition: usb.c:386
int _resetusb(usbdevice *kb, const char *file, int line)
_resetusb Reset a USB device.
Definition: usb.c:426
void os_sendindicators(usbdevice *kb)
os_sendindicators update the indicators for the special keys (Numlock, Capslock and what else...
Definition: usb_linux.c:213
int _nk95cmd(usbdevice *kb, uchar bRequest, ushort wValue, const char *file, int line)
_nk95cmd If we control a non RGB keyboard, set the keyboard via ioctl with usbdevfs_ctrltransfer ...
Definition: usb_linux.c:188
int _usbrecv(usbdevice *kb, const uchar *out_msg, uchar *in_msg, const char *file, int line)
_usbrecv Request data from a USB device by first sending an output packet and then reading the respon...
Definition: usb.c:601
void usbkill()
Stop the USB system.
Definition: usb_linux.c:835
int os_usbsend(usbdevice *kb, const uchar *out_msg, int is_recv, const char *file, int line)
os_usbsend sends a data packet (MSG_SIZE = 64) Bytes long
Definition: usb_linux.c:68