Skip to content

Bluetooth support#44

Open
reinauer wants to merge 11 commits into
borb:mainfrom
reinauer:bluetooth
Open

Bluetooth support#44
reinauer wants to merge 11 commits into
borb:mainfrom
reinauer:bluetooth

Conversation

@reinauer

Copy link
Copy Markdown
Contributor

This PR implements Bluetooth support for amigahid-pico when using
a Pico W instead of a Pico.

The OLED display can be used to coordinate pairing of keyboards and
mice.

My tests with a Logitech Pebble Bluetooth LE mouse were successful,
however I have not tested a large amount of Bluetooth HID devices
yet.

Assembly of the adapter will be a little trickier around the debug
port, but it can easily be done without spinning a new amigahid-pico
board with three bodge wires.

The PR is based on top of my previous PR to fix quadrature mouse
handling, so these commits are in thir PR as well:

  • platform/amiga: fix quadrature mouse delta handling
  • debug: add HID and mouse status diagnostics
  • debug: gate input tracing behind build flags
  • platform/amiga: queue mouse motion across cores
  • debug: gate HID status behind a build flag

Bluetooth specific commits:

  • input: track USB HID state by source
  • bluetooth: add Pico W HID host support
  • debug: show Bluetooth state and pairing on OLED

reinauer added 11 commits April 18, 2026 16:30
Keep mouse motion in 16-bit accumulators and preserve divider
remainders between output batches.

This stops small axis-only movement from being dropped before it
reaches the Amiga quadrature generator. It also aligns the initial
quadrature state with the idle line levels used at init.
Show HID mount state on the OLED, including device address,
instance, protocol and receive-report status.

Also print the latest mouse deltas and button bitmap, and reset
stale report counts on mount and unmount so the status line stays
accurate.
Add DEBUG_MOUSE and DEBUG_KEYBOARD build options so the
per-report mouse trace and per-key keyboard trace can be
compiled out of the default build.

This keeps the debug code available when needed without
forcing the hot input paths to update UART and the OLED on
every event.
Replace the shared x/y accumulators with a queue-backed handoff
between the USB host side and the quadrature output loop.

This removes the racy cross-core read-modify-write pattern that
could drop motion under load. It also lets the quadrature loop
merge newly arrived deltas between output steps.
Add DEBUG_HID_STATUS so the OLED HID mount and receive status
line can be compiled out of the default build.

This keeps the status display available for diagnosis without
forcing line 2 updates in normal use.
Move keyboard and mouse state out of usb_hid.c into a shared input
bridge and allocate slots by device address plus interface number.
Reset that state on mount and disconnect so each source keeps its
own keys, buttons and LED state.

This avoids cross-talk between composite or multi-device HID
setups and gives USB and Bluetooth a common path into the Amiga
input code.
Add an optional BTstack-based HID host for Pico W builds and hook
it into the main loop without taking over core1. Classic HID and
BLE boot keyboard and mouse reports are queued back into the shared
input bridge, while the build only enables the feature on CYW43
boards.

This keeps the existing USB and quadrature mouse paths intact while
allowing Bluetooth keyboards and mice to drive the Amiga through
the same input handling code.
Display Bluetooth status on the OLED and show pairing prompts such
as PIN code and passkey confirmation on the last line. Clear those
when pairing completes, scanning restarts or a link closes so the
screen reflects the current Bluetooth state.

This makes Pico W bring-up and pairing usable without relying on
UART logs, and it keeps mouse debug visible whenever no Bluetooth
prompt is active.
Clear the internal caps lock state when a local Ctrl-Amiga-Amiga reset
is asserted and best-effort track resets seen on the keyboard reset
line. Also resync attached USB keyboard LEDs when the state is cleared.

This keeps the Pico and host keyboard from disagreeing about caps lock
after a reset, which otherwise leaves the LED and next caps keypress in
the wrong state.
Move the blocking Amiga keyboard wire transmission out of the USB HID
callback path and into a small event queue serviced from amiga_service.
Keep key translation, modifier tracking, caps lock handling and reset
state updates immediate, but defer the sleep-heavy serial send work.

This reduces how long core0 stays away from USB host processing while
keys are being sent, which should cut mixed keyboard and mouse latency.
Add support for HID mouse wheel reports in the Amiga quadrature
mouse backend by emitting TankMouse/Cocolino side-channel packets.

The TankMouse driver polls the middle/POT line and reads encoded
wheel data from the low Amiga mouse counter bits. Queue wheel
reports, answer polls with the expected up/down codes, and restore
quadrature phase after sampling so pointer motion stays stable.

Suppress wheel packets while mouse buttons are held, matching the
driver limitation. Add debug hooks for incoming wheel reports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant