Need help with USBHID

What are you developing?
Post Reply
User avatar
Mangy_Dog
Posts: 8
Joined: Wed Mar 27, 2019 6:50 pm
Location: UK
OS: Win10
IDE: Slober, ArduinoIDE (for building)
Core: Rogers, Daves, Maybe the Offical core... Maybe
Board: Baite Maple mini, mostly...

Need help with USBHID

Post by Mangy_Dog » Mon Sep 02, 2019 10:56 am

So im working on a USB controller for a built in Pi hat setup. A retro handheld, but im having a few little problems
First my when i activate both xbox360 and keyboard and usnhid (keyboard required usb hid?) in the USB Composite library. I dont get any usb devices found.
I wanted a basic USBkeyboard to do some shortcut commands for things like volume up and down to the main system.
However commenting out the keyboard side of things and just running xbox, the system reports to find a xbox controller. However my button report rate is in the region of 1 or 2 reports a second. This is way way way too slow. My goal was around 500 reports a second or at least 100.
Manual report is set in theh setup portion of my code but here is the HID handling code... Am i doing my xbox360.button statuses wrong?

Code: Select all

static void hidUPDATE(void *pvParameters)
    {
    for (;;)
	{
	vTaskDelay(2);
	int ang = 0;

	if (digitalRead(UP) == LOW && digitalRead(DWN) == HIGH
		&& digitalRead(LFT) == HIGH && digitalRead(RHT) == HIGH)
	    {
	    ang = 0;
	    }
	else if (digitalRead(UP) == LOW && digitalRead(RHT) == LOW)
	    {
	    ang = 45;
	    }
	else if (digitalRead(RHT) == LOW && digitalRead(DWN) == HIGH
		&& digitalRead(LFT) == HIGH && digitalRead(UP) == HIGH)
	    {
	    ang = 90;
	    }
	else if (digitalRead(DWN) == LOW && digitalRead(RHT) == LOW)
	    {
	    ang = 135;
	    }
	else if (digitalRead(DWN) == LOW && digitalRead(UP) == HIGH
		&& digitalRead(LFT) == HIGH && digitalRead(RHT) == HIGH)
	    {
	    ang = 180;
	    }
	else if (digitalRead(DWN) == LOW && digitalRead(LFT) == LOW)
	    {
	    ang = 225;
	    }

	else if (digitalRead(LFT) == LOW && digitalRead(DWN) == HIGH
		&& digitalRead(UP) == HIGH && digitalRead(RHT) == HIGH)
	    {
	    ang = 270;
	    }

	else if (digitalRead(UP) == LOW && digitalRead(LFT) == LOW)
	    {
	    ang = 315;
	    }

	else
	    {
	    ang = -1;
	    }
	XBox360.hat(ang);
	//still need to find out what range xbox360 reports up to and convert analog to that.
	XBox360.X(analogRead(LFTANAX));  
	XBox360.Y(analogRead(LFTANAY));
	XBox360.XRight(analogRead(RHTANAX));
	XBox360.YRight(analogRead(RHTANAY));

	XBox360.button(1, !digitalRead(ABUT));
	XBox360.button(2, !digitalRead(BBUT));
	XBox360.button(3, !digitalRead(XBUT));
	XBox360.button(4, !digitalRead(YBUT));

	XBox360.button(5, !digitalRead(L1BUT));
	XBox360.button(6, !digitalRead(R1BUT));

	if (digitalRead(L2BUT)==LOW)
	    {
	    XBox360.sliderLeft(256); //need to find out what the range is to convert button to full press of trigger.
	    }
	if (digitalRead(R2BUT)==LOW)
	    {
	XBox360.sliderRight(256);
	    }

	XBox360.button(7, !digitalRead(SELBUT));
	XBox360.button(8, !digitalRead(STARTBUT));


	OPTBUTT();

	XBox360.button(12, !digitalRead(LFTANABUT));
	XBox360.button(13, !digitalRead(RHTANABUT));

	XBox360.send();

        if (!digitalRead(PLUSBUT))
        	{
               // Keyboard.print(0xAF);
        	}
        if (!digitalRead(NEGBUT))
        	{
		//Keyboard.print(0xAE);
        	}

	}
    }
Nutsy from the old forums... I go by Mangy_Dog now and I'm also on freenode #electronics irc.

User avatar
Mangy_Dog
Posts: 8
Joined: Wed Mar 27, 2019 6:50 pm
Location: UK
OS: Win10
IDE: Slober, ArduinoIDE (for building)
Core: Rogers, Daves, Maybe the Offical core... Maybe
Board: Baite Maple mini, mostly...

Re: Need help with USBHID

Post by Mangy_Dog » Mon Sep 02, 2019 3:55 pm

More info...

Hooked up my HID to my pc... manual reporting doesnt seem to work at all. on the fly reporting kinda sort of works but the button mapping is WAY off... the .hat subclass doesnt effect hat status and buttons 1234 which are normally ABXY are triggering the hat in the gamepad prefs in windows.

Currently i cant tell you what the analogue joycons are doing as im still waiting for the connectors for those to turn up.
Nutsy from the old forums... I go by Mangy_Dog now and I'm also on freenode #electronics irc.

ag123
Posts: 163
Joined: Thu Mar 07, 2019 6:15 am
Location: Singapore
OS: linux
IDE: eclipse, arduino 1.8.5
Core: Roger's
Board: Maple mini, Bluepill

Re: Need help with USBHID

Post by ag123 » Mon Sep 02, 2019 4:05 pm

i'm not sure if the os end may have a role to play too,
https://en.wikipedia.org/wiki/USB_human ... vice_class
USB mice have lower latencies than PS/2 mice because standard USB mice are often polled at a default rate of 125 Hz while standard PS/2 mice send interrupts at a default rate of 100 Hz when they have data to send to the computer

User avatar
Mangy_Dog
Posts: 8
Joined: Wed Mar 27, 2019 6:50 pm
Location: UK
OS: Win10
IDE: Slober, ArduinoIDE (for building)
Core: Rogers, Daves, Maybe the Offical core... Maybe
Board: Baite Maple mini, mostly...

Re: Need help with USBHID

Post by Mangy_Dog » Mon Sep 02, 2019 4:22 pm

well tbh considering the application is a retro console. 100hz is fine too :p

But the real new issue is not being able to set manual reporting and the button mapping be way off what it should be.
Maybe might library is an old build? if it is wheres a new one? :D
Nutsy from the old forums... I go by Mangy_Dog now and I'm also on freenode #electronics irc.

User avatar
Mangy_Dog
Posts: 8
Joined: Wed Mar 27, 2019 6:50 pm
Location: UK
OS: Win10
IDE: Slober, ArduinoIDE (for building)
Core: Rogers, Daves, Maybe the Offical core... Maybe
Board: Baite Maple mini, mostly...

Re: Need help with USBHID

Post by Mangy_Dog » Tue Sep 03, 2019 2:50 pm

if anyone can help me with this mapping it would be really great...

Currently the xbox260.hat(angle) doesnt seem to do anything at all... Even looking at the library its just a varable but doesnt seem to go anywhere... xbox360.Buttons 1 2 3 4 are mapped to up down left right, when it should be abxy according to joystick prefs...

What is the correct layout?
Nutsy from the old forums... I go by Mangy_Dog now and I'm also on freenode #electronics irc.

User avatar
Mangy_Dog
Posts: 8
Joined: Wed Mar 27, 2019 6:50 pm
Location: UK
OS: Win10
IDE: Slober, ArduinoIDE (for building)
Core: Rogers, Daves, Maybe the Offical core... Maybe
Board: Baite Maple mini, mostly...

Re: Need help with USBHID

Post by Mangy_Dog » Thu Sep 05, 2019 1:00 pm

I managed to contact the library author and he was very helpful...
As for button mapping. While not incredibly intuitive ie buttons 1234 dont trigger buttons 1234 in the joystick prefs.... Buttons 1 2 3 4 actually edit the button states of bit 1 2 3 4 of a 2 byte transmission...
Alexander linked me this
https://www.partsnotincluded.com/revers ... -usb-data/

Having a read through you can find the 2 bytes that represent the button states. Using that guide you can easily figure out what button maps to what byte and so what button in the xbox driver.

last issue i need to sort out is having both keyboard and buttons working so I can set volume controls in my project...
Nutsy from the old forums... I go by Mangy_Dog now and I'm also on freenode #electronics irc.

Post Reply