Commit Graph

6 Commits

Author SHA1 Message Date
Red Bear OS 230a219c5f USB: graceful disconnect handling in usbhidd — survive transfer errors
Replaced .context("failed to get report")? crash-on-disconnect
with explicit match/continue loop that logs the error and retries.

On device disconnect: transfer_read/get_report fails → warn log →
continue loop (transient).  Driver survives USB unplug/replug
without process exit.  On permanent failure: loop exits normally.

Pattern to replicate across all class drivers.
2026-07-07 17:32:08 +03:00
Red Bear OS 2206ca8f94 usbhidd: P5 slice 3 — gamepad support (axes + 32 buttons)
Add gamepad HID support following Linux 7.1 hid-input.c patterns:

  Gamepad axes (GenericDesktop page 0x01):
    - X (0x30), Y (0x31): stored in gamepad_axes[0..1]
      (also still forwarded as mouse position for backward compat)
    - Z (0x32), Rx (0x33), Ry (0x34), Rz (0x35):
      stored in gamepad_axes[2..5] (triggers + right stick)
    - Hat Switch (0x39): stored in hat_switch (i8)

  Gamepad buttons (Button page 0x09):
    - Extended from 3 to 32 buttons
    - First 3 buttons still tracked as mouse buttons (backward compat)
    - All button states tracked in gamepad_buttons (u32 bitmask)

  State tracking:
    - 6-axis array (gamepad_axes: [i32; 6])
    - 32-button bitmask (gamepad_buttons: u32)
    - D-pad hat switch (hat_switch: i8)

Cross-reference: Linux 7.1
  - drivers/hid/hid-input.c: hidinput_configure_usage()
  - map_abs(ABS_X|ABS_Y|ABS_Z|ABS_RX|ABS_RY|ABS_RZ|ABS_HAT0X)
  - BTN_GAMEPAD / BTN_SOUTH / BTN_EAST / BTN_TR / BTN_TL

This means USB gamepads (Xbox, PlayStation, Switch Pro, generic HID)
will now produce axis and button events through ProducerHandle.
2026-07-07 12:21:43 +03:00
Red Bear OS f98dd4339f usbhidd: P5 slice 2 — keyboard LED sync via SET_REPORT
Add Caps Lock, Num Lock, and Scroll Lock LED synchronization
following Linux 7.1 hid-input.c: hidinput_output_event().

Led state tracking:
  - Caps Lock   (usage 0x39) → toggles bit 1
  - Scroll Lock (usage 0x47) → toggles bit 2
  - Num Lock    (usage 0x53) → toggles bit 0

SET_REPORT (Output) via XhciClientHandle::device_request():
  - PortReqTy::Class, PortReqRecipient::Interface
  - bRequest = 0x09 (SET_REPORT)
  - wValue = (0x02 << 8) | 0x00  (Output report type, report ID 0)
  - wIndex = interface_num
  - Data = 1-byte LED state

The SET_REPORT is sent only when the LED state changes (tracked
with last_led_state sentinel).  A failed SET_REPORT is logged at
warn level but does not block the input loop.

Cross-reference: Linux 7.1
  - drivers/hid/hid-input.c: hidinput_output_event()
  - drivers/hid/usbhid/hid-core.c: usbhid_output_report()
  - HID 1.11 spec §7.2.1: SET_REPORT request

This means USB keyboards with Caps/Num/Scroll Lock LEDs will now
have their LEDs synchronized with the host lock state.
2026-07-07 12:16:05 +03:00
Red Bear OS 5276fcb739 usbhidd: P5 slice 1 — consumer key (media key) support
Add support for HID Consumer page (usage page 0x0C) as key events.
Cross-referenced with Linux 7.1 drivers/hid/hid-input.c consumer
usage mapping.

Changes:
  send_key_event() now handles usage_page 0x0C with a concrete
  mapping table:

    0x00E2 → scancode 0xF0  (Mute)
    0x00E9 → scancode 0xF1  (Volume Up)
    0x00EA → scancode 0xF2  (Volume Down)
    0x00B0 → scancode 0xF3  (Play)
    0x00B1 → scancode 0xF4  (Pause)
    0x00B3 → scancode 0xF5  (Next Track)
    0x00B4 → scancode 0xF6  (Previous Track)
    0x00B5 → scancode 0xF7  (Stop)
    0x00CD → scancode 0xF3  (Play/Pause)
    0x0183 → scancode 0xF8  (AL Config)
    0x018A → scancode 0xF9  (Email)
    0x0192 → scancode 0xFA  (Calculator)
    0x0194 → scancode 0xFB  (My Computer)
    0x0221 → scancode 0xFC  (Search)
    0x0223 → scancode 0xFD  (Home)

  Event loop now dispatches usage_page 0x0C to send_key_event,
  treating it identically to keyboard key press/release.

  OrbKeyEvent.scancode is u8, so we use the 0xF0-0xFF vendor-key
  block instead of the full Linux evdev encoding (0xC0000 | usage).

Cross-reference: Linux 7.1
  - drivers/hid/hid-input.c: hidinput_configure_usage()
  - include/uapi/linux/input-event-codes.h: KEY_VOLUMEUP, etc.

This means USB keyboards with media keys (Volume, Mute, Play/Pause,
Next/Previous Track) will now produce scancodes the display server
can map to media actions.
2026-07-07 12:11:12 +03:00
Red Bear OS de9d1f495f base: ps2d/inputd — add startup info logs for boot diagnostics
Both daemons previously produced no Info-level output on successful start,
making it impossible to confirm from the boot log whether ps2d and inputd
were actually alive. The kernel serial log shows no [INFO] ps2d: or [INFO]
inputd: lines during normal boot, leading operators to assume the input
stack was dead when in fact it was working.

This adds two log::info!() calls:

- ps2d main.rs: after daemon.ready(), log that ps2d has registered
  its ProducerHandle and is listening on serio/0 (keyboard) and
  serio/1 (mouse).

- inputd main.rs: after setup_logging, log that inputd has registered
  scheme:input and is waiting for handles.

These are emitted only on the successful startup path; existing
.error!()/.warn!() calls continue to surface real failures. No behavior
change; no functional effect on input handling.
2026-06-30 02:23:30 +03:00
Red Bear OS dd08b76a39 Red Bear OS base baseline from 0.1.0 pre-patched archive 2026-06-27 09:21:43 +03:00