1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-07-01 01:38:44 +00:00

Dualshock 3: Set LED on init and fix endpoints

This commit is contained in:
cathery 2019-11-07 13:45:51 +03:00
parent 99c195e3d3
commit d8c5237f84
2 changed files with 69 additions and 58 deletions

View File

@ -98,60 +98,33 @@ struct Dualshock3ButtonData
} __attribute__((packed));
/*
typedef enum _DS3_FEATURE_VALUE
{
Ds3FeatureDeviceAddress = 0x03F2,
Ds3FeatureStartDevice = 0x03F4,
Ds3FeatureHostAddress = 0x03F5
} DS3_FEATURE_VALUE;
#define DS3_HID_COMMAND_ENABLE_SIZE 0x04
#define DS3_HID_OUTPUT_REPORT_SIZE 0x30
#define DS3_VENDOR_ID 0x054C
#define DS3_PRODUCT_ID 0x0268
#define DS4_HID_OUTPUT_REPORT_SIZE 0x20
#define DS4_VENDOR_ID 0x054C
#define DS4_PRODUCT_ID 0x05C4
#define DS4_2_PRODUCT_ID 0x09CC
#define DS4_WIRELESS_ADAPTER_PRODUCT_ID 0x0BA0
#define PS_MOVE_NAVI_PRODUCT_ID 0x042F
const uint8_t PS3_REPORT_BUFFER[] = {
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0x27, 0x10, 0x00, 0x32,
0xff, 0x27, 0x10, 0x00, 0x32,
0xff, 0x27, 0x10, 0x00, 0x32,
0xff, 0x27, 0x10, 0x00, 0x32,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
//Used to set the LEDs on the controllers
const uint8_t LEDS[] = {
0x01, // LED1
0x02, // LED2
0x04, // LED3
0x08, // LED4
0x09, // LED5
0x0A, // LED6
0x0C, // LED7
0x0D, // LED8
0x0E, // LED9
0x0F // LED10
};
*/
enum Dualshock3LEDValue
{
DS3LED_1 = 0x01,
DS3LED_2 = 0x02,
DS3LED_3 = 0x04,
DS3LED_4 = 0x08,
DS3LED_5 = 0x09,
DS3LED_6 = 0x0A,
DS3LED_7 = 0x0C,
DS3LED_8 = 0x0D,
DS3LED_9 = 0x0E,
DS3LED_10 = 0x0F,
};
#define LED_PERMANENT 0xff, 0x27, 0x00, 0x00, 0x32
class Dualshock3Controller : public IController
{
private:
IUSBEndpoint *m_inPipe = nullptr;
IUSBEndpoint *m_outPipe = nullptr;
IUSBInterface *m_interface = nullptr;
Dualshock3ButtonData m_buttonData;
@ -186,5 +159,9 @@ public:
Status SendInitBytes();
Status SetRumble(uint8_t strong_magnitude, uint8_t weak_magnitude);
static Status SendCommand(IUSBInterface *interface, Dualshock3FeatureValue feature, void *buffer, uint16_t size);
Status SetLED(Dualshock3LEDValue value);
static void LoadConfig(const ControllerConfig *config);
};

View File

@ -21,6 +21,7 @@ Status Dualshock3Controller::Initialize()
if (S_FAILED(rc))
return rc;
SetLED(DS3LED_1);
return rc;
}
void Dualshock3Controller::Exit()
@ -46,28 +47,44 @@ Status Dualshock3Controller::OpenInterfaces()
{
//Send an initial control packet
uint8_t initBytes[] = {0x42, 0x0C, 0x00, 0x00};
rc = interface->ControlTransfer(0x21, 0x09, Ds3FeatureStartDevice, 0, sizeof(initBytes), initBytes);
rc = SendCommand(interface.get(), Ds3FeatureStartDevice, initBytes, sizeof(initBytes));
if (S_FAILED(rc))
return 60;
IUSBEndpoint *inEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_IN, 0);
if (inEndpoint)
{
rc = inEndpoint->Open();
if (S_FAILED(rc))
return 61;
m_interface = interface.get();
m_inPipe = inEndpoint;
if (!m_inPipe)
{
for (int i = 0; i != 15; ++i)
{
IUSBEndpoint *inEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_IN, i);
if (inEndpoint)
{
rc = inEndpoint->Open();
if (S_FAILED(rc))
return 61;
m_inPipe = inEndpoint;
break;
}
}
}
IUSBEndpoint *outEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_OUT, 1);
if (outEndpoint)
if (!m_outPipe)
{
rc = outEndpoint->Open();
if (S_FAILED(rc))
return 62;
for (int i = 0; i != 15; ++i)
{
IUSBEndpoint *outEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_OUT, i);
if (outEndpoint)
{
rc = outEndpoint->Open();
if (S_FAILED(rc))
return 62;
m_outPipe = outEndpoint;
m_outPipe = outEndpoint;
break;
}
}
}
if (!m_inPipe || !m_outPipe)
@ -186,6 +203,23 @@ Status Dualshock3Controller::SetRumble(uint8_t strong_magnitude, uint8_t weak_ma
return 9;
}
Status Dualshock3Controller::SendCommand(IUSBInterface *interface, Dualshock3FeatureValue feature, void *buffer, uint16_t size)
{
return interface->ControlTransfer(0x21, 0x09, static_cast<uint16_t>(feature), 0, size, buffer);
}
Status Dualshock3Controller::SetLED(Dualshock3LEDValue value)
{
uint8_t ledPacket[]{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
static_cast<uint8_t>(value << 1),
LED_PERMANENT,
LED_PERMANENT,
LED_PERMANENT,
LED_PERMANENT};
return SendCommand(m_interface, Ds3FeatureUnknown1, ledPacket, sizeof(ledPacket));
}
void Dualshock3Controller::LoadConfig(const ControllerConfig *config)
{
_dualshock3ControllerConfig = *config;