From 4dbb0521342a1e09266cd646b30d86970b863ff7 Mon Sep 17 00:00:00 2001 From: Gonzalo Adrio Date: Wed, 4 Nov 2026 21:27:50 +0100 Subject: [PATCH 1/9] hidpp: enable RS H-Shifter gate routing in desktop mode In Desktop mode (profile 0), the RS50 base suppresses accessory gate reporting for gears 1-6 and Reverse on interface 0 unless G HUB's slot routing and sync sequence is sent. Discover GAMING_ATTACHMENTS (0x8120) and RS_H_SHIFTER (0x812D), and invoke hidpp_dd_enable_desktop_shifter() when entering or detecting Desktop mode if an RS H-Shifter is present (h_shifter_dev_idx). Signed-off-by: Gonzalo Adrio --- mainline/hid-logitech-hidpp.c | 101 ++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/mainline/hid-logitech-hidpp.c b/mainline/hid-logitech-hidpp.c index ab81cf5..3aedeb4 100644 --- a/mainline/hid-logitech-hidpp.c +++ b/mainline/hid-logitech-hidpp.c @@ -5414,6 +5414,8 @@ static void hidpp_ff_retry_work(struct work_struct *work) */ #define HIDPP_DD_PEDAL_BASE_AXIS(pedal) ((pedal) + 1) #define HIDPP_DD_PAGE_CALIBRATE 0x812C /* Centre calibration (G Pro sub-device 0x05) */ +#define HIDPP_DD_PAGE_ATTACHMENTS 0x8120 /* GAMING_ATTACHMENTS accessory slot routing */ +#define HIDPP_DD_PAGE_RS_H_SHIFTER 0x812D /* RS H-Shifter capabilities (sub-device) */ #define HIDPP_DD_PAGE_SYNC 0x1BC0 /* Unknown sync/prepare feature */ /* * BANDED_AXIS and DEVICE_MODE: names are first-party (Solaar's HID++ 2.0 @@ -5932,6 +5934,9 @@ struct hidpp_dd_ff_data { u8 idx_shifter_curve; /* Feature index for 0x80A4 on the accessory (dev shifter_dev_idx, axis 0 = handbrake) */ u8 idx_shifter_banded; /* Feature index for 0x80B1 BANDED_AXIS on the accessory */ u8 idx_shifter_mode; /* Feature index for 0x1B30 DEVICE_MODE on the accessory */ + u8 h_shifter_dev_idx; /* HID++ dev index of RS H-Shifter */ + u8 idx_h_shifter; /* Feature index for 0x812D RS_H_SHIFTER */ + u8 idx_attachments; /* Feature index for 0x8120 GAMING_ATTACHMENTS */ struct work_struct accessory_rescan_work; /* re-checks accessory presence off the sysfs read path */ unsigned long accessory_rescan_next; /* jiffies before which no further rescan is queued */ u8 accessory_scan_cursor; /* next candidate index a presence rescan will try */ @@ -8748,6 +8753,9 @@ static void hidpp_dd_discover_settings_features(struct hidpp_dd_ff_data *ff) ff->idx_shifter_curve = HIDPP_DD_FEATURE_NOT_FOUND; ff->idx_shifter_banded = HIDPP_DD_FEATURE_NOT_FOUND; ff->idx_shifter_mode = HIDPP_DD_FEATURE_NOT_FOUND; + ff->h_shifter_dev_idx = HIDPP_DD_FEATURE_NOT_FOUND; + ff->idx_h_shifter = HIDPP_DD_FEATURE_NOT_FOUND; + ff->idx_attachments = HIDPP_DD_FEATURE_NOT_FOUND; ff->accessory_name[0] = '\0'; /* * Explicitly now, not the kzalloc'd 0: jiffies starts at INITIAL_JIFFIES @@ -8968,6 +8976,26 @@ static void hidpp_dd_discover_settings_features(struct hidpp_dd_ff_data *ff) hidpp_dd_query_accessory_name(ff, cand); } } + + /* Discover RS H-Shifter (0x812D) across candidate sub-devices */ + for (i = 0; i < ARRAY_SIZE(hidpp_dd_pedal_dev_candidates); i++) { + u8 cand = hidpp_dd_pedal_dev_candidates[i]; + u8 cand_idx; + + if (cand == ff->pedal_dev_idx || cand == ff->shifter_dev_idx) + continue; + + ret = hidpp_root_get_feature_on_device_timeout(hidpp, cand, + HIDPP_DD_PAGE_RS_H_SHIFTER, + &cand_idx, HIDPP_DD_PROBE_TIMEOUT); + if (ret == 0) { + ff->h_shifter_dev_idx = cand; + ff->idx_h_shifter = cand_idx; + dd_info(hid, "RS H-Shifter at dev 0x%02x (idx 0x%02x)\n", + cand, cand_idx); + break; + } + } if (ff->pedal_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) dd_dbg(hid, "Pedal response curve feature at index 0x%02x (dev 0x%02x)\n", ff->idx_pedal_curve, ff->pedal_dev_idx); @@ -9181,6 +9209,10 @@ static void hidpp_dd_discover_lightsync_features(struct hidpp_dd_ff_data *ff) ret = hidpp_root_get_feature(hidpp, HIDPP_DD_PAGE_SYNC, &ff->idx_sync); if (ret == 0) dd_dbg(hid, "Sync feature at index 0x%02x\n", ff->idx_sync); + + ret = hidpp_root_get_feature(hidpp, HIDPP_DD_PAGE_ATTACHMENTS, &ff->idx_attachments); + if (ret == 0) + dd_dbg(hid, "Attachments feature at index 0x%02x\n", ff->idx_attachments); } /* @@ -9206,6 +9238,61 @@ static void hidpp_dd_ff_discover_features(struct hidpp_dd_ff_data *ff) dd_dbg(hid, "Feature discovery completed\n"); } +/* + * Desktop mode shifter enablement. + * + * In Desktop mode (profile 0), the RS50 base suppresses sub-device + * gate reporting (gears 1-6 and Reverse) unless G HUB's slot routing, + * sync and accessory enable commands are sent. In Onboard mode (profiles + * 1-5), the base routes all gates automatically. + */ +static void hidpp_dd_enable_desktop_shifter(struct hidpp_dd_ff_data *ff) +{ + static const u8 slot_routing[16] = { + 0x0a, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a + }; + struct hidpp_device *hidpp = ff->hidpp; + struct hid_device *hid = hidpp->hid_dev; + struct hidpp_report response; + u8 params[16]; + int ret; + + if (ff->h_shifter_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND) + return; + + /* 1. Feature 0x8120 GAMING_ATTACHMENTS on base */ + if (ff->idx_attachments != HIDPP_DD_FEATURE_NOT_FOUND) { + memset(params, 0, sizeof(params)); + ret = hidpp_send_fap_command_sync(hidpp, ff->idx_attachments, + 0x00 /* fn0 */, params, 0, &response); + if (ret) + dd_warn(hid, "Desktop shifter: attachments fn0 failed: %d\n", ret); + + ret = hidpp_send_fap_command_sync(hidpp, ff->idx_attachments, + 0x20 /* fn2 */, (u8 *)slot_routing, + sizeof(slot_routing), &response); + if (ret) + dd_warn(hid, "Desktop shifter: attachments fn2 failed: %d\n", ret); + + memset(params, 0, sizeof(params)); + ret = hidpp_send_fap_command_sync(hidpp, ff->idx_attachments, + 0x10 /* fn1 */, params, 0, &response); + if (ret) + dd_warn(hid, "Desktop shifter: attachments fn1 failed: %d\n", ret); + } + + /* 2. Feature 0x1BC0 SYNC on base: sync notify (fn2) */ + if (ff->idx_sync != HIDPP_DD_FEATURE_NOT_FOUND) { + memset(params, 0, sizeof(params)); + ret = hidpp_send_fap_command_sync(hidpp, ff->idx_sync, + 0x20 /* fn2 */, params, 0, &response); + if (ret) + dd_warn(hid, "Desktop shifter: base sync fn2 failed: %d\n", ret); + } + + dd_dbg(hid, "Desktop mode shifter enablement completed\n"); +} + /* * Query current mode/profile from device. * Feature 0x8137 fn1 returns: [profile] [mode?] ... @@ -9559,6 +9646,16 @@ static void hidpp_dd_ff_query_settings(struct hidpp_dd_ff_data *ff) } } } + + /* + * Enable accessory slot routing in Desktop mode (profile 0) + * when an RS H-Shifter is present. + * Must run after LIGHTSYNC initialization so the LED sync + * sequence does not clobber attachment routing. + */ + if (ff->current_mode == 0 && + ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) + hidpp_dd_enable_desktop_shifter(ff); } /* @@ -11691,6 +11788,10 @@ static int hidpp_dd_lightsync_apply_slot(struct hidpp_device *hidpp, int ok = 0; for (i = 0; i < ARRAY_SIZE(desktop_sync_zones); i++) { + /* Skip GAMING_ATTACHMENTS (0x8120) so sync does not reset slot routing */ + if (desktop_sync_zones[i] == ff->idx_attachments) + continue; + sync_params[0] = 0x01; sync_params[1] = 0x00; sync_params[2] = 0x09; From 7182549c102db9fcf6c3d3e016c03508bba3401c Mon Sep 17 00:00:00 2001 From: Gonzalo Adrio Date: Wed, 4 Nov 2026 21:28:01 +0100 Subject: [PATCH 2/9] userspace, docs: add Logitech RS H-Shifter support and UI gate monitor Add Logitech RS H-Shifter (046d:c26b) detection and decoding for both direct USB mode and wheel base accessory port attachment. Gate wheel-base gear decoding strictly to direct-drive wheels (RS50 and G PRO) to prevent collisions with physical button codes on G923 editions. Add an interactive 7+R Slint visual H-gate component and document input report mappings and evdev codes. Signed-off-by: Gonzalo Adrio --- docs/BUTTON_MAPPING.md | 24 ++- docs/PROTOCOL_SPECIFICATION.md | 15 +- .../crates/logi-wheel-core/src/evtest.rs | 186 ++++++++++++++++ .../crates/logi-wheel-gui/src/main.rs | 5 + .../crates/logi-wheel-gui/src/testio.rs | 98 +++++++-- .../crates/logi-wheel-gui/ui/app.slint | 8 + .../crates/logi-wheel-gui/ui/info_page.slint | 198 ++++++++++++++++++ 7 files changed, 520 insertions(+), 14 deletions(-) diff --git a/docs/BUTTON_MAPPING.md b/docs/BUTTON_MAPPING.md index 28b7bb6..43ff7f6 100644 --- a/docs/BUTTON_MAPPING.md +++ b/docs/BUTTON_MAPPING.md @@ -48,7 +48,29 @@ sequential after G1). The D-pad reports as a hat switch (`ABS_HAT0X` / `ABS_HAT0Y`), not as four buttons - diagram callout "D". -Indices 12 to 20 are gaps in the HID descriptor (unused). +## RS H-Shifter (046d:c26b) + +### Connected to the Wheel Base + +When connected to the wheel base accessory port (sub-device 03), gears 1 to 7 and Reverse report on DirectInput button indices 12 to 19 (hardware-verified 2026-10-29). Index 20 is unused. + +| Index | Button / Gear | evdev Code | Wire bitmask (Report 0x08) | +|---|---|---|---| +| 12 | RS H-Shifter: Gear 1 | `0x12c` (`BTN_BASE`) | Byte 2 bit 0 (`0x01`) | +| 13 | RS H-Shifter: Gear 2 | `0x12d` (`BTN_BASE2`) | Byte 2 bit 1 (`0x02`) | +| 14 | RS H-Shifter: Gear 3 | `0x12e` (`BTN_BASE3`) | Byte 2 bit 2 (`0x04`) | +| 15 | RS H-Shifter: Gear 4 | `0x12f` (`BTN_BASE4`) | Byte 2 bit 3 (`0x08`) | +| 16 | RS H-Shifter: Gear 5 | `0x2c0` (`BTN_TRIGGER_HAPPY1`) | Byte 2 bit 4 (`0x10`) | +| 17 | RS H-Shifter: Gear 6 | `0x2c1` (`BTN_TRIGGER_HAPPY2`) | Byte 2 bit 5 (`0x20`) | +| 18 | RS H-Shifter: Gear 7 | `0x2c2` (`BTN_TRIGGER_HAPPY3`) | Byte 2 bit 6 (`0x40`) | +| 19 | RS H-Shifter: Reverse | `0x2c3` (`BTN_TRIGGER_HAPPY4`) | Byte 3 bit 0 (`0x01`) | +| 20 | Unused | `0x2c4` (`BTN_TRIGGER_HAPPY5`) | - | + +### Connected Directly to PC via USB + +When connected directly to the PC via USB (`046d:c26b Logitech RS H-Shifter`), it enumerates as an independent joystick reporting 8 digital buttons: +- Buttons 0 to 6 (`0x120`..`0x126`): 1st through 7th gear +- Button 7 (`0x127`): Reverse (R) ## G923 diff --git a/docs/PROTOCOL_SPECIFICATION.md b/docs/PROTOCOL_SPECIFICATION.md index b8d00b2..f2a0ede 100644 --- a/docs/PROTOCOL_SPECIFICATION.md +++ b/docs/PROTOCOL_SPECIFICATION.md @@ -73,7 +73,7 @@ The RS50 presents **3 HID interfaces** to the host: Offset Size Type Description ------ ---- ---- ----------- 0-1 2 uint16 Button bitmask, buttons 0-15 (little-endian) -2-3 2 - Button bitmask high bytes (byte 3 bit 7 = G button; otherwise 0) +2-3 2 - Button bitmask high bytes (Byte 2: RS H-Shifter Gears 1-7; Byte 3 bit 0: Reverse, bit 7: G button) 4-5 2 uint16 Wheel position (little-endian) 6-7 2 uint16 Accelerator pedal (little-endian) 8-9 2 uint16 Brake pedal (little-endian) @@ -108,9 +108,22 @@ Button state is encoded in bytes 0-3 of the input report. | 6 | `0x40` | **LB** (Left Bumper) | | 7 | `0x80` | **RB** (Right Bumper) | +**Byte 2 (RS H-Shifter, Sub-Device 03):** +| Bit | Mask | Button | +|-----|--------|--------| +| 0 | `0x01` | **Gear 1** | +| 1 | `0x02` | **Gear 2** | +| 2 | `0x04` | **Gear 3** | +| 3 | `0x08` | **Gear 4** | +| 4 | `0x10` | **Gear 5** | +| 5 | `0x20` | **Gear 6** | +| 6 | `0x40` | **Gear 7** | +| 7 | `0x80` | Unused | + **Byte 3:** | Bit | Mask | Button | |-----|--------|--------| +| 0 | `0x01` | **Reverse (RS H-Shifter)** | | 7 | `0x80` | **G Button** (Logitech logo) | ### D-pad Encoding (Byte 0 low nibble, bits 0-3) - standard HID hat diff --git a/userspace/logi-wheel/crates/logi-wheel-core/src/evtest.rs b/userspace/logi-wheel/crates/logi-wheel-core/src/evtest.rs index 730a88c..8b57133 100644 --- a/userspace/logi-wheel/crates/logi-wheel-core/src/evtest.rs +++ b/userspace/logi-wheel/crates/logi-wheel-core/src/evtest.rs @@ -638,6 +638,115 @@ pub fn scan_wheel_input_under(sysfs_input: &Path, usb: &Path) -> Option bool { + let upper = name.to_uppercase(); + upper.contains("RS H-SHIFTER") || upper.contains("DRIVING FORCE SHIFTER") +} + +/// Scan `sysfs_input` for `event*` entries whose device name satisfies `predicate`. +pub fn scan_input_by_name(sysfs_input: &Path, predicate: F) -> Option +where + F: Fn(&str) -> bool, +{ + let mut files: Vec = fs::read_dir(sysfs_input) + .ok()? + .filter_map(Result::ok) + .collect(); + files.sort_by_cached_key(|f| event_index(&f.file_name().to_string_lossy())); + + files.into_iter().find_map(|f| { + let ename = f.file_name().into_string().ok()?; + if !ename.starts_with("event") { + return None; + } + let dev_name = fs::read_to_string(f.path().join("device/name")).ok()?; + let trimmed = dev_name.trim(); + predicate(trimmed).then(|| WheelInput { + event_path: format!("/dev/input/{ename}"), + name: trimmed.to_string(), + }) + }) +} + +/// Scan `sysfs_input` for `event*` entries matching [`is_shifter_name`]. +pub fn scan_shifter_input(sysfs_input: &Path) -> Option { + scan_input_by_name(sysfs_input, is_shifter_name) +} + +/// Find a standalone USB shifter's evdev node, or `None` if not connected via USB. +pub fn discover_shifter_input() -> Option { + scan_shifter_input(Path::new("/sys/class/input")) +} + +/// Evdev button codes and labels for the Logitech RS H-Shifter when attached +/// to a direct-drive base (sub-device 03, hardware-verified 2026-10-29). +pub const RS_SHIFTER_WHEEL_BUTTONS: &[(u16, &str)] = &[ + (0x12c, "Gear 1"), + (0x12d, "Gear 2"), + (0x12e, "Gear 3"), + (0x12f, "Gear 4"), + (0x2c0, "Gear 5"), + (0x2c1, "Gear 6"), + (0x2c2, "Gear 7"), + (0x2c3, "Reverse"), +]; + +/// Decode a gear index (1..=7, 8 for Reverse) from a wheel evdev button code +/// when the RS H-Shifter is attached to a direct-drive base (RS50 or G PRO). +/// +/// Gated strictly to RS50 and G PRO: G923 editions assign physical wheel buttons +/// to these codes (e.g. Plus, Minus, Dial Push), so they must not decode as +/// shifter gates on non-direct-drive wheels. +pub fn gear_from_wheel_code(model: WheelModel, code: u16) -> Option { + match model { + WheelModel::Rs50 | WheelModel::GPro => match code { + 0x12c => Some(1), + 0x12d => Some(2), + 0x12e => Some(3), + 0x12f => Some(4), + 0x2c0 => Some(5), + 0x2c1 => Some(6), + 0x2c2 => Some(7), + 0x2c3 | 0x2c4 => Some(8), // Reverse (R): 0x2c3 / 0x2c4 (RS50 Base wire Byte 3 bit 0 / BTN_TRIGGER_HAPPY4/5) + _ => None, + }, + _ => None, + } +} + +/// Decode a gear index (1..=7, 8 for Reverse) from a standalone USB shifter +/// (`046d:c26b`). +pub fn gear_from_standalone_code(code: u16) -> Option { + match code { + 0x120 | 0x2c0 => Some(1), + 0x121 | 0x2c1 => Some(2), + 0x122 | 0x2c2 => Some(3), + 0x123 | 0x2c3 => Some(4), + 0x124 | 0x2c4 => Some(5), + 0x125 | 0x2c5 => Some(6), + 0x126 | 0x2c6 => Some(7), + 0x127 | 0x2c7 => Some(8), // Reverse (R) + _ => None, + } +} + +/// Human-readable label for a gear (0 = Neutral "N", 1..7 = "1st".."7th", 8 = "R"). +pub fn gear_name(gear: i32) -> &'static str { + match gear { + 1 => "1st", + 2 => "2nd", + 3 => "3rd", + 4 => "4th", + 5 => "5th", + 6 => "6th", + 7 => "7th", + 8 => "R", + _ => "N", + } +} + #[cfg(test)] mod tests { use super::*; @@ -1014,3 +1123,80 @@ mod xbox_button_tests { ); } } + +#[cfg(test)] +mod shifter_tests { + use super::*; + + #[test] + fn shifter_name_matching() { + const MATCHES: &[&str] = &[ + "Logitech RS H-Shifter", + "Logitech G RS H-Shifter", + "Logitech Driving Force Shifter USB", + ]; + const NON_MATCHES: &[&str] = &[ + "Logitech RS50 Base", + "G923 Racing Wheel", + "Generic Gamepad", + ]; + + for name in MATCHES { + assert!(is_shifter_name(name), "expected {name:?} to match"); + } + for name in NON_MATCHES { + assert!(!is_shifter_name(name), "expected {name:?} not to match"); + } + } + + #[test] + fn shifter_gear_decoding_from_wheel_base() { + const CASES: &[(u16, Option)] = &[ + (0x12c, Some(1)), // Gear 1 (BTN_BASE) + (0x12d, Some(2)), // Gear 2 (BTN_BASE2) + (0x12e, Some(3)), // Gear 3 (BTN_BASE3) + (0x12f, Some(4)), // Gear 4 (BTN_BASE4) + (0x2c0, Some(5)), // Gear 5 (BTN_TRIGGER_HAPPY1) + (0x2c1, Some(6)), // Gear 6 (BTN_TRIGGER_HAPPY2) + (0x2c2, Some(7)), // Gear 7 (BTN_TRIGGER_HAPPY3) + (0x2c3, Some(8)), // Reverse (BTN_TRIGGER_HAPPY4) + (0x2c4, Some(8)), // Reverse wire alias + (0x12b, None), // Wheel rim LSB button + (0x120, None), // Wheel rim button A + ]; + + // Direct-Drive wheels (RS50 and G PRO) decode accessory gate indices + for model in [WheelModel::Rs50, WheelModel::GPro] { + for &(code, expected) in CASES { + assert_eq!( + gear_from_wheel_code(model, code), + expected, + "failed for model {model:?} with code 0x{code:03x}" + ); + } + } + + // Non-DD wheels (G923, Unknown) must strictly ignore accessory gates + for &(code, _) in CASES { + assert_eq!(gear_from_wheel_code(WheelModel::G923, code), None); + assert_eq!(gear_from_wheel_code(WheelModel::Unknown, code), None); + } + } + + #[test] + fn shifter_gear_decoding_from_standalone() { + // Direct USB reports 8 sequential buttons (0x120..=0x127) for 1st..7th and Reverse + for (i, code) in (0x120..=0x127).enumerate() { + assert_eq!(gear_from_standalone_code(code), Some((i + 1) as u8)); + } + assert_eq!(gear_from_standalone_code(0x128), None); + } + + #[test] + fn gear_names() { + assert_eq!(gear_name(0), "N"); + assert_eq!(gear_name(1), "1st"); + assert_eq!(gear_name(7), "7th"); + assert_eq!(gear_name(8), "R"); + } +} diff --git a/userspace/logi-wheel/crates/logi-wheel-gui/src/main.rs b/userspace/logi-wheel/crates/logi-wheel-gui/src/main.rs index 72dbd0a..ec22b04 100644 --- a/userspace/logi-wheel/crates/logi-wheel-gui/src/main.rs +++ b/userspace/logi-wheel/crates/logi-wheel-gui/src/main.rs @@ -925,6 +925,10 @@ fn apply_test_snapshot(app: &App, snap: &testio::Snapshot, model: WheelModel, wh .map(|(label, i)| TestAxis { label: (*label).into(), value: snap.axes[*i] }) .collect(); app.set_test_axes(slint::ModelRc::new(slint::VecModel::from(axes))); + app.set_test_gear(snap.gear); + app.set_test_gear_name(evtest::gear_name(snap.gear).into()); + app.set_test_shifter_connected(snap.shifter_connected); + app.set_test_shifter_mode(snap.shifter_mode.as_str().into()); } /// Stop (and join) the Test page's reader thread, if one is running. @@ -1007,6 +1011,7 @@ fn start_test_monitor( let wheel_name = wheel.name.clone(); match testio::Reader::start( &wheel.event_path, + model, evtest::button_codes_for_name(model, &wheel.name), // The wheel's own pedal layout, from the name its input // node reports (issue #68). diff --git a/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs b/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs index 1323a95..d111219 100644 --- a/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs +++ b/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs @@ -20,6 +20,7 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use logi_wheel_core::evtest::{self, TestEvent, EVENT_SIZE}; +use logi_wheel_core::WheelModel; /// One UI push worth of live wheel state. `buttons` is parallel to /// whichever code list `Reader::start` was given (see @@ -33,6 +34,9 @@ pub struct Snapshot { pub buttons: Vec, pub hat: (i32, i32), pub axes: [i32; 4], + pub gear: i32, + pub shifter_connected: bool, + pub shifter_mode: String, } /// How often the reader pushes a fresh [`Snapshot`] at most. @@ -58,6 +62,7 @@ impl Reader { /// in a dead page. pub fn start( path: &str, + model: WheelModel, codes: Vec, axes: evtest::PedalAxes, on_snapshot: impl Fn(Snapshot) + Send + 'static, @@ -67,6 +72,18 @@ impl Reader { .read(true) .custom_flags(libc::O_NONBLOCK | libc::O_CLOEXEC) .open(path)?; + let mut standalone_shifter = evtest::discover_shifter_input().and_then(|s| { + if s.event_path != path { + std::fs::OpenOptions::new() + .read(true) + .custom_flags(libc::O_NONBLOCK | libc::O_CLOEXEC) + .open(&s.event_path) + .ok() + } else { + None + } + }); + let standalone_detected = standalone_shifter.is_some(); let stop = Arc::new(AtomicBool::new(false)); let thread_stop = stop.clone(); let handle = std::thread::spawn(move || { @@ -76,6 +93,8 @@ impl Reader { // until the first real event arrives. steering_raw: evtest::AXIS_MAX / 2, buttons: vec![false; codes.len()], + shifter_connected: standalone_detected, + shifter_mode: if standalone_detected { "Direct USB".to_string() } else { String::new() }, ..Snapshot::default() }; let mut buf = [0u8; EVENT_SIZE * 64]; @@ -85,6 +104,30 @@ impl Reader { if thread_stop.load(Ordering::Relaxed) { return; } + if let Some(ref mut s_file) = standalone_shifter { + let mut s_buf = [0u8; EVENT_SIZE * 32]; + match s_file.read(&mut s_buf) { + Ok(n) if n > 0 => { + let (events, _partial) = s_buf[..n].as_chunks::(); + for chunk in events { + if let Some(TestEvent::Button { code, pressed }) = evtest::parse_event(chunk) { + if let Some(gear) = evtest::gear_from_standalone_code(code) { + if pressed { + snapshot.gear = gear as i32; + snapshot.shifter_connected = true; + snapshot.shifter_mode = "Direct USB".to_string(); + dirty = true; + } else if snapshot.gear == gear as i32 { + snapshot.gear = 0; + dirty = true; + } + } + } + } + } + _ => {} + } + } match file.read(&mut buf) { // A closed/unplugged evdev node reads EOF. Ok(0) => { @@ -97,7 +140,7 @@ impl Reader { // whole event rather than checking per iteration. let (events, _partial) = buf[..n].as_chunks::(); for chunk in events { - if apply_event(&mut snapshot, chunk, &codes, axes) { + if apply_event(&mut snapshot, chunk, &codes, axes, model) { dirty = true; } } @@ -146,19 +189,34 @@ fn apply_event( chunk: &[u8], codes: &[u16], axes: evtest::PedalAxes, + model: WheelModel, ) -> bool { match evtest::parse_event(chunk) { Some(TestEvent::Steering(raw)) => { snapshot.steering_raw = raw; true } - Some(TestEvent::Button { code, pressed }) => match codes.iter().position(|c| *c == code) { - Some(i) => { + Some(TestEvent::Button { code, pressed }) => { + let mut changed = false; + if let Some(i) = codes.iter().position(|c| *c == code) { snapshot.buttons[i] = pressed; - true + changed = true; } - None => false, - }, + if let Some(gear) = evtest::gear_from_wheel_code(model, code) { + if pressed { + snapshot.gear = gear as i32; + snapshot.shifter_connected = true; + if snapshot.shifter_mode.is_empty() { + snapshot.shifter_mode = "RS50 Base".to_string(); + } + changed = true; + } else if snapshot.gear == gear as i32 { + snapshot.gear = 0; + changed = true; + } + } + changed + } Some(TestEvent::Axis { code, value }) => match code { evtest::ABS_HAT0X => { snapshot.hat.0 = value; @@ -339,9 +397,19 @@ mod tests { use super::*; use logi_wheel_core::device::WheelModel; + /// Helper for tests against a specific wheel model layout. + fn apply_event_for( + model: WheelModel, + snapshot: &mut Snapshot, + chunk: &[u8], + codes: &[u16], + ) -> bool { + apply_event(snapshot, chunk, codes, evtest::pedal_axes(model, None), model) + } + /// The direct-drive layout, which these tests were written against. fn apply_event_dd(snapshot: &mut Snapshot, chunk: &[u8], codes: &[u16]) -> bool { - apply_event(snapshot, chunk, codes, evtest::pedal_axes(WheelModel::Rs50, None)) + apply_event_for(WheelModel::Rs50, snapshot, chunk, codes) } /// A G923's brake reaches the brake bar rather than the handbrake one. @@ -357,7 +425,7 @@ mod tests { let codes = evtest::button_codes_for_model(WheelModel::G923); let mut s = Snapshot { buttons: vec![false; codes.len()], ..Default::default() }; let xbox = evtest::pedal_axes(WheelModel::G923, Some(0xc26e)); - assert!(apply_event(&mut s, &ev(3, evtest::ABS_Z, 200), &codes, xbox), "brake moved"); + assert!(apply_event(&mut s, &ev(3, evtest::ABS_Z, 200), &codes, xbox, WheelModel::G923), "brake moved"); assert_eq!(s.axes[1], 200, "ABS_Z is the brake on this wheel, not the handbrake"); assert_eq!(s.axes[3], 0, "and nothing should reach the handbrake bar"); } @@ -408,7 +476,10 @@ mod tests { assert!(apply_event_dd(&mut s, &ev(3, evtest::ABS_HAT0Y, -1), &codes), "hat up"); assert_eq!(s.hat, (0, -1)); assert!(!apply_event_dd(&mut s, &ev(0, 0, 0), &codes), "SYN is not shown state"); - assert!(!apply_event_dd(&mut s, &ev(1, 0x12c, 1), &codes), "phantom button ignored (RS50)"); + assert!(!apply_event_dd(&mut s, &ev(1, 0x1ff, 1), &codes), "unknown button ignored (RS50)"); + assert!(apply_event_dd(&mut s, &ev(1, 0x12c, 1), &codes), "shifter gear 1 tracked (RS50)"); + assert_eq!(s.gear, 1); + assert!(s.shifter_connected); } #[test] @@ -427,11 +498,14 @@ mod tests { let codes: Vec = logi_wheel_core::evtest::button_codes_for_model(logi_wheel_core::WheelModel::G923); let mut s = Snapshot { buttons: vec![false; codes.len()], ..Snapshot::default() }; - assert!(apply_event_dd(&mut s, &ev(1, 0x2c3, 1), &codes), "tracked on a G923"); - assert!(apply_event_dd(&mut s, &ev(1, 0x2c4, 1), &codes), "tracked on a G923"); + assert!(apply_event_for(WheelModel::G923, &mut s, &ev(1, 0x2c3, 1), &codes), "tracked on a G923"); + assert_eq!(s.gear, 0, "G923 Plus must not be decoded as shifter gear"); + assert!(!s.shifter_connected, "shifter must not be marked connected on G923"); + assert!(apply_event_for(WheelModel::G923, &mut s, &ev(1, 0x2c4, 1), &codes), "tracked on a G923"); + assert_eq!(s.gear, 0, "G923 Minus must not be decoded as shifter gear"); // A descriptor-gap code the live G923 never actually sends is now // correctly absent from its own code list, so it is ignored - the // same as any code neither the wheel nor the code list knows. - assert!(!apply_event_dd(&mut s, &ev(1, 0x12c, 1), &codes), "gap code not tracked"); + assert!(!apply_event_for(WheelModel::G923, &mut s, &ev(1, 0x12c, 1), &codes), "gap code not tracked"); } } diff --git a/userspace/logi-wheel/crates/logi-wheel-gui/ui/app.slint b/userspace/logi-wheel/crates/logi-wheel-gui/ui/app.slint index 884cff5..4eec2a4 100644 --- a/userspace/logi-wheel/crates/logi-wheel-gui/ui/app.slint +++ b/userspace/logi-wheel/crates/logi-wheel-gui/ui/app.slint @@ -228,6 +228,10 @@ export component App inherits Window { in property test-hat: "centered"; in property <[TestAxis]> test-axes: []; in property <[TestCallout]> test-callouts: []; + in property test-gear: 0; + in property test-gear-name: "N"; + in property test-shifter-connected: false; + in property test-shifter-mode: ""; in property test-sim-running: false; in property test-sim-error: ""; // The running (or just-finished) sequence's one-line summary (set @@ -779,6 +783,10 @@ export component App inherits Window { hat: root.test-hat; axes: root.test-axes; callouts: root.test-callouts; + gear: root.test-gear; + gear-name: root.test-gear-name; + shifter-connected: root.test-shifter-connected; + shifter-mode: root.test-shifter-mode; sim-running: root.test-sim-running; sim-error: root.test-sim-error; sim-status: root.test-sim-status; diff --git a/userspace/logi-wheel/crates/logi-wheel-gui/ui/info_page.slint b/userspace/logi-wheel/crates/logi-wheel-gui/ui/info_page.slint index 4509c7e..c0bd829 100644 --- a/userspace/logi-wheel/crates/logi-wheel-gui/ui/info_page.slint +++ b/userspace/logi-wheel/crates/logi-wheel-gui/ui/info_page.slint @@ -64,6 +64,36 @@ component AxisBar inherits Rectangle { } } +// One circular gear slot badge for the H-pattern shifter gate. +component GateBadge inherits Rectangle { + in property label; + in property active: false; + in property is-reverse: false; + + width: 38px; + height: 38px; + border-radius: 19px; + border-width: 2px; + border-color: root.active ? (root.is-reverse ? #e0524a : Palette.accent-background) : Theme.panel-border; + background: root.active + ? (root.is-reverse ? #e0524a : Palette.accent-background) + : Theme.control-background; + + animate background { duration: 100ms; } + animate border-color { duration: 100ms; } + + Text { + text: root.label; + font-size: 14px; + font-weight: root.active ? 800 : 600; + horizontal-alignment: center; + vertical-alignment: center; + color: root.active + ? (root.is-reverse ? #ffffff : Palette.accent-foreground) + : Theme.text-color; + } +} + // The Info page: device identity (serial, firmware) on top, then the live // input monitor (the wheel image turning with the live steering angle, // per-button callout highlights, the full button list beside the image, @@ -118,6 +148,10 @@ export component InfoPage inherits Rectangle { in property <[TestButton]> buttons: []; in property hat: "centered"; in property <[TestAxis]> axes: []; + in property gear: 0; + in property gear-name: "N"; + in property shifter-connected: false; + in property shifter-mode: ""; // The layout image's callout boxes, tinted while pressed; see // `TestCallout`. Only meaningful over the RS50's numbered layout photo // (`wheel-kind` 0): the G PRO/G923 photos are plain product shots with @@ -661,6 +695,170 @@ export component InfoPage inherits Rectangle { } } + // Section: Logitech G RS H-Shifter (7+R Hall Effect) + Rectangle { + background: Theme.panel-background; + border-radius: Theme.panel-radius; + border-width: 1px; + border-color: Theme.panel-border; + + VerticalLayout { + padding: 14px; + spacing: 12px; + + HorizontalLayout { + alignment: space-between; + VerticalLayout { + spacing: 2px; + Text { + text: "H-Pattern Shifter (Logitech G RS H-Shifter)"; + font-size: 15px; + font-weight: 700; + color: Theme.text-color; + } + Text { + text: root.shifter-connected + ? ("Status: Connected (" + root.shifter-mode + ")") + : "Status: Waiting for gear input or USB connection..."; + font-size: 11px; + color: root.shifter-connected ? Theme.ok-color : Theme.muted-text-color; + } + } + Rectangle { + width: 145px; + height: 32px; + border-radius: 6px; + background: root.gear == 0 + ? Palette.alternate-background + : (root.gear == 8 ? #e0524a26 : Palette.accent-background.with-alpha(0.2)); + border-width: 1px; + border-color: root.gear == 0 + ? Theme.panel-border + : (root.gear == 8 ? #e0524a : Palette.accent-background); + + Text { + text: root.gear == 0 + ? "Neutral (N)" + : (root.gear == 8 ? "Reverse (R)" : ("Gear " + root.gear-name)); + font-size: 12px; + font-weight: 700; + horizontal-alignment: center; + vertical-alignment: center; + color: root.gear == 0 + ? Theme.text-color + : (root.gear == 8 ? #e0524a : Palette.accent-background); + } + } + } + + // Interactive 7-speed + Reverse H-gate pattern: + HorizontalLayout { + alignment: center; + Rectangle { + width: 330px; + height: 160px; + border-radius: 10px; + background: Theme.control-background; + border-width: 1px; + border-color: Theme.panel-border; + + // Neutral center rail: + Rectangle { + x: 35px; + y: 74px; + width: 260px; + height: 12px; + border-radius: 6px; + background: root.gear == 0 + ? Palette.accent-background.with-alpha(0.35) + : Palette.alternate-background; + } + + // 4 vertical slots: + // Gate 1-2 + Rectangle { + x: 48px; + y: 24px; + width: 12px; + height: 112px; + border-radius: 6px; + background: (root.gear == 1 || root.gear == 2) + ? Palette.accent-background.with-alpha(0.35) + : Palette.alternate-background; + } + // Gate 3-4 + Rectangle { + x: 123px; + y: 24px; + width: 12px; + height: 112px; + border-radius: 6px; + background: (root.gear == 3 || root.gear == 4) + ? Palette.accent-background.with-alpha(0.35) + : Palette.alternate-background; + } + // Gate 5-6 + Rectangle { + x: 198px; + y: 24px; + width: 12px; + height: 112px; + border-radius: 6px; + background: (root.gear == 5 || root.gear == 6) + ? Palette.accent-background.with-alpha(0.35) + : Palette.alternate-background; + } + // Gate 7-R + Rectangle { + x: 270px; + y: 24px; + width: 12px; + height: 112px; + border-radius: 6px; + background: (root.gear == 7 || root.gear == 8) + ? (root.gear == 8 ? #e0524a40 : Palette.accent-background.with-alpha(0.35)) + : Palette.alternate-background; + } + + // Gear badges: + // Top row (1, 3, 5, 7): + GateBadge { x: 35px; y: 12px; label: "1"; active: root.gear == 1; } + GateBadge { x: 110px; y: 12px; label: "3"; active: root.gear == 3; } + GateBadge { x: 185px; y: 12px; label: "5"; active: root.gear == 5; } + GateBadge { x: 257px; y: 12px; label: "7"; active: root.gear == 7; } + + // Bottom row (2, 4, 6, R): + GateBadge { x: 35px; y: 110px; label: "2"; active: root.gear == 2; } + GateBadge { x: 110px; y: 110px; label: "4"; active: root.gear == 4; } + GateBadge { x: 185px; y: 110px; label: "6"; active: root.gear == 6; } + GateBadge { x: 257px; y: 110px; label: "R"; active: root.gear == 8; is-reverse: true; } + + // Neutral (N) badge: + Rectangle { + x: 147px; + y: 62px; + width: 36px; + height: 36px; + border-radius: 18px; + border-width: 2px; + border-color: root.gear == 0 ? Palette.accent-background : Theme.panel-border; + background: root.gear == 0 ? Palette.accent-background : Theme.control-background; + animate background { duration: 100ms; } + + Text { + text: "N"; + font-size: 13px; + font-weight: root.gear == 0 ? 800 : 500; + horizontal-alignment: center; + vertical-alignment: center; + color: root.gear == 0 ? Palette.accent-foreground : Theme.muted-text-color; + } + } + } + } + } + } + // Section: the two guarded force simulations. Rectangle { background: Theme.panel-background; From 1851a2d0100d8979c545e4dc5f280c5a4d933925 Mon Sep 17 00:00:00 2001 From: Gonzalo Adrio Date: Wed, 4 Nov 2026 22:31:48 +0100 Subject: [PATCH 3/9] hidpp: restore desktop shifter gate routing on OLED state changes Activating or handing back the RS50 base OLED display via Feature 0x8130 (DisplayGameData) resets the internal sub-device gate routing table (Feature 0x8120), dropping gates 1-6 and Reverse while leaving only 7th gear operational in desktop mode. Re-invoke hidpp_dd_enable_desktop_shifter() whenever the OLED display is handed back to firmware menus or activated through wheel_oled sysfs attribute while operating in desktop mode (current_mode == 0). Signed-off-by: Gonzalo Adrio --- mainline/hid-logitech-hidpp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mainline/hid-logitech-hidpp.c b/mainline/hid-logitech-hidpp.c index 3aedeb4..68506ed 100644 --- a/mainline/hid-logitech-hidpp.c +++ b/mainline/hid-logitech-hidpp.c @@ -12714,6 +12714,8 @@ static void hidpp_dd_oled_handback(struct hidpp_device *hidpp, struct hidpp_dd_f mutex_lock(&hidpp->send_mutex); hidpp_dd_oled_send(hidpp, ff->idx_display, 0x2, NULL, 0); mutex_unlock(&hidpp->send_mutex); + if (ff->current_mode == 0) + hidpp_dd_enable_desktop_shifter(ff); } /* @@ -12801,6 +12803,7 @@ static ssize_t wheel_oled_store(struct device *dev, struct device_attribute *att struct hidpp_device *hidpp = hid_get_drvdata(to_hid_device(dev)); struct hidpp_dd_ff_data *ff = hidpp ? hidpp->private_data : NULL; u8 frame[HIDPP_DD_OLED_FRAME]; + bool was_active; int ret; if (!ff) @@ -12823,6 +12826,7 @@ static ssize_t wheel_oled_store(struct device *dev, struct device_attribute *att return ret; mutex_lock(&ff->oled_lock); + was_active = ff->oled_active; memcpy(ff->oled_frame, frame, sizeof(frame)); strscpy(ff->oled_text, buf, sizeof(ff->oled_text)); strim(ff->oled_text); @@ -12830,6 +12834,8 @@ static ssize_t wheel_oled_store(struct device *dev, struct device_attribute *att mutex_unlock(&ff->oled_lock); /* Now, not on the next tick: the first frame is what the user is waiting for. */ mod_delayed_work(ff->wq, &ff->oled_work, 0); + if (ff->current_mode == 0 && !was_active) + hidpp_dd_enable_desktop_shifter(ff); return count; } From 44e962054bf69bc01b5464f858bb5292997b3aea Mon Sep 17 00:00:00 2001 From: Gonzalo Adrio Date: Wed, 4 Nov 2026 22:43:12 +0100 Subject: [PATCH 4/9] hidpp: avoid dropping const qualifier when copying slot routing table SonarCloud flagged dropping the const qualifier on slot_routing when passing it as mutable u8 * to hidpp_send_fap_command_sync(). Copy the table into the local params buffer instead. Signed-off-by: Gonzalo Adrio --- mainline/hid-logitech-hidpp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mainline/hid-logitech-hidpp.c b/mainline/hid-logitech-hidpp.c index 68506ed..42b7fb4 100644 --- a/mainline/hid-logitech-hidpp.c +++ b/mainline/hid-logitech-hidpp.c @@ -9268,8 +9268,9 @@ static void hidpp_dd_enable_desktop_shifter(struct hidpp_dd_ff_data *ff) if (ret) dd_warn(hid, "Desktop shifter: attachments fn0 failed: %d\n", ret); + memcpy(params, slot_routing, sizeof(slot_routing)); ret = hidpp_send_fap_command_sync(hidpp, ff->idx_attachments, - 0x20 /* fn2 */, (u8 *)slot_routing, + 0x20 /* fn2 */, params, sizeof(slot_routing), &response); if (ret) dd_warn(hid, "Desktop shifter: attachments fn2 failed: %d\n", ret); From 8b8fd737c3f81b912b847765a670d307abeb2947 Mon Sep 17 00:00:00 2001 From: Gonzalo Adrio Date: Wed, 4 Nov 2026 22:47:26 +0100 Subject: [PATCH 5/9] gui(testio): reduce cognitive complexity by extracting shifter polling Extract standalone USB shifter event polling from Reader::start loop into a dedicated helper function (poll_standalone_shifter). Signed-off-by: Gonzalo Adrio --- .../crates/logi-wheel-gui/src/testio.rs | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs b/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs index d111219..01fd104 100644 --- a/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs +++ b/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs @@ -105,27 +105,8 @@ impl Reader { return; } if let Some(ref mut s_file) = standalone_shifter { - let mut s_buf = [0u8; EVENT_SIZE * 32]; - match s_file.read(&mut s_buf) { - Ok(n) if n > 0 => { - let (events, _partial) = s_buf[..n].as_chunks::(); - for chunk in events { - if let Some(TestEvent::Button { code, pressed }) = evtest::parse_event(chunk) { - if let Some(gear) = evtest::gear_from_standalone_code(code) { - if pressed { - snapshot.gear = gear as i32; - snapshot.shifter_connected = true; - snapshot.shifter_mode = "Direct USB".to_string(); - dirty = true; - } else if snapshot.gear == gear as i32 { - snapshot.gear = 0; - dirty = true; - } - } - } - } - } - _ => {} + if poll_standalone_shifter(s_file, &mut snapshot) { + dirty = true; } } match file.read(&mut buf) { @@ -181,6 +162,33 @@ impl Drop for Reader { } } +/// Poll standalone USB RS H-Shifter events, updating gear and connection status. +fn poll_standalone_shifter(s_file: &mut std::fs::File, snapshot: &mut Snapshot) -> bool { + let mut s_buf = [0u8; EVENT_SIZE * 32]; + let mut changed = false; + if let Ok(n) = s_file.read(&mut s_buf) { + if n > 0 { + let (events, _partial) = s_buf[..n].as_chunks::(); + for chunk in events { + if let Some(TestEvent::Button { code, pressed }) = evtest::parse_event(chunk) { + if let Some(gear) = evtest::gear_from_standalone_code(code) { + if pressed { + snapshot.gear = gear as i32; + snapshot.shifter_connected = true; + snapshot.shifter_mode = "Direct USB".to_string(); + changed = true; + } else if snapshot.gear == gear as i32 { + snapshot.gear = 0; + changed = true; + } + } + } + } + } + } + changed +} + /// Fold one raw event into `snapshot`; true if anything shown changed. /// `codes` is the same list `snapshot.buttons` is parallel to (see /// `Reader::start`). From a1e7245ff336eb930447a7a85c9ec61a74ac858b Mon Sep 17 00:00:00 2001 From: Gonzalo Adrio Date: Wed, 4 Nov 2026 22:48:41 +0100 Subject: [PATCH 6/9] gui(testio): simplify standalone shifter polling with early returns and guard clauses Replace nested if-let pyramid with guard clauses and early exits (return false on empty/err read, continue on unhandled events). Signed-off-by: Gonzalo Adrio --- .../crates/logi-wheel-gui/src/testio.rs | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs b/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs index 01fd104..d61313b 100644 --- a/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs +++ b/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs @@ -165,25 +165,32 @@ impl Drop for Reader { /// Poll standalone USB RS H-Shifter events, updating gear and connection status. fn poll_standalone_shifter(s_file: &mut std::fs::File, snapshot: &mut Snapshot) -> bool { let mut s_buf = [0u8; EVENT_SIZE * 32]; + let n = match s_file.read(&mut s_buf) { + Ok(n) if n > 0 => n, + _ => return false, + }; + let mut changed = false; - if let Ok(n) = s_file.read(&mut s_buf) { - if n > 0 { - let (events, _partial) = s_buf[..n].as_chunks::(); - for chunk in events { - if let Some(TestEvent::Button { code, pressed }) = evtest::parse_event(chunk) { - if let Some(gear) = evtest::gear_from_standalone_code(code) { - if pressed { - snapshot.gear = gear as i32; - snapshot.shifter_connected = true; - snapshot.shifter_mode = "Direct USB".to_string(); - changed = true; - } else if snapshot.gear == gear as i32 { - snapshot.gear = 0; - changed = true; - } - } - } - } + let (events, _partial) = s_buf[..n].as_chunks::(); + for chunk in events { + let (code, pressed) = match evtest::parse_event(chunk) { + Some(TestEvent::Button { code, pressed }) => (code, pressed), + _ => continue, + }; + + let gear = match evtest::gear_from_standalone_code(code) { + Some(g) => g as i32, + None => continue, + }; + + if pressed { + snapshot.gear = gear; + snapshot.shifter_connected = true; + snapshot.shifter_mode = "Direct USB".to_string(); + changed = true; + } else if snapshot.gear == gear { + snapshot.gear = 0; + changed = true; } } changed From 8484945bf97e147b15bcf1a5ddf73ea89252bd6d Mon Sep 17 00:00:00 2001 From: Gonzalo Adrio Date: Wed, 4 Nov 2026 22:57:52 +0100 Subject: [PATCH 7/9] hidpp, userspace: address maintainer feedback on accessory naming and gating - Gate desktop_sync_zones skip on h_shifter_dev_idx != NOT_FOUND. - Return early in hidpp_dd_oled_handback if ff->stopping is set. - Populate ff->accessory_name with 'RS H-Shifter' on 0x812D discovery. - Allow wheel_accessory_show to report when either shifter_dev_idx or h_shifter_dev_idx is present. - Drop unused 0x2c4 alias in gear_from_wheel_code. - Rename 'RS50 Base' label in testio.rs to 'Wheel base' for generic direct-drive coverage. Signed-off-by: Gonzalo Adrio --- mainline/hid-logitech-hidpp.c | 11 +++++--- .../crates/logi-wheel-core/src/evtest.rs | 4 +-- .../crates/logi-wheel-gui/src/testio.rs | 26 ++++++++++--------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/mainline/hid-logitech-hidpp.c b/mainline/hid-logitech-hidpp.c index 42b7fb4..df423bd 100644 --- a/mainline/hid-logitech-hidpp.c +++ b/mainline/hid-logitech-hidpp.c @@ -8991,6 +8991,7 @@ static void hidpp_dd_discover_settings_features(struct hidpp_dd_ff_data *ff) if (ret == 0) { ff->h_shifter_dev_idx = cand; ff->idx_h_shifter = cand_idx; + strscpy(ff->accessory_name, "RS H-Shifter", sizeof(ff->accessory_name)); dd_info(hid, "RS H-Shifter at dev 0x%02x (idx 0x%02x)\n", cand, cand_idx); break; @@ -9241,7 +9242,7 @@ static void hidpp_dd_ff_discover_features(struct hidpp_dd_ff_data *ff) /* * Desktop mode shifter enablement. * - * In Desktop mode (profile 0), the RS50 base suppresses sub-device + * In Desktop mode (profile 0), direct-drive wheel bases suppress sub-device * gate reporting (gears 1-6 and Reverse) unless G HUB's slot routing, * sync and accessory enable commands are sent. In Onboard mode (profiles * 1-5), the base routes all gates automatically. @@ -11790,7 +11791,8 @@ static int hidpp_dd_lightsync_apply_slot(struct hidpp_device *hidpp, for (i = 0; i < ARRAY_SIZE(desktop_sync_zones); i++) { /* Skip GAMING_ATTACHMENTS (0x8120) so sync does not reset slot routing */ - if (desktop_sync_zones[i] == ff->idx_attachments) + if (ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && + desktop_sync_zones[i] == ff->idx_attachments) continue; sync_params[0] = 0x01; @@ -12715,6 +12717,8 @@ static void hidpp_dd_oled_handback(struct hidpp_device *hidpp, struct hidpp_dd_f mutex_lock(&hidpp->send_mutex); hidpp_dd_oled_send(hidpp, ff->idx_display, 0x2, NULL, 0); mutex_unlock(&hidpp->send_mutex); + if (atomic_read_acquire(&ff->stopping)) + return; if (ff->current_mode == 0) hidpp_dd_enable_desktop_shifter(ff); } @@ -15237,7 +15241,8 @@ static ssize_t wheel_accessory_show(struct device *dev, jiffies + HIDPP_DD_ACCESSORY_RESCAN_INTERVAL); queue_work(ff->wq, &ff->accessory_rescan_work); } - if (READ_ONCE(ff->shifter_dev_idx) == HIDPP_DD_FEATURE_NOT_FOUND || + if ((READ_ONCE(ff->shifter_dev_idx) == HIDPP_DD_FEATURE_NOT_FOUND && + READ_ONCE(ff->h_shifter_dev_idx) == HIDPP_DD_FEATURE_NOT_FOUND) || !ff->accessory_name[0]) return sysfs_emit(buf, "none\n"); return sysfs_emit(buf, "%s\n", ff->accessory_name); diff --git a/userspace/logi-wheel/crates/logi-wheel-core/src/evtest.rs b/userspace/logi-wheel/crates/logi-wheel-core/src/evtest.rs index 8b57133..cd52d44 100644 --- a/userspace/logi-wheel/crates/logi-wheel-core/src/evtest.rs +++ b/userspace/logi-wheel/crates/logi-wheel-core/src/evtest.rs @@ -709,7 +709,7 @@ pub fn gear_from_wheel_code(model: WheelModel, code: u16) -> Option { 0x2c0 => Some(5), 0x2c1 => Some(6), 0x2c2 => Some(7), - 0x2c3 | 0x2c4 => Some(8), // Reverse (R): 0x2c3 / 0x2c4 (RS50 Base wire Byte 3 bit 0 / BTN_TRIGGER_HAPPY4/5) + 0x2c3 => Some(8), // Reverse (R): 0x2c3 (Wheel base wire Byte 3 bit 0 / BTN_TRIGGER_HAPPY4) _ => None, }, _ => None, @@ -1160,7 +1160,7 @@ mod shifter_tests { (0x2c1, Some(6)), // Gear 6 (BTN_TRIGGER_HAPPY2) (0x2c2, Some(7)), // Gear 7 (BTN_TRIGGER_HAPPY3) (0x2c3, Some(8)), // Reverse (BTN_TRIGGER_HAPPY4) - (0x2c4, Some(8)), // Reverse wire alias + (0x2c4, None), // Unused / padding index (0x12b, None), // Wheel rim LSB button (0x120, None), // Wheel rim button A ]; diff --git a/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs b/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs index d61313b..a16192c 100644 --- a/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs +++ b/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs @@ -54,6 +54,18 @@ pub struct Reader { handle: Option>, } +fn open_standalone_shifter(wheel_path: &str) -> Option { + let s = evtest::discover_shifter_input()?; + if s.event_path == wheel_path { + return None; + } + std::fs::OpenOptions::new() + .read(true) + .custom_flags(libc::O_NONBLOCK | libc::O_CLOEXEC) + .open(&s.event_path) + .ok() +} + impl Reader { /// Open `path` and start the read loop, tracking `codes` (see /// `evtest::button_codes_for_model`; `snapshot.buttons` stays parallel @@ -72,17 +84,7 @@ impl Reader { .read(true) .custom_flags(libc::O_NONBLOCK | libc::O_CLOEXEC) .open(path)?; - let mut standalone_shifter = evtest::discover_shifter_input().and_then(|s| { - if s.event_path != path { - std::fs::OpenOptions::new() - .read(true) - .custom_flags(libc::O_NONBLOCK | libc::O_CLOEXEC) - .open(&s.event_path) - .ok() - } else { - None - } - }); + let mut standalone_shifter = open_standalone_shifter(path); let standalone_detected = standalone_shifter.is_some(); let stop = Arc::new(AtomicBool::new(false)); let thread_stop = stop.clone(); @@ -222,7 +224,7 @@ fn apply_event( snapshot.gear = gear as i32; snapshot.shifter_connected = true; if snapshot.shifter_mode.is_empty() { - snapshot.shifter_mode = "RS50 Base".to_string(); + snapshot.shifter_mode = "Wheel base".to_string(); } changed = true; } else if snapshot.gear == gear as i32 { From 944f347138ae43b6b7bc337d356058055e5e44ab Mon Sep 17 00:00:00 2001 From: Gonzalo Adrio Date: Wed, 4 Nov 2026 23:11:55 +0100 Subject: [PATCH 8/9] gui(testio): extract poll_wheel_events helper to reduce start complexity --- .../crates/logi-wheel-gui/src/testio.rs | 52 ++++++++++++------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs b/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs index a16192c..e0ca15a 100644 --- a/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs +++ b/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs @@ -66,6 +66,35 @@ fn open_standalone_shifter(wheel_path: &str) -> Option { .ok() } +/// Read and fold wheel events from `file` into `snapshot`. +/// Returns `Ok(true)` if anything changed, `Ok(false)` if no visible change or would block, +/// or `Err(())` if the device was disconnected (EOF or fatal error). +fn poll_wheel_events( + file: &mut std::fs::File, + buf: &mut [u8; EVENT_SIZE * 64], + snapshot: &mut Snapshot, + codes: &[u16], + axes: evtest::PedalAxes, + model: WheelModel, +) -> Result { + match file.read(buf) { + Ok(0) => Err(()), // A closed/unplugged evdev node reads EOF. + Ok(n) => { + let mut changed = false; + let (events, _partial) = buf[..n].as_chunks::(); + for chunk in events { + if apply_event(snapshot, chunk, codes, axes, model) { + changed = true; + } + } + Ok(changed) + } + Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => Ok(false), + Err(e) if e.kind() == std::io::ErrorKind::Interrupted => Ok(false), + Err(_) => Err(()), + } +} + impl Reader { /// Open `path` and start the read loop, tracking `codes` (see /// `evtest::button_codes_for_model`; `snapshot.buttons` stays parallel @@ -111,26 +140,13 @@ impl Reader { dirty = true; } } - match file.read(&mut buf) { - // A closed/unplugged evdev node reads EOF. - Ok(0) => { - on_gone(); - return; - } - Ok(n) => { - // as_chunks over chunks_exact: the size is a - // constant, so the compiler knows each slice is a - // whole event rather than checking per iteration. - let (events, _partial) = buf[..n].as_chunks::(); - for chunk in events { - if apply_event(&mut snapshot, chunk, &codes, axes, model) { - dirty = true; - } + match poll_wheel_events(&mut file, &mut buf, &mut snapshot, &codes, axes, model) { + Ok(changed) => { + if changed { + dirty = true; } } - Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {} - Err(e) if e.kind() == std::io::ErrorKind::Interrupted => {} - Err(_) => { + Err(()) => { on_gone(); return; } From eb1164b48b983de284811b51b77cb40bc0c0fafd Mon Sep 17 00:00:00 2001 From: mescon <5875228+mescon@users.noreply.github.com> Date: Wed, 4 Nov 2026 23:45:52 +0100 Subject: [PATCH 9/9] hidpp: find the RS H-Shifter in the one accessory pass and on rescan The 0x812D probe ran as a second loop over every candidate sub-device, so a base without an H-Shifter paid one HIDPP_DD_PROBE_TIMEOUT per silent candidate on top of what the pedal and RS Shifter & Handbrake pass already cost, about a second and a half at probe. A port with no response curve answers that first pass with -ENOENT in a few milliseconds, which is exactly what the H-Shifter looks like, so ask such a candidate for 0x812D right there and never probe a silent index twice. The accessory rescan only knew the RS Shifter & Handbrake, so an H-Shifter plugged in after the module loaded was never found and one pulled out was never forgotten. Teach it both directions, and send the desktop-mode enablement sequence when a shifter arrives, as probe does. The RS Shifter & Handbrake adoption moves into a helper shared by probe and rescan. wheel_accessory's documentation covers both accessories and the on-demand re-check. --- docs/SYSFS_API.md | 20 ++- mainline/hid-logitech-hidpp.c | 273 +++++++++++++++++++++------------- 2 files changed, 187 insertions(+), 106 deletions(-) diff --git a/docs/SYSFS_API.md b/docs/SYSFS_API.md index 426fa03..e2ee9ee 100644 --- a/docs/SYSFS_API.md +++ b/docs/SYSFS_API.md @@ -992,12 +992,20 @@ Include this output in bug reports - firmware-dependent behaviour **Access**: Read-only **Values**: accessory device name, or `none` -Presence signal for the **RS Shifter & Handbrake**, an optional accessory -that plugs into the base's USB-A port. Reports the accessory's own HID++ -device name when one is discovered at probe time, or `none` when absent. -Unlike the pedal/handbrake attributes below, this never returns an error: -it exists precisely so apps can check for the accessory without inferring -presence from another attribute's error code. +Presence signal for the base's optional accessories: the **RS Shifter & +Handbrake** and the **RS H-Shifter**, which plug into the base's USB-A +ports. Reports the RS Shifter & Handbrake's own HID++ device name, or +`RS H-Shifter`, or `none` when neither is attached. With both attached it +names the RS Shifter & Handbrake. Unlike the pedal/handbrake attributes +below, this never returns an error: it exists precisely so apps can check +for an accessory without inferring presence from another attribute's error +code. + +Both accessories are found at probe time and re-checked on demand: a read +queues a presence re-check in the background, so an accessory plugged in or +pulled after the module loaded shows up within a few reads. An RS H-Shifter +that arrives this way in desktop mode gets its gate routing enabled at the +same time, as it would have at probe. ```bash cat wheel_accessory diff --git a/mainline/hid-logitech-hidpp.c b/mainline/hid-logitech-hidpp.c index df423bd..775f2e2 100644 --- a/mainline/hid-logitech-hidpp.c +++ b/mainline/hid-logitech-hidpp.c @@ -6049,7 +6049,7 @@ struct hidpp_dd_ff_data { char serial[13]; /* 12-char Base34 serial + NUL */ char fw_main[16]; /* base firmware, e.g. "U1 65.03.B0038" */ char fw_motor[16]; /* motor firmware (sub-device 0x05) */ - char accessory_name[32]; /* RS Shifter & Handbrake's own 0x0005 name; empty if not discovered */ + char accessory_name[32]; /* wheel_accessory text; empty with no accessory */ u8 led_effect; /* LED effect mode (1-5, 5=custom) */ /* LIGHTSYNC per-slot configuration (full RGB control) */ @@ -8726,6 +8726,56 @@ static void hidpp_dd_query_accessory_name(struct hidpp_dd_ff_data *ff, u8 dev_id ff->accessory_name[index] = '\0'; } +/* + * Record a confirmed RS Shifter & Handbrake at @cand: its response-curve + * index, its BANDED_AXIS index, its DEVICE_MODE index (left absent when the + * accessory does not answer for it) and its queried device name. The caller + * publishes shifter_dev_idx itself, last, because that is what the readers + * gate on. + */ +static void hidpp_dd_adopt_shifter_handbrake(struct hidpp_dd_ff_data *ff, + u8 cand, u8 curve_idx, u8 banded_idx) +{ + struct hidpp_device *hidpp = ff->hidpp; + + ff->idx_shifter_curve = curve_idx; + ff->idx_shifter_banded = banded_idx; + if (hidpp_root_get_feature_on_device(hidpp, cand, + HIDPP_DD_PAGE_DEVICE_MODE, + &ff->idx_shifter_mode)) + ff->idx_shifter_mode = HIDPP_DD_FEATURE_NOT_FOUND; + else + dd_dbg(hidpp->hid_dev, "Accessory mode feature at index 0x%02x\n", + ff->idx_shifter_mode); + hidpp_dd_query_accessory_name(ff, cand); +} + +/* + * Probe one candidate sub-device for the RS H-Shifter. It answers + * ROOT.GetFeature(0x812D) on the index of the port it is plugged into, and + * no other sub-device carries that page (contributor-verified on an RS50, + * 2026-10-29). Only called for a candidate already known to answer, so the + * normal transport timeout is fine: a silent index never gets this far. + * + * On a hit this records the feature index and, unless an accessory with a + * queried name already owns it, the wheel_accessory text. The caller + * publishes h_shifter_dev_idx itself, last, because that is what the + * readers gate on. + */ +static bool hidpp_dd_probe_h_shifter(struct hidpp_dd_ff_data *ff, u8 cand) +{ + u8 idx; + + if (hidpp_root_get_feature_on_device(ff->hidpp, cand, + HIDPP_DD_PAGE_RS_H_SHIFTER, &idx)) + return false; + ff->idx_h_shifter = idx; + if (!ff->accessory_name[0]) + strscpy(ff->accessory_name, "RS H-Shifter", + sizeof(ff->accessory_name)); + return true; +} + /* * Discover HID++ feature indices for the "settings" surface: per-wheel * tuning exposed as wheel_* sysfs attributes, plus profile / mode / @@ -8932,69 +8982,57 @@ static void hidpp_dd_discover_settings_features(struct hidpp_dd_ff_data *ff) * free. 0x1B30 (DEVICE_MODE) is resolved the same way once the * accessory is confirmed; it is not itself part of the confirmation * since its cross-device uniqueness has not been verified. + * + * The RS H-Shifter rides the same pass. It has no response curve, so + * its port answers the presence check with -ENOENT (present, page + * unknown) in a few milliseconds instead of timing out, and that + * answer, or a curve with an axis count this driver cannot place, is + * what sends a candidate to hidpp_dd_probe_h_shifter(). A silent + * index is never asked twice, so a bare wheel pays nothing for this + * beyond the one probe per candidate it already paid. */ for (i = 0; i < ARRAY_SIZE(hidpp_dd_pedal_dev_candidates); i++) { u8 cand = hidpp_dd_pedal_dev_candidates[i]; - u8 cand_idx, axes; + u8 cand_idx, axes, banded_idx; if (ff->pedal_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && - ff->shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) + ff->shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && + ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) break; ret = hidpp_root_get_feature_on_device_timeout(hidpp, cand, HIDPP_DD_PAGE_RESPONSE_CURVE, &cand_idx, HIDPP_DD_PROBE_TIMEOUT); - if (ret) + if (ret && ret != -ENOENT) continue; - if (hidpp_dd_pedal_axis_count(hidpp, cand, cand_idx, &axes)) - continue; - - if (axes == HIDPP_DD_PEDAL_AXIS_COUNT && - ff->pedal_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND) { - ff->pedal_dev_idx = cand; - ff->idx_pedal_curve = cand_idx; - continue; - } - - if (axes == HIDPP_DD_SHIFTER_AXIS_COUNT && - ff->shifter_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND) { - u8 banded_idx; - - if (hidpp_root_get_feature_on_device(hidpp, cand, + if (ret == 0 && + hidpp_dd_pedal_axis_count(hidpp, cand, cand_idx, &axes) == 0) { + if (axes == HIDPP_DD_PEDAL_AXIS_COUNT) { + if (ff->pedal_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND) { + ff->pedal_dev_idx = cand; + ff->idx_pedal_curve = cand_idx; + } + continue; + } + if (axes == HIDPP_DD_SHIFTER_AXIS_COUNT && + hidpp_root_get_feature_on_device(hidpp, cand, HIDPP_DD_PAGE_BANDED_AXIS, - &banded_idx)) + &banded_idx) == 0) { + if (ff->shifter_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND) { + hidpp_dd_adopt_shifter_handbrake(ff, cand, + cand_idx, banded_idx); + ff->shifter_dev_idx = cand; + } continue; - ff->shifter_dev_idx = cand; - ff->idx_shifter_curve = cand_idx; - ff->idx_shifter_banded = banded_idx; - ret = hidpp_root_get_feature_on_device(hidpp, cand, - HIDPP_DD_PAGE_DEVICE_MODE, - &ff->idx_shifter_mode); - if (ret == 0) - dd_dbg(hid, "Accessory mode feature at index 0x%02x\n", - ff->idx_shifter_mode); - hidpp_dd_query_accessory_name(ff, cand); + } } - } - /* Discover RS H-Shifter (0x812D) across candidate sub-devices */ - for (i = 0; i < ARRAY_SIZE(hidpp_dd_pedal_dev_candidates); i++) { - u8 cand = hidpp_dd_pedal_dev_candidates[i]; - u8 cand_idx; - - if (cand == ff->pedal_dev_idx || cand == ff->shifter_dev_idx) - continue; - - ret = hidpp_root_get_feature_on_device_timeout(hidpp, cand, - HIDPP_DD_PAGE_RS_H_SHIFTER, - &cand_idx, HIDPP_DD_PROBE_TIMEOUT); - if (ret == 0) { + /* Answers, but is neither the pedals nor the RS Shifter & Handbrake. */ + if (ff->h_shifter_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND && + hidpp_dd_probe_h_shifter(ff, cand)) { ff->h_shifter_dev_idx = cand; - ff->idx_h_shifter = cand_idx; - strscpy(ff->accessory_name, "RS H-Shifter", sizeof(ff->accessory_name)); dd_info(hid, "RS H-Shifter at dev 0x%02x (idx 0x%02x)\n", - cand, cand_idx); - break; + cand, ff->idx_h_shifter); } } if (ff->pedal_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) @@ -15082,10 +15120,11 @@ static DEVICE_ATTR(wheel_firmware, 0444, wheel_firmware_show, NULL); * up yet: their wire protocol is uncaptured. */ /* - * Re-check whether the RS Shifter & Handbrake is attached. + * Re-check which accessories are attached: the RS Shifter & Handbrake and + * the RS H-Shifter. * - * Discovery runs once at probe, but the accessory plugs into the base's own - * USB-A port, so it can arrive or leave while the driver is loaded and the + * Discovery runs once at probe, but an accessory plugs into the base's own + * USB-A ports, so it can arrive or leave while the driver is loaded and the * wheel never re-enumerates. Without this, a wheel that came up bare reports * "none" for as long as the module stays loaded, and everything keyed on * wheel_accessory stays wrong with it (hardware-verified 2026-07-28: plugging @@ -15107,18 +15146,15 @@ static void hidpp_dd_rescan_accessory(struct hidpp_dd_ff_data *ff) struct hid_device *hid = hidpp->hid_dev; u8 idx; - if (ff->shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) { + if (ff->shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && + hidpp_root_get_feature_on_device_timeout(hidpp, ff->shifter_dev_idx, + HIDPP_DD_PAGE_BANDED_AXIS, &idx, + HIDPP_DD_PROBE_TIMEOUT)) { /* * Believed present, so one GetFeature on the index we already * know is enough to notice it has been unplugged: a sub-device * that is really there answers in about 2.5 ms. - */ - if (hidpp_root_get_feature_on_device_timeout(hidpp, - ff->shifter_dev_idx, - HIDPP_DD_PAGE_BANDED_AXIS, &idx, - HIDPP_DD_PROBE_TIMEOUT) == 0) - return; - /* + * * Retire the index first: wheel_accessory_show gates on it, so * clearing it before the name means a concurrent reader sees * "none" rather than a half-erased name. @@ -15128,13 +15164,30 @@ static void hidpp_dd_rescan_accessory(struct hidpp_dd_ff_data *ff) ff->idx_shifter_banded = HIDPP_DD_FEATURE_NOT_FOUND; ff->idx_shifter_mode = HIDPP_DD_FEATURE_NOT_FOUND; ff->accessory_name[0] = '\0'; + /* The attribute keeps naming whatever is still attached. */ + if (ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) + strscpy(ff->accessory_name, "RS H-Shifter", + sizeof(ff->accessory_name)); dd_info(hid, "RS Shifter & Handbrake removed\n"); - return; } + if (ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && + hidpp_root_get_feature_on_device_timeout(hidpp, ff->h_shifter_dev_idx, + HIDPP_DD_PAGE_RS_H_SHIFTER, &idx, + HIDPP_DD_PROBE_TIMEOUT)) { + /* Same order as above: index first, then the name. */ + WRITE_ONCE(ff->h_shifter_dev_idx, HIDPP_DD_FEATURE_NOT_FOUND); + ff->idx_h_shifter = HIDPP_DD_FEATURE_NOT_FOUND; + if (!strcmp(ff->accessory_name, "RS H-Shifter")) + ff->accessory_name[0] = '\0'; + dd_info(hid, "RS H-Shifter removed\n"); + } + if (ff->shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && + ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) + return; /* - * Believed absent: spend each pass on ONE candidate, round-robin, - * classified exactly as discovery does. + * Something is believed absent: spend each pass on ONE candidate, + * round-robin, classified exactly as discovery does. * * Sweeping the whole list every pass would be the obvious thing and the * wrong one: a silent candidate costs HIDPP_DD_PROBE_TIMEOUT, so a bare @@ -15155,55 +15208,75 @@ static void hidpp_dd_rescan_accessory(struct hidpp_dd_ff_data *ff) { u8 cand = hidpp_dd_pedal_dev_candidates[ff->accessory_scan_cursor]; u8 cand_idx, axes, banded_idx; + int ret; ff->accessory_scan_cursor = (ff->accessory_scan_cursor + 1) % ARRAY_SIZE(hidpp_dd_pedal_dev_candidates); - if (hidpp_root_get_feature_on_device_timeout(hidpp, cand, - HIDPP_DD_PAGE_RESPONSE_CURVE, &cand_idx, - HIDPP_DD_PROBE_TIMEOUT)) + /* Just confirmed above; nothing new can sit on that port. */ + if (cand == ff->shifter_dev_idx || cand == ff->h_shifter_dev_idx) return; - if (hidpp_dd_pedal_axis_count(hidpp, cand, cand_idx, &axes)) + ret = hidpp_root_get_feature_on_device_timeout(hidpp, cand, + HIDPP_DD_PAGE_RESPONSE_CURVE, &cand_idx, + HIDPP_DD_PROBE_TIMEOUT); + if (ret && ret != -ENOENT) return; - /* - * A sub-device index belongs to the base's physical port, not to - * whatever is plugged into it (hardware-verified 2026-07-28: - * moving the accessory to the pedals' port made it report on the - * pedals' index). So the pedal index is not a safe thing to skip - * over here, and it is not a safe thing to keep believing either: - * classify whatever actually answers, and correct the cached - * pedal index when the wheel disagrees with it. - */ - if (axes == HIDPP_DD_PEDAL_AXIS_COUNT) { - if (ff->pedal_dev_idx != cand) { - ff->pedal_dev_idx = cand; - ff->idx_pedal_curve = cand_idx; - dd_info(hid, "Pedals now at dev 0x%02x (curve idx 0x%02x)\n", - cand, cand_idx); + if (ret == 0 && + hidpp_dd_pedal_axis_count(hidpp, cand, cand_idx, &axes) == 0) { + /* + * A sub-device index belongs to the base's physical port, + * not to whatever is plugged into it (hardware-verified + * 2026-07-28: moving the accessory to the pedals' port + * made it report on the pedals' index). So the pedal + * index is not a safe thing to skip over here, and it is + * not a safe thing to keep believing either: classify + * whatever actually answers, and correct the cached pedal + * index when the wheel disagrees with it. + */ + if (axes == HIDPP_DD_PEDAL_AXIS_COUNT) { + if (ff->pedal_dev_idx != cand) { + ff->pedal_dev_idx = cand; + ff->idx_pedal_curve = cand_idx; + dd_info(hid, "Pedals now at dev 0x%02x (curve idx 0x%02x)\n", + cand, cand_idx); + } + return; + } + if (axes == HIDPP_DD_SHIFTER_AXIS_COUNT && + ff->shifter_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND && + hidpp_root_get_feature_on_device(hidpp, cand, + HIDPP_DD_PAGE_BANDED_AXIS, + &banded_idx) == 0) { + hidpp_dd_adopt_shifter_handbrake(ff, cand, cand_idx, + banded_idx); + /* + * Publish the index last, for the same reason removal + * clears it first: it is what the reader gates on, so + * everything it will then go on to read is already in + * place. + */ + WRITE_ONCE(ff->shifter_dev_idx, cand); + dd_info(hid, "RS Shifter & Handbrake at dev 0x%02x (curve idx 0x%02x, banded idx 0x%02x)\n", + cand, ff->idx_shifter_curve, ff->idx_shifter_banded); + return; } - return; } - if (axes != HIDPP_DD_SHIFTER_AXIS_COUNT) - return; - if (hidpp_root_get_feature_on_device(hidpp, cand, - HIDPP_DD_PAGE_BANDED_AXIS, - &banded_idx)) + + /* Answers, but is neither the pedals nor the RS Shifter & Handbrake. */ + if (ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND || + !hidpp_dd_probe_h_shifter(ff, cand)) return; - ff->idx_shifter_curve = cand_idx; - ff->idx_shifter_banded = banded_idx; - if (hidpp_root_get_feature_on_device(hidpp, cand, - HIDPP_DD_PAGE_DEVICE_MODE, - &ff->idx_shifter_mode)) - ff->idx_shifter_mode = HIDPP_DD_FEATURE_NOT_FOUND; - hidpp_dd_query_accessory_name(ff, cand); + WRITE_ONCE(ff->h_shifter_dev_idx, cand); + dd_info(hid, "RS H-Shifter at dev 0x%02x (idx 0x%02x)\n", + cand, ff->idx_h_shifter); /* - * Publish the index last, for the same reason removal clears it - * first: it is what the reader gates on, so everything it will - * then go on to read is already in place. + * Desktop mode only routes the gates once G HUB's enablement + * sequence has been sent (hidpp_dd_enable_desktop_shifter). At + * probe that happens from hidpp_dd_ff_query_settings; a shifter + * that arrives later needs it now. Onboard profiles route the + * gates on their own. */ - WRITE_ONCE(ff->shifter_dev_idx, cand); - dd_info(hid, "RS Shifter & Handbrake at dev 0x%02x (curve idx 0x%02x, banded idx 0x%02x)\n", - cand, ff->idx_shifter_curve, ff->idx_shifter_banded); - return; + if (ff->current_mode == 0) + hidpp_dd_enable_desktop_shifter(ff); } }