USB HID interface

Troubles with your machine? Just want to speak about the latest improvements? This is the place!

Moderators: Mug UK, Zorro 2, spiny, Greenious, Moderator Team

User avatar
Methanoid
Captain Atari
Captain Atari
Posts: 314
Joined: Mon Jan 26, 2004 2:41 pm
Location: England.. where else?

Re: USB HID interface

Post by Methanoid »

olivierg wrote: Sun Apr 18, 2021 4:48 pm I do not agree with you:
For 'Ratari mouse' used a PI is not a good idea, it takes too long to start.
The initial project is too expensive and complex (probably for this reason it is abandoned).

You need a simple and inexpensive solution, with 2-4 USB ports for KB MS JOYSTICK USB with the 2 DB9 connectors for the old joysticks.
Ratari could have been converted to a build root (I think thats the term) Pi solution that could boot in 2-3 seconds. Andrew designed it for fun and the software was quick and dirty. Someone with more Pi knowledge could have taken that to the next level
joska
Hardware Guru
Hardware Guru
Posts: 5011
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: USB HID interface

Post by joska »

3 seconds after power-on my MSTE has finished booting. So a reset would be required to invoke the boot-manager with such a slow keyboard.

Of course, the Pi could pull down the reset-line (which is available on the keyboard connector for all machines with internal keyboards) until it's ready, but this will slow down power-on.
Jo Even

VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
fieldofcows
Retro freak
Retro freak
Posts: 12
Joined: Thu Apr 08, 2021 10:47 pm

Re: USB HID interface

Post by fieldofcows »

I bought myself a Mega ST without a keyboard so have made my own keyboard emulator based on the HD6301 emulation code in Steem. I currently have it working with a USB keyboard, mouse and joystick running on either a Rasbperry Pi 4 or Raspberry Pi Zero W although it will probably work on most variants.

I too am not happy with the boot time, although I tend to just leave the RPi powered from an external source. To address this (and based on the views I read above) I've been porting the code to a Raspberry Pi Pico. Currently I have the emulation running but I've had a really hard time getting the USB host code to work, particularly with a hub. It seems the RP2040 USB controller and reference code do not work very well. I've managed to fix or workaround most of the issues and have it working now so I should be able to get the pico working as a keyboard emulator within the next couple of days.

For anyone interested the code is here: https://github.com/fieldofcows/atari-st-rpikb. This doesn't include the pico port yet and it is still a work in progress.
User avatar
Methanoid
Captain Atari
Captain Atari
Posts: 314
Joined: Mon Jan 26, 2004 2:41 pm
Location: England.. where else?

Re: USB HID interface

Post by Methanoid »

fieldofcows wrote: Thu Apr 29, 2021 7:15 am For anyone interested the code is here: https://github.com/fieldofcows/atari-st-rpikb. This doesn't include the pico port yet and it is still a work in progress.
Brilliant... I was only after mouse emulation but this is great. I have two unused Picos so will definitely try on those when its available. I got my STe a few days ago and spent this morning cleaning the keyboard, just left the keys to dry. Your timing is excellent :D
fieldofcows
Retro freak
Retro freak
Posts: 12
Joined: Thu Apr 08, 2021 10:47 pm

Re: USB HID interface

Post by fieldofcows »

Methanoid wrote: Thu Apr 29, 2021 12:44 pm Brilliant... I was only after mouse emulation but this is great. I have two unused Picos so will definitely try on those when its available. I got my STe a few days ago and spent this morning cleaning the keyboard, just left the keys to dry. Your timing is excellent :D
What are you hoping to do? Use the original keyboard along with a USB mouse? With my Pico implementation you would have to unplug the STe keyboard and replace it with the pico meaning the mouse and keyboard would both have to be USB. Although it might be interesting to see if I can modify it to support a configuration where the original keyboard can be used.
User avatar
Methanoid
Captain Atari
Captain Atari
Posts: 314
Joined: Mon Jan 26, 2004 2:41 pm
Location: England.. where else?

Re: USB HID interface

Post by Methanoid »

Hi, well my friend Dr Amstrong made his Rasp Pi based mouse interface (up the page I posted his video link) ... I can always do that but if I could do that on a Pico it would be smaller and tidier. I've spare Picos and only one Zero (which I have earmarked for another retro job!)

I do like the original STe keyboard (especially since its cleaned and reassembled now!) but a modern mouse would just be SO much better. Didnt much like the ball mouse back in the eighties! (plus this STE didnt come with ANY mouse!)
fieldofcows
Retro freak
Retro freak
Posts: 12
Joined: Thu Apr 08, 2021 10:47 pm

Re: USB HID interface

Post by fieldofcows »

Ok, so I have a plan that will make the pico-based keyboard emulator more widely useful. I'll finish making it a full IKBD emulator meaning you can plug it in as a replacement for a missing Mega ST keyboard and connect a USB keyboard mouse and joystick. As part of this I convert the USB mouse movements into pulses that emulate the sensors on the original Atari ST mouse, allowing the original IKBD ROM to sense these pulses and tell the ST of the mouse movement (exactly as the Steem emulator does when emulating the HD6301).

But, seeing as I'm generating these simulated pulses, it wouldn't take much effort to bring those out to pico GPIO pins. It should then be possible to connect this to an ST mouse port (via a level converter?) to allow a USB mouse to work on the ST. This will allow you to use my pico code to be a full keyboard replacement or just a USB mouse interface, the only difference being how you connect it to the ST.
User avatar
Methanoid
Captain Atari
Captain Atari
Posts: 314
Joined: Mon Jan 26, 2004 2:41 pm
Location: England.. where else?

Re: USB HID interface

Post by Methanoid »

fieldofcows wrote: Thu Apr 29, 2021 10:14 pm Ok, so I have a plan that will make the pico-based keyboard emulator more widely useful. I'll finish making it a full IKBD emulator meaning you can plug it in as a replacement for a missing Mega ST keyboard and connect a USB keyboard mouse and joystick. As part of this I convert the USB mouse movements into pulses that emulate the sensors on the original Atari ST mouse, allowing the original IKBD ROM to sense these pulses and tell the ST of the mouse movement (exactly as the Steem emulator does when emulating the HD6301).

But, seeing as I'm generating these simulated pulses, it wouldn't take much effort to bring those out to pico GPIO pins. It should then be possible to connect this to an ST mouse port (via a level converter?) to allow a USB mouse to work on the ST. This will allow you to use my pico code to be a full keyboard replacement or just a USB mouse interface, the only difference being how you connect it to the ST.
Thank you :D . I believe Dr Armstrong's Pi mouse didnt use level converters as he suggested that 3.3v was detected same as 5v pulse so didnt need it. So maybe try it before you design in something that might not be needed?
MegaSTEarian
Captain Atari
Captain Atari
Posts: 400
Joined: Tue Aug 18, 2020 5:23 pm

Re: USB HID interface

Post by MegaSTEarian »

Methanoid wrote: Tue Jun 19, 2018 8:12 am Everytime I search I find great projects like this which have died.... Is anyone? Did anyone? I'd love to be able to use a modern mouse on an STE, maybe even use my regular PC KB & Mouse via a KVM switch...
Isn't this actually solved with the use of NetUSBee on AtariST/STE/Mega/MegaSTE/Falcon/TT and the Lightning USB adapter for MegaSTE/TT?

They have a pretty good mouse and keyboard driver, both projects are alive and selling, there are even version of lightning available for ST -needs some soldering AFAIK.

You connect a powered USB hub and your mouse/keyboard there and you're done. Supports KVM as well (have tested that, worked with my USB KVM).

If there was a driver for USB joystick it would be absolutely wonderful!
User avatar
Fujiyama
Atari Super Hero
Atari Super Hero
Posts: 832
Joined: Thu Jul 12, 2007 8:21 am
Location: Norway

Re: USB HID interface

Post by Fujiyama »

I haven't really looked into the NetUSB much because my cartridge port is full of daisy-chained MIDI expansion devices, so I don't think it would work unfortunately.
Mega STe with MonSTer & IDE-CF adapter | STe with MonSTer & dual IDE-CF adapter | SM-144 | NEC Multisync 1990SXi | IDE doubler | ST_ESCC | RSVE | ICD Link II | Link '97 | HD floppy drive/AJAX | HD floppy module | Minolta PCMCIA card-drive | Realtime Clock module | Discovery cartridge | Unitor-2 | Export | Combiner | Steady Eye | Human Touch | Unicorn USB

Are you a good person?
joska
Hardware Guru
Hardware Guru
Posts: 5011
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: USB HID interface

Post by joska »

MegaSTEarian wrote: Sat May 01, 2021 8:41 am Isn't this actually solved with the use of NetUSBee on AtariST/STE/Mega/MegaSTE/Falcon/TT and the Lightning USB adapter for MegaSTE/TT?
With these drivers your mouse and keyboard only works after loading the USB drivers. Also, they only work with clean applications that use the TOS keyboard/mouse/joystick vectors. This excludes most games.
Jo Even

VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
User avatar
Fujiyama
Atari Super Hero
Atari Super Hero
Posts: 832
Joined: Thu Jul 12, 2007 8:21 am
Location: Norway

Re: USB HID interface

Post by Fujiyama »

Ah! Two other reasons why it won't work for me.
The first problem (only works after loading USB drivers) appears trivial if everything works OK (i.e. the TOS 2.06 memory test while booting up can be skipped entirely by reburning the TOS EPROMs or (as I've done it) re-flashing the MonSTer flash-ROMs using your MonSTer flashing utility to skip the memory test) so you don't have to wait until the boot process is done.
But it won't let you do the usual keyboard shortcuts upon booting to bypass the AUTO folder, ACCessories or harddisk driver, and if you've messed up (i.e. disabled the USB driver then rebooted the computer) you're going to get stuck, unless you attach an Atari keyboard again...
Not for me.

The second problem is that I run a lot of MIDI software which isn't "clean", so again this isn't for me.
Mega STe with MonSTer & IDE-CF adapter | STe with MonSTer & dual IDE-CF adapter | SM-144 | NEC Multisync 1990SXi | IDE doubler | ST_ESCC | RSVE | ICD Link II | Link '97 | HD floppy drive/AJAX | HD floppy module | Minolta PCMCIA card-drive | Realtime Clock module | Discovery cartridge | Unitor-2 | Export | Combiner | Steady Eye | Human Touch | Unicorn USB

Are you a good person?
fieldofcows
Retro freak
Retro freak
Posts: 12
Joined: Thu Apr 08, 2021 10:47 pm

Re: USB HID interface

Post by fieldofcows »

So I've got the pico mostly working now. I've hooked it up to the ST and both the mouse and keyboard work. The mouse has a bit of lag and the scaling needs to be setup correctly but nothing that can't be fixed. I'll have to implement USB HID code for the joystick but I don't think this will be too hard. Once I've done that, I'll tidy up the code a bit, work out what to do with the Pico-SDK patches I needed to make to get USB working then push it to github with some instructions on how to set it all up.
MegaSTEarian
Captain Atari
Captain Atari
Posts: 400
Joined: Tue Aug 18, 2020 5:23 pm

Re: USB HID interface

Post by MegaSTEarian »

joska wrote: Sat May 01, 2021 11:41 am
MegaSTEarian wrote: Sat May 01, 2021 8:41 am Isn't this actually solved with the use of NetUSBee on AtariST/STE/Mega/MegaSTE/Falcon/TT and the Lightning USB adapter for MegaSTE/TT?
With these drivers your mouse and keyboard only works after loading the USB drivers. Also, they only work with clean applications that use the TOS keyboard/mouse/joystick vectors. This excludes most games.
Ahh, yes. Can’t use it before the OS.
fieldofcows
Retro freak
Retro freak
Posts: 12
Joined: Thu Apr 08, 2021 10:47 pm

Re: USB HID interface

Post by fieldofcows »

Methanoid wrote: Fri Apr 30, 2021 9:50 am Thank you :D . I believe Dr Armstrong's Pi mouse didnt use level converters as he suggested that 3.3v was detected same as 5v pulse so didnt need it. So maybe try it before you design in something that might not be needed?
I need to use a level converter for the IKBD connection as the pico is receiving serial data from the ST with 5V levels. However, I'm not sure if it would be necessary for the mouse connection. They are so cheap and I've got a small stock of them so when I test it out I'll probably just use it to be safe.

I spent some time refining the mouse code yesterday. This works by taking the mouse data from USB and turning it into a frequency at which the encoded quadrature mouse signal is then generated from. This is then sampled on the emulated GPIO by the Atari keyboard ROM code and converted into serial data to send to the ST. The previous code (mostly borrowed from Steem) was using the emulated HD6301 clock cycles to update the mouse signals but I wanted to produce an output that can then be tapped and used as an Atari mouse emulator by plugging it into a mouse port on an ST so I based the timings off the RP2040 clock instead. Ideally I could use the RP2040 PIO for this - something to look at later.

Anyway, it's working quite well now. The mouse responds nicely and at a good speed. The photo shows the output of the USB->Atari mouse conversion on 2 GPIO outputs for the X axis.

Image
User avatar
Methanoid
Captain Atari
Captain Atari
Posts: 314
Joined: Mon Jan 26, 2004 2:41 pm
Location: England.. where else?

Re: USB HID interface

Post by Methanoid »

very nice... have you tried different mice (Dr Armstrong reported some were usable and others not depending on their DPI settings) - it may be the code will need to be tweaked by end users for "mouse speed" ??

I did get myself a USB mouse adapter (but its one of those PS2-protocol-only ones - so this is definitely better). But this could allow wireless mice too :-)
fieldofcows
Retro freak
Retro freak
Posts: 12
Joined: Thu Apr 08, 2021 10:47 pm

Re: USB HID interface

Post by fieldofcows »

I've tried a couple of mice. One wireless, one wired. Both plugged into the hub built into the USB keyboard I'm using. It took a lot of effort to fix the issues in the Pico SDK USB host code to get the hub and multiple devices working!

I think the mouse jumping issue is due to the use of the USB HID mouse boot protocol. This is the simplest way to get a mouse working but is not what an OS normally uses. It looks like both mice that I have tried incorrectly overflow the allowed values causing a positive number to turn negative on fast mouse movements. I've put a bit of code in to detect this but it's hard to get it exactly right. I'll probably try to use the HID report and switch out of boot mode to get a better resolution and more reliability.
User avatar
Methanoid
Captain Atari
Captain Atari
Posts: 314
Joined: Mon Jan 26, 2004 2:41 pm
Location: England.. where else?

Re: USB HID interface

Post by Methanoid »

Great.. will you produce two "branches" of your Github then? one for Pico for USB mice and one for full IKBD emu? I better get practicing my soldering :-)

I might also be able to test the USB mouse mode for Amiga (think its 2 wires swapped)
fieldofcows
Retro freak
Retro freak
Posts: 12
Joined: Thu Apr 08, 2021 10:47 pm

Re: USB HID interface

Post by fieldofcows »

Methanoid wrote: Mon May 03, 2021 11:54 am Great.. will you produce two "branches" of your Github then? one for Pico for USB mice and one for full IKBD emu? I better get practicing my soldering :-)
No need for two branches. The pico can perform both functions with the same software. You would just wire it up differently depending on which function you want.

I do have my old 520STFM in the loft. I might dig it out and see if I can get it going to see if the mouse emulation works. Although it hasn't been powered on for around 30 years so I'm a bit reluctant to just power it on without checking on those electrolytics.
User avatar
Methanoid
Captain Atari
Captain Atari
Posts: 314
Joined: Mon Jan 26, 2004 2:41 pm
Location: England.. where else?

Re: USB HID interface

Post by Methanoid »

Cool, well keep us posted when you are "finished" and there's some Noob level instructions on GH ;-)
User avatar
olivierg
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 130
Joined: Wed Jul 27, 2016 2:10 pm
Location: Belgium
Contact:

Re: USB HID interface

Post by olivierg »

I seem to have read that the Pico was strict 3V3.

I imagined a diagram to make it clearer:
ATARI RP2040 MK V1.jpg
But we can forget the 8P header for internal use, I think that a simple RJ12 -> Header 8P adapter is sufficient.
You do not have the required permissions to view the files attached to this post.
TT030 4/32 TOS 3.06 SCSI2SD 5.x HD, Mega STE 4Mb TOS 2.06 DD, Mega ST4 DD miniCosmosEX, Mega ST2 DD, 1040 STE DD, 2 x 1040STFM DD, 2 x 1040STF, MegaFile 30, Lynx 1
User avatar
olivierg
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 130
Joined: Wed Jul 27, 2016 2:10 pm
Location: Belgium
Contact:

Re: USB HID interface

Post by olivierg »

Methanoid wrote: Thu Apr 29, 2021 12:44 pm Brilliant... I was only after mouse emulation but this is great. I have two unused Picos so will definitely try on those when its available. I got my STe a few days ago and spent this morning cleaning the keyboard, just left the keys to dry. Your timing is excellent :D
Use Smallymouse for connect USB mouse to MegaST keyboard.
TT030 4/32 TOS 3.06 SCSI2SD 5.x HD, Mega STE 4Mb TOS 2.06 DD, Mega ST4 DD miniCosmosEX, Mega ST2 DD, 1040 STE DD, 2 x 1040STFM DD, 2 x 1040STF, MegaFile 30, Lynx 1
User avatar
Methanoid
Captain Atari
Captain Atari
Posts: 314
Joined: Mon Jan 26, 2004 2:41 pm
Location: England.. where else?

Re: USB HID interface

Post by Methanoid »

I dont have a MegaST. I think you quoted wrong post :-D
User avatar
olivierg
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 130
Joined: Wed Jul 27, 2016 2:10 pm
Location: Belgium
Contact:

Re: USB HID interface

Post by olivierg »

Hello fieldofcows,

I have open the git for checking the port used for serial communication with ST.
Can you confirm in src\pico\serialport.cpp:
#define UART_TX_PIN 4
#define UART_RX_PIN 5
I imagine the number represents the GPIOs?
(Sorry for those stupid questions, but I'm less than a beginner).

I try to create small PCB for testing.

Thanks
Olivier
TT030 4/32 TOS 3.06 SCSI2SD 5.x HD, Mega STE 4Mb TOS 2.06 DD, Mega ST4 DD miniCosmosEX, Mega ST2 DD, 1040 STE DD, 2 x 1040STFM DD, 2 x 1040STF, MegaFile 30, Lynx 1
fieldofcows
Retro freak
Retro freak
Posts: 12
Joined: Thu Apr 08, 2021 10:47 pm

Re: USB HID interface

Post by fieldofcows »

olivierg wrote: Sat May 08, 2021 8:58 am Can you confirm in src\pico\serialport.cpp:
#define UART_TX_PIN 4
#define UART_RX_PIN 5
I imagine the number represents the GPIOs?
Hi, yes they are GPIOs and not physical pins. The physical pins are 6 & 7.

I'm tidying up the config at the moment. I'll try to make the definitions clearer.
Post Reply

Return to “Hardware”