picotouch
A Pico 2 that gives a Mac a second, hardware pointer and keyboard driven over USB serial. The host writes commands to the board's serial port, and the board sends them back as real HID input on the same USB link. macOS treats that input as the user's own, so it works on prompts that ignore synthetic events, such as the privacy and security dialogs (verified on a TCC Automation prompt).
There is no touchscreen: macOS has no touchscreen driver. The pointer is an absolute HID pointer, the kind QEMU's usb-tablet uses, which macOS drives natively. Beside it is an ordinary relative mouse, for movement that has to look like a hand on a mouse (captcha sliders, hover-tracking widgets).
USB interfaces
| Interface | What it's for |
|---|---|
| CDC-ACM "picotouch commands" | The command channel (below). macOS names it /dev/cu.usbmodem… after the USB location; picotouch list finds it by product name and serial. |
| HID "picotouch input" | Report 1 is the absolute pointer: 5 buttons, X and Y in 0–32767, a vertical wheel and horizontal pan. Report 2 is a standard 6-key keyboard. |
| HID "picotouch mouse" | A standard relative mouse: 5 buttons, X and Y moves of −127–127 counts, wheel and pan. It has an interface of its own because macOS ignores the absolute pointer's buttons when a relative mouse shares its interface. |
| RP2 reset interface | Lets picotool's -f reach a running board, as in picobridge: picotool load … -f reflashes without pressing BOOTSEL, picotool reboot -f --ser <serial> restarts it. |
Command channel
One command per line (\n; \r is ignored), decimal arguments, one answer
line per command. The board reads the next line only after answering the last,
and it answers ok only once the host has collected the HID report, so a
command is done when its ok arrives.
| Command | Meaning |
|---|---|
pointer B X Y W P |
Buttons held B (bit 0 left, 1 right, 2 middle, 3 back, 4 forward), position X Y (0–32767 across the display), then scroll W wheel detents (positive is up) and P pan detents (positive is right), each −127–127. |
motion B DX DY W P |
Buttons held B on the relative mouse (bits as for pointer), a move of DX DY counts (positive is right and down), then W wheel and P pan detents, each −127–127. |
keyboard M [K…] |
Modifiers held M (bit 0 control, 1 shift, 2 option, 3 command; 4–7 the right-hand ones) and up to 6 keys held, as HID keyboard usages. |
release |
Let go of every button and key, on both pointing devices. |
info N |
Answers `picotouch protocol=2 serial= held=<0 |
A bad command answers error <reason>. The protocol number changes with any
incompatible change, and the host tool refuses a board with another number.
The board sends one report at a time and reads the next command only once the host has it, so every report reaches the host in the order its command was sent, across all three devices.
macOS treats the two pointing devices as two mice. A button is down while
either one holds it, and each device's buttons are let go of on that device:
motion 0 … doesn't let go of a button pointer pressed. Any absolute
report that differs from the one before puts the pointer back at its
position, even one that only changes the buttons, so a drag made with
relative moves has to press and let go with motion. macOS ignores an
absolute report that is the same as the one before, even when the other
mouse has moved the pointer since; the host tool's move sends two reports
for that reason (below).
Nothing stays held by accident. The board lets go of everything when the host closes the port, and when a button or key has been held for 5 s with no command in between. A host that holds something longer (a slow drag) has to keep sending.
Host tool
cmd/picotouch (Go, macOS) drives a board on the Mac it is plugged into:
go build -o picotouch ./cmd/picotouch
./picotouch list # serial and port of each board
./picotouch move 2560 720
./picotouch glide 2560 720 # the relative mouse, as a hand would; -hold left drags
./picotouch motion 40 -25 # the relative mouse, raw counts; -hold, -step
./picotouch click 2732 998 # -button right, -count 2
./picotouch drag 100 100 400 300
./picotouch scroll 2560 720 -3 # 3 detents down
./picotouch key cmd+space escape
./picotouch type 'hello, world'
./picotouch release
Positions are global display points on the main display, the coordinates
screencapture, CGEvent and window lists use. On a HiDPI display that is half
the pixel count. The tool aims each one at the middle of its point; on iso
(one 5120×1440 display) every position tested landed exactly on its point.
How macOS spreads the absolute range over several displays hasn't been
checked; the tool assumes the main display only.
move, and the start of click, drag and scroll, send the absolute
position twice, first one unit off (inside the same point) and then on it,
so the move lands even when the last absolute report was at that position
and something else has moved the pointer since.
glide moves along a slight curve with the bell-shaped speed of a reaching
hand and a tremor under a point, in a time that grows with the distance
(about 0.3 s for a few points, 1.2 s across iso's display; -duration sets
it). macOS accelerates relative motion, so a count isn't a point: glide
reads the pointer's position after every report and steers back onto its
path, and ends on the target point. motion sends raw counts, at most
-step (default 10) per report, 8 ms apart, along a straight line.
type uses a US ANSI layout. Apps may still change what arrives: TextEdit,
for example, turns ' and " into curly quotes.
The device package is the same thing as a library: Find, Open,
CursorPosition, and Pointer, Move, Motion, Glide, Keyboard and
Release on the open board.
macOS notes
- The first time the board's keyboard appears, macOS opens the Keyboard Setup Assistant ("Your Raspberry Pi device cannot be identified"). Quit it; macOS then treats the keyboard as ANSI. The board can click Quit itself.
- An Apple silicon laptop asks once whether to allow a new USB accessory. A desktop Mac doesn't.
Build
export PICO_SDK_PATH=~/opt/pico-sdk PATH=~/opt/arm-gnu-toolchain-15.3.rel2-darwin-arm64-arm-none-eabi/bin:$PATH
cmake -S firmware -B firmware/build -G Ninja && ninja -C firmware/build # flash image
cmake -S firmware -B firmware/build-ram -G Ninja -DPICOTOUCH_NO_FLASH=ON && ninja -C firmware/build-ram # RAM-only
picotouch builds with Pico SDK 2.3.1, and configure fails on any other release. A build directory keeps the SDK path it was configured with, so after changing SDKs, delete it and configure again.
Load
picotool load -x firmware/build-ram/picotouch.uf2 --ser <serial> -f # run from RAM
picotool load -v -x firmware/build/picotouch.uf2 --ser <serial> -f # write to flash
Drop -f for a board already in BOOTSEL. A blank board starts in BOOTSEL.
Brick safety
- The watchdog (2 s) resets a hung loop. A reboot caused by the watchdog, or any hard fault, goes into BOOTSEL instead of rerunning the image, so a hang can't turn into a boot loop that picotool can't reach.
- A RAM-only (
no_flash) build leaves flash alone, and a normal reset brings back whatever is in flash. - A USB-requested BOOTSEL reboot always keeps PICOBOOT enabled. Hosts can only turn off the mass-storage drive.