USB mouse interceptor and injector for Teensy 4.1
Sits between a mouse and a target PC, forwarding HID reports at up to 8kHz while accepting movement injection commands from a control PC over serial. Written in bare metal Rust targeting the NXP iMXRT1062 EHCI controller directly.
Control PC ──(USB Serial)──► Teensy 4.1 ──(USB Device)──► Target PC
▲
(USB Host)
│
Mouse
- Nix with flakes enabled, or manually install:
- Rust toolchain with
thumbv7em-none-eabihftarget cargo-binutils(forcargo objcopy)teensy-loader-cligcc-arm-embedded
- Rust toolchain with
- Teensy 4.1 board
- USB mouse for testing
-
Enter the dev shell:
direnv allow -
Build:
cargo build --release -
Convert to hex:
cargo objcopy --release -- -O ihex teensytrap.hex -
Flash (press the button on the Teensy):
teensy-loader-cli -w -v --mcu=imxrt1062 teensytrap.hex
src/
├── main.rs entry point, init, main loop
├── usb/ low-level USB controller drivers
│ ├── ehci.rs host controller (USB2)
│ ├── device.rs device controller (USB1)
│ ├── qh.rs host Queue Head descriptors
│ ├── qtd.rs host Transfer Descriptors
│ ├── periodic.rs periodic frame list, 8kHz scheduling
│ ├── async_schedule.rs async schedule for control transfers
│ └── transaction.rs transfer submission and completion
├── host/ upstream mouse handling
│ ├── enumerate.rs full device enumeration
│ ├── hid.rs HID report descriptor parser
│ └── mouse.rs mouse report interpretation
├── device/ downstream device to target PC
│ ├── descriptors.rs 1:1 descriptor cloning
│ ├── endpoint.rs proxy endpoint (any type/direction)
│ └── proxy_device.rs transparent proxy device
├── proxy/ forwarding and injection
│ ├── forward.rs endpoint traffic routing
│ └── inject.rs mouse movement injection
└── serial/ control PC communication
└── command.rs injection command parser
This project is licensed under the MIT License. See LICENSE for details.