Skip to content

Commit 6517ea8

Browse files
Ballistyxxclaude
andcommitted
kart-core: enable the Hori wheel under PlatformIO/CLI flashing
The bundled USBHost_t36 (v0.2) only claims Xbox One controllers whose VID/PID are in a hardcoded table (Microsoft devices only). The Hori "Racing Wheel Overdrive" (0F0D:0152) uses the standard Xbox One GIP interface and works once its VID/PID is in that table — but without it JoystickController::claim() bails and the wheel never enumerates. This is why the project previously had to flash from the Arduino IDE (whose Teensyduino shipped a newer USBHost_t36 that knew the wheel); every PlatformIO flash failed to see the wheel. patch_usbhost_t36.py is a pre-build extra_scripts step that idempotently injects the wheel's VID/PID into the framework's joystick.cpp before each build. The Teensy can now be flashed from the CLI with the wheel working in production — no Arduino IDE required. Verified on hardware: enum=1/type=3, axis 0 sweeps the full ±32768 range and STEER set_cdeg tracks it proportionally to ±3000 (±30°), streaming to the Steervo at 50 Hz (steer_link=1). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent e640a14 commit 6517ea8

3 files changed

Lines changed: 67 additions & 5 deletions

File tree

docs/traction-bringup.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,21 @@ Shutdown: lift throttle → DRIVE button (disarm) → SAFE → THEN key off.
170170

171171
## Flashing workflow (important)
172172

173-
- **Flash from the Arduino IDE**, not `pio … -t upload`. The CLI's auto-reboot
174-
into the bootloader fails on this rig (the program button is hard to reach in
175-
the enclosure), *and* — crucially — the wheel only re-enumerates on the
176-
Teensy USB host after the IDE flow power-cycles it. A CLI soft-reboot leaves
177-
the wheel dark.
173+
- **CLI flashing works** now (`pio … -t upload`, or the Teensy Loader GUI +
174+
program button). The Hori wheel enumerates under the PlatformIO build because
175+
**`patch_usbhost_t36.py`** (a pre-build `extra_scripts` step) injects the
176+
wheel's VID/PID (`0F0D:0152`) into USBHost_t36's `JoystickController` table at
177+
build time. Before that fix the bundled USBHost_t36 (v0.2) didn't know the
178+
wheel, so it only worked when flashed from the Arduino IDE — whose Teensyduino
179+
shipped a USBHost_t36 that already recognized it. That's why the IDE *used to*
180+
be required; it no longer is.
181+
- **After any flash, the USB host needs a fresh connect to re-enumerate the
182+
wheel.** A soft-reboot leaves an already-connected wheel dark, so either
183+
**hot-plug the wheel** (unplug/replug at the Teensy USB-A host port) or
184+
power-cycle the board after flashing. Confirm with `WHEELRAW` (`enum=1`,
185+
`type=3`).
186+
- The program button can be hard to reach in the enclosure; the Teensy Loader
187+
GUI waits for the press.
178188
- kart-core is a PlatformIO project; the IDE needs a flat sketch. Run
179189
**`firmware/kart-core/gen_arduino_sketch.sh`** to (re)generate
180190
`arduino/kart_core/` from the canonical `src/` + `lib/` + `firmware/common`
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
# PlatformIO pre-build script: teach USBHost_t36's JoystickController about the
3+
# Hori "Racing Wheel Overdrive" (VID 0x0F0D / PID 0x0152).
4+
#
5+
# Why: the bundled USBHost_t36 (v0.2) only claims Xbox One controllers whose
6+
# VID/PID are in its hardcoded table (Microsoft devices only). The Hori wheel
7+
# uses the standard Xbox One GIP interface (class 0xFF/0x47/0xD0) and works fine
8+
# once its VID/PID is in that table — but without it, JoystickController::claim()
9+
# bails at the VID/PID check and the wheel never enumerates as a joystick. This
10+
# is exactly why the project previously HAD to flash from the Arduino IDE (whose
11+
# Teensyduino shipped a USBHost_t36 that knew the wheel). Patching here lets us
12+
# flash from PlatformIO/CLI with the wheel working in production.
13+
#
14+
# This runs before every build, finds the framework's joystick.cpp, and inserts
15+
# the table entry if it is missing (idempotent). It re-applies automatically
16+
# after a toolchain reinstall, and always patches the matching library version
17+
# (no vendored fork to drift from the core).
18+
19+
import os
20+
21+
Import("env") # noqa: F821 (injected by PlatformIO)
22+
23+
VID_PID = "0x0f0d, 0x0152"
24+
ENTRY = " { 0x0f0d, 0x0152, XBOXONE, false }, // Hori Racing Wheel Overdrive (added by patch_usbhost_t36.py)\n"
25+
ANCHOR = "pid_vid_mapping[] = {"
26+
27+
pkg_dir = env.PioPlatform().get_package_dir("framework-arduinoteensy") # noqa: F821
28+
joystick_cpp = os.path.join(pkg_dir, "libraries", "USBHost_t36", "joystick.cpp")
29+
30+
if not os.path.isfile(joystick_cpp):
31+
print("patch_usbhost_t36: WARNING joystick.cpp not found at %s" % joystick_cpp)
32+
else:
33+
with open(joystick_cpp, "r") as f:
34+
src = f.read()
35+
if VID_PID in src.lower():
36+
print("patch_usbhost_t36: Hori wheel (0F0D:0152) already present")
37+
else:
38+
idx = src.find(ANCHOR)
39+
if idx == -1:
40+
print("patch_usbhost_t36: WARNING anchor %r not found; wheel may not "
41+
"enumerate (USBHost_t36 layout changed?)" % ANCHOR)
42+
else:
43+
insert_at = src.find("\n", idx) + 1
44+
src = src[:insert_at] + ENTRY + src[insert_at:]
45+
with open(joystick_cpp, "w") as f:
46+
f.write(src)
47+
print("patch_usbhost_t36: added Hori wheel (0F0D:0152) to "
48+
"JoystickController VID/PID table")

firmware/kart-core/platformio.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ build_flags = -Wall -Wextra
1717
platform = teensy
1818
board = teensy41
1919
framework = arduino
20+
; Teach USBHost_t36 about the Hori wheel (0F0D:0152) before building, so the
21+
; Teensy can be flashed from PlatformIO/CLI with the wheel working — no Arduino
22+
; IDE needed. See patch_usbhost_t36.py.
23+
extra_scripts = pre:patch_usbhost_t36.py
2024
lib_deps =
2125
https://github.com/tonton81/WDT_T4.git
2226

0 commit comments

Comments
 (0)