From 2f91ddf8a8ff7bd11f9020453bac5969d246c479 Mon Sep 17 00:00:00 2001 From: "ngs.ch" Date: Wed, 15 Feb 2023 03:49:09 +0900 Subject: [PATCH 1/6] Move "detected_os" variable to global --- quantum/os_detection.c | 19 ++++++++++--------- quantum/os_detection.h | 2 ++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/quantum/os_detection.c b/quantum/os_detection.c index b1511afb149a..11304e8e6db5 100644 --- a/quantum/os_detection.c +++ b/quantum/os_detection.c @@ -36,7 +36,6 @@ struct setups_data_t { uint8_t cnt_04; uint8_t cnt_ff; uint16_t last_wlength; - os_variant_t detected_os; }; struct setups_data_t setups_data = { @@ -44,40 +43,41 @@ struct setups_data_t setups_data = { .cnt_02 = 0, .cnt_04 = 0, .cnt_ff = 0, - .detected_os = OS_UNSURE, }; +os_variant_t detected_os = OS_UNSURE; + // Some collected sequences of wLength can be found in tests. void make_guess(void) { if (setups_data.count < 3) { return; } if (setups_data.cnt_ff >= 2 && setups_data.cnt_04 >= 1) { - setups_data.detected_os = OS_WINDOWS; + detected_os = OS_WINDOWS; return; } if (setups_data.count == setups_data.cnt_ff) { // Linux has 3 packets with 0xFF. - setups_data.detected_os = OS_LINUX; + detected_os = OS_LINUX; return; } if (setups_data.count == 5 && setups_data.last_wlength == 0xFF && setups_data.cnt_ff == 1 && setups_data.cnt_02 == 2) { - setups_data.detected_os = OS_MACOS; + detected_os = OS_MACOS; return; } if (setups_data.count == 4 && setups_data.cnt_ff == 0 && setups_data.cnt_02 == 2) { // iOS and iPadOS don't have the last 0xFF packet. - setups_data.detected_os = OS_IOS; + detected_os = OS_IOS; return; } if (setups_data.cnt_ff == 0 && setups_data.cnt_02 == 3 && setups_data.cnt_04 == 1) { // This is actually PS5. - setups_data.detected_os = OS_LINUX; + detected_os = OS_LINUX; return; } if (setups_data.cnt_ff >= 1 && setups_data.cnt_02 == 0 && setups_data.cnt_04 == 0) { // This is actually Quest 2 or Nintendo Switch. - setups_data.detected_os = OS_LINUX; + detected_os = OS_LINUX; return; } } @@ -99,11 +99,12 @@ void process_wlength(const uint16_t w_length) { } os_variant_t detected_host_os(void) { - return setups_data.detected_os; + return detected_os; } void erase_wlength_data(void) { memset(&setups_data, 0, sizeof(setups_data)); + detected_os = OS_UNSURE; } #endif // OS_DETECTION_ENABLE diff --git a/quantum/os_detection.h b/quantum/os_detection.h index e643dcd27fab..8069657abaf1 100644 --- a/quantum/os_detection.h +++ b/quantum/os_detection.h @@ -27,6 +27,8 @@ typedef enum { OS_IOS, } os_variant_t; +extern os_variant_t detected_os; + void process_wlength(const uint16_t w_length); os_variant_t detected_host_os(void); void erase_wlength_data(void); From cb87ced6e2655fc4e3ff007076cb3f4d4af9352c Mon Sep 17 00:00:00 2001 From: "ngs.ch" Date: Wed, 15 Feb 2023 03:57:18 +0900 Subject: [PATCH 2/6] include "detected_os" in master to slave communication --- quantum/os_detection.h | 3 ++ quantum/split_common/transaction_id_define.h | 4 +++ quantum/split_common/transactions.c | 30 ++++++++++++++++++++ quantum/split_common/transport.h | 8 ++++++ 4 files changed, 45 insertions(+) diff --git a/quantum/os_detection.h b/quantum/os_detection.h index 8069657abaf1..eb02142f4153 100644 --- a/quantum/os_detection.h +++ b/quantum/os_detection.h @@ -27,6 +27,9 @@ typedef enum { OS_IOS, } os_variant_t; +/* splits where the slave side needs to process for rgb/oled functionality + * define "SPLIT_DETECTED_OS_ENABLE" to enable + */ extern os_variant_t detected_os; void process_wlength(const uint16_t w_length); diff --git a/quantum/split_common/transaction_id_define.h b/quantum/split_common/transaction_id_define.h index 18d3826b838c..e7a811556dc9 100644 --- a/quantum/split_common/transaction_id_define.h +++ b/quantum/split_common/transaction_id_define.h @@ -109,6 +109,10 @@ enum serial_transaction_id { SPLIT_TRANSACTION_IDS_USER, #endif // SPLIT_TRANSACTION_IDS_USER +#if defined(SPLIT_DETECTED_OS_ENABLE) + PUT_DETECTED_OS, +#endif // define(SPLIT_DETECTED_OS_ENABLE) + NUM_TOTAL_TRANSACTIONS }; diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index 8e1961b58623..00fbe2711404 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c @@ -790,6 +790,33 @@ static void haptic_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sla #endif // defined(HAPTIC_ENABLE) && defined(SPLIT_HAPTIC_ENABLE) +//////////////////////////////////////////////////// +// Detected OS + +#if defined(SPLIT_DETECTED_OS_ENABLE) + +static bool detected_os_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + static uint32_t last_detected_os_update = 0; + bool okay = send_if_condition(PUT_DETECTED_OS, &last_detected_os_update, (detected_os != split_shmem->detected_os), &detected_os, sizeof(os_variant_t)); + return okay; +} + +static void detected_os_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + memcpy(&detected_os, &split_shmem->detected_os, sizeof(os_variant_t)); +} + +# define TRANSACTIONS_DETECTED_OS_MASTER() TRANSACTION_HANDLER_MASTER(detected_os) +# define TRANSACTIONS_DETECTED_OS_SLAVE() TRANSACTION_HANDLER_SLAVE_AUTOLOCK(detected_os) +# define TRANSACTIONS_DETECTED_OS_REGISTRATIONS [PUT_DETECTED_OS] = trans_initiator2target_initializer(detected_os), + +#else // define(SPLIT_DETECTED_OS_ENABLE) + +# define TRANSACTIONS_DETECTED_OS_MASTER() +# define TRANSACTIONS_DETECTED_OS_SLAVE() +# define TRANSACTIONS_DETECTED_OS_REGISTRATIONS + +#endif // define(SPLIT_DETECTED_OS_ENABLE) + //////////////////////////////////////////////////// split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { @@ -818,6 +845,7 @@ split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = { TRANSACTIONS_POINTING_REGISTRATIONS TRANSACTIONS_WATCHDOG_REGISTRATIONS TRANSACTIONS_HAPTIC_REGISTRATIONS + TRANSACTIONS_DETECTED_OS_REGISTRATIONS // clang-format on #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) @@ -846,6 +874,7 @@ bool transactions_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix TRANSACTIONS_POINTING_MASTER(); TRANSACTIONS_WATCHDOG_MASTER(); TRANSACTIONS_HAPTIC_MASTER(); + TRANSACTIONS_DETECTED_OS_MASTER(); return true; } @@ -867,6 +896,7 @@ void transactions_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[ TRANSACTIONS_POINTING_SLAVE(); TRANSACTIONS_WATCHDOG_SLAVE(); TRANSACTIONS_HAPTIC_SLAVE(); + TRANSACTIONS_DETECTED_OS_SLAVE(); } #if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h index adee4470d22b..41e7e28b5db8 100644 --- a/quantum/split_common/transport.h +++ b/quantum/split_common/transport.h @@ -133,6 +133,10 @@ typedef struct _rpc_sync_info_t { } rpc_sync_info_t; #endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) +#if defined(SPLIT_DETECTED_OS_ENABLE) +# include "os_detection.h" +#endif // define(SPLIT_DETECTED_OS_ENABLE) + typedef struct _split_shared_memory_t { #ifdef USE_I2C int8_t transaction_id; @@ -209,6 +213,10 @@ typedef struct _split_shared_memory_t { uint8_t rpc_m2s_buffer[RPC_M2S_BUFFER_SIZE]; uint8_t rpc_s2m_buffer[RPC_S2M_BUFFER_SIZE]; #endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) + +#if defined(SPLIT_DETECTED_OS_ENABLE) + os_variant_t detected_os; +#endif // define(SPLIT_DETECTED_OS_ENABLE) } split_shared_memory_t; extern split_shared_memory_t *const split_shmem; From bba39f5200970e1e0f52654ca38241af7ea62755 Mon Sep 17 00:00:00 2001 From: "ngs.ch" Date: Sat, 18 Feb 2023 00:55:21 +0900 Subject: [PATCH 3/6] Add "defined(OS_DETECTION_ENABLE)" to #if statement --- quantum/split_common/transaction_id_define.h | 4 ++-- quantum/split_common/transactions.c | 6 +++--- quantum/split_common/transport.h | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/quantum/split_common/transaction_id_define.h b/quantum/split_common/transaction_id_define.h index e7a811556dc9..fd8894b72954 100644 --- a/quantum/split_common/transaction_id_define.h +++ b/quantum/split_common/transaction_id_define.h @@ -109,9 +109,9 @@ enum serial_transaction_id { SPLIT_TRANSACTION_IDS_USER, #endif // SPLIT_TRANSACTION_IDS_USER -#if defined(SPLIT_DETECTED_OS_ENABLE) +#if defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) PUT_DETECTED_OS, -#endif // define(SPLIT_DETECTED_OS_ENABLE) +#endif // defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) NUM_TOTAL_TRANSACTIONS }; diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index 00fbe2711404..17dce5b121e8 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c @@ -793,7 +793,7 @@ static void haptic_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sla //////////////////////////////////////////////////// // Detected OS -#if defined(SPLIT_DETECTED_OS_ENABLE) +#if defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) static bool detected_os_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { static uint32_t last_detected_os_update = 0; @@ -809,13 +809,13 @@ static void detected_os_handlers_slave(matrix_row_t master_matrix[], matrix_row_ # define TRANSACTIONS_DETECTED_OS_SLAVE() TRANSACTION_HANDLER_SLAVE_AUTOLOCK(detected_os) # define TRANSACTIONS_DETECTED_OS_REGISTRATIONS [PUT_DETECTED_OS] = trans_initiator2target_initializer(detected_os), -#else // define(SPLIT_DETECTED_OS_ENABLE) +#else // defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) # define TRANSACTIONS_DETECTED_OS_MASTER() # define TRANSACTIONS_DETECTED_OS_SLAVE() # define TRANSACTIONS_DETECTED_OS_REGISTRATIONS -#endif // define(SPLIT_DETECTED_OS_ENABLE) +#endif // defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) //////////////////////////////////////////////////// diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h index 41e7e28b5db8..361059735340 100644 --- a/quantum/split_common/transport.h +++ b/quantum/split_common/transport.h @@ -133,9 +133,9 @@ typedef struct _rpc_sync_info_t { } rpc_sync_info_t; #endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) -#if defined(SPLIT_DETECTED_OS_ENABLE) +#if defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) # include "os_detection.h" -#endif // define(SPLIT_DETECTED_OS_ENABLE) +#endif // defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) typedef struct _split_shared_memory_t { #ifdef USE_I2C @@ -214,9 +214,9 @@ typedef struct _split_shared_memory_t { uint8_t rpc_s2m_buffer[RPC_S2M_BUFFER_SIZE]; #endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) -#if defined(SPLIT_DETECTED_OS_ENABLE) +#if defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) os_variant_t detected_os; -#endif // define(SPLIT_DETECTED_OS_ENABLE) +#endif // defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) } split_shared_memory_t; extern split_shared_memory_t *const split_shmem; From 87cdecc4f5268350dc407ed3e0e653f24be5ca67 Mon Sep 17 00:00:00 2001 From: "ngs.ch" Date: Sat, 18 Feb 2023 01:03:06 +0900 Subject: [PATCH 4/6] change from global variable to function --- quantum/os_detection.c | 6 ++++++ quantum/os_detection.h | 9 ++++----- quantum/split_common/transactions.c | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/quantum/os_detection.c b/quantum/os_detection.c index 11304e8e6db5..be6cf85903ed 100644 --- a/quantum/os_detection.c +++ b/quantum/os_detection.c @@ -106,6 +106,12 @@ void erase_wlength_data(void) { memset(&setups_data, 0, sizeof(setups_data)); detected_os = OS_UNSURE; } + +# if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) +void slave_update_detected_host_os(os_variant_t os) { + detected_os = os; +} +# endif //defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) #endif // OS_DETECTION_ENABLE #ifdef OS_DETECTION_DEBUG_ENABLE diff --git a/quantum/os_detection.h b/quantum/os_detection.h index eb02142f4153..fcdd6198f4bd 100644 --- a/quantum/os_detection.h +++ b/quantum/os_detection.h @@ -27,14 +27,13 @@ typedef enum { OS_IOS, } os_variant_t; -/* splits where the slave side needs to process for rgb/oled functionality - * define "SPLIT_DETECTED_OS_ENABLE" to enable - */ -extern os_variant_t detected_os; - void process_wlength(const uint16_t w_length); os_variant_t detected_host_os(void); void erase_wlength_data(void); + +# if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) +void slave_update_detected_host_os(os_variant_t os); +# endif // defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) #endif #ifdef OS_DETECTION_DEBUG_ENABLE diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index 17dce5b121e8..bbf336e0598c 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c @@ -797,12 +797,13 @@ static void haptic_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sla static bool detected_os_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { static uint32_t last_detected_os_update = 0; + os_variant_t detected_os = detected_host_os(); bool okay = send_if_condition(PUT_DETECTED_OS, &last_detected_os_update, (detected_os != split_shmem->detected_os), &detected_os, sizeof(os_variant_t)); return okay; } static void detected_os_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { - memcpy(&detected_os, &split_shmem->detected_os, sizeof(os_variant_t)); + slave_update_detected_host_os(split_shmem->detected_os); } # define TRANSACTIONS_DETECTED_OS_MASTER() TRANSACTION_HANDLER_MASTER(detected_os) From da9de79fc44eb2f574796266a57611f5342f4f09 Mon Sep 17 00:00:00 2001 From: "ngs.ch" Date: Sun, 26 Feb 2023 02:37:22 +0900 Subject: [PATCH 5/6] fix format --- quantum/os_detection.c | 22 +++++++++++----------- quantum/os_detection.h | 4 ++-- quantum/split_common/transactions.c | 4 ++-- quantum/split_common/transport.h | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/quantum/os_detection.c b/quantum/os_detection.c index be6cf85903ed..4a94e4e41679 100644 --- a/quantum/os_detection.c +++ b/quantum/os_detection.c @@ -31,18 +31,18 @@ uint16_t usb_setups[STORED_USB_SETUPS]; #ifdef OS_DETECTION_ENABLE struct setups_data_t { - uint8_t count; - uint8_t cnt_02; - uint8_t cnt_04; - uint8_t cnt_ff; - uint16_t last_wlength; + uint8_t count; + uint8_t cnt_02; + uint8_t cnt_04; + uint8_t cnt_ff; + uint16_t last_wlength; }; struct setups_data_t setups_data = { - .count = 0, - .cnt_02 = 0, - .cnt_04 = 0, - .cnt_ff = 0, + .count = 0, + .cnt_02 = 0, + .cnt_04 = 0, + .cnt_ff = 0, }; os_variant_t detected_os = OS_UNSURE; @@ -107,11 +107,11 @@ void erase_wlength_data(void) { detected_os = OS_UNSURE; } -# if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) +# if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) void slave_update_detected_host_os(os_variant_t os) { detected_os = os; } -# endif //defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) +# endif //defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) #endif // OS_DETECTION_ENABLE #ifdef OS_DETECTION_DEBUG_ENABLE diff --git a/quantum/os_detection.h b/quantum/os_detection.h index fcdd6198f4bd..3496ea0ed219 100644 --- a/quantum/os_detection.h +++ b/quantum/os_detection.h @@ -31,9 +31,9 @@ void process_wlength(const uint16_t w_length); os_variant_t detected_host_os(void); void erase_wlength_data(void); -# if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) +# if defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) void slave_update_detected_host_os(os_variant_t os); -# endif // defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) +# endif // defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) #endif #ifdef OS_DETECTION_DEBUG_ENABLE diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index bbf336e0598c..fa783aa9c663 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c @@ -797,8 +797,8 @@ static void haptic_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sla static bool detected_os_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { static uint32_t last_detected_os_update = 0; - os_variant_t detected_os = detected_host_os(); - bool okay = send_if_condition(PUT_DETECTED_OS, &last_detected_os_update, (detected_os != split_shmem->detected_os), &detected_os, sizeof(os_variant_t)); + os_variant_t detected_os = detected_host_os(); + bool okay = send_if_condition(PUT_DETECTED_OS, &last_detected_os_update, (detected_os != split_shmem->detected_os), &detected_os, sizeof(os_variant_t)); return okay; } diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h index 361059735340..252dd5a10218 100644 --- a/quantum/split_common/transport.h +++ b/quantum/split_common/transport.h @@ -134,7 +134,7 @@ typedef struct _rpc_sync_info_t { #endif // defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER) #if defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) -# include "os_detection.h" +# include "os_detection.h" #endif // defined(OS_DETECTION_ENABLE) && defined(SPLIT_DETECTED_OS_ENABLE) typedef struct _split_shared_memory_t { From d655ec82ff0d6f32fc943953ec955733b8123af0 Mon Sep 17 00:00:00 2001 From: "ngs.ch" Date: Mon, 27 Feb 2023 14:35:30 +0900 Subject: [PATCH 6/6] fix format --- quantum/os_detection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quantum/os_detection.c b/quantum/os_detection.c index 4a94e4e41679..e606227136af 100644 --- a/quantum/os_detection.c +++ b/quantum/os_detection.c @@ -111,8 +111,8 @@ void erase_wlength_data(void) { void slave_update_detected_host_os(os_variant_t os) { detected_os = os; } -# endif //defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) -#endif // OS_DETECTION_ENABLE +# endif // defined(SPLIT_KEYBOARD) && defined(SPLIT_DETECTED_OS_ENABLE) +#endif // OS_DETECTION_ENABLE #ifdef OS_DETECTION_DEBUG_ENABLE void print_stored_setups(void) {