USB Gamepad outputs revisited

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
fovea1959
 
Posts: 26
Joined: Tue Jan 29, 2013 2:39 pm

USB Gamepad outputs revisited

Post by fovea1959 »

An extension of viewtopic.php?p=938955#p938955

I have modified the gamepad example to have 2 output bits:

Code: Select all

GAMEPAD_REPORT_DESCRIPTOR = bytes((
    0x05, 0x01,  # Usage Page (Generic Desktop Ctrls)
    0x09, 0x05,  # Usage (Game Pad)
    0xA1, 0x01,  # Collection (Application)
    0x85, 0x04,  #   Report ID (4)
    #
    0x05, 0x09,  #   Usage Page (Button)
    0x19, 0x01,  #   Usage Minimum (Button 1)
    0x29, 0x10,  #   Usage Maximum (Button 16)
    0x15, 0x00,  #   Logical Minimum (0)
    0x25, 0x01,  #   Logical Maximum (1)
    0x75, 0x01,  #   Report Size (1)
    0x95, 0x10,  #   Report Count (16)
    0x81, 0x02,  #   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
    #
    0x05, 0x01,  #   Usage Page (Generic Desktop Ctrls)
    0x15, 0x81,  #   Logical Minimum (-127)
    0x25, 0x7F,  #   Logical Maximum (127)
    0x09, 0x30,  #   Usage (X)
    0x09, 0x31,  #   Usage (Y)
    0x09, 0x32,  #   Usage (Z)
    0x09, 0x35,  #   Usage (Rz)
    0x75, 0x08,  #   Report Size (8)
    0x95, 0x04,  #   Report Count (4)
    0x81, 0x02,  #   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
    #
    0x05, 0x09,  #   Usage Page (Button)
    0x19, 0x01,  #   Usage Minimum (0x01)
    0x29, 0x02,  #   Usage Maximum (0x02)
    0x15, 0x00,  #   Logical Minimum (0)
    0x25, 0x01,  #   Logical Maximum (1)
    0x35, 0x00,  #   Physical Minimum (0)
    0x45, 0x01,  #   Physical Maximum (1)
    0x75, 0x01,  #   Report Size (1)
    0x95, 0x02,  #   Report Count (2)
    0x91, 0x0a,  #   Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
    0xC0,        # End Collection
))


I have added some .get_last_received_report() calls into hid_gamepad.py, trying to clear the incoming reports every time I try to _send.

I have the problem now that I get this now (but only on a Windows host, connecting to a Linux host is ok, though I have not been able to verify actually sending the data out in Linux).

Code: Select all

Traceback (most recent call last):
  File "code.py", line 36, in <module>
  File "hid_gamepad.py", line 71, in press_buttons
  File "hid_gamepad.py", line 146, in _send
OSError: USB busy
Line 146 of _send is immediately preceded by a call to get_last_received_report (code is attached)

Does anyone have any success with sending data *to* a CircuitPython gamepad device? This is CircuitPython 7.3.2 on an RP2040 (an actual Raspberry Pi Pico...)
Attachments
hid_gamepad.py
(5.37 KiB) Downloaded 5 times
code.py
(802 Bytes) Downloaded 4 times
boot.py
(2.15 KiB) Downloaded 4 times

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: USB Gamepad outputs revisited

Post by danhalbert »

Try the latest 8.0.0 beta: there was an improvement to this mechanism in https://github.com/adafruit/circuitpython/pull/6767, though it may not fix this problem.

User avatar
fovea1959
 
Posts: 26
Joined: Tue Jan 29, 2013 2:39 pm

Re: USB Gamepad outputs revisited

Post by fovea1959 »

Still have the problem on 8.0.0-beta6.

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: USB Gamepad outputs revisited

Post by danhalbert »

Are you using a simple program on the host computer side (what OS?) that is sending this data back? Could you share that? Or are you connected to some specialized device?

User avatar
fovea1959
 
Posts: 26
Joined: Tue Jan 29, 2013 2:39 pm

Re: USB Gamepad outputs revisited

Post by fovea1959 »

On the host side, I am just using the Windows 10 "Set up game controllers" tool. If I don't include the outputs in the USB descriptor, all is well; if I do, any attempt to _send from the RP2040 to the host gets the USB error.

Now I have things to the point where it does not show up as a gamepad; I have somehow munged up the USB desciptor.

I'll be digging into this a little more today; I'll put Wireshark on it and see if I can get a capture of what the hey is happening.

User avatar
fovea1959
 
Posts: 26
Joined: Tue Jan 29, 2013 2:39 pm

Re: USB Gamepad outputs revisited

Post by fovea1959 »

Setting aside the "USB busy" issue for a sec, and concentrating on seeing if I can get the host to send data at all. It sends, but not getting received.

I am running this program on the Linux host:

Code: Select all

import hid
import time

# MSP430
vid = 0x2047
pid = 0x0997

# Pico
vid = 0x239a
pid = 0x80f4

with hid.Device(vid, pid) as h:
    print(h.manufacturer)
    print(h.product)
    print(h.serial)

    on = True
    while True:
        b = 0xff if on else 0x00
        h.write(bytes([b, b]))
        time.sleep(1)
        on = not on
I can run this against an MSP430 with an identical USB descriptor, and it works fine there; the MSP430 is getting data.

When I run it against the Pico, CircuitPython 8.0.0-beta6, and the attached program, the calls to get_last_received_report() are coming up dry.

I can watch the USB interface with Wireshark, and can see the data going out (and again, it works against the MSP430).

Trying to figure out where the data is getting lost. Is there something I can do at the python level, or do I need to start doing a custom build to get more debug information?
Attachments
code.py
(362 Bytes) Downloaded 3 times
boot.py
(2.92 KiB) Downloaded 2 times

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: USB Gamepad outputs revisited

Post by danhalbert »

What USB stack are you using on the MSP430? Is it TinyUSB, or is it from the MSP430 SDK? CircuitPython uses TinyUSB.

User avatar
fovea1959
 
Posts: 26
Joined: Tue Jan 29, 2013 2:39 pm

Re: USB Gamepad outputs revisited

Post by fovea1959 »

Using something from the MSP430 stack...

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”