Author Topic: troubles making my output features reports carry data.  (Read 20716 times)

ulao

  • Frequent Contributor
  • ****
  • Posts: 172
troubles making my output features reports carry data.
« on: November 07, 2021, 05:00:46 pm »
I have a device with software that I developed a ways back. The device used a older v-USB usb stack and the new device uses LUFA.  I pretty much am making a replica of the old device. There are some small changes but for the most parts its the same thing. These device used the USB_PID force feedback to send data FFB data and they both do that well. The old device I believe set the pipe0 to both  in and out and I do not see how to do that with LUFA but as it is with LUFA using FFB, there is an out and and in pipe.

      #define JOYSTICK_EPADDR_IN         (ENDPOINT_DIR_IN | EPNUM1)
      #define JOYSTICK_EPADDR_OUT      (ENDPOINT_DIR_OUT | EPNUM2)
      Endpoint_ConfigureEndpoint(JOYSTICK_EPADDR_OUT, EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, ENDPOINT_DIR_OUT);
      Endpoint_ConfigureEndpoint(JOYSTICK_EPADDR_IN,  EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, ENDPOINT_DIR_IN);

The new device also accepts get reports, and does so just fine but sent report always have empty payloads. See attached.

I confirmed my device sees the report 18 and the length is 9, but the data are missing.

I wrote the software so I can break point and see the data set to go out (it's correct), the report descriptor matches 1:1 and the device config is nearly the same (see below). but I do not get any data.

new device:
Connection Status Device connected
Current Configuration 1
Speed Full (12 Mbit/s)
Device Address 2
Number Of Open Pipes 2

Device Descriptor
Offset Field Size Value Description
0 bLength 1 12h 
1 bDescriptorType 1 01h Device
2 bcdUSB 2 0200h USB Spec 2.0
4 bDeviceClass 1 00h Class info in Ifc Descriptors
5 bDeviceSubClass 1 00h 
6 bDeviceProtocol 1 00h 
7 bMaxPacketSize0 1 40h 64 bytes
8 idVendor 2 16D0h 
10 idProduct 2 0D04h 
12 bcdDevice 2 0200h 2.00
14 iManufacturer 1 01h "Bliss-Box"
15 iProduct 1 02h 
16 iSerialNumber 1 04h "0001"
17 bNumConfigurations 1 01h 

Configuration Descriptor 1 Bus Powered, 200 mA
Offset Field Size Value Description
0 bLength 1 09h 
1 bDescriptorType 1 02h Configuration
2 wTotalLength 2 0029h 
4 bNumInterfaces 1 01h 
5 bConfigurationValue 1 01h 
6 iConfiguration 1 00h 
7 bmAttributes 1 80h Bus Powered
 4..0: Reserved  ...00000   
 5: Remote Wakeup  ..0.....  No
 6: Self Powered  .0......  No, Bus Powered
 7: Reserved (set to one)
(bus-powered for 1.0)  1.......   
8 bMaxPower 1 64h 200 mA

Interface Descriptor 0/0 HID, 2 Endpoints
Offset Field Size Value Description
0 bLength 1 09h 
1 bDescriptorType 1 04h Interface
2 bInterfaceNumber 1 00h 
3 bAlternateSetting 1 00h 
4 bNumEndpoints 1 02h 
5 bInterfaceClass 1 03h HID
6 bInterfaceSubClass 1 00h 
7 bInterfaceProtocol 1 00h 
8 iInterface 1 00h 

HID Descriptor
Offset Field Size Value Description
0 bLength 1 09h 
1 bDescriptorType 1 21h HID
2 bcdHID 2 0111h 1.11
4 bCountryCode 1 00h 
5 bNumDescriptors 1 01h 
6 bDescriptorType 1 22h Report
7 wDescriptorLength 2 04ECh 1260 bytes

Endpoint Descriptor 02 2 Out, Interrupt, 1 ms
Offset Field Size Value Description
0 bLength 1 07h 
1 bDescriptorType 1 05h Endpoint
2 bEndpointAddress 1 02h 2 Out
3 bmAttributes 1 03h Interrupt
 1..0: Transfer Type  ......11  Interrupt
 7..2: Reserved  000000..   
4 wMaxPacketSize 2 0040h 64 bytes
6 bInterval 1 01h 1 ms

Endpoint Descriptor 81 1 In, Interrupt, 1 ms
Offset Field Size Value Description
0 bLength 1 07h 
1 bDescriptorType 1 05h Endpoint
2 bEndpointAddress 1 81h 1 In
3 bmAttributes 1 03h Interrupt
 1..0: Transfer Type  ......11  Interrupt
 7..2: Reserved  000000..   
4 wMaxPacketSize 2 000Eh 14 bytes
6 bInterval 1 01h 1 ms



old device:
Connection Status Device connected
Current Configuration 1
Speed Low (1.5 Mbit/s)
Device Address 4
Number Of Open Pipes 2

Device Descriptor 4-PLAY(GP)PORT.1
Offset Field Size Value Description
0 bLength 1 12h 
1 bDescriptorType 1 01h Device
2 bcdUSB 2 0110h USB Spec 1.1
4 bDeviceClass 1 00h Class info in Ifc Descriptors
5 bDeviceSubClass 1 00h 
6 bDeviceProtocol 1 00h 
7 bMaxPacketSize0 1 08h 8 bytes
8 idVendor 2 16D0h 
10 idProduct 2 0D04h 
12 bcdDevice 2 0400h 4.00
14 iManufacturer 1 01h "BLISS-BOX"
15 iProduct 1 02h "4-PLAY(GP)PORT.1"
16 iSerialNumber 1 03h "1000"
17 bNumConfigurations 1 01h 

Configuration Descriptor 1 Bus Powered, 200 mA
Offset Field Size Value Description
0 bLength 1 09h 
1 bDescriptorType 1 02h Configuration
2 wTotalLength 2 0029h 
4 bNumInterfaces 1 01h 
5 bConfigurationValue 1 01h 
6 iConfiguration 1 00h 
7 bmAttributes 1 00h Bus Powered
 4..0: Reserved  ...00000   
 5: Remote Wakeup  ..0.....  No
 6: Self Powered  .0......  No, Bus Powered
 7: Reserved (set to one)
(bus-powered for 1.0)  0.......   
8 bMaxPower 1 64h 200 mA

Interface Descriptor 0/0 HID, 2 Endpoints
Offset Field Size Value Description
0 bLength 1 09h 
1 bDescriptorType 1 04h Interface
2 bInterfaceNumber 1 00h 
3 bAlternateSetting 1 00h 
4 bNumEndpoints 1 02h 
5 bInterfaceClass 1 03h HID
6 bInterfaceSubClass 1 00h 
7 bInterfaceProtocol 1 00h 
8 iInterface 1 00h 

HID Descriptor
Offset Field Size Value Description
0 bLength 1 09h 
1 bDescriptorType 1 21h HID
2 bcdHID 2 0110h 1.10
4 bCountryCode 1 00h 
5 bNumDescriptors 1 01h 
6 bDescriptorType 1 22h Report
7 wDescriptorLength 2 04ECh 1260 bytes

Endpoint Descriptor 81 1 In, Interrupt, 8 ms
Offset Field Size Value Description
0 bLength 1 07h 
1 bDescriptorType 1 05h Endpoint
2 bEndpointAddress 1 81h 1 In
3 bmAttributes 1 03h Interrupt
 1..0: Transfer Type  ......11  Interrupt
 7..2: Reserved  000000..   
4 wMaxPacketSize 2 0008h 8 bytes
6 bInterval 1 08h 8 ms

Endpoint Descriptor 01 1 Out, Interrupt, 8 ms
Offset Field Size Value Description
0 bLength 1 07h 
1 bDescriptorType 1 05h Endpoint
2 bEndpointAddress 1 01h 1 Out
3 bmAttributes 1 03h Interrupt
 1..0: Transfer Type  ......11  Interrupt
 7..2: Reserved  000000..   
4 wMaxPacketSize 2 0008h 8 bytes
6 bInterval 1 08h 8 ms


What could I possible have wrong here?







Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: troubles making my output features reports carry data.
« Reply #1 on: November 07, 2021, 09:18:50 pm »
Feature reports must use control transfers (endpoint zero).

ulao

  • Frequent Contributor
  • ****
  • Posts: 172
Re: troubles making my output features reports carry data.
« Reply #2 on: November 07, 2021, 10:06:19 pm »
Ok, I do remember reading that. I added another endpoint 1 out but still no luck, how does the driver know what endpoint to use? IF it defaults to the first for feature reports then its still not working, I guess, because the data is still empty.


Endpoint Descriptor 02 2 Out, Interrupt, 1 ms
Offset Field Size Value Description
0 bLength 1 07h 
1 bDescriptorType 1 05h Endpoint
2 bEndpointAddress 1 02h 2 Out
3 bmAttributes 1 03h Interrupt
 1..0: Transfer Type  ......11  Interrupt
 7..2: Reserved  000000..   
4 wMaxPacketSize 2 0040h 64 bytes
6 bInterval 1 01h 1 ms

Endpoint Descriptor 01 1 Out, Interrupt, 1 ms
Offset Field Size Value Description
0 bLength 1 07h 
1 bDescriptorType 1 05h Endpoint
2 bEndpointAddress 1 01h 1 Out
3 bmAttributes 1 03h Interrupt
 1..0: Transfer Type  ......11  Interrupt
 7..2: Reserved  000000..   
4 wMaxPacketSize 2 000Eh 14 bytes
6 bInterval 1 01h 1 ms

Endpoint Descriptor 81 1 In, Interrupt, 1 ms
Offset Field Size Value Description
0 bLength 1 07h 
1 bDescriptorType 1 05h Endpoint
2 bEndpointAddress 1 81h 1 In
3 bmAttributes 1 03h Interrupt
 1..0: Transfer Type  ......11  Interrupt
 7..2: Reserved  000000..   
4 wMaxPacketSize 2 000Eh 14 bytes
6 bInterval 1 01h 1 ms


Renate

  • Frequent Contributor
  • ****
  • Posts: 97
Re: troubles making my output features reports carry data.
« Reply #3 on: November 08, 2021, 05:59:03 am »
HID requires an IN endpoint (even if you don't want or require it), and an optional OUT endpoint.
In no case can you have a third endpoint.

For control back to a HID device you can use (pick one):
  • Output report to OUT endpoint
  • Output report to control (0) endpoint
  • Feature report to control (0) endpoint
  • Vendor request to control (0) endpoint

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: troubles making my output features reports carry data.
« Reply #4 on: November 08, 2021, 10:03:01 am »
Renate is correct.

ulao

  • Frequent Contributor
  • ****
  • Posts: 172
Re: troubles making my output features reports carry data.
« Reply #5 on: November 08, 2021, 06:33:30 pm »
Ok, fair enough but that really confused me on how the Force FeedBack HID PID stuff works then?

How was it working on Endpoint  02  Out  ?

Also now that I have just the in and out on Endpint 1, the FFB application freezes up and the data is not hitting my device. I was doing something like

Endpoint_SelectEndpoint(EPNUM1); 
do in data
Endpoint_SelectEndpoint(EPNUM2);
so out data

and thusly changed to
 Endpoint_SelectEndpoint(EPNUM1); 
do in data
so out data

but no output data is seen. I also still have the same problem with out features report.

I'm now configured like so:

Endpoint Descriptor 81 1 In, Interrupt, 1 ms
Offset Field Size Value Description
0 bLength 1 07h 
1 bDescriptorType 1 05h Endpoint
2 bEndpointAddress 1 81h 1 In
3 bmAttributes 1 03h Interrupt
 1..0: Transfer Type  ......11  Interrupt
 7..2: Reserved  000000..   
4 wMaxPacketSize 2 000Eh 14 bytes
6 bInterval 1 01h 1 ms

Endpoint Descriptor 01 1 Out, Interrupt, 1 ms
Offset Field Size Value Description
0 bLength 1 07h 
1 bDescriptorType 1 05h Endpoint
2 bEndpointAddress 1 01h 1 Out
3 bmAttributes 1 03h Interrupt
 1..0: Transfer Type  ......11  Interrupt
 7..2: Reserved  000000..   
4 wMaxPacketSize 2 000Eh 14 bytes
6 bInterval 1 01h 1 ms








ulao

  • Frequent Contributor
  • ****
  • Posts: 172
Re: troubles making my output features reports carry data.
« Reply #6 on: November 08, 2021, 06:50:56 pm »
So this is interesting.

 
this makes the out pipe work
      Endpoint_ConfigureEndpoint(JOYSTICK_EPADDR_IN,  EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, ENDPOINT_DIR_IN);
      Endpoint_ConfigureEndpoint(JOYSTICK_EPADDR_OUT, EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, ENDPOINT_DIR_OUT);


this makes the in pipe work
      Endpoint_ConfigureEndpoint(JOYSTICK_EPADDR_OUT, EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, ENDPOINT_DIR_OUT);
      Endpoint_ConfigureEndpoint(JOYSTICK_EPADDR_IN,  EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, ENDPOINT_DIR_IN);

There must be a way to do both?
« Last Edit: November 08, 2021, 06:54:27 pm by ulao »

Renate

  • Frequent Contributor
  • ****
  • Posts: 97
Re: troubles making my output features reports carry data.
« Reply #7 on: November 09, 2021, 08:32:05 am »
I don't know the framework that you're using so I can't really say.
I'd guess that somehow you are initializing the same endpoint on your device twice.

Some devices can have EP1-IN, EP1-OUT, EP2-IN, etc.
Other devices can only have EP1-IN, EP2-OUT, EP3-IN, etc.

I'd check the definition of JOYSTICK_EPADDR_IN and JOYSTICK_EPADDR_OUT.
Maybe from your old code you have them both set to 1 instead of 1, 2?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: troubles making my output features reports carry data.
« Reply #8 on: November 09, 2021, 12:36:30 pm »
If you are changing the descriptors and reattaching to a Windows host, to force Windows to forget the previous descriptors, with the device attached, open Windows Device Manager and uninstall the device (under Driver). Then reattach.

ulao

  • Frequent Contributor
  • ****
  • Posts: 172
Re: troubles making my output features reports carry data.
« Reply #9 on: November 09, 2021, 05:05:19 pm »
Yup I'm used to the windows cashe crap... I make sure to remove the device each time.

..so yeah I think that is my issue right here..
Endpoint_ConfigureEndpoint(JOYSTICK_EPADDR_IN,  EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, ENDPOINT_DIR_IN);
Endpoint_ConfigureEndpoint(JOYSTICK_EPADDR_OUT, EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, ENDPOINT_DIR_OUT);

but my question is how do you make it both in and out?

      #define JOYSTICK_EPADDR_IN         (ENDPOINT_DIR_IN | EPNUM1)
      #define JOYSTICK_EPADDR_OUT      (ENDPOINT_DIR_OUT | EPNUM1)

so 0x80 | 1 and 0x00 | 1 does not really work right? I would have guessed there was a bidirectional option but we know there is not.  This is something I never understood. If the last bit tells the address to be in (0x80) and for out it's 0ff (0cx00), we can not differentiate.  The pipe is at the end.


in feature -- Vendor data this is on endpoint 0 default.
out feature -- Vendor data  this is on endpoint 0 default.


in interrupts Normal gamepad data pulls for the OS this should be on 0x81
out interrupts. FFB commands (HID PID) this should be on 0x0-1
 
but not clear how to set that up?








« Last Edit: November 09, 2021, 08:26:47 pm by ulao »

ulao

  • Frequent Contributor
  • ****
  • Posts: 172
Re: troubles making my output features reports carry data.
« Reply #10 on: November 09, 2021, 06:44:02 pm »
From the LUFA doc
Quote
Initialize the control endpoint
In the last chapter, the USB controller of the AT90USB1287 was successfully configured as a USB device. Now we need endpoints so the microcontroller can act as a USB device.
Every USB-capable device requires at least one endpoint, the so-called control endpoint. This endpoint is the only endpoint that can be configured as an IN and OUT endpoint at the same time and is used to control and initialize the USB device.
The AT90USB1287 has a total of 832 bytes of memory (DPRAM) that can be used for a total of seven USB endpoints. This memory is divided as follows:
Max. 64 Bytes for endpoint 0 (Default control endpoint)
Max. 256 Bytes for one endpoint (split up in 1/2 banks)

    Max. 64 Bytes for the other endpoints (split up in in 1/2 banks)

Before the endpoints can be used, they must be configured. Each configuration or memory reservation of an endpoint must be done in ascending order. So endpoint 0 must be created first, followed by endpoint 1, endpoint 2, etc.

so my issue may be the config endpoints, and they are as follows.
static bool Endpoint_ConfigureEndpoint    (    const uint8_t     Address,
      const uint8_t     Type,
      const uint16_t     Size,
      const uint8_t     Banks
   )    


so for my data 4 cases..

in feature -- this is on the default in endpoint 0
out feature -- this is on the default out endpoint 0

in interrupts Normal gamepad data pulls for the OS this will go on pipe 1 (0x81)
out interrupts. FFB commands (HID PID)  this will also go on pipe 1 (0x01)

I'm close but still not sure how the LUFA config works for setting both directions up on a pipe.

also everything I read says I can only have 3 endpoints with hid, the two defaults plus one. Does that mean
0 in  (1)
0 out (2)
1 in or out (3) not both ?




« Last Edit: November 09, 2021, 08:58:34 pm by ulao »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: troubles making my output features reports carry data.
« Reply #11 on: November 09, 2021, 09:57:56 pm »
From the HID spec:

Pipe                            Description                                                                                          Required
Control (Endpoint 0)   USB control, class request codes, and polled data (Message data). Y
Interrupt In                  Data in, that is, data from device (Stream data).                                Y
Interrupt Out               Data out, that is, data to the device (Stream data).                            N

The term "endpoint" can be confusing. Endpoint 0 is bidirectional. Interrupt IN and Interrupt OUT are endpoint addresses, which may share the same endpoint number.

Renate

  • Frequent Contributor
  • ****
  • Posts: 97
Re: troubles making my output features reports carry data.
« Reply #12 on: November 10, 2021, 07:16:16 am »
The term "endpoint" can be confusing.
You finally did mention the actual device AT90USB1287 which is for our purposes identical to the ATMega32u4 (which I do know).
The USB controller supports 7 endpoint addresses, numbered 0-6. Address 0 (control endpoint) supports in/out. Addresses 1-6 support either in or out (but not both simultaneously). Unlike some other devices you cannot have EP1-IN and EP1-OUT.
Your endpoint addresses should be 0 (control), 1, 2. In your endpoint descriptor it should say 0x81 or 0x02. I'm guessing, but the first argument in Endpoint_ConfigureEndpoint should be 1 or 2 with no 0x80 bit.
« Last Edit: November 10, 2021, 07:19:13 am by Renate »

ulao

  • Frequent Contributor
  • ****
  • Posts: 172
Re: troubles making my output features reports carry data.
« Reply #13 on: November 10, 2021, 07:53:26 am »
that is pretty much what I have now.


Endpoint Descriptor 81 1 In, Interrupt, 1 ms
Offset Field Size Value Description
0 bLength 1 07h 
1 bDescriptorType 1 05h Endpoint
2 bEndpointAddress 1 81h 1 In
3 bmAttributes 1 03h Interrupt
 1..0: Transfer Type  ......11  Interrupt
 7..2: Reserved  000000..   
4 wMaxPacketSize 2 0040h 64 bytes
6 bInterval 1 01h 1 ms

Endpoint Descriptor 02 2 Out, Interrupt, 1 ms
Offset Field Size Value Description
0 bLength 1 07h 
1 bDescriptorType 1 05h Endpoint
2 bEndpointAddress 1 02h 2 Out
3 bmAttributes 1 03h Interrupt
 1..0: Transfer Type  ......11  Interrupt
 7..2: Reserved  000000..   
4 wMaxPacketSize 2 0040h 64 bytes
6 bInterval 1 01h 1 ms


1) My in features reports do make it in
2) My out features reports do not make it out
3) MY gamepad EP1 in works
4) My FFB data EP2 works

This was my original problem, I can not get the feature reports working for "set". Although now I seem to understand things better and have it set up.

1) I only have 3 enpoints, default + 2 more
2) my default should be in and out
3) my EP 1 is in exclusively.
4) my EP 2 is out exclusively.

Interestingly if I remove EP2 the features control sets make it in ok. So I still must have something configured wrong.

I set up the device configure change for
      #define JOYSTICK_EPADDR_IN         (ENDPOINT_DIR_IN | EPNUM1)
      #define JOYSTICK_EPADDR_OUT      (ENDPOINT_DIR_OUT | EPNUM2)
      Endpoint_ConfigureEndpoint(JOYSTICK_EPADDR_IN,  EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, 1);
      Endpoint_ConfigureEndpoint(JOYSTICK_EPADDR_OUT, EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, 1);      

and from what I read I do not need to configure the default endpoint for out, is should just be working but the payload is always empty like I originally stated. But if all things are correct and I'm following the "rules" then I guess its up for LUFA to help.

Here is an interesting point that I'd much like an explanation on. Jan?

on my old device I had the same setup except that my out was also EP 1. the Force feedback data used my default control pipe. If I enabled my second pipe, then it used that pipe and I saw it come in as out instead of control. Does the driver always use the last pipe were possible and if no pipes are configure for "out" it just uses the default control pipe?

also one more thing I would like to clear up and I think its chip specific.
pipe 0 gets a max of 64 bytes
pipe 1 can have 256 bytes ( I only need 64)
pipe 2 can have 64 bytes  ( I only need 64)

but how do the banks work. does pipe 1 and 2 share banks?
Max. 64 Bytes for endpoint 0 (Default control endpoint)
Max. 256 Bytes for one endpoint (split up in 1/2 banks)
Max. 64 Bytes for the other endpoints (split up in in 1/2 banks)





« Last Edit: November 10, 2021, 09:20:50 am by ulao »

Renate

  • Frequent Contributor
  • ****
  • Posts: 97
Re: troubles making my output features reports carry data.
« Reply #14 on: November 10, 2021, 10:14:48 am »
In HID the OUT endpoint is optional. If you don't have one your Windows driver will send a SET_REPORT request to the control endpoint instead.

So, I'm confused at the current state of affairs. Do you have endpoints 1 & 2 working correctly for normal read/write reports now?
Is the problem now getting data from a SET_FEATURE request?