randyrossi / bmc64

A bare metal Commodore 64 emulator for the Raspberry Pi with true 50hz/60hz smooth scrolling, low input latency and better audio/video sync.
GNU General Public License v3.0
474 stars 56 forks source link

USB Keyboard using KMK Firmware not detected #233

Closed aminch closed 1 year ago

aminch commented 1 year ago

Hi,

I'm creating a KMK firmware implementation for use on the Pi Pico to allow connecting an original C64 keyboard via USB.

The implementation works and the keyboard functions normally on WIndows/Mac/Linux (Raspberry Pi OS), but when I connect the keyboard to BMC64, it doesn't seem to be detected.

I know there is limited USB support with BMC64 which might be an issue. Are there any log files I can look at on start up to see what is going wrong? Or any other pointers on what could be the issue here?

I'm also happy to share the implementation if testing is required.

Thanks

mcgurk commented 1 year ago

I don't have Pi Pico but I guess it can be "a multiple USB-device". Check that serial port over USB is not enabled. Observe Windows Device Manager and check what what devices comes up when you plug it in. If anything other than Keyboard comes up (e.g. serial/COM-port), there is the problem.

You can check what USB-devices it announces with dmesg in Linux and there is some programs that gives debug information of USB-devices for Windows (and propably for MacOS). Plug it in and check what comes to Linux dmesg. Until you are 100% sure that it acts as single USB device (keyboard) it would not work with BMC64.

Arduino with Arduino IDE have "acts also as serial-port"-problem: https://github.com/randyrossi/bmc64/issues/211

aminch commented 1 year ago

This was one of my first thoughts. I followed this to disable the Mass Storage Device and USB Serial.

I believe the keyboard is the only thing showing up in Windows now.

I don't know if there is other HID configuration I should change or disable?

mcgurk commented 1 year ago

I would compare Linux dmesg (or some USB-device information software) output with Pi Pico and known working USB keyboard. Any live Linux would do, even virtual machine with USB-support.

I googled little and usbview seems handy program for Windows: https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/usbview

Edit: maybe even better: https://www.uwe-sieber.de/usbtreeview_e.html

aminch commented 1 year ago

Thanks for the tips... I will look it to that and report back!

mcgurk commented 1 year ago

maybe even better program for Windows (very easy to download and run): https://www.uwe-sieber.de/usbtreeview_e.html

aminch commented 1 year ago

I tried that tool and it shows that the Pico is multiple USB types.

So I implemented a boot.py on the Pico to disable everything except as a HID Keyboard, just like other keyboard devices I checked. See below:

    import board, digitalio
    import storage
    import usb_midi
    import usb_cdc
    import usb_hid

    # On C64 keyboard the Restore key is exclusively connected on GP6
    button = digitalio.DigitalInOut(board.GP6) # - (Restore key)
    button.pull = digitalio.Pull.UP

    # Hold the Restore key down to make the USB drive mount and enable midi, 
    # the usb serial and MOUSE AND CONSUMER_CONTROL HID modes
    if button.value:
       storage.disable_usb_drive()
       usb_midi.disable()
       usb_cdc.disable()   # Disable both serial devices.
       usb_hid.enable((usb_hid.Device.KEYBOARD,))   # Enable just KEYBOARD.

This also didn't work.

Could there be an issue with the timing of start up? BMC documentation said that once booted you cannot add or remove USB devices, and the Pico doesn't appear to be instant on, it has a couple of seconds to boot, so if it wasn't initialised before BMC boots it could be a reason that BMC doesn't see it, maybe?

I also tried to power the Pico externally so it had booted before I turned on BMC, but that also didn't work. The LED on the Pico flashes when you start BMC, so when USB power is applied it could also be rebooting leading to the same situation as above.

Is there any way to get logging information during boot up on BMC to see what is happening?

randyrossi commented 1 year ago

Logging can be turned on but you need to wire up a serial connection somehow. I've used a USB <-> serial adapter. I've also used a beaglebone and another raspberry pi would also work. The debugging can be turned on in the config. But I would first try to load some of the sample kernels that the Circle project publishes. There is one that tests the keyboard.

https://github.com/rsta2/circle/tree/master/sample/08-usbkeyboard

However, circle has moved on from where BMC64 took a snapshot of it. But if you get it working with that sample kernel, then there is hope.

On Thu, Mar 23, 2023 at 1:49 PM aminch @.***> wrote:

I tried that tool and it shows that the Pico is multiple USB types.

So I implemented a boot.py on the Pico to disable everything except as a HID Keyboard, just like other keyboard devices I checked. See below:

import board, digitalio
import storage
import usb_midi
import usb_cdc
import usb_hid

# On C64 keyboard the Restore key is exclusively connected on GP6
button = digitalio.DigitalInOut(board.GP6) # - (Restore key)
button.pull = digitalio.Pull.UP

# Hold the Restore key down to make the USB drive mount and enable midi,
# the usb serial and MOUSE AND CONSUMER_CONTROL HID modes
if button.value:
   storage.disable_usb_drive()
   usb_midi.disable()
   usb_cdc.disable()   # Disable both serial devices.
   usb_hid.enable((usb_hid.Device.KEYBOARD,))   # Enable just KEYBOARD.

This also didn't work.

Could there be an issue with the timing of start up? BMC documentation said that once booted you cannot add or remove USB devices, and the Pico doesn't appear to be instant on, it has a couple of seconds to boot, so if it wasn't initialised before BMC boots it could be a reason that BMC doesn't see it, maybe?

I also tried to power the Pico externally so it had booted before I turned on BMC, but that also didn't work. The LED on the Pico flashes when you start BMC, so when USB power is applied it could also be rebooting leading to the same situation as above.

Is there any way to get logging information during boot up on BMC to see what is happening?

— Reply to this email directly, view it on GitHub https://github.com/randyrossi/bmc64/issues/233#issuecomment-1481628356, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI3HKCERD2VDKTZ3ELNGODW5SEI3ANCNFSM6AAAAAAWE53NEE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Randy Rossi

aminch commented 1 year ago

Thanks for the advice, I can give these a shot.

aminch commented 1 year ago

I tried some of the suggestions but I couldn't figure out what was wrong. My guess is still that it takes too long to boot the KMK firmware and BMC64 doesn't see the device.

In the end I ported the keyboard to QMK, since that worked and had some other features I wanted: https://github.com/aminch/c64p

You can close this issue, thanks again.