Shop OBEX P1 Docs P2 Docs Learn Events
P2 Hosted USB Keyboard/Mouse - Page 7 — Parallax Forums

P2 Hosted USB Keyboard/Mouse

123457»

Comments

  • RS_JimRS_Jim Posts: 1,768
    edited 2022-02-01 15:30

    The actual pin numbers used are 22 and 23 not the miss printed 24 and 25. used basepin of 16 and the add to in the code. @ada thanks for the input of working with higher clock speeds. I am using with mouse not keyboard and I get nothing past the initial setup info that includes the cog and version numbers. If I read the listing file correctly there are a bunch of print traps already in the test code that should print out the mouse data etc. Not happening. I wonder if I somehow need to configure for a low speed USB. Not sure how to.
    Jim

  • RaymanRayman Posts: 14,738

    So, you have DM=22 and DP=23? That should work.
    If you post the code, we can take a look to see if something is wrong there...

    Most mice seem to work although I seem to recall there being a few that don't...

    Actually, it'd be nice if this driver could fall back to PS/2 mode if USB mode fails... I was reading that a lot of mice still support PS/2 mode...

  • @Rayman The following are the only changes I have made to the KbMObjTest.spin2 file:
    System stuff:
    _xtlfreq = cfg#_xtlfreq
    _clkfreq = cfg#_clkfreq_def
    SER_RX = cfg#SER_RX
    SER_TX = cfg#SER_TX
    SER_BAUD = 2_000_000

       ' _clkmode = $010007f8
        _clkfreq = 200_000_000
        _fclkfreq = float(_clkfreq)
        baud = 2_000_000  '230_400
    

    Jim

  • evanhevanh Posts: 16,022

    @Rayman said:
    Actually, it'd be nice if this driver could fall back to PS/2 mode if USB mode fails... I was reading that a lot of mice still support PS/2 mode...

    Ir don't work like that. It's nothing to do with USB. That's the mouse/keyboard reconfiguring when it detects it has been plugged into a PS2 port.

    So, you'd also have to electrically trick the device as well as making the port PS2 functional.

  • Further investigation after an interupt to get flexprop 5.9.8 installed and running. I can see where a keyboard event is being handled in the test program, but I cannot find where the mouse data even gets recognized.

     if (usbA.byte[KBCON] and (data := usb1.key))
           handleKeyData(data)
    

    there is no such data recognizer for the mouse data so I don't see it getting passed to the mouse data handler. Any bright ideas?
    Jim

  • RaymanRayman Posts: 14,738

    Here's a version that I modified to provide the mouse position:

    There's what looks like a slightly older version in the Tetris demo here:
    https://www.parallax.com/tetris/

    That might give you tips on how to use it...

  • @Rayman
    In trying to compile WVGA HDMI Simple... I get a compiler error "expected 4 Parm got 5) seems that @MX is not expected by KBM routine start fn.
    Jim

  • RaymanRayman Posts: 14,738
    edited 2022-02-13 00:05

    @RS_Jim I just extracted the above zip to an empty folder and the loaded it into Prop Tool. Seems OK.

    There are probably various versions of the modified driver... Could be files with same name have slightly different content...
    Try extracting the zip to a new folder. Restart Prop Tool and then open WVGA_HDMI_Simple_wUsbMouse_1a.spin2 and try to compile.
    Think it should work.

    As you probably know, you'll have to go into the driver to set DM/DP pins to match your setup.

  • @Rayman
    The issue is with an @mx included in the start call to the mouse. Compiler says I have too many parameters being sent to the start call and looking at start, it is the @mx at the end of start. I compiled from a download from post 188. I did edit to conform to my environment, but that did not change the call. I am not using prop tool but @ersmith flexprop in a Linux environment with a 25Mhz P2 xtal. Do not have the panel but I wanted to use your mouse driver. once I know it will compile, I will lift your start up code for the mouse and do a simple program to display the XY bytes from the mouse. The whole idea is to use the mouse to control the speed and direction of a couple of motors.
    Jim
    See my post in General Discussion about crazy joystick idea.

  • evanhevanh Posts: 16,022

    Did it work?

  • RS_JimRS_Jim Posts: 1,768
    edited 2022-02-17 14:24

    @evanh
    in a word, no I don't have the vga set up to test it right now.
    here is my test program:
    It compiles but hangs after printing that the mouse is loaded.
    Jim

    I realized after I attached the file, I did not include the config file. That sets the clock speed for a 25MHz xtal and a 200MHz sys clock..
    Jim

  • evanhevanh Posts: 16,022

    Okay, compiling is the answer I was after.

    I noted there was something odd with the encoding of the text source for 1CogKbM_rja3b.spin2. It was compiling in newest Flexspin but not in Pnut. Pnut was getting even weirder errors again.

    What I did to make that work was convert file 1CogKbM_rja3b.spin2 from something called UCS2 encoding to UFT8 encoding. No editing of the source code.

  • RaymanRayman Posts: 14,738

    Maybe try a USB keyboard? That seems to always work...

    Am wondering if the 25 MHz crystal is the problem... Anybody gotten this to work with 25 MHz crystal?
    Don't really know why that would be a problem though, especially at 200 MHz which is even multiple of both 20 and 25 MHz...
    Still, maybe I'd try other clock speeds if won't work at 200 MHz...

  • I get no response from keyboard either.
    Jim

  • RaymanRayman Posts: 14,738
    edited 2022-02-20 12:44

    If you’re providing 5V power and ground and have dm/dp wired up right, it should work.

    But it’s easy to make a mistake when doing a custom setup. A lot easier with the eval board and USB adapter.

    Don’t think the crystal is an issue but not 100% on that.

  • RaymanRayman Posts: 14,738

    Also dm and dp wires need to be short if not on a pcb …

  • @Rayman said:
    Also dm and dp wires need to be short if not on a pcb …

    Ah ha, that could be the problem! Will work on that next.
    Jim

  • Turns out there's a pretty big bug with the keyboard handling: it expects the report to have all the pressed keys left-aligned. This isn't actually what happens, at least with my PS/2 adapter. That keeps a key in the slot that was the first free one when it got pressed. So if you press X, press Y, then release X, then press X again, you'll get "XYXY" (extra Y press because it thought that all keys were released when only Y was pressed)

  • dgatelydgately Posts: 1,630
    edited 2022-05-27 03:00

    Tried this keyboard with garryj's newest driver, but keyboard/mouse not found at any ClkFreq...
    https://tindie.com/products/arturo182/bb-q20-keyboard-with-trackpad-usbi2cpmod/#specs
    Docs: https://solder.party/docs/bbq20kbd/

    It would be a nice, small keyboard with mouse for P2s...

    The creator is available on Discord https://discord.com/channels/715539174857375774/715539175335657573 for discussion...

    Demo Client v0.1.4 + USB low/full speed keyboard/mouse                          
    Sysclock: 180000000, Clkmode: $10008FB, Baud: 2000000                           
    P2RevB+ detected, USB driver version v0.1.4                                     
    PortA started: cogID 1, event pin# 16                                           
    PortB started: cogID 2, event pin# 20                                           
    Reset and suspend/resume actions set to USB portA                               
    PortA boot protocol keyboard/mouse not found                                                                                 
    
  • @dgately said:
    Tried this keyboard with garryj's newest driver, but keyboard/mouse not found at any ClkFreq...
    https://tindie.com/products/arturo182/bb-q20-keyboard-with-trackpad-usbi2cpmod/#specs
    Docs: https://solder.party/docs/bbq20kbd/

    Can you try this driver from the USB Gamepad thread ?

    Otherwise, if you can capture the usb descriptor (raw hex dump, if possible), I can look at it.

  • dgatelydgately Posts: 1,630
    edited 2022-05-27 14:03

    @macca said:
    Can you try this driver from the USB Gamepad thread ?

    Otherwise, if you can capture the usb descriptor (raw hex dump, if possible), I can look at it.

    EDIT

    Mini Client + USB low/full speed keyboard/mouse v0.1.4                          
    Sysclock: 180000000, Clkmode: $10008FB, Baud: 2000000                           
    P2RevB+ detected, USB driver version v0.1.4                                     
    PortA started: cogID 1, event pin# 16                                           
    PortA gamepad configured                                                        
    PortA descriptor:                                                               
    05 (04) 01 usage page 1                                                         
    09 (08) 06 usage 6                                                              
    A1 (A0) 01 collection 1                                                         
    05 (04) 07 usage page 7                                                         
    19 (18) E0 usage min 224                                                        
    29 (28) E7 usage max 231                                                        
    15 (14) 00 logical min 0                                                        
    25 (24) 01 logical max 1                                                        
    95 (94) 08 report count 8                                                       
    75 (74) 01 report size 1                                                        
    81 (80) 02 input (offset = 0)                                                   
    95 (94) 01 report count 1                                                       
    75 (74) 08 report size 8                                                        
    81 (80) 01 input (offset = 8)                                                   
    05 (04) 08 usage page 8                                                         
    19 (18) 01 usage min 1                                                          
    29 (28) 05 usage max 5                                                          
    95 (94) 05 report count 5                                                       
    75 (74) 01 report size 1                                                        
    91 (90) 02 output                                                               
    95 (94) 01 report count 1                                                       
    75 (74) 03 report size 3                                                        
    91 (90) 01 output                                                               
    05 (04) 07 usage page 7                                                         
    19 (18) 00 usage min 0                                                          
    2A (28) 00FF usage max 255                                                      
    15 (14) 00 logical min 0                                                        
    26 (24) 00FF logical max 255                                                    
    95 (94) 06 report count 6                                                       
    75 (74) 08 report size 8                                                        
    81 (80) 00 input (offset = 16)                                                  
    C0 (C0) end collection   
    

    That gives me keyboard support!
    The optical mouse still does not work:
    How do I dump the USB descriptor?

    Mini Client + USB low/full speed keyboard/mouse/gamepad v0.1.4+r3               
    Sysclock: 180000000, Clkmode: $10008FB, Baud: 2000000                           
    P2RevB+ detected, USB driver version v0.1.4+r3                                  
    PortA started: cogID 1, event pin# 16                                           
    PortA device idVendor=1209, idProduct=B182, bcdDevice=0200                      
    PortA unsupported gamepad                                                       
    PortA [00 00 14 00 00 00 00 00 00 00] axes [X:ND Y:ND Z:ND RX:ND RY:ND RZ:ND] ha
    ts [] btn [0]                                                                   
    PortA [00 00 00 00 00 00 00 00 00 00] axes [X:ND Y:ND Z:ND RX:ND RY:ND RZ:ND] ha
    ts [] btn [0]                                                                   
    PortA [00 00 1A 00 00 00 00 00 00 00] axes [X:ND Y:ND Z:ND RX:ND RY:ND RZ:ND] ha
    ts [] btn [0]                                                                   
    PortA [00 00 00 00 00 00 00 00 00 00] axes [X:ND Y:ND Z:ND RX:ND RY:ND RZ:ND] ha
    ts [] btn [0]                                                                   
    PortA [00 00 08 00 00 00 00 00 00 00] axes [X:ND Y:ND Z:ND RX:ND RY:ND RZ:ND] ha
    ts [] btn [0]                                                                   
    PortA [00 00 00 00 00 00 00 00 00 00] axes [X:ND Y:ND Z:ND RX:ND RY:ND RZ:ND] ha
    ts [] btn [0]                                                                   
    PortA [00 00 15 00 00 00 00 00 00 00] axes [X:ND Y:ND Z:ND RX:ND RY:ND RZ:ND] ha
    ts [] btn [0]                                                                   
    PortA [00 00 00 00 00 00 00 00 00 00] axes [X:ND Y:ND Z:ND RX:ND RY:ND RZ:ND] ha
    ts [] btn [0]                                                                   
    PortA [00 00 17 00 00 00 00 00 00 00] axes [X:ND Y:ND Z:ND RX:ND RY:ND RZ:ND] ha
    ts [] btn [0]                                                                   
    PortA [00 00 00 00 00 00 00 00 00 00] axes [X:ND Y:ND Z:ND RX:ND RY:ND RZ:ND] ha
    ts [] btn [0]                                                                   
    PortA [00 00 1C 00 00 00 00 00 00 00] axes [X:ND Y:ND Z:ND RX:ND RY:ND RZ:ND] ha
    ts [] btn [0]                                                                   
    PortA [00 00 00 00 00 00 00 00 00 00] axes [X:ND Y:ND Z:ND RX:ND RY:ND RZ:ND] ha
    ts [] btn [0]
    
  • maccamacca Posts: 806
    edited 2022-05-27 14:18

    @dgately said:
    That gives me keyboard support!
    The optical mouse still does not work:
    How do I dump the USB descriptor?

    Good, attached is a version of the driver that dumps the configuration descriptor bytes, enable debug and you should see a line with:
    Cog1 hconfig_base = and a list of hex bytes.
    This should give more informations about how the devices are configured (and maybe explains why it notifies the keyboad activity as gamepad...)

    Edit: because the keyboard isn't recognized! It is detected as an unsupported gamepad which sends the report packets anyway...

  • @macca said:
    Good, attached is a version of the driver that dumps the configuration descriptor bytes, enable debug and you should see a line with:
    Cog1 hconfig_base = and a list of hex bytes.
    This should give more informations about how the devices are configured (and maybe explains why it notifies the keyboad activity as gamepad...)

    Edit: because the keyboard isn't recognized! It is detected as an unsupported gamepad which sends the report packets anyway...

    Cog0  INIT $0000_0000 $0000_0000 load                                           
    Cog0  INIT $0000_0404 $0000_0000 load                                           
    Mini Client + USB low/full speed keyboard/mouse/gamepad v0.1.4+r3               
    Sysclock: 180000000, Clkmode: $10008FB, Baud: 2000000                           
    Cog1  INIT $0000_3C38 $0000_5830 load                                           
    Cog1  hconfig_base = $09, $02, $94, $00, $05, $01, $00, $A0, $32, $09, $04, $00,
     $00, $01, $03, $00, $00, $04, $09, $21, $11, $01, $00, $01, $22, $41, $00, $07,
     $05, $81, $03, $08, $00, $0A, $09, $04, $01, $00, $01, $03, $00, $00, $05, $09,
     $21, $11, $01, $00, $01, $22, $4D, $00, $07, $05, $82, $03, $08, $00, $0A, $09,
     $04, $04, $00, $02, $FF, $00, $00, $07, $07, $05, $02, $02, $40, $00, $00, $07,
     $05, $84, $02, $40, $00, $00, $08, $0B, $02, $02, $02, $02, $00, $00, $09, $04,
     $02, $00, $01, $02, $02, $00, $07, $05, $24, $00, $20, $01, $05, $24, $01, $00,
     $03, $04, $24, $02, $02, $05, $24, $06, $02, $03, $07, $05, $85, $03, $08, $00,
     $10, $09, $04, $03, $00, $02, $0A, $00, $00, $00, $07, $05, $03, $02, $40, $00,
     $00, $07, $05, $86, $02, $40, $00, $00                                         
    Cog1  class=$03, subclass=$00, protocol=$00                                     
    Cog1  class=$03, subclass=$00, protocol=$00                                     
    Cog1  class=$FF, subclass=$00, protocol=$00                                     
    Cog1  class=$02, subclass=$02, protocol=$00                                     
    Cog1  class=$0A, subclass=$00, protocol=$00                                     
    Cog1  Report Desc. $05, $01, $09, $06, $A1, $01, $05, $07, $19, $E0, $29, $E7, $
    15, $00, $25, $01, $95, $08, $75, $01, $81, $02, $95, $01, $75, $08, $81, $01, $
    05, $08, $19, $01, $29, $05, $95, $05, $75, $01, $91, $02, $95, $01, $75, $03, $
    91, $01, $05, $07, $19, $00, $2A, $FF, $00, $15, $00, $26, $FF, $00, $95, $06, $
    75, $08, $81, $00, $C0                                                          
    P2RevB+ detected, USB driver version v0.1.4+r3                                  
    PortA started: cogID 1, event pin# 16                                           
    PortA device idVendor=1209, idProduct=B182, bcdDevice=0200                      
    PortA unsupported gamepad
    
  • @dgately said:
    Cog1 class=$03, subclass=$00, protocol=$00
    Cog1 class=$03, subclass=$00, protocol=$00
    Cog1 class=$FF, subclass=$00, protocol=$00
    Cog1 class=$02, subclass=$02, protocol=$00
    Cog1 class=$0A, subclass=$00, protocol=$00

    Ok, I think I see how it works. The device identifies itself as generic HID (not keyboard or mouse specific), the driver detects this as a Gamepad, however the report descriptor sets the usage as keyboard (and I guess as mouse for the other interface) but is ignored, that's why it reports unsupported gamepad.
    The driver should be modified to detect the keyboard/mouse setting in the report and enable the keboard and/or mouse support.
    A bit complicated, but doable.

  • More info (from: USB Descriptor and Request Parser)

    1209 B182: Solder Party - BBQ20KBD
    
    0x05, 0x01,        // Usage Page (Generic Desktop Ctrls)
    0x09, 0x06,        // Usage (Keyboard)
    0xA1, 0x01,        // Collection (Application)
    0x05, 0x07,        //   Usage Page (Kbrd/Keypad)
    0x19, 0xE0,        //   Usage Minimum (0xE0)
    0x29, 0xE7,        //   Usage Maximum (0xE7)
    0x15, 0x00,        //   Logical Minimum (0)
    0x25, 0x01,        //   Logical Maximum (1)
    0x95, 0x08,        //   Report Count (8)
    0x75, 0x01,        //   Report Size (1)
    0x81, 0x02,        //   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
    0x95, 0x01,        //   Report Count (1)
    0x75, 0x08,        //   Report Size (8)
    0x81, 0x01,        //   Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
    0x05, 0x08,        //   Usage Page (LEDs)
    0x19, 0x01,        //   Usage Minimum (Num Lock)
    0x29, 0x05,        //   Usage Maximum (Kana)
    0x95, 0x05,        //   Report Count (5)
    0x75, 0x01,        //   Report Size (1)
    0x91, 0x02,        //   Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
    0x95, 0x01,        //   Report Count (1)
    0x75, 0x03,        //   Report Size (3)
    0x91, 0x01,        //   Output (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
    0x05, 0x07,        //   Usage Page (Kbrd/Keypad)
    0x19, 0x00,        //   Usage Minimum (0x00)
    0x2A, 0xFF, 0x00,  //   Usage Maximum (0xFF)
    0x15, 0x00,        //   Logical Minimum (0)
    0x26, 0xFF, 0x00,  //   Logical Maximum (255)
    0x95, 0x06,        //   Report Count (6)
    0x75, 0x08,        //   Report Size (8)
    0x81, 0x00,        //   Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
    0xC0,              // End Collection
    // 65 bytes
    
    1209 B182: Solder Party - BBQ20KBD
    
    0x05, 0x01,        // Usage Page (Generic Desktop Ctrls)
    0x09, 0x02,        // Usage (Mouse)
    0xA1, 0x01,        // Collection (Application)
    0x09, 0x01,        //   Usage (Pointer)
    0xA1, 0x00,        //   Collection (Physical)
    0x05, 0x09,        //     Usage Page (Button)
    0x19, 0x01,        //     Usage Minimum (0x01)
    0x29, 0x05,        //     Usage Maximum (0x05)
    0x15, 0x00,        //     Logical Minimum (0)
    0x25, 0x01,        //     Logical Maximum (1)
    0x95, 0x05,        //     Report Count (5)
    0x75, 0x01,        //     Report Size (1)
    0x81, 0x02,        //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
    0x95, 0x01,        //     Report Count (1)
    0x75, 0x03,        //     Report Size (3)
    0x81, 0x01,        //     Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
    0x05, 0x01,        //     Usage Page (Generic Desktop Ctrls)
    0x09, 0x30,        //     Usage (X)
    0x09, 0x31,        //     Usage (Y)
    0x15, 0x81,        //     Logical Minimum (-127)
    0x25, 0x7F,        //     Logical Maximum (127)
    0x95, 0x02,        //     Report Count (2)
    0x75, 0x08,        //     Report Size (8)
    0x81, 0x06,        //     Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position)
    0x09, 0x38,        //     Usage (Wheel)
    0x15, 0x81,        //     Logical Minimum (-127)
    0x25, 0x7F,        //     Logical Maximum (127)
    0x95, 0x01,        //     Report Count (1)
    0x75, 0x08,        //     Report Size (8)
    0x81, 0x06,        //     Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position)
    0x05, 0x0C,        //     Usage Page (Consumer)
    0x0A, 0x38, 0x02,  //     Usage (AC Pan)
    0x15, 0x81,        //     Logical Minimum (-127)
    0x25, 0x7F,        //     Logical Maximum (127)
    0x95, 0x01,        //     Report Count (1)
    0x75, 0x08,        //     Report Size (8)
    0x81, 0x06,        //     Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position)
    0xC0,              //   End Collection
    0xC0,              // End Collection
    // 77 bytes
    
    
  • Seems this is much more complicated than expected.
    I assumed to be able to test using a normal keyboard because it can operate with both boot and report protocols but for some reasons this doesn't work, I guess there is something else to do other than using the right interface.
    The driver then needs some bigger change to be able to handle more than one device with the hid report interface.

    At this time, the quickest way is ask the firmware author to implement the boot protocol for both keyboard and mouse interfaces (or implement yourself if you have familiarity with the Pi Pico SDK), AFAIK it is just a matter of setting the correct hid class/subclass/protocol values.

  • pik33pik33 Posts: 2,383

    From the instruction:

    The board uses the Raspberry Pi RP2040 MCU to poll the keyboard and trackpad and put the key press information into a FIFO.

    You can use the I2C interface to read the FIFO, reconfigure the chip, and change the keyboar backlight.

    Connect the keyboard to a P2 using this I2C may be the simplest possible way to use it.

  • @pik33 said:
    From the instruction:

    The board uses the Raspberry Pi RP2040 MCU to poll the keyboard and trackpad and put the key press information into a FIFO.
    You can use the I2C interface to read the FIFO, reconfigure the chip, and change the keyboar backlight.

    Connect the keyboard to a P2 using this I2C may be the simplest possible way to use it.

    Yeah, but having a small plug-and-play solution, using USB seemed the goal.

Sign In or Register to comment.