USBJoystick 0.12

USB Joystick driver for RISC OS 5
richw
Posts: 159
Joined: Sat Sep 14, 2013 9:05 pm

Re: USB Joystick driver

Post by richw »

Can you download and run Reporter (like in my first post) and save the log from that (as a text file) when you run the USBJoystick module? It might help me find out why.

Also, if you can download and run USBDescriptors from here http://ftpc.iconbar.com/usb/USBDescriptors.zip and save the output to a text file. This may also help. I suspect the adaptor supplies invalid (or empty) HID data - that’s what my PSX USB adaptor does (so I can’t use it).
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

richw wrote: Wed Mar 28, 2018 8:44 pm Any chance you can run Reporter and observe the output when you start the USBJoystick module? It will only list (and try and talk to) devices that it believes are USB HID compliant, and ‘look like’ gamepads/joysticks. The ‘look like’ algorithm came from XMAME, which apparently uses the same sort of approach Microsoft used in Windows. I am not totally surprised that a steering wheel might be too funky, but you’d think an FF joystick would work (are they quite old?).
I'll try Reporter tonight. If I understand correctly, I also need to have the device plugged in before running USBJoystick - I've been plugging them in after so far!

I couldn't tell you how old they are, the Wheel possibly 8 years old, the Joystick a bit older.
richw wrote: Wed Mar 28, 2018 8:44 pm
I have however made the changes to ADFFS to translate the Acorn Joystick interface to RTFM...just need to test it, if I can find a Joystick that will show up.
Ah, so you trap those memory reads, and just issue a Joystick_Read SWI? That should ‘just work’ as they say. I have a feeling converting to Joystick_Status might be even easier.
The IOC Abort handler deals with reads/write to IOC memory space, I've added four registers for Econet @ 33A0000. At VSync I'm reading Joysticks 0 and 1 via Joystick_Read and setting the Up/Down/Left/Right/Fire bits in registers 2 and 3 accordingly.

Here's the Reporter output for the MS ForceFeedback 2:

Code: Select all

Checking device 'USB1' with handle '0' (class 09, subclass 00, protocol 01)
Checking device 'USB2' with handle '0' (class 09, subclass 00, protocol 02)
Checking device 'USB3' with handle '0' (class ff, subclass 00, protocol 01)
Checking device 'USB4' with handle '0' (class 00, subclass 00, protocol 00)
Device HID descriptor: Length=9, Type=33, NumDes=1
Got HID device descriptor data, length 81, will parse
Will use joystick number 0 (next available) for this HID parse
Got hid report size/dlen: 8
Cleared down joy_data, starting parse
Got nothing - free memory and exit
Parsed HID device descriptor
Device HID descriptor: Length=9, Type=33, NumDes=1
Got HID device descriptor data, length 128, will parse
Will use joystick number 0 (next available) for this HID parse
Got hid report size/dlen: 8
Cleared down joy_data, starting parse
Got nothing - free memory and exit
Parsed HID device descriptor
Device HID descriptor: Length=9, Type=33, NumDes=1
Got HID device descriptor data, length 54, will parse
Will use joystick number 0 (next available) for this HID parse
Got hid report size/dlen: 2
Cleared down joy_data, starting parse
Got nothing - free memory and exit
Parsed HID device descriptor
Checking device 'USB5' with handle '0' (class 00, subclass 00, protocol 00)
Device HID descriptor: Length=9, Type=33, NumDes=1
Got HID device descriptor data, length 1343, will parse
Will use joystick number 0 (next available) for this HID parse
Got hid report size/dlen: 0
Error: Not enough memory for joystick raw data buffer.
Parsed HID device descriptor
And here's the USBdescriptor for it:

Code: Select all

=============================================
 Device USB5
=============================================
:  0 :  2 : total size of ServiceCall block : 93
:  2 :  2 : offset to descriptor list       : 0x20
:  4 : 20 : name                            : USB5
: 24 :  1 : bus number                      : 1
: 25 :  1 : device address                  : 5
: 26 :  1 : host address                    : 2
: 27 :  1 : host port                       : 4
: 28 :  1 : speed                           : 2 full speed
---------------------------------------------

 Standard Device Descriptor
+----+----+---------------------------+----------+------------+
:Off :Sz  :Name                       :Value hex :Value dec   :
+----+----+---------------------------+----------+------------+
:  0 :  1 : bLength                   :       12 :         18 : 
:  1 :  1 : bDescriptorType           :        1 :          1 : 
:  2 :  2 : bcdUSB                    :      110 :        272 : 
:  4 :  1 : bDeviceClass              :        0 :          0 : 
:  5 :  1 : bDeviceSubClass           :        0 :          0 : 
:  6 :  1 : bDeviceProtocol           :        0 :          0 : 
:  7 :  1 : bMaxPacketSize            :        8 :          8 : 
:  8 :  2 : idVendor                  :      45e :       1118 : 
: 10 :  2 : idProduct                 :       1b :         27 : 
: 12 :  2 : bcdDevice                 :      a00 :       2560 : 
: 14 :  1 : iManufacturer             :        1 :          1 : 'Microsoft'
: 15 :  1 : iProduct                  :        2 :          2 : 'SideWinder Force Feedback 2 Joystick'
: 16 :  1 : iSerialNumber             :        0 :          0 : ''
: 17 :  1 : bNumConfigurations        :        1 :          1 : 
+----+----+---------------------------+----------+------------+

 Standard Configuration Descriptor
+----+----+---------------------------+----------+------------+
:Off :Sz  :Name                       :Value hex :Value dec   :
+----+----+---------------------------+----------+------------+
:  0 :  1 : bLength                   :        9 :          9 : 
:  1 :  1 : bDescriptorType           :        2 :          2 : 
:  2 :  2 : wTotalLength              :       29 :         41 : 
:  4 :  1 : bNumInterfaces            :        1 :          1 : 
:  5 :  1 : bConfigurationValue       :        1 :          1 : 
:  6 :  1 : iConfiguration            :        0 :          0 : ''
:  7 :  1 : bmAttributes              :       a0 :        160 : (bit7) USB 1.0 bus powered (bit6) Bus powered, (bit5) Remote wakeup
:  8 :  1 : bMaxPower                 :       32 :         50 : 100mA
+----+----+---------------------------+----------+------------+

     Standard Interface Descriptor
    +----+----+---------------------------+----------+------------+
    :Off :Sz  :Name                       :Value hex :Value dec   :
    +----+----+---------------------------+----------+------------+
    :  0 :  1 : bLength                   :        9 :          9 : 
    :  1 :  1 : bDescriptorType           :        4 :          4 : 
    :  2 :  1 : bInterfaceNumber          :        0 :          0 : 
    :  3 :  1 : bAlternateSetting         :        0 :          0 : 
    :  4 :  1 : bNumEndpoints             :        2 :          2 : 
    :  5 :  1 : bInterfaceClass           :        3 :          3 : HID
    :  6 :  1 : bInterfaceSubClass        :        0 :          0 : 
    :  7 :  1 : bInterfaceProtocol        :        0 :          0 : 
    :  8 :  1 : iInterface                :        0 :          0 : ''
    +----+----+---------------------------+----------+------------+

         HID Device Descriptor
        +----+----+---------------------------+----------+------------+
        :Off :Sz  :Name                       :Value hex :Value dec   :
        +----+----+---------------------------+----------+------------+
        :  0 :  1 : bLength                   :        9 :          9 : 
        :  1 :  1 : bDescriptorType           :       21 :         33 : 
        :  2 :  2 : bcdHID                    :      100 :        256 : 
        :  4 :  1 : bCountryCode              :        0 :          0 : 
        :  5 :  1 : bNumDescriptors           :        1 :          1 : 
        :  6 :  1 : bReportDescType           :       22 :         34 : 
        :  7 :  2 : wReportDescLength         :      53f :       1343 : 
        +----+----+---------------------------+----------+------------+

         Usage Page (Generic Desktop Controls)         :05 01 
         Usage (Joystick)                              :09 04 
         Collection (Application)                      :a1 01 
           Report ID (1)                                 :85 01 
           Usage (Pointer)                               :09 01 
           Collection (Physical)                         :a1 00 
             Unit                                          :66 00 00 
             Unit Exponent                                 :55 00 
             Logical Minimum                               :16 00 fe 
             Logical Maximum                               :26 ff 01 
             Physical Minimum                              :35 00 
             Physical Maximum                              :46 ff 03 
             Report Count (1)                              :95 01 
             Report Size (10)                              :75 0a 
             Usage (X)                                     :09 30 
             ...Input                                      :81 02 
             Report Size (6)                               :75 06 
             ...Input                                      :81 01 
             Usage (Y)                                     :09 31 
             Report Size (10)                              :75 0a 
             ...Input                                      :81 02 
             Report Size (6)                               :75 06 
             Report Count (1)                              :95 01 
             ...Input                                      :81 01 
             Logical Minimum                               :15 e0 
             Logical Maximum                               :25 1f 
             Physical Minimum                              :35 00 
             Physical Maximum                              :45 3f 
             Unit                                          :66 14 00 
             Usage (Rz)                                    :09 35 
             ...Input                                      :81 02 
             Report Size (2)                               :75 02 
             ...Input                                      :81 01 
             Unit                                          :66 00 00 
           End Collection                                :c0 
           Report Size (7)                               :75 07 
           Report Count (1)                              :95 01 
           Logical Minimum                               :15 00 
           Logical Maximum                               :25 7f 
           Physical Minimum                              :35 00 
           Physical Maximum                              :45 7f 
           Usage (Slider)                                :09 36 
           ...Input                                      :81 02 
           Report Size (1)                               :75 01 
           ...Input                                      :81 01 
           Usage (Hat Switch)                            :09 39 
           Logical Minimum                               :15 00 
           Logical Maximum                               :25 07 
           Physical Minimum                              :35 00 
           Physical Maximum                              :46 3b 01 
           Unit                                          :66 14 00 
           Report Size (4)                               :75 04 
           Report Count (1)                              :95 01 
           ...Input                                      :81 42 
           Report Count (1)                              :95 01 
           ...Input                                      :81 01 
           Unit                                          :66 00 00 
           Usage Page (Button)                           :05 09 
           Usage Minimum                                 :19 01 
           Usage Maximum                                 :29 08 
           Logical Minimum                               :15 00 
           Logical Maximum                               :25 01 
           Physical Minimum                              :35 00 
           Physical Maximum                              :45 01 
           Report Count (8)                              :95 08 
           Report Size (1)                               :75 01 
           ...Input                                      :81 02 
           Report Count (4)                              :95 04 
           Report Size (8)                               :75 08 
           ...Input                                      :81 01 
           Usage Page (PID page)                         :05 0f 
           Usage ()                                      :09 92 
           Collection (Logical)                          :a1 02 
             Report ID (2)                                 :85 02 
             Usage ()                                      :09 9f 
             Usage ()                                      :09 a0 
             Usage ()                                      :09 a4 
             Usage ()                                      :09 a5 
             Usage ()                                      :09 a6 
             Logical Minimum                               :15 00 
             Logical Maximum                               :25 01 
             Physical Minimum                              :35 00 
             Physical Maximum                              :45 01 
             Report Size (1)                               :75 01 
             Report Count (5)                              :95 05 
             ...Input                                      :81 02 
             Report Count (3)                              :95 03 
             ...Input                                      :81 03 
             Usage ()                                      :09 94 
             Logical Minimum                               :15 00 
             Logical Maximum                               :25 01 
             Physical Minimum                              :35 00 
             Physical Maximum                              :45 01 
             Report Size (1)                               :75 01 
             Report Count (1)                              :95 01 
             ...Input                                      :81 02 
             Usage ()                                      :09 22 
             Logical Minimum                               :15 01 
             Logical Maximum                               :25 28 
             Physical Minimum                              :35 01 
             Physical Maximum                              :45 28 
             Report Size (7)                               :75 07 
             Report Count (1)                              :95 01 
             ...Input                                      :81 02 
           End Collection                                :c0 
           Usage ()                                      :09 21 
           Collection (Logical)                          :a1 02 
             Report ID (1)                                 :85 01 
             Usage ()                                      :09 22 
             Logical Minimum                               :15 01 
             Logical Maximum                               :25 28 
             Physical Minimum                              :35 01 
             Physical Maximum                              :45 28 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 25 
             Collection (Logical)                          :a1 02 
               Usage ()                                      :09 26 
               Usage ()                                      :09 27 
               Usage ()                                      :09 30 
               Usage ()                                      :09 31 
               Usage ()                                      :09 32 
               Usage ()                                      :09 33 
               Usage ()                                      :09 34 
               Usage ()                                      :09 40 
               Usage ()                                      :09 41 
               Usage ()                                      :09 42 
               Usage ()                                      :09 43 
               Usage ()                                      :09 28 
               Logical Maximum                               :25 0c 
               Logical Minimum                               :15 01 
               Physical Minimum                              :35 01 
               Physical Maximum                              :45 0c 
               Report Size (8)                               :75 08 
               Report Count (1)                              :95 01 
               ...Output                                     :91 00 
             End Collection                                :c0 
             Usage ()                                      :09 50 
             Usage ()                                      :09 54 
             Usage ()                                      :09 51 
             Logical Minimum                               :15 00 
             Logical Maximum                               :26 ff 7f 
             Physical Minimum                              :35 00 
             Physical Maximum                              :46 ff 7f 
             Unit                                          :66 03 10 
             Unit Exponent                                 :55 fd 
             Report Size (16)                              :75 10 
             Report Count (3)                              :95 03 
             ...Output                                     :91 02 
             Unit Exponent                                 :55 00 
             Unit                                          :66 00 00 
             Usage ()                                      :09 52 
             Logical Minimum                               :15 00 
             Logical Maximum                               :26 ff 00 
             Physical Minimum                              :35 00 
             Physical Maximum                              :46 10 27 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 53 
             Logical Minimum                               :15 01 
             Logical Maximum                               :25 08 
             Physical Minimum                              :35 01 
             Physical Maximum                              :45 08 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 55 
             Collection (Logical)                          :a1 02 
               Usage Page (Generic Desktop Controls)         :05 01 
               Usage (X)                                     :09 30 
               Usage (Y)                                     :09 31 
               Logical Minimum                               :15 00 
               Logical Maximum                               :25 01 
               Report Size (1)                               :75 01 
               Report Count (2)                              :95 02 
               ...Output                                     :91 02 
             End Collection                                :c0 
             Usage Page (PID page)                         :05 0f 
             Usage ()                                      :09 56 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Report Count (5)                              :95 05 
             ...Output                                     :91 03 
             Usage ()                                      :09 57 
             Collection (Logical)                          :a1 02 
               Usage ()                                      :0b 01 00 0a 00 
               Usage ()                                      :0b 02 00 0a 00 
               Unit                                          :66 14 00 
               Unit Exponent                                 :55 fe 
               Logical Minimum                               :15 00 
               Logical Maximum                               :26 ff 00 
               Physical Minimum                              :35 00 
               Physical Maximum                              :47 a0 8c 00 00 
               Unit                                          :66 00 00 
               Report Size (8)                               :75 08 
               Report Count (2)                              :95 02 
               ...Output                                     :91 02 
               Unit Exponent                                 :55 00 
               Unit                                          :66 00 00 
             End Collection                                :c0 
             Usage Page (PID page)                         :05 0f 
             Usage ()                                      :09 a7 
             Unit                                          :66 03 10 
             Unit Exponent                                 :55 fd 
             Logical Minimum                               :15 00 
             Logical Maximum                               :26 ff 7f 
             Physical Minimum                              :35 00 
             Physical Maximum                              :46 ff 7f 
             Report Size (16)                              :75 10 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Unit                                          :66 00 00 
             Unit Exponent                                 :55 00 
           End Collection                                :c0 
           Usage Page (PID page)                         :05 0f 
           Usage ()                                      :09 5a 
           Collection (Logical)                          :a1 02 
             Report ID (2)                                 :85 02 
             Usage ()                                      :09 22 
             Logical Minimum                               :15 01 
             Logical Maximum                               :25 28 
             Physical Minimum                              :35 01 
             Physical Maximum                              :45 28 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 5b 
             Usage ()                                      :09 5d 
             Logical Minimum                               :15 00 
             Logical Maximum                               :26 ff 00 
             Physical Minimum                              :35 00 
             Physical Maximum                              :46 10 27 
             Report Count (2)                              :95 02 
             ...Output                                     :91 02 
             Usage ()                                      :09 5c 
             Usage ()                                      :09 5e 
             Unit                                          :66 03 10 
             Unit Exponent                                 :55 fd 
             Logical Maximum                               :26 ff 7f 
             Physical Maximum                              :46 ff 7f 
             Report Size (16)                              :75 10 
             ...Output                                     :91 02 
             Physical Maximum                              :45 00 
             Unit                                          :66 00 00 
             Unit Exponent                                 :55 00 
           End Collection                                :c0 
           Usage ()                                      :09 5f 
           Collection (Logical)                          :a1 02 
             Report ID (3)                                 :85 03 
             Usage ()                                      :09 22 
             Logical Minimum                               :15 01 
             Logical Maximum                               :25 28 
             Physical Minimum                              :35 01 
             Physical Maximum                              :45 28 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 23 
             Logical Minimum                               :15 00 
             Logical Maximum                               :25 01 
             Physical Minimum                              :35 00 
             Physical Maximum                              :45 01 
             Report Size (4)                               :75 04 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 58 
             Collection (Logical)                          :a1 02 
               Usage ()                                      :0b 01 00 0a 00 
               Usage ()                                      :0b 02 00 0a 00 
               Report Size (2)                               :75 02 
               Report Count (2)                              :95 02 
               ...Output                                     :91 02 
             End Collection                                :c0 
             Logical Minimum                               :15 80 
             Logical Maximum                               :25 7f 
             Physical Minimum                              :36 f0 d8 
             Physical Maximum                              :46 10 27 
             Usage ()                                      :09 60 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Physical Minimum                              :36 f0 d8 
             Physical Maximum                              :46 10 27 
             Usage ()                                      :09 61 
             Usage ()                                      :09 62 
             Report Count (2)                              :95 02 
             ...Output                                     :91 02 
             Logical Minimum                               :15 00 
             Logical Maximum                               :26 ff 00 
             Physical Minimum                              :35 00 
             Physical Maximum                              :46 10 27 
             Usage ()                                      :09 63 
             Usage ()                                      :09 64 
             Report Size (8)                               :75 08 
             Report Count (2)                              :95 02 
             ...Output                                     :91 02 
             Usage ()                                      :09 65 
             Physical Maximum                              :46 10 27 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
           End Collection                                :c0 
           Usage ()                                      :09 6e 
           Collection (Logical)                          :a1 02 
             Report ID (4)                                 :85 04 
             Usage ()                                      :09 22 
             Logical Minimum                               :15 01 
             Logical Maximum                               :25 28 
             Physical Minimum                              :35 01 
             Physical Maximum                              :45 28 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 70 
             Logical Minimum                               :15 00 
             Logical Maximum                               :26 ff 00 
             Physical Minimum                              :35 00 
             Physical Maximum                              :46 10 27 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 6f 
             Logical Minimum                               :15 80 
             Logical Maximum                               :25 7f 
             Physical Minimum                              :36 f0 d8 
             Physical Maximum                              :46 10 27 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 71 
             Unit                                          :66 14 00 
             Unit Exponent                                 :55 fe 
             Logical Minimum                               :15 00 
             Logical Maximum                               :26 ff 00 
             Physical Minimum                              :35 00 
             Physical Maximum                              :47 a0 8c 00 00 
             ...Output                                     :91 02 
             Usage ()                                      :09 72 
             Logical Maximum                               :26 ff 7f 
             Physical Maximum                              :46 ff 7f 
             Unit                                          :66 03 10 
             Unit Exponent                                 :55 fd 
             Report Size (16)                              :75 10 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Unit                                          :66 00 00 
             Unit Exponent                                 :55 00 
           End Collection                                :c0 
           Usage ()                                      :09 73 
           Collection (Logical)                          :a1 02 
             Report ID (5)                                 :85 05 
             Usage ()                                      :09 22 
             Logical Minimum                               :15 01 
             Logical Maximum                               :25 28 
             Physical Minimum                              :35 01 
             Physical Maximum                              :45 28 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 70 
             Logical Minimum                               :16 01 ff 
             Logical Maximum                               :26 ff 00 
             Physical Minimum                              :36 f0 d8 
             Physical Maximum                              :46 10 27 
             Report Size (16)                              :75 10 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
           End Collection                                :c0 
           Usage ()                                      :09 74 
           Collection (Logical)                          :a1 02 
             Report ID (6)                                 :85 06 
             Usage ()                                      :09 22 
             Logical Minimum                               :15 01 
             Logical Maximum                               :25 28 
             Physical Minimum                              :35 01 
             Physical Maximum                              :45 28 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 75 
             Usage ()                                      :09 76 
             Logical Minimum                               :15 80 
             Logical Maximum                               :25 7f 
             Physical Minimum                              :36 f0 d8 
             Physical Maximum                              :46 10 27 
             Report Size (8)                               :75 08 
             Report Count (2)                              :95 02 
             ...Output                                     :91 02 
           End Collection                                :c0 
           Usage ()                                      :09 68 
           Collection (Logical)                          :a1 02 
             Report ID (7)                                 :85 07 
             Usage ()                                      :09 22 
             Logical Minimum                               :15 01 
             Logical Maximum                               :25 28 
             Physical Minimum                              :35 01 
             Physical Maximum                              :45 28 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 6c 
             Logical Minimum                               :15 00 
             Logical Maximum                               :26 10 27 
             Physical Minimum                              :35 00 
             Physical Maximum                              :46 10 27 
             Report Size (16)                              :75 10 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 69 
             Logical Minimum                               :15 81 
             Logical Maximum                               :25 7f 
             Physical Minimum                              :35 00 
             Physical Maximum                              :46 ff 00 
             Report Size (8)                               :75 08 
             Report Count (12)                             :95 0c 
             ...Output                                     :92 02 01 
           End Collection                                :c0 
           Usage ()                                      :09 66 
           Collection (Logical)                          :a1 02 
             Report ID (8)                                 :85 08 
             Usage Page (Generic Desktop Controls)         :05 01 
             Usage (X)                                     :09 30 
             Usage (Y)                                     :09 31 
             Logical Minimum                               :15 81 
             Logical Maximum                               :25 7f 
             Physical Minimum                              :35 00 
             Physical Maximum                              :46 ff 00 
             Report Size (8)                               :75 08 
             Report Count (2)                              :95 02 
             ...Output                                     :91 02 
           End Collection                                :c0 
           Usage Page (PID page)                         :05 0f 
           Usage ()                                      :09 77 
           Collection (Logical)                          :a1 02 
             Report ID (10)                                :85 0a 
             Usage ()                                      :09 22 
             Logical Minimum                               :15 01 
             Logical Maximum                               :25 28 
             Physical Minimum                              :35 01 
             Physical Maximum                              :45 28 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 78 
             Collection (Logical)                          :a1 02 
               Usage ()                                      :09 79 
               Usage ()                                      :09 7a 
               Usage ()                                      :09 7b 
               Logical Minimum                               :15 01 
               Logical Maximum                               :25 03 
               Report Size (8)                               :75 08 
               Report Count (1)                              :95 01 
               ...Output                                     :91 00 
             End Collection                                :c0 
             Usage ()                                      :09 7c 
             Logical Minimum                               :15 00 
             Logical Maximum                               :26 ff 00 
             Physical Minimum                              :35 00 
             Physical Maximum                              :46 ff 00 
             ...Output                                     :91 02 
           End Collection                                :c0 
           Usage ()                                      :09 90 
           Collection (Logical)                          :a1 02 
             Report ID (11)                                :85 0b 
             Usage ()                                      :09 22 
             Logical Maximum                               :25 28 
             Logical Minimum                               :15 01 
             Physical Minimum                              :35 01 
             Physical Maximum                              :45 28 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
           End Collection                                :c0 
           Usage ()                                      :09 96 
           Collection (Logical)                          :a1 02 
             Report ID (12)                                :85 0c 
             Usage ()                                      :09 97 
             Usage ()                                      :09 98 
             Usage ()                                      :09 99 
             Usage ()                                      :09 9a 
             Usage ()                                      :09 9b 
             Usage ()                                      :09 9c 
             Logical Minimum                               :15 01 
             Logical Maximum                               :25 06 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 00 
           End Collection                                :c0 
           Usage ()                                      :09 7d 
           Collection (Logical)                          :a1 02 
             Report ID (13)                                :85 0d 
             Usage ()                                      :09 7e 
             Logical Minimum                               :15 00 
             Logical Maximum                               :26 ff 00 
             Physical Minimum                              :35 00 
             Physical Maximum                              :46 10 27 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
           End Collection                                :c0 
           Usage ()                                      :09 6b 
           Collection (Logical)                          :a1 02 
             Report ID (14)                                :85 0e 
             Usage ()                                      :09 22 
             Logical Minimum                               :15 01 
             Logical Maximum                               :25 28 
             Physical Minimum                              :35 01 
             Physical Maximum                              :45 28 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 6d 
             Logical Minimum                               :15 00 
             Logical Maximum                               :26 ff 00 
             Physical Minimum                              :35 00 
             Physical Maximum                              :46 ff 00 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Usage ()                                      :09 51 
             Unit                                          :66 03 10 
             Unit Exponent                                 :55 fd 
             Logical Minimum                               :15 00 
             Logical Maximum                               :26 ff 7f 
             Physical Minimum                              :35 00 
             Physical Maximum                              :46 ff 7f 
             Report Size (16)                              :75 10 
             Report Count (1)                              :95 01 
             ...Output                                     :91 02 
             Unit Exponent                                 :55 00 
             Unit                                          :66 00 00 
           End Collection                                :c0 
           Usage ()                                      :09 ab 
           Collection (Logical)                          :a1 02 
             Report ID (1)                                 :85 01 
             Usage ()                                      :09 25 
             Collection (Logical)                          :a1 02 
               Usage ()                                      :09 26 
               Usage ()                                      :09 27 
               Usage ()                                      :09 30 
               Usage ()                                      :09 31 
               Usage ()                                      :09 32 
               Usage ()                                      :09 33 
               Usage ()                                      :09 34 
               Usage ()                                      :09 40 
               Usage ()                                      :09 41 
               Usage ()                                      :09 42 
               Usage ()                                      :09 43 
               Usage ()                                      :09 28 
               Logical Maximum                               :25 0c 
               Logical Minimum                               :15 01 
               Physical Minimum                              :35 01 
               Physical Maximum                              :45 0c 
               Report Size (8)                               :75 08 
               Report Count (1)                              :95 01 
               ...Feature                                    :b1 00 
             End Collection                                :c0 
             Usage Page (Generic Desktop Controls)         :05 01 
             Usage (Select)                                :09 3b 
             Logical Minimum                               :15 00 
             Logical Maximum                               :26 ff 01 
             Physical Minimum                              :35 00 
             Physical Maximum                              :46 ff 01 
             Report Size (10)                              :75 0a 
             Report Count (1)                              :95 01 
             ...Feature                                    :b1 02 
             Report Size (6)                               :75 06 
             ...Feature                                    :b1 01 
           End Collection                                :c0 
           Usage Page (PID page)                         :05 0f 
           Usage ()                                      :09 89 
           Collection (Logical)                          :a1 02 
             Report ID (2)                                 :85 02 
             Usage ()                                      :09 22 
             Logical Maximum                               :25 28 
             Logical Minimum                               :15 01 
             Physical Minimum                              :35 01 
             Physical Maximum                              :45 28 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Feature                                    :b1 02 
             Usage ()                                      :09 8b 
             Collection (Logical)                          :a1 02 
               Usage ()                                      :09 8c 
               Usage ()                                      :09 8d 
               Usage ()                                      :09 8e 
               Logical Maximum                               :25 03 
               Logical Minimum                               :15 01 
               Physical Minimum                              :35 01 
               Physical Maximum                              :45 03 
               Report Size (8)                               :75 08 
               Report Count (1)                              :95 01 
               ...Feature                                    :b1 00 
             End Collection                                :c0 
             Usage ()                                      :09 ac 
             Logical Minimum                               :15 00 
             Logical Maximum                               :27 ff ff 00 00 
             Physical Minimum                              :35 00 
             Physical Maximum                              :47 ff ff 00 00 
             Report Size (16)                              :75 10 
             Report Count (1)                              :95 01 
             ...Feature                                    :b1 00 
           End Collection                                :c0 
           Usage ()                                      :09 7f 
           Collection (Logical)                          :a1 02 
             Report ID (3)                                 :85 03 
             Usage ()                                      :09 80 
             Report Size (16)                              :75 10 
             Report Count (1)                              :95 01 
             Logical Minimum                               :15 00 
             Physical Minimum                              :35 00 
             Logical Maximum                               :27 ff ff 00 00 
             Physical Maximum                              :47 ff ff 00 00 
             ...Feature                                    :b1 02 
             Usage ()                                      :09 83 
             Logical Maximum                               :26 ff 00 
             Physical Maximum                              :46 ff 00 
             Report Size (8)                               :75 08 
             Report Count (1)                              :95 01 
             ...Feature                                    :b1 02 
             Usage ()                                      :09 a9 
             Usage ()                                      :09 aa 
             Report Size (1)                               :75 01 
             Report Count (2)                              :95 02 
             Logical Minimum                               :15 00 
             Logical Maximum                               :25 01 
             Physical Minimum                              :35 00 
             Physical Maximum                              :45 01 
             ...Feature                                    :b1 02 
             Report Size (6)                               :75 06 
             Report Count (1)                              :95 01 
             ...Feature                                    :b1 03 
           End Collection                                :c0 
         End Collection                                :c0 

         Standard Endpoint Descriptor
        +----+----+---------------------------+----------+------------+
        :Off :Sz  :Name                       :Value hex :Value dec   :
        +----+----+---------------------------+----------+------------+
        :  0 :  1 : bLength                   :        7 :          7 : 
        :  1 :  1 : bDescriptorType           :        5 :          5 : 
        :  2 :  1 : bEndpointAddress          :       81 :        129 : Endpoint 1 - IN
        :  3 :  1 : bmAttributes              :        3 :          3 : Interrupt
        :  4 :  2 : wMaxPacketSize            :       40 :         64 : 1 x 64 byte max packets
        :  6 :  1 : bInterval                 :        1 :          1 : 
        +----+----+---------------------------+----------+------------+

         Standard Endpoint Descriptor
        +----+----+---------------------------+----------+------------+
        :Off :Sz  :Name                       :Value hex :Value dec   :
        +----+----+---------------------------+----------+------------+
        :  0 :  1 : bLength                   :        7 :          7 : 
        :  1 :  1 : bDescriptorType           :        5 :          5 : 
        :  2 :  1 : bEndpointAddress          :        2 :          2 : Endpoint 2 - OUT
        :  3 :  1 : bmAttributes              :        3 :          3 : Interrupt
        :  4 :  2 : wMaxPacketSize            :       10 :         16 : 1 x 16 byte max packets
        :  6 :  1 : bInterval                 :        4 :          4 : 
        +----+----+---------------------------+----------+------------+
The ThrustMaster Steering Wheel doesn't have a Descriptor - which might explain why it BSOD's Windows 10 when I plug it in!
Vanfanel
Posts: 576
Joined: Mon Sep 16, 2013 12:01 am

Re: USB Joystick driver

Post by Vanfanel »

@richw: Here I have included both the output of reporter and usbdescriptor. I have included both on a ZIP so thread doesn't become too long. Thanks for your efforts on it!
Attachments
usbjoystick_debug_info.zip
(3.79 KiB) Downloaded 310 times
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

I've had a look at the HID descriptor of the MS FF 2 Joystick, which appears valid. Adding some debug reporting into parse.c, hid_get_item_raw appears to parse the descriptor okay, but hid_get_item returns 0. My guess is there's an issue with the Report Id as a lot of the code relies on this to match.
richw
Posts: 159
Joined: Sat Sep 14, 2013 9:05 pm

Re: USB Joystick driver

Post by richw »

Jon, funny you should say that. I’ve been looking at that just this second! There is indeed a feature I had not considered! I’ve put in the interface index into the offset, and now the aforementioned code in parse.c is working. I have a PSX/USB adaptor which previously didn’t work, and now it works! I’ve also fixed a couple of memory allocation issues. I would like to get the hot plug working (it half-works, so something has broken it) and then I’ll release 0.04.

Your USBDescriptor/Reporter stuff is interesting. I guess USB4 was the steering wheel with no HID descriptor? That looks to have confused things. Your USB5 device (the Microsoft FF Joystick) looks OK in USBDescriptors, so I’m not sure why that’s failed. It doesn’t look like the bug I’ve just fixed (but not yet released). Maybe the nonsense with the wheel has borked it? Can you try removing the wheel, then running the module again?

I’ve also found a reboot, or *USBReset <n> (where n is the device number, e.g. 4 for USB4) handy if things get messy.

Thank you very much for the feedback and encouragement!
richw
Posts: 159
Joined: Sat Sep 14, 2013 9:05 pm

Re: USB Joystick driver

Post by richw »

Vanfanel wrote: Wed Mar 28, 2018 10:18 pm My joystick is a PSX original joystick that uses a GreenAsia adapter
I cannot be 100% sure, but I am quietly confident that this will work on the next release (0.04). I have a similar adaptor which I ignored because I thought it wasn’t HID-compliant. But I plugged it in earlier this evening, and it showed me a bug in my code.
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

richw wrote: Thu Mar 29, 2018 9:28 pm Your USBDescriptor/Reporter stuff is interesting. I guess USB4 was the steering wheel with no HID descriptor?
I believe USB4 is the in-built mouse in the pi-top, which can be ignored.

Earlier, I hardcoded the Report ID to match the MS FF2 to get it to recognise the device. Although the HID parse does read the Axis, Hat and Buttons none of them are correct when you use Read. The reported buttons appear to be directions on the Hat and none of the physical buttons appear to do anything. The X Axis returns random values and the Y Axis does very little. The Z Axis (twisting the handle) appears to be correct.

Digging through the HID code, the routine that reads the data appears to assume the item data is always byte aligned. I'm sure when I looked into this years ago the data was a bitstream, so if the first value for example was 10 bits, bit 11 will be the start of the next value. I'm going to dump the whole data tomorrow and watch which bits change when I alter the axis, as the data is clearly coming in, just not being read correctly.
richw
Posts: 159
Joined: Sat Sep 14, 2013 9:05 pm

Re: USB Joystick driver

Post by richw »

I thought I read somewhere that the reports were padded out to always be byte aligned. Perhaps I have imagined it?!

I will continue with my PSX pad tomorrow evening. I only get an hour here and there, as developing professionally limits your enthusiasm for keeping going in your own time!
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

Looking at the data dumped inside hid_get_data, the Joystick data is all off by 1 byte. Here's an example of the Joystick at top/left:

Code: Select all

01  <--- extra byte
00  - X Axis High byte
fe  - X Axis Low Byte
00  - Y Axis High Byte
fe  - Y Axis Low Byte
...
X Axis is defined as hpos=0 and size=10. hpos should however be 8 because of that extra byte on the front...I've not figured out where the extra byte is coming from. The first Usage in the Descriptor is the X Axis, so in theory it should be at hpos=0?

As for byte alignment, I misread the code, it does handle misaligned data but introduces a possible bug. It starts off reading from aligned bytes and then shifts the word down to correct for the initial misalignment. The way it's coded however, there's the potential for data of size>24 to overrun if the data is misaligned.

In c.data, I believe the section in hid_get_data should be recoded from:

Code: Select all

	for (i = 0; i < end; i++)
		data |= buf[offs + i] << (i*8);
	data >>= hpos % 8;
to:

Code: Select all

	for (i = 0; i < end; i++)
		data |= (buf[offs + i] << (i*8)) >> (hpos % 8);
After botching for the extra byte so I could test RTFM - which appears to work incidentally, there's an issue with the data coming from Joystick_Read, which is wrapping. It looks like the X/Y Axis aren't being scaled down to range from -127 to 127. In my case the X/Y Axis are wrapping at least four times as the Joystick goes from -512 to +511.

Should the scaling in swi_joystick_read not be dividing by acorn_scale_factor - it's currently multiplying. In my case acorn_scale_factor=4, range=1024 (Min=-512 Max=511). There's also the potential for it to wrap, as the max value Acorn support is 127 not 128, in my case if Y Axis=-512 it wraps to 128 (ie -127)
JonAbbott
Posts: 2938
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: USB Joystick driver

Post by JonAbbott »

I've now dumped the raw USB data coming from the Joystick and sure enough, there's an extra byte on the front of the data, which is always 01. Is the Descriptor wrong? Or is one of the preceding values in the Descriptor adding the 01?

EDIT: I've figured out where the extra 01 is coming from...I quote from the USB spec:
Repord ID - Unsigned value that specifies the Report ID. If a Report ID tag is used anywhere in Report descriptor, all data reports for the device are
preceded by a single byte ID field. All items succeeding the first Report ID tag but preceding a second Report ID tag are included in a report prefixed by a 1-byte ID. All items succeeding the second but preceding a third Report ID tag are included in a second report prefixed by a second ID, and so on.
So the code needs to offset the data by 1 if there's a Report ID field.

EDIT2: Not sure if this is the correct way to fix it, but this problem can be resolved by increasing the pos when a Report ID is encountered. Change the following code within hid_get_item_raw in c.parse from:

Code: Select all

			case 8:
				c->report_ID = dval;
				s->kindpos[hid_input] =
				    s->kindpos[hid_output] =
				    s->kindpos[hid_feature] = 0;
				break;
to:

Code: Select all

			case 8:
				c->report_ID = dval;
				s->kindpos[hid_input] =
				    s->kindpos[hid_output] =
				    s->kindpos[hid_feature] = 8;
				break;
Post Reply