P2 Hosted USB Keyboard/Mouse

garryjgarryj Posts: 265
edited 2019-05-20 - 19:29:08 in Propeller 2
Edit: 2019-05-20: added the P2asm version .zip package.
Edit: 2019-05-18: update v0.02 (minor changes) and added the port A/B and the verbose enumeration .zip packages.

P2-Eval board + Serial Host accessory board, using pins 16..24 (16..25 if using A/B ports). Pin definitions are at the top of the 1CogKbm.spin2 file.
Sysclock 160MHz, 230400 baud serial.
Compile/run using fastspin and loadp2 and its built-in -t option terminal.

Spin2USBKbm-v0.02.zip:
The Spin2 top object file is KbMObjTest.spin2. The 1CogKbM.spin2 file is a one cog USB host + keyboard/mouse driver. The P2 pin usage is documented at the top of the 1CogKbm.spin2 file. The top object also loads the SmartSerial.spin and std_text_routines.spinh files that are packaged with Spin2gui.

Spin2USBKbMx2-v0.02.zip:
The same as above, but loads a second 1CogKbM object to utilize both ports (A-lower/B-upper) of the Serial Host accessory board.

USBEnumerate.zip
This is older code (three cogs) that outputs the contents of the various USB descriptors read at device enumeration. If you have a keyboard/mouse that is not recognized (or any other USB device) , the descriptor information may help when troubleshooting. Sometimes at cold startup, it may not detect a device when connected. If this happens, a reload of the code should get it going.

P2asmUSBKbm-v0.02.zip
P2asm version of the one cog USBKbM demo.
garryj

Comments

  • @Ozpropdev will be really excited to see this, Garry. I think his current setup takes 2 cogs for the keyboard, and we were wondering whether adding mouse/second keyboard would take a 3rd or even 4th cog.

    Great progress, and in Spin2 too. Thanks for your ongoing efforts
  • Nice work!
    I was hoping this was possible.

    I think 250 MHz is going to be the sweet spot though.
    Prop Info and Apps: http://www.rayslogic.com/
  • Cool @garryj :cool:
    Looking forward to replacing my current USB keyboard code in Self hosted Micropython to this.
    :) :) :)
    Melbourne, Australia
  • This looks great, thank you @garryj!

    I've tried several mice now and they've worked fine. Unfortunately I'm having trouble with keyboards. I've tried two keyboards. The first wasn't detected properly (it triggered the DEV_UNKNOWN "Boot protocol keyboard/mouse not found") so perhaps it just doesn't support boot protocol? The second was a wireless combo keyboard/mouse; the mouse part works fine, but only a few function keys are recognized and they're completely wrong (e.g. F1 is coming out as 'd' and F2 as backspace). Have you seen that before?

    Thanks,
    Eric

  • ersmith wrote: »
    This looks great, thank you @garryj!

    I've tried several mice now and they've worked fine. Unfortunately I'm having trouble with keyboards. I've tried two keyboards. The first wasn't detected properly (it triggered the DEV_UNKNOWN "Boot protocol keyboard/mouse not found") so perhaps it just doesn't support boot protocol? The second was a wireless combo keyboard/mouse; the mouse part works fine, but only a few function keys are recognized and they're completely wrong (e.g. F1 is coming out as 'd' and F2 as backspace). Have you seen that before?

    Thanks,
    Eric

    Yes, during device enumeration "boot protocol" interfaces must be defined. I have an early MS wireless keyboard/mouse combo where the keyboard supported boot protocol and the mouse did not. Are the keyboards wired, or wireless? If the device is wireless and BlueTooth it's likely it won't work, as it appears that BlueTooth devices that support boot protocol are pretty rare.

    For keyboards, do the alpha, numeric and punctuation keys emit the proper characters? The demo doesn't process keys outside the (US)ASCII $20..$7f "printable" range, so function keys and cursor navigation keys will emit their raw scancode, instead.
    garryj
  • For keyboards, do the alpha, numeric and punctuation keys emit the proper characters? The demo doesn't process keys outside the (US)ASCII $20..$7f "printable" range, so function keys and cursor navigation keys will emit their raw scancode, instead.
    For the wireless keyboard the alpha, numeric, and punctuation keys emitted nothing at all. The only keys that did anything were function keys, and they were emitting keys from the middle alpha row (d, h, j, k). Weird.

    Third time lucky though, I managed to find another USB keyboard and it's actually working correctly. Now to hook your code up to mine. It looks very well commented and should be easy to integrate. Thanks for writing this!

    Eric
  • garryjgarryj Posts: 265
    edited 2019-05-17 - 19:29:49
    I'm glad to hear that you had one that works!

    Could you post the brand & model# of the failing keyboard keyboards? I've got six keyboards of various types in my test pool and they're all working for me. I'd like to investigate further as to why your's fail.

    garryj
  • Sure. The two failing keyboards are a Sony PS/2 keyboard (that one wasn't even recognized) and a Logitech K400 wireless keyboard/mouse combo (that one the mouse worked fine, but only a few keys did anything and they came out wrong: the alphanumeric keys did not respond at all but a few function keys produced alpha characters). An Asus USB keyboard worked fine though.
  • Yeah, the PS/2 keyboard probably didn't advertise the boot protocol. The Logitech K400 has me scratching my head a bit. Nothing it its specs suggest that it wouldn't support boot protocol. One of my test keyboards is a Logitech wireless K520, and it works. Trouble-shooting USB without an analyzer handy can get one pulling out their hair pretty quickly :zombie:
    garryj
  • roglohrogloh Posts: 1,053
    edited 2019-05-18 - 03:25:45
    garryj wrote: »
    Trouble-shooting USB without an analyzer handy can get one pulling out their hair pretty quickly :zombie:
    @garryj,
    Could other COG(s) of the P2 somehow become a USB analyzer I wonder? Would it be possible to monitor/timestamp/log USB transaction activity in real time? If so, that could become a handy tool as well, particularly during driver/device bringup.
  • I tried 3 different keyboards and they all worked. Thanks garryj!

    I had a wireless combo but having trouble finding it...
    Prop Info and Apps: http://www.rayslogic.com/
  • Borrowed a Logitech wireless kb/mouse combo and it works.
    KB is K330, mouse is m215
    Prop Info and Apps: http://www.rayslogic.com/
  • avsa242avsa242 Posts: 140
    edited 2019-05-20 - 20:02:42
    I tried these:
    Microsoft Media Pro (wired) keyboard, M/N 1031: works
    Logitech K270 (wireless) keyboard and mouse, M/N Y-R0042: both work

    Both come back after being disconnected and reconnected

    If I can find its receiver, I have an old Logitech diNovo Edge keyboard (has a builtin touchpad) I can try

    EDIT:
    Yeah, no luck with the diNovo... Boot protocol keyboard/mouse not found as ersmith ran into above. The receiver is, IIRC, combination BT and non-specific 2.4GHz RF (maybe mostly for when the PC first starts and there is no Bluetooth stack yet?).

    Cheers,
    Jesse
    --
    WIP Spin drivers for various devices: LSM9DS1 IMU (SPI) | Newhaven 4x20 OLED (I2C) | MLX90621 (I2C) | SHT3x (I2C) | SSD1306 OLED (I2C; P1-SPIN, P2-SPIN2) | TCS3x7x (I2C) | MAX31856 (SPI) | BMP280 (I2C) | TMC2130 (SPI) | nRF24L01+ (SPI) | MLX90614 (I2C) | MAX9744 (I2C) | DS28CM00 (I2C) | TSL2591 (I2C) | CC1101 (SPI) | SX1231 (SPI)
  • garryjgarryj Posts: 265
    edited 2019-05-18 - 23:21:35
    rogloh wrote: »
    garryj wrote: »
    Trouble-shooting USB without an analyzer handy can get one pulling out their hair pretty quickly :zombie:
    @garryj,
    Could other COG(s) of the P2 somehow become a USB analyzer I wonder? Would it be possible to monitor/timestamp/log USB transaction activity in real time? If so, that could become a handy tool as well, particularly during driver/device bringup.

    Yeah, a sniffer cog could monitor the usb pretty easily. The challenging part, as you mentioned, would be the filters that you need to build a comprehensive picture of the parts of the data stream that you're interested in. It's not even close, as an analyzer, but I've added some older code to the top post that outputs descriptor contents at device enumeration that may shed some light on why a keyboard/mouse device is not being recognized.
    garryj
  • Added the p2asm version of the one cog keyboard/mouse demo to the first post.
    garryj
  • Looks like it might be time for a Google Doc of working Mice, KB and Combos.

    J
Sign In or Register to comment.