ps2x2pico icon indicating copy to clipboard operation
ps2x2pico copied to clipboard

Built-in software USB Hub on PIO SM

Open javavi opened this issue 1 year ago • 25 comments

When using the ps2x2pico adapter to simultaneously connect a USB keyboard and mouse, you have to connect them via an external USB hub, which creates additional inconveniences and not all of them are suitable. Perhaps a good solution would be to use the Pico-PIO-USB library for software implementation of two separate USB-A ports for separate connection of a USB keyboard and USB mouse? At the same time, the hardware USB port of Pico will remain free for other applications... for example, connecting gamepads with mapping to keyboard buttons. https://github.com/sekigon-gonnoc/Pico-PIO-USB

javavi avatar Dec 01 '24 12:12 javavi

Hi, I'm actually using this already for the ITX-Llama integration: https://github.com/eivindbohler/itxllama/pull/2 Here a patch for TinyUSB is needed to activate both native and PIO USB ports.

I think this would be most suitable with a custom PCB discussed here: https://github.com/No0ne/ps2x2pico/issues/57

No0ne avatar Dec 01 '24 12:12 No0ne

Currently both PIOs are used for PS/2 output and input. So either PS/2 input has to be disabled or a Pico 2 (RP2350) will be needed.

No0ne avatar Dec 01 '24 12:12 No0ne

But isn’t it possible to spin both PS/2 on one PIO only on different SM, and USB on another PIO?

javavi avatar Dec 01 '24 21:12 javavi

Yes thats what I'm doing on the ITX-Llama. There is no PS/2 input/passthru on the ITX-Llama, but the normal ps2x2pico has that feature enabled.

No0ne avatar Dec 02 '24 04:12 No0ne

Currently both PIOs are used for PS/2 output and input. So either PS/2 input has to be disabled or a Pico 2 (RP2350) will be needed.

But in RP2040, one PIO has four SMs, is it really impossible to process two PS/2 interfaces with them? And use another PIO for software implementation of USB... Here is the Pico-PIO-USB library that puts forward such requirements: Resource Usage

  • 1 PIO, 3 state machines, 32 instructions
  • Two GPIO for D+/D- (Series 22ohm resitors are better)
  • 15KB ROM and RAM
  • (For Host) One 1ms repeating timer

javavi avatar Dec 03 '24 11:12 javavi

Yes, its already working, one PIO is used for output and one for input. If the input is disabled it can be used for USB as seen on the ITX-Llama.

Do you want to try this out?

No0ne avatar Dec 03 '24 11:12 No0ne

Do you want to try this out?

Yes, it would be interesting, where can I see the schematic and firmware?

javavi avatar Dec 03 '24 11:12 javavi

I don't have any schematic as I don't have any KiCAD skills, but we can agree on using GPIO16/17 and GPIO18/19 as D+/D- and I'll send you a testing firmware build.

No0ne avatar Dec 03 '24 11:12 No0ne

I don't have any schematic as I don't have any KiCAD skills, but we can agree on using GPIO16/17 and GPIO18/19 as D+/D- and I'll send you a testing firmware build.

OK! I'll try to assemble a prototype of such an adapter device and let you know... and also, will it be possible to use arbitrary pairs of ports for USB interfaces, for example GP0, GP1 and GP2, GP3?

javavi avatar Dec 03 '24 11:12 javavi

Correct, any GPIO pairs are working (without space between D+/D- and none of the PS/2 pins ;)

No0ne avatar Dec 03 '24 11:12 No0ne

2xUSB-PIO-2xPS2 I plan to do it according to this scheme

javavi avatar Dec 03 '24 15:12 javavi

Try this: pio-usb-test.zip

No0ne avatar Dec 03 '24 20:12 No0ne

Today, I quickly assembled this circuit, flashed your firmware... And yes! It works! photo_2024-12-05_01-34-46

javavi avatar Dec 04 '24 23:12 javavi

Just a question out of curiosity: Is it possible to do this so that in addition to the ports of the software USB Hub, the built-in USB in Pico also works?

javavi avatar Dec 05 '24 10:12 javavi

I also have an adapter made for standard firmware, but I can solder two USB ports to it. Could you rebuild your software for this connection scheme? 2xUSB-PIO-2xPS2_V2

  • It would be good to have a port configurator for freedom of schematic creativity.

javavi avatar Dec 05 '24 10:12 javavi

Now all three ports should work: pio+native-usb-test.zip

No0ne avatar Dec 05 '24 11:12 No0ne

I made an adapter on a normal breadboard, checked it with the latest firmware and it works in all combinations of USB keyboard and mouse connections, even if two keyboards or two mice are connected at the same time. Cool!!! photo_2024-12-05_15-35-33

javavi avatar Dec 05 '24 13:12 javavi

:wave: I'd be happy to put together a KiCAD schematic and PCB for this. I have a few questions first:

  1. Can we slap two PS/2 ports on there in parallel for people who don't have a combo PS/2 port? (just wire all 6 pins to both ports and expect that people will not do something weird like connect them to two computers at once)
  2. Do you have a part number for the ZD 3V3 so I don't mess it up?
  3. Are those really just 22 ohm resistors?
  4. For the PCB, do we want to stick with the Raspberry Pi Pico or Pico 2, or switch to the Waveshare RP2040-zero?

Personally, I like the smaller form factor of the Waveshare and the built-in USB-C port. I'm not super keen on making boards for both the rPi & Waveshare footprints since I'd then feel obligated to build, test and stock them for people who want a ps2x2pico without any soldering.

Oh, and I guess maybe we should move this conversation over to #57 since it's about the hardware and this ticket is about the software?

hax0rbana-adam avatar Dec 05 '24 18:12 hax0rbana-adam

Can we slap two PS/2 ports on there in parallel for people who don't have a combo PS/2 port? (just wire all 6 pins to both ports and expect that people will not do something weird like connect them to two computers at once)

I'd second this. Properly wired PS/2 combo-port breakout cables are surprisingly difficult to find cheaply in Canada so, for the ps2x2pico I built, I just bought a dirt-cheap PS/2 male-to-male cable (Seriously. Why?) from China, cut it in half, and made some little printer-paper-and-scotch/sellotape flags to say which one to plug into the keyboard port and which one to plug into the mouse port.

For the PCB, do we want to stick with the Raspberry Pi Pico or Pico 2, or switch to the Waveshare RP2040-zero?

As a data point, I like the USB-C port on my YD-RP2040, but a big part of the reason I chose it was that it was the most inexpensive thing I could find. I didn't want to be paying more for the PS/2-to-USB adapter than I paid for the thin client I was repurposing into a fanless Win98SE retro PC.

ssokolow avatar Dec 05 '24 18:12 ssokolow

Now all three ports should work: pio+native-usb-test.zip

Which version of the source code does this file correspond to? I would like to make a version. Is that possible?

zoushiyin avatar Dec 09 '24 12:12 zoushiyin

Its currently in a separate branch: https://github.com/No0ne/ps2x2pico/tree/65-built-in-software-usb-hub-on-pio-sm

No0ne avatar Dec 09 '24 12:12 No0ne

Look, people are already making adapter boards using a simplified scheme. :)) photo_2024-12-09_18-38-57 photo_2024-12-09_18-40-25 photo_2024-12-09_18-41-03 photo_2024-12-09_18-41-12 https://github.com/xtremespb/usb2ps2-zero

javavi avatar Dec 09 '24 16:12 javavi

Its currently in a separate branch: https://github.com/No0ne/ps2x2pico/tree/65-built-in-software-usb-hub-on-pio-sm Hello, @No0ne

I hope this message finds you well. I have followed the schematic from this comment to design my PCB for the Pico Zero version. After flashing the firmware, I noticed that there is no response from the inputs and outputs. Additionally, I am unsure where to set the GPIO pins for the USB port, and the LED configuration has not been updated for the Zero version, so the LEDs do not light up.

However, when I flash the latest code, the USB host input for keyboard and mouse works correctly, and the PS/2 output also functions as expected.

zoushiyin avatar Jan 04 '25 13:01 zoushiyin

@No0ne I soldered another minimalistic adapter based on RP2040-Zero, I wanted to use slightly different ports to connect to PS/2, but I couldn't compile the firmware. The code from the branch [65-built-in-software-usb-hub-on-pio-sm] compiles but doesn't work at all. Could you help with the firmware for this connection scheme? Image Image

javavi avatar Jul 05 '25 09:07 javavi

@No0ne Everything worked out! It was just necessary to apply a patch to the library TinyUSB 0.17.0

javavi avatar Jul 16 '25 10:07 javavi