Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make "detected_host_os()" available on the SLAVE side of the split keyboard #19854

Merged
merged 7 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions quantum/os_detection.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,48 @@ 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 = {
.count = 0,
.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;
}
}
Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions quantum/os_detection.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ 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;
drashna marked this conversation as resolved.
Show resolved Hide resolved

void process_wlength(const uint16_t w_length);
os_variant_t detected_host_os(void);
void erase_wlength_data(void);
Expand Down
4 changes: 4 additions & 0 deletions quantum/split_common/transaction_id_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ enum serial_transaction_id {
SPLIT_TRANSACTION_IDS_USER,
#endif // SPLIT_TRANSACTION_IDS_USER

#if defined(SPLIT_DETECTED_OS_ENABLE)
drashna marked this conversation as resolved.
Show resolved Hide resolved
PUT_DETECTED_OS,
#endif // define(SPLIT_DETECTED_OS_ENABLE)

NUM_TOTAL_TRANSACTIONS
};

Expand Down
30 changes: 30 additions & 0 deletions quantum/split_common/transactions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
drashna marked this conversation as resolved.
Show resolved Hide resolved

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] = {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions quantum/split_common/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
drashna marked this conversation as resolved.
Show resolved Hide resolved
# include "os_detection.h"
#endif // define(SPLIT_DETECTED_OS_ENABLE)

typedef struct _split_shared_memory_t {
#ifdef USE_I2C
int8_t transaction_id;
Expand Down Expand Up @@ -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)
drashna marked this conversation as resolved.
Show resolved Hide resolved
os_variant_t detected_os;
#endif // define(SPLIT_DETECTED_OS_ENABLE)
} split_shared_memory_t;

extern split_shared_memory_t *const split_shmem;