USBJoystick 0.12

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

Re: USB Joystick driver

Post by richw » Mon Oct 08, 2018 11:06 pm

Odd. If you use the read *command, does it look like the correct axes and buttons respond?

The raw data might be misleading. I need to enhance the output to show the last 20 reads or something, as the data formats are not always the same.

I was reading up on bytev earlier. Looks reasonable!

JonAbbott
Posts: 2114
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex

Re: USB Joystick driver

Post by JonAbbott » Tue Oct 09, 2018 11:25 am

richw wrote:
Mon Oct 08, 2018 11:06 pm
If you use the read *command, does it look like the correct axes and buttons respond?
No it doesn't show any changes, but USBJoystick_Debug only ever shows the padding value which also explains why the first four buttons are always shown as being down.
richw wrote:
Mon Oct 08, 2018 11:06 pm
The raw data might be misleading. I need to enhance the output to show the last 20 reads or something, as the data formats are not always the same.
I read the raw data directly from the endpoint, so you could compare it to values from your clone.

I'll modify the source later to ignore the padding and see if that gets it working.

JonAbbott
Posts: 2114
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex

Re: USB Joystick driver

Post by JonAbbott » Tue Oct 09, 2018 2:48 pm

JonAbbott wrote:
Tue Oct 09, 2018 11:25 am
I'll modify the source later to ignore the padding and see if that gets it working.
By dropping the padding and the first 4 bytes of the USB data, the XB360 controller works correctly, so either the HID descriptor is different for an official XB360 wireless, or its not being parsed correctly. If you dump the raw USB data on your clone, does it match mine? I'm guessing everything is 4 bytes to the left? Unfortunately, I don't have a wired controller to see if wireless is adding 4 extra bytes on the front.

Here's the hack I added to upcallv_hook_handler after the buffer_read() call:

Code: Select all

  if (joy_data[i].vendor_id==0x45e && joy_data[i].product_id==0x719) {
    unsigned int zz2 = 0;
    for (unsigned int zz = 0; zz<joy_data[i].dlen; zz++) {
      if (zz!=3) {
        zz2+=buffer[zz];
      }
    }
    if (zz2==0 && buffer[3]==0xf0) {
      read = 0;
    }
    else {
      if (read == joy_data[i].dlen) {
        joy_data[i].good_reads++;
        joy_data[i].good_reads_delta++;
        memcpy(joy_data[i].data_buf, buffer+4, joy_data[i].dlen-4);
        joystick_decode(i);
      }
      else {
        joy_data[i].bad_reads++;
        joy_data[i].bad_reads_delta++;
      }
      return VECTOR_PASSON;
    }
  }
This also fixed the 8/16bit weirdness, which I guess was down to combination of the data being shifted and the D-Pad being mapped instead of the left thumbstick.

richw
Posts: 112
Joined: Sat Sep 14, 2013 9:05 pm

Re: USB Joystick driver

Post by richw » Tue Oct 09, 2018 5:04 pm

I have been doing some reading of the drivers for other platforms: the wireless one uses the same HID report descriptor format (as the wired), BUT in the received data packet, there is additional information. The first few bytes indicate something else, then the rest is identical, as you've found. I thought that there would be a touch more to it, which is why I was distracting myself by looking at ByteV, and hoping you'd spot the craziness in the 8/16-bit Acorn SWI handler. :)

I think I'll add in a proper 'device type', so I can cleanly differentiate between standard/xb360/xb360wireless (+ others as they appear) in the code.

So... the bit I don't understand... why does your SideWinder FF not work? Surely it doesn't work with the above hack?!

JonAbbott
Posts: 2114
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex

Re: USB Joystick driver

Post by JonAbbott » Wed Oct 10, 2018 9:51 am

richw wrote:
Tue Oct 09, 2018 5:04 pm
So... the bit I don't understand... why does your SideWinder FF not work? Surely it doesn't work with the above hack?!
I've just retested and its now working correctly :?

richw
Posts: 112
Joined: Sat Sep 14, 2013 9:05 pm

Re: USB Joystick driver

Post by richw » Wed Oct 10, 2018 5:41 pm

Phew - glad to hear it!

I've got my basic first draft of the I/O podule ADC emulation up-and-running, but I need to throw together a BASIC test utility, as I have nothing else to test it with. I think covering the official OSByte calls and BASIC's ADVAL command should be enough, but until we try it with some real software, we don't know for sure.

JonAbbott
Posts: 2114
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex

Re: USB Joystick driver

Post by JonAbbott » Sat Oct 20, 2018 11:50 am

JonAbbott wrote:
Fri Oct 05, 2018 9:59 pm
I have a Thrustmaster Force Feedback Steering Wheel (VID_06F8 PID_0004) I was going to try with it, but I need to be able to inject the HID descriptor as it doesn't have one.
I've finally figured this thing out. The data appears to be coming in the wrong endpoint - it's no wonder Windows crashes the second its plugged in!

Its not at straight forward as embedding a descriptor though. Essentially, it returns the following so needs a mini driver:

Code: Select all

02 03 XX 00 - if the first byte returned is 02, then 4 bytes are returned where XX is a counter which I'm assuming is something to do with the force feedback motor.  This can be ignored.

03 SL SH AA BB Z1 Z2 Z3 - if the first byte returned is 03 then 8 bytes are returned where:

Steering    = <SH SL> = F800 (left), 0000 (centre), 0800 (right)
Accelerator = <AA> = FF when off, reducing to 00 when fully on
Brake       = <BB> = FF when off, reducing to 00 when fully on

Buttons     = <Z1 Z2 Z3> where:
Back        = __ _8 __
Start       = __ _4 __
Down paddle = __ _2 __
Up paddle   = __ _1 __
Up gear     = __ 1_ __
Down gear   = __ 2_ __
D-Pad down  = __ __ _1
D-Pad left  = __ __ _2
D-Pad up    = __ 4_ __
D-Pad right = __ 8_ __
View hat    = __ __ X_  where X is the direction, F being centred:
                         7 0 1
                          \|/
                         6-F-2
                          /|\
                         5 4 3
Need to figure out the best way to implement this, possibly a mini driver that can send data to USBJoystick via an interface so we can add additional devices in the future that don't comply with HID?

richw
Posts: 112
Joined: Sat Sep 14, 2013 9:05 pm

Re: USB Joystick driver

Post by richw » Sat Oct 20, 2018 8:53 pm

Interesting. I could come up with some more extensions to USBJoystick to handle this (and therefore similar) devices. The completely thorough solution would be to provide some sort of binary interface to allow mini driver modules to register. Or maybe the data format above could be described in some way... some sort of config file. Looking at it, it the bit with the inputs in sounds like it would be possible to build a HID report descriptor for, so maybe it's even easier?

JonAbbott
Posts: 2114
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex

Re: USB Joystick driver

Post by JonAbbott » Sat Oct 20, 2018 11:19 pm

richw wrote:
Sat Oct 20, 2018 8:53 pm
The completely thorough solution would be to provide some sort of binary interface to allow mini driver modules to register.
That was my initial thought as well. If the driver could register with USBJoystick passing it an HID descriptor, then it could just call USBJoystick later with data so it can be handled in the existing code with minimal change on your side.

You'll probably want to register an SWI block. We need one anyway for a configuration app, so it can display all Joystick inputs and allow manual configuration of the mappings.

richw
Posts: 112
Joined: Sat Sep 14, 2013 9:05 pm

Re: USB Joystick driver

Post by richw » Thu Oct 25, 2018 9:05 pm

I have just published version 0.12 to the initial post in this thread. I have removed the floats - maybe the FP aborts will go away?

I’ve also started on I/O module ADC support, but it is not yet complete.

Post Reply