42 #define V_CORSAIR 0x1b1c
43 #define V_CORSAIR_STR "1b1c"
45 #define P_K63_NRGB 0x1b40
46 #define P_K63_NRGB_STR "1b40"
47 #define IS_K63(kb) ((kb)->vendor == V_CORSAIR && (kb)->product == P_K63_NRGB)
50 #define P_K65_STR "1b17"
51 #define P_K65_NRGB 0x1b07
52 #define P_K65_NRGB_STR "1b07"
53 #define P_K65_LUX 0x1b37
54 #define P_K65_LUX_STR "1b37"
55 #define P_K65_RFIRE 0x1b39
56 #define P_K65_RFIRE_STR "1b39"
57 #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))
60 #define P_K68_STR "1b3f"
61 #define IS_K68(kb) ((kb)->vendor == V_CORSAIR && (kb)->product == P_K68)
64 #define P_K70_STR "1b13"
65 #define P_K70_NRGB 0x1b09
66 #define P_K70_NRGB_STR "1b09"
67 #define P_K70_LUX 0x1b33
68 #define P_K70_LUX_STR "1b33"
69 #define P_K70_LUX_NRGB 0x1b36
70 #define P_K70_LUX_NRGB_STR "1b36"
71 #define P_K70_RFIRE 0x1b38
72 #define P_K70_RFIRE_STR "1b38"
73 #define P_K70_RFIRE_NRGB 0x1b3a
74 #define P_K70_RFIRE_NRGB_STR "1b3a"
75 #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))
78 #define P_K95_STR "1b11"
79 #define P_K95_NRGB 0x1b08
80 #define P_K95_NRGB_STR "1b08"
81 #define P_K95_PLATINUM 0x1b2d
82 #define P_K95_PLATINUM_STR "1b2d"
83 #define IS_K95(kb) ((kb)->vendor == V_CORSAIR && ((kb)->product == P_K95 || (kb)->product == P_K95_NRGB || (kb)->product == P_K95_PLATINUM))
85 #define P_STRAFE 0x1b20
86 #define P_STRAFE_STR "1b20"
87 #define P_STRAFE_NRGB 0x1b15
88 #define P_STRAFE_NRGB_STR "1b15"
89 #define P_STRAFE_NRGB_2 0x1b44
90 #define P_STRAFE_NRGB_2_STR "1b44"
91 #define IS_STRAFE(kb) ((kb)->vendor == V_CORSAIR && ((kb)->product == P_STRAFE || (kb)->product == P_STRAFE_NRGB || (kb)->product == P_STRAFE_NRGB_2))
94 #define P_M65_STR "1b12"
95 #define P_M65_PRO 0x1b2e
96 #define P_M65_PRO_STR "1b2e"
97 #define IS_M65(kb) ((kb)->vendor == V_CORSAIR && ((kb)->product == P_M65 || (kb)->product == P_M65_PRO))
99 #define P_SABRE_O 0x1b14
100 #define P_SABRE_O_STR "1b14"
101 #define P_SABRE_L 0x1b19
102 #define P_SABRE_L_STR "1b19"
103 #define P_SABRE_N 0x1b2f
104 #define P_SABRE_N_STR "1b2f"
105 #define P_SABRE_O2 0x1b32
106 #define P_SABRE_O2_STR "1b32"
107 #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))
109 #define P_SCIMITAR 0x1b1e
110 #define P_SCIMITAR_STR "1b1e"
111 #define P_SCIMITAR_PRO 0x1b3e
112 #define P_SCIMITAR_PRO_STR "1b3e"
113 #define IS_SCIMITAR(kb) ((kb)->vendor == V_CORSAIR && ((kb)->product == P_SCIMITAR || (kb)->product == P_SCIMITAR_PRO))
115 #define P_HARPOON 0x1b3c
116 #define P_HARPOON_STR "1b3c"
117 #define IS_HARPOON(kb) ((kb)->vendor == V_CORSAIR && (kb)->product == P_HARPOON)
119 #define P_GLAIVE 0x1b34
120 #define P_GLAIVE_STR "1b34"
121 #define IS_GLAIVE(kb) ((kb)->vendor == V_CORSAIR && (kb)->product == P_GLAIVE)
146 #define IS_RGB(vendor, product) ((vendor) == (V_CORSAIR) && (product) != (P_K65_NRGB) && (product) != (P_K70_NRGB) && (product) != (P_K95_NRGB))
151 #define IS_MONOCHROME(vendor, product) ((vendor) == (V_CORSAIR) && ((product) == (P_K68) || (product) == (P_STRAFE_NRGB) || (product) == (P_STRAFE_NRGB_2)))
154 #define IS_RGB_DEV(kb) IS_RGB((kb)->vendor, (kb)->product)
157 #define IS_MONOCHROME_DEV(kb) IS_MONOCHROME((kb)->vendor, (kb)->product)
160 #define IS_FULLRANGE(kb) (IS_RGB((kb)->vendor, (kb)->product) && (kb)->product != P_K65 && (kb)->product != P_K70 && (kb)->product != P_K95)
163 #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) || (product) == (P_GLAIVE) || (product) == (P_HARPOON)))
166 #define IS_MOUSE_DEV(kb) IS_MOUSE((kb)->vendor, (kb)->product)
169 #define IS_PLATINUM(kb) ((kb)->vendor == V_CORSAIR && ((kb)->product == P_K95_PLATINUM))
172 #define IS_V2_OVERRIDE(kb) (IS_PLATINUM(kb) || IS_K63(kb) || IS_K68(kb) || IS_HARPOON(kb) || IS_GLAIVE(kb) || (kb)->product == P_STRAFE_NRGB_2)
178 #define DELAY_SHORT(kb) \
179 clock_nanosleep(CLOCK_MONOTONIC, 0, &(struct timespec) {.tv_nsec = ((int) (kb->usbdelay)) * 1000000}, NULL) // base (default: 5ms)
182 #define DELAY_MEDIUM(kb) \
183 clock_nanosleep(CLOCK_MONOTONIC, 0, &(struct timespec) {.tv_nsec = ((int) (kb->usbdelay)) * 10000000}, NULL) // x10 (default: 50ms)
186 #define DELAY_LONG(kb) \
187 clock_nanosleep(CLOCK_MONOTONIC, 0, &(struct timespec) {.tv_nsec = 100000000}, NULL) // long, fixed 100ms
192 #define USB_DELAY_DEFAULT 5
246 #define resetusb(kb) _resetusb(kb, __FILE_NOPATH__, __LINE__)
271 #define usbsend(kb, messages, count) _usbsend(kb, messages, count, __FILE_NOPATH__, __LINE__)
288 #define usbrecv(kb, out_msg, in_msg) _usbrecv(kb, out_msg, in_msg, __FILE_NOPATH__, __LINE__)
328 #define nk95cmd(kb, command) _nk95cmd(kb, (command) >> 16 & 0xFF, (command) & 0xFFFF, __FILE_NOPATH__, __LINE__)
333 #define NK95_HWOFF 0x020030
336 #define NK95_HWON 0x020001
339 #define NK95_M1 0x140001
342 #define NK95_M2 0x140002
345 #define NK95_M3 0x140003
int usbmain()
Start the USB main loop. Returns program exit code when finished.
int os_resetusb(usbdevice *kb, const char *file, int line)
os_resetusb is the os specific implementation for resetting usb
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.
void os_closeusb(usbdevice *kb)
os_closeusb unclaim it, destroy the udev device and clear data structures at kb
const char * vendor_str(short vendor)
uncomment to see USB packets sent to the device
int os_usbrecv(usbdevice *kb, uchar *in_msg, const char *file, int line)
os_usbrecv receives a max MSGSIZE long buffer from usb device
int os_setupusb(usbdevice *kb)
os_setupusb OS-specific setup for a specific usb device.
int usb_tryreset(usbdevice *kb)
usb_tryreset does what the name means: Try to reset the usb via resetusb()
int closeusb(usbdevice *kb)
closeusb Close a USB device and remove device entry.
int _usbsend(usbdevice *kb, const uchar *messages, int count, const char *file, int line)
_usbsend send a logical message completely to the given device
const char * product_str(short product)
product_str returns a condensed view on what type of device we have.
int revertusb(usbdevice *kb)
revertusb sets a given device to inactive (hardware controlled) mode if not a fw-ugrade is indicated ...
void setupusb(usbdevice *kb)
setupusb starts a thread with kb as parameter and _setupusb() as entrypoint.
int _resetusb(usbdevice *kb, const char *file, int line)
_resetusb Reset a USB device.
void os_sendindicators(usbdevice *kb)
os_sendindicators update the indicators for the special keys (Numlock, Capslock and what else...
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 ...
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...
void usbkill()
Stop the USB system.
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