1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-11-19 05:09:49 +00:00

Begin implementing Xbox One Adapter

This commit is contained in:
cathery 2019-11-11 22:42:24 +03:00
parent 1219a249be
commit 444288d533
5 changed files with 94 additions and 26 deletions

View File

@ -7,11 +7,25 @@
//https://github.com/quantus/xbox-one-controller-protocol //https://github.com/quantus/xbox-one-controller-protocol
//https://cs.chromium.org/chromium/src/device/gamepad/xbox_controller_mac.mm //https://cs.chromium.org/chromium/src/device/gamepad/xbox_controller_mac.mm
enum VendorRequest
{
MT_VEND_DEV_MODE = 0x1,
MT_VEND_WRITE = 0x2,
MT_VEND_MULTI_WRITE = 0x6,
MT_VEND_MULTI_READ = 0x7,
MT_VEND_READ_EEPROM = 0x9,
MT_VEND_WRITE_FCE = 0x42,
MT_VEND_WRITE_CFG = 0x46,
MT_VEND_READ_CFG = 0x47,
};
class XboxOneAdapter : public IController class XboxOneAdapter : public IController
{ {
private: private:
IUSBEndpoint *m_inPipePacket = nullptr;
IUSBEndpoint *m_inPipe = nullptr; IUSBEndpoint *m_inPipe = nullptr;
IUSBEndpoint *m_outPipe = nullptr; IUSBEndpoint *m_outPipe = nullptr;
IUSBInterface *m_interface = nullptr;
public: public:
XboxOneAdapter(std::unique_ptr<IUSBDevice> &&interface); XboxOneAdapter(std::unique_ptr<IUSBDevice> &&interface);
@ -26,4 +40,5 @@ public:
virtual ControllerType GetType() { return CONTROLLER_XBOXONEW; } virtual ControllerType GetType() { return CONTROLLER_XBOXONEW; }
Status SendInitBytes(); Status SendInitBytes();
Status ControlWrite(IUSBInterface *interface, uint16_t address, uint32_t value, VendorRequest request = MT_VEND_MULTI_WRITE);
}; };

View File

@ -0,0 +1,9 @@
#pragma once
#include <stdint.h>
#define MT_FW_RESOURCE "Firmware.bin"
#define MT_MCU_ILM_OFFSET 0x80000
#define MT_MCU_DLM_OFFSET 0x100000 + 0x10800
#define MT_FW_CHUNK_SIZE 0x3800
#define MT_DMA_COMPLETE 0xc0000000
#define MT_FW_LOAD_IVB 0x12

View File

@ -1,4 +1,5 @@
#include "Controllers/XboxOneAdapter.h" #include "Controllers/XboxOneAdapter.h"
#include "Controllers/XboxOneAdapter/Firmware.h"
#include <cmath> #include <cmath>
#include "../../source/log.h" #include "../../source/log.h"
@ -44,55 +45,60 @@ Status XboxOneAdapter::OpenInterfaces()
if (S_FAILED(rc)) if (S_FAILED(rc))
return rc; return rc;
/* if (interface->GetDescriptor()->bInterfaceProtocol != 255)
if (interface->GetDescriptor()->bInterfaceProtocol != 208)
continue; continue;
if (interface->GetDescriptor()->bNumEndpoints < 2) if (interface->GetDescriptor()->bNumEndpoints < 2)
continue; continue;
*/
m_interface = interface.get();
if (!m_inPipePacket)
{
IUSBEndpoint *inEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_IN, 3);
if (inEndpoint)
{
rc = inEndpoint->Open();
if (S_FAILED(rc))
return 3333;
m_inPipePacket = inEndpoint;
}
}
if (!m_inPipe) if (!m_inPipe)
{ {
for (uint8_t i = 0; i != 15; ++i) IUSBEndpoint *inEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_IN, 4);
if (inEndpoint)
{ {
IUSBEndpoint *inEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_IN, i); rc = inEndpoint->Open();
if (inEndpoint) if (S_FAILED(rc))
{ return 4444;
rc = inEndpoint->Open();
if (S_FAILED(rc))
return 5555;
m_inPipe = inEndpoint; m_inPipe = inEndpoint;
break;
}
} }
} }
if (!m_outPipe) if (!m_outPipe)
{ {
for (uint8_t i = 0; i != 15; ++i) IUSBEndpoint *outEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_OUT, 3);
if (outEndpoint)
{ {
IUSBEndpoint *outEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_OUT, i); rc = outEndpoint->Open();
if (outEndpoint) if (S_FAILED(rc))
{ return 5555;
rc = outEndpoint->Open();
if (S_FAILED(rc))
return 6666;
m_outPipe = outEndpoint; m_outPipe = outEndpoint;
break;
}
} }
} }
} }
if (!m_inPipe || !m_outPipe) if (!m_inPipe || !m_outPipe || !m_inPipePacket)
return 69; return 69;
return rc; return rc;
} }
void XboxOneAdapter::CloseInterfaces() void XboxOneAdapter::CloseInterfaces()
{ {
//m_device->Reset(); //m_device->Reset();
@ -101,5 +107,42 @@ void XboxOneAdapter::CloseInterfaces()
Status XboxOneAdapter::SendInitBytes() Status XboxOneAdapter::SendInitBytes()
{ {
Status rc;
rc = ControlWrite(m_interface, 0x9018, 0, MT_VEND_WRITE_CFG);
if (S_FAILED(rc))
return rc;
rc = ControlWrite(m_interface, 0x0800, 0x01);
if (S_FAILED(rc))
return rc;
rc = ControlWrite(m_interface, 0x09a0, 0x400230);
if (S_FAILED(rc))
return rc;
rc = ControlWrite(m_interface, 0x09a4, 0x01);
if (S_FAILED(rc))
return rc;
rc = ControlWrite(m_interface, 0x09a8, 0x01);
if (S_FAILED(rc))
return rc;
rc = ControlWrite(m_interface, 0x09c4, 0x44);
if (S_FAILED(rc))
return rc;
rc = ControlWrite(m_interface, 0x0a6c, 0x03);
if (S_FAILED(rc))
return rc;
return 0; return 0;
}
Status XboxOneAdapter::ControlWrite(IUSBInterface *interface, uint16_t address, uint32_t value, VendorRequest request)
{
Status rc;
if (request == MT_VEND_DEV_MODE)
{
rc = interface->ControlTransfer(0x42, request, address, 0, 0, nullptr);
}
else
{
rc = interface->ControlTransfer(0x42, request, address, 0, sizeof(uint32_t), &value);
}
return rc;
} }

View File

@ -0,0 +1 @@
#include "Controllers/XboxOneAdapter/Firmware.h"

View File

@ -39,7 +39,7 @@ include $(DEVKITPRO)/libnx/switch_rules
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
TARGET := sys-con TARGET := sys-con
BUILD := buildSysmodule BUILD := buildSysmodule
SOURCES := source SwitchUSB/source ControllerUSB/source ControllerUSB/source/Controllers inih SOURCES := source SwitchUSB/source ControllerUSB/source ControllerUSB/source/Controllers ControllerUSB/source/Controllers/XboxOneAdapter inih
DATA := data DATA := data
INCLUDES := include SwitchUSB/include ControllerUSB/include inih INCLUDES := include SwitchUSB/include ControllerUSB/include inih
#ROMFS := romfs #ROMFS := romfs