palm-client: pilot-link patch for Visor USB on macOS, verified link

macOS briefly holds the Visor right after HotSync enumerates it, so
pilot-link's single USBDeviceOpen failed with kIOReturnExclusiveAccess
and the Visor reported the connection couldn't be established. The
patch retries the open for up to 2 s. pilot-xfer -l now lists the
Visor Neo's databases.
This commit is contained in:
rich committed 2026-11-01 10:52:12 -05:00
1 parent 5163a3cd1c
commit decded0375
3 files changed
+48 -2

No files matched your search

+3 -1
View File
@@ -22,7 +22,8 @@
### Palm client
- [x] Toolchain set up: prc-tools-remix 2.3.6 + PilRC + Palm OS 3.5 SDK in Docker (`palm-client/Dockerfile`)
- [x] Scaffold: builds `visormesh.prc` (main form + "Query radio" → CMD_DEVICE_QUERY); protocol framing with host tests
- [ ] Install over USB from the dev Mac: build pilot-link (desrod) into ~/.local, `make install` tested with the Visor
- [x] USB link from the dev Mac: pilot-link (desrod @6d696653 + `tools/pilot-link-darwin-usb-open-retry.patch`) lists the Visor's databases
- [ ] `make install` puts VisorMesh on the Visor
- [ ] Emulator: CloudpilotEmu with a Palm OS 3.5 ROM (the Visor isn't emulated); optionally POSE + a Visor Neo ROM in a Windows VM
- [ ] Original Handspring SDK headers (Springboard `HsCard*` APIs; the PalmOne `HsExt.h` lacks them), needed for module-ROM work only
- [ ] Port springSD bus routines; SC16IS740 driver
@@ -51,3 +52,4 @@
- J1 (IC1HA-68RD-1.27SH(51)) found to be obsolete at DigiKey and Mouser. Ordered 1 NOS from eBay at $24.
- Removed the unverified XKB/LCSC substitute from the hardware README (it's a vertical SMD socket, not a straddle).
- Starting Palm client development.
- macOS USB sync to the Visor works with pilot-link from desrod's repo. Fixed a race where macOS holds the Visor briefly when it appears, so pilot-link's single open attempt failed with exclusive access. The retry patch is saved in `palm-client/tools/`.
+7 -1
View File
@@ -40,12 +40,18 @@ pilot-link isn't in Homebrew any more, so build https://github.com/desrod/pilot-
brew install autoconf automake libtool pkg-config libpng readline popt
git clone https://github.com/desrod/pilot-link.git ~/src/pilot-link
cd ~/src/pilot-link
git checkout 6d696653 # the commit the patch below was made against
git apply /path/to/visormesh/palm-client/tools/pilot-link-darwin-usb-open-retry.patch
./autogen.sh --prefix=$HOME/.local --enable-conduits && make -j"$(sysctl -n hw.ncpu)" && make install
```
**The patch is needed for the Visor on macOS.** When the Visor appears on USB after HotSync, macOS's own USB driver holds it for a moment. Unpatched pilot-link tries to open it once, fails with `kIOReturnExclusiveAccess` (`0xe00002c5`), and the Visor shows "The connection between your handheld computer and the desktop could not be established". The patch retries the open for up to 2 seconds.
To debug USB on macOS, add `CPPFLAGS="-DPI_DEBUG=1"` to `make`, then run with `PILOT_DEBUG="DEV SLP" PILOT_DEBUG_LEVEL=DEBUG`. Without that flag, `darwinusb.c` logs nothing, because it doesn't include `config.h`.
The Makefile uses `~/.local/bin/pilot-xfer` when it exists. On Linux, use the kernel `visor` driver and `make install PORT=/dev/ttyUSB1`.
**Not tested end to end yet.** pilot-link's macOS USB support was tested with a Tungsten E2, not a Visor.
Verified: `pilot-xfer -p usb: -l` lists the Visor Neo's databases from macOS on Apple Silicon. The Visor is behind a USB hub, so a hub works.
## Testing without hardware
@@ -0,0 +1,38 @@
diff --git a/libpisock/darwinusb.c b/libpisock/darwinusb.c
index d6c89a0f..56c39d49 100644
--- a/libpisock/darwinusb.c
+++ b/libpisock/darwinusb.c
@@ -78,6 +78,7 @@
#include <mach/mach.h>
#include <stdio.h>
#include <pthread.h>
+#include <unistd.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOMessage.h>
@@ -731,6 +732,7 @@ device_added (void *refCon, io_iterator_t iterator)
input_pipe_number = 0xff,
output_pipe_number = 0xff,
pipe_info_retrieved = 0;
+ int open_tries;
LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "darwinusb: device_added\n"));
@@ -782,7 +784,17 @@ device_added (void *refCon, io_iterator_t iterator)
LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "darwinusb: Accepted USB device, vendor: 0x%04x product: 0x%04x\n", vendor, product));
+ /* macOS's own USB driver can hold the device for a moment right
+ * after it appears (seen with a Handspring Visor), so retry for up
+ * to 2 seconds instead of giving up on the first attempt.
+ */
kr = (*dev)->USBDeviceOpen (dev);
+ for (open_tries = 0; kr == kIOReturnExclusiveAccess && open_tries < 20; open_tries++)
+ {
+ LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "darwinusb: device busy (exclusive access), retrying open\n"));
+ usleep (100000);
+ kr = (*dev)->USBDeviceOpen (dev);
+ }
if (kr != kIOReturnSuccess)
{
LOG((PI_DBG_DEV, PI_DBG_LVL_ERR, "darwinusb: unable to open device (kr=0x%08x)\n", kr));