SukkoPera / PsxNewLib

Playstation controller interface library for Arduino
GNU General Public License v3.0
128 stars 27 forks source link

Multitap (devel branch) #18

Open sonik-br opened 2 years ago

sonik-br commented 2 years ago

Hi!

I'm doing some tests with the multitap feature of the devel branch. Using HardwareSpi. Code works fine until I disable/enable interrupts for reading controller. Like this

noInterrupts();
const bool success = psx.read (0, controller);
interrupts();

Code just hangs.

Any idea why?

SukkoPera commented 2 years ago

IIRC the code uses interrupts to detect the falling edge on the ACK line between bytes, so it needs interrupts to be enabled. What would be the reason for disabling them BTW? 😅

I think there's also a "backend" that doesn't use the ACK line as in previous versions, but can't remember exactly.

sonik-br commented 2 years ago

Just trying to get it to run as fast as possible. But the ACK pin is not even connected XD

SukkoPera commented 2 years ago

Mmmmh...

So, the PsxDriverHwSpiWithAck driver uses a pin-change interrupt to detect the falling edge on the ACK pin.

If you are not using that, but rather the PsxDriverHwSpi driver, it doesn't seem to require interrupts, but maybe the Arduino SPI library does?

If you want to go faster, you can raise the SPI clock, anyway.

sonik-br commented 2 years ago

The old lib works fine in HwSpi mode with disabled interrupts. But that's ok. I will test with the guncon and see if the added latency will impact it. Fell free to close this. I still need to add guncon support for doing the test and it can take a while.

SukkoPera commented 2 years ago

OK, I think the code hangs because of this (the value returned by millis() will not increment while interrupts are disabled).

Adding a setAttentionInterval(0) call might fix the issue but make sure not to poll the controller too often.

sonik-br commented 2 years ago

Just calling setAttentionInterval(0) did not fix. Had to comment out the line. :)

I will add support for the guncon and test to see if it's required to disable the interrupts.