Created
June 26, 2021 21:40
-
-
Save mcrapet/40f8000b59a0a6b720c6c0e947012bf2 to your computer and use it in GitHub Desktop.
ckb-next-daemon K100 hack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/daemon/bragi_common.c b/src/daemon/bragi_common.c | |
index 03d8edd..9b61a3a 100644 | |
--- a/src/daemon/bragi_common.c | |
+++ b/src/daemon/bragi_common.c | |
@@ -4,8 +4,8 @@ | |
// Gets a property using the bragi protocol | |
// Error when return value < 0 | |
int bragi_get_property(usbdevice* kb, const uchar prop) { | |
- uchar pkt[64] = {BRAGI_MAGIC, BRAGI_GET, prop, 0}; | |
- uchar response[64] = {0}; | |
+ uchar pkt[1024] = {BRAGI_MAGIC, BRAGI_GET, prop, 0}; | |
+ uchar response[1024] = {0}; | |
if(!usbrecv(kb, pkt, sizeof(pkt), response)) | |
return -1; | |
if(response[2]) { | |
@@ -18,8 +18,8 @@ int bragi_get_property(usbdevice* kb, const uchar prop) { | |
// Sets a property using the bragi protocol | |
// Error when return value < 0. Success == 0 | |
int bragi_set_property(usbdevice* kb, const uchar prop, const uchar val) { | |
- uchar pkt[64] = {BRAGI_MAGIC, BRAGI_SET, prop, 0, val, 0}; | |
- uchar response[64] = {0}; | |
+ uchar pkt[1024] = {BRAGI_MAGIC, BRAGI_SET, prop, 0, val, 0}; | |
+ uchar response[1024] = {0}; | |
if(!usbrecv(kb, pkt, sizeof(pkt), response)) | |
return -1; | |
if(response[2]) { | |
diff --git a/src/daemon/keymap.c b/src/daemon/keymap.c | |
index 58c2ce9..fb801ed 100644 | |
--- a/src/daemon/keymap.c | |
+++ b/src/daemon/keymap.c | |
@@ -547,7 +547,7 @@ static inline void handle_bragi_key_input(unsigned char* kbinput, const unsigned | |
else | |
CLEAR_KEYBIT(kbinput, hid_codes[bit + 223]); | |
} | |
- | |
+ | |
// Followed by rwin at urbinput[14], bit 0 | |
if((urbinput[13] >> bit) & 1) | |
SET_KEYBIT(kbinput, hid_codes[bit + 223]); | |
@@ -569,12 +569,12 @@ void process_input_urb(void* context, unsigned char* buffer, int urblen, ushort | |
// Get first byte of the response | |
uchar firstbyte = buffer[0]; | |
- // If the response starts with CMD_GET (0x0e), or it came from ep4 with bragi, that means it needs to go to os_usbrecv() | |
- if(urblen == MSG_SIZE && (firstbyte == CMD_GET || (kb->protocol == PROTO_BRAGI && ep == 0x84))){ | |
+ // If the response starts with CMD_GET (0x0e), or it came from ep2 with bragi, that means it needs to go to os_usbrecv() | |
+ if(urblen == 1024 && (firstbyte == CMD_GET || (kb->protocol == PROTO_BRAGI && ep == 0x82))){ | |
int retval = pthread_mutex_lock(intmutex(kb)); | |
if(retval) | |
ckb_fatal("Error locking interrupt mutex %i", retval); | |
- memcpy(kb->interruptbuf, buffer, MSG_SIZE); | |
+ memcpy(kb->interruptbuf, buffer, 1024); | |
// signal os_usbrecv() that the data is ready. | |
retval = pthread_cond_broadcast(intcond(kb)); | |
if(retval) | |
@@ -882,7 +882,7 @@ void corsair_bragi_mousecopy(unsigned char* kbinput, const unsigned char* urbinp | |
else | |
CLEAR_KEYBIT(kbinput, MOUSE_BUTTON_FIRST + corsair_bragi_lut[bit]); | |
} | |
- | |
+ | |
char wheel = urbinput[2]; | |
if(wheel > 0) | |
SET_KEYBIT(kbinput, MOUSE_EXTRA_FIRST); | |
diff --git a/src/daemon/usb.c b/src/daemon/usb.c | |
index 3b5e009..c706f5e 100644 | |
--- a/src/daemon/usb.c | |
+++ b/src/daemon/usb.c | |
@@ -69,6 +69,7 @@ device_desc models[] = { | |
{ V_CORSAIR, P_STRAFE_NRGB_2, }, | |
{ V_CORSAIR, P_STRAFE_MK2, }, | |
{ V_CORSAIR, P_K95_PLATINUM_XT, }, | |
+ { V_CORSAIR, P_K100, }, | |
// Mice | |
{ V_CORSAIR, P_M65, }, | |
{ V_CORSAIR, P_M65_PRO, }, | |
@@ -158,6 +159,8 @@ const char* vendor_str(ushort vendor){ | |
/// product_str() needs the \a product \a ID | |
/// | |
const char* product_str(ushort product){ | |
+ if(product == P_K100) | |
+ return "k100"; | |
if(product == P_K95 || product == P_K95_LEGACY) | |
return "k95"; | |
if(product == P_K95_PLATINUM || product == P_K95_PLATINUM_XT) | |
diff --git a/src/daemon/usb.h b/src/daemon/usb.h | |
index 3fb17d0..1f4ac39 100644 | |
--- a/src/daemon/usb.h | |
+++ b/src/daemon/usb.h | |
@@ -84,7 +84,8 @@ | |
#define P_K95_LEGACY 0x1b08 | |
#define P_K95_PLATINUM 0x1b2d | |
#define P_K95_PLATINUM_XT 0x1b89 // Don't think this needs to be in the macro | |
-#define IS_K95(kb) ((kb)->vendor == V_CORSAIR && ((kb)->product == P_K90_LEGACY || (kb)->product == P_K95 || (kb)->product == P_K95_LEGACY || (kb)->product == P_K95_PLATINUM)) | |
+#define P_K100 0x1b7c | |
+#define IS_K95(kb) ((kb)->vendor == V_CORSAIR && ((kb)->product == P_K90_LEGACY || (kb)->product == P_K95 || (kb)->product == P_K95_LEGACY || (kb)->product == P_K95_PLATINUM || (kb)->product == P_K100)) | |
#define P_STRAFE 0x1b20 | |
#define P_STRAFE_NRGB 0x1b15 /* 3-bit lighting, 9-bit protocol */ | |
@@ -265,7 +266,7 @@ const char* product_str(ushort product); | |
#define USB_DELAY_DEFAULT 5 | |
// This should be removed in the future when we implement autodetection | |
-#define USES_BRAGI(vendor, product) ((vendor) == (V_CORSAIR) && ((product) == (P_IRONCLAW_W_U) || (product) == (P_IRONCLAW_W_D) || (product) == (P_K95_PLATINUM_XT))) | |
+#define USES_BRAGI(vendor, product) ((vendor) == (V_CORSAIR) && ((product) == (P_IRONCLAW_W_U) || (product) == (P_IRONCLAW_W_D) || (product) == (P_K95_PLATINUM_XT) || (product) == (P_K100))) | |
/// Start the USB main loop. Returns program exit code when finished | |
int usbmain(); | |
diff --git a/src/daemon/usb_bragi.c b/src/daemon/usb_bragi.c | |
index 297124c..e3c18f2 100644 | |
--- a/src/daemon/usb_bragi.c | |
+++ b/src/daemon/usb_bragi.c | |
@@ -10,9 +10,9 @@ void bragi_fill_input_eps(usbdevice* kb) | |
int bragi_usb_write(usbdevice* kb, void* out, int len, int is_recv, const char* file, int line) | |
{ | |
- if(len != 64) | |
+ if(len != 1024) | |
{ | |
- ckb_fatal_fn("len != 64 not yet supported in Bragi backend", file, line); | |
+ ckb_fatal_fn("len != 1024 not yet supported in Bragi backend", file, line); | |
return -1; | |
} | |
@@ -23,7 +23,7 @@ int bragi_usb_write(usbdevice* kb, void* out, int len, int is_recv, const char* | |
// All firmware versions for normal HID devices have the OUT endpoint at the end | |
// Devices with no input, such as the Polaris, have it at the start. | |
- unsigned int ep = (IS_SINGLE_EP(kb) ? 1 : kb->epcount); | |
+ unsigned int ep = 1; //(IS_SINGLE_EP(kb) ? 1 : kb->epcount); | |
int res = os_usb_interrupt_out(kb, ep, len, out, file, line); | |
// Unlock on failure | |
if(is_recv && res < 1) | |
@@ -33,9 +33,9 @@ int bragi_usb_write(usbdevice* kb, void* out, int len, int is_recv, const char* | |
int bragi_usb_read(usbdevice* kb, void* in, int len, int dummy, const char* file, int line) | |
{ | |
- if(len != 64) | |
+ if(len != 1024) | |
{ | |
- ckb_fatal_fn("len != 64 not yet supported in Bragi backend", file, line); | |
+ ckb_fatal_fn("len != 1024 not yet supported in Bragi backend", file, line); | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment