Crate pscontroller_rs [−] [src]
Playstation Controller driver for Rust's Embedded Hardware Abstraction Layer
The original PlayStation and most of its peripherals are 20+ years old at this point, but they're easy to interface with for fun projects, and wireless variants are easy to come by while being pretty cheap ($28 Canadian for two as of this writing).
The current state of this library is such that it's fairly naïve to which controller is plugged in, and will make a guess based on the device type (1 - 15) and how many 16bit words are being returned. For those who know the protocol, this library reads the second byte from the poll command and wraps the response in a struct based on that so it's lightweight on memory
Efficiencies can be made here, and things will likely improve, but the darn thing is useful now so let's start using it! If you find things to fix, please make an issue.
Hardware
Because the PlayStation could have up to four devices sharing the same SPI bus (two controllers and two memory cards), they made the data out (MISO) pin open drain so you'll need to add your own resistor. In my testing with a voltage divider on a PlayStation 2, the value is around 220 - 500 ohms. I'm not sure if the controller jack assembly contains one of these yet, so you should double check with a multimeter before plugging anything in.
Structs
Classic |
Represents the classic Controller |
ControllerConfiguration |
Holds information about the controller's configuration and constants |
DualShock |
Represents the DualShock 1 controller |
DualShock2 |
Represents the DualShock 2 controller |
GamepadButtons |
The digital buttons of the gamepad |
GuitarHero |
Represents a Guitar Hero controller |
JogCon |
Represents the Namco JogCon controller |
NegCon |
Represents the Namco NegCon controller |
NegconButtons |
The digital buttons of the Namco NegCon |
PlayStationPort |
The main event! Create a port using an SPI bus and start commanding controllers! |
Enums
Device |
Possible devices that can be returned by the poll command to the controller. Currently, we're relying both on the device type (high nybble) and the number of 16bit words its returning (low nybble) to guess the device type. |
Error |
Errors that can arrise from trying to communicate with the controller |
JogControl |
What we want the JogCon's wheel to do after we poll it |
JogState |
What state the JogCon's wheel was in last poll |
MultitapPort |
The active port to set on the Multitap |
Traits
HasStandardButtons |
Many controllers have the same set of buttons (Square, Circle, L3, R1, etc). The devices that do have these buttons implement this trait. Depite the original Controller not having L3 and R3, they are brought out regardless and just considered unpressable. |