5.1 KiB
USB4VC Technical Notes
Get USB4VC | Official Discord | Getting Started | Table of Contents
This document contains technical information for USB4VC, which should be helpful for tinkering, contributing, and making your own Protocol Cards.
Still mostly under construction, aiming to add more details before public release in April. In the meantime, if you have any particular technical questions or comments, let me know!
Linux Input Event Codes
Raspberry Pi runs Linux, which uses Input Event Codes. Here's a very simplified description:
- Connected input devices show up in
/dev/inputas files:
$ ls /dev/input/
event0 event1 event2 mice mouse0 mouse1
-
Reading from one of those files returns input events. Try
cat /dev/input/mice! -
On RPi, 16 Bytes are returned each time there is an event. They are arranged as follows:
| Byte | Name |
|---|---|
| 0-7 | Timestamp |
| 8-9 | Event Type |
| 10-11 | Event Code |
| 12-15 | Event Value |
-
A list of all Event Type, Code and Values can be found here
-
Keyboard keys and mouse/gamepad buttons are EV_KEY type, mouse moments are EV_REL (relative) type, and joystick moments are EV_ABS (absolute) type.
-
Once you know the Event Type, you can look up Event Code to see which key/button/axes is being updated.
-
Event Value will be 1 (pressed) or 0 (released) for buttons, and a signed value for relative or absolute axes.
-
Here's a good article that goes into a bit more details.
-
You can install
evtestand see what your device is returning in real time. -
USB4VC reads those events from all input devices, processes them, and send them out to the Protocol Card.
Hardware Pinout
The Protocol Card connector is the same as the Raspberry Pi Header, although the pins are flipped around.
Most of the pins are already in use:
SPI Communication Protocol
Raspberri Pi communicates with Protocol Card through SPI. Here's a quick introduction if you're unfamiliar.
RPi is master, P-card is slave. Mode 0 is used (CPOL and CPHA both 0), SCLK is 2MHz.
[include a sample capture.]
RPi and P-Card communicates via fixed-length 32-byte packets. Detailed description of messaging protocol can be found here.
Latency Information
Input latency can be introduced during all stages of input chain. Using keyboards as example, we have:
-
Step 1: Switch physically depressed
-
Step 2: Keyboard sends out event on USB/Bluetooth
-
Step 3: Raspberry Pi processes the event and informs the Protocol Card
-
Step 4: Protocol Card sends out the keystroke to retro computer
-
Step 5: Retro computer responds to the keystroke.
The part we're interested in is Step 3 and 4, as any time spent here is the additional delay from USB4VC.
To accurately measure the delay, I used a logic analyzer connecting to keyboard USB lines and PS/2 output on the IBM PC Protocol Card. Here is the delay in action:
From the keystroke appearing on USB, to keystroke appearing on PS/2, it took 487 microseconds.
Zoomed out capture with multiple keypresses:
I tested out different generations of Raspberry Pis, and here is the result:
| RPi Generation | Avg. Latency |
|---|---|
| 2 | 1ms |
| 3 | 0.63ms |
| 4 | 0.5ms |
You can find the capture files here, open with saleae app, search PID ACK for USB input events, more info in this video
Developing your own Protocol Card
USB4VC will send out keyboard and mouse event on SPI regardless of whether a protocol card is inserted or not. Although it will display appropriate options for switching protocols if the protocol card ID is recognized.
SPI Format, AVR based arduino probably wont work, suggested to use STM32, include link.
RPi Header pinout, explain what each pin does.
Current limits etc.
Questions or Comments?
Feel free to ask in official Discord Chatroom, raise a Github issue, DM on Twitter, or email dekunukem gmail.com!


