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

Remove Xbox One Adapter

This commit is contained in:
cathery 2020-01-12 05:16:55 +03:00
parent 48cacf557a
commit 49fc7a8738
12 changed files with 2 additions and 357 deletions

View File

@ -38,7 +38,6 @@ sys-con comes with a config folder located at `sdmc:/config/sys-con/`. It contai
- [x] **~~Undocked USB Support~~** Works with a USB-C OTG adapter. Some knock-off brands may not support OTG.
- [x] **~~Xbox 360 Wireless adapter~~**
- [x] **~~Dualshock 4 Support~~**
- [ ] **[Xbox One Wireless adapter](https://github.com/cathery/sys-con/issues/36)**
- [ ] **[Rumble Support](https://github.com/cathery/sys-con/issues/1)**
- [ ] **[Bluetooth Support](https://github.com/cathery/sys-con/issues/5)**
- [ ] **[Motion Controls Support](https://github.com/cathery/sys-con/issues/9)**

View File

@ -1,2 +0,0 @@
; Doesn't work properly yet, disabled
firmware_path = /config/sys-con/firmware/XboxOneAdapter.bin

View File

@ -20,15 +20,6 @@ enum VendorIDs : uint16_t
enum ProductIDs : uint16_t
{
PRODUCT_XBOX360 = 0x28e,
/*
PRODUCT_XBOX360_WIRELESS = 0x28F,
PRODUCT_XBOX360_WIRELESS_MODULE = 0x765,
PRODUCT_XBOX360_WIRELESS_ADAPTER = 0x719,
PRODUCT_XBOX360_WIRELESS_N_ADAPTER = 0x2A8,
PRODUCT_XBOX360_WIRELESS_NETWORK_ADAPTER = 0x292,
PRODUCT_XBOX360_WIRELESS_RECEIVER = 0x2A1,
PRODUCT_XBOX360_WIRELESS_RECEIVER_2 = 0x291,
*/
PRODUCT_XBOXONE2013 = 0x2d1,
PRODUCT_XBOXONE2015 = 0x2dd,
PRODUCT_XBOXONEELITE = 0x2e3,

View File

@ -4,6 +4,5 @@
#include "Controllers/Xbox360WirelessController.h"
#include "Controllers/XboxController.h"
#include "Controllers/XboxOneController.h"
#include "Controllers/XboxOneAdapter.h"
#include "Controllers/Dualshock3Controller.h"
#include "Controllers/Dualshock4Controller.h"

View File

@ -1,227 +0,0 @@
#include "Controllers/XboxOneAdapter.h"
#include "Controllers/XboxOneAdapter/Firmware.h"
#include <cmath>
#include "../../Sysmodule/source/log.h"
#include <fstream>
#include "cstring"
static ControllerConfig _xboxoneadapterConfig{};
static char firmwarePath[100];
XboxOneAdapter::XboxOneAdapter(std::unique_ptr<IUSBDevice> &&interface)
: IController(std::move(interface))
{
}
XboxOneAdapter::~XboxOneAdapter()
{
Exit();
}
Result XboxOneAdapter::Initialize()
{
Result rc;
rc = OpenInterfaces();
if (R_FAILED(rc))
return rc;
rc = SendInitBytes();
if (R_FAILED(rc))
return rc;
return rc;
}
void XboxOneAdapter::Exit()
{
CloseInterfaces();
}
Result XboxOneAdapter::OpenInterfaces()
{
Result rc;
rc = m_device->Open();
if (R_FAILED(rc))
return rc;
std::vector<std::unique_ptr<IUSBInterface>> &interfaces = m_device->GetInterfaces();
for (auto &&interface : interfaces)
{
rc = interface->Open();
if (R_FAILED(rc))
return rc;
if (interface->GetDescriptor()->bInterfaceProtocol != 255)
continue;
if (interface->GetDescriptor()->bNumEndpoints < 2)
continue;
m_interface = interface.get();
if (!m_inPipePacket)
{
IUSBEndpoint *inEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_IN, 3);
if (inEndpoint)
{
rc = inEndpoint->Open();
if (R_FAILED(rc))
return 3333;
m_inPipePacket = inEndpoint;
}
}
if (!m_inPipe)
{
IUSBEndpoint *inEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_IN, 4);
if (inEndpoint)
{
rc = inEndpoint->Open();
if (R_FAILED(rc))
return 4444;
m_inPipe = inEndpoint;
}
}
if (!m_outPipe)
{
IUSBEndpoint *outEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_OUT, 3);
if (outEndpoint)
{
rc = outEndpoint->Open();
if (R_FAILED(rc))
return 5555;
m_outPipe = outEndpoint;
}
}
}
if (!m_inPipe || !m_outPipe || !m_inPipePacket)
return 69;
return rc;
}
void XboxOneAdapter::CloseInterfaces()
{
//m_device->Reset();
m_device->Close();
}
Result XboxOneAdapter::SendInitBytes()
{
Result rc;
DmaConfig config = {};
config.rxBulkEnabled = 1;
config.txBulkEnabled = 1;
ControlWrite(m_interface, MT_USB_U3DMA_CFG, config.value, MT_VEND_WRITE_CFG);
ControlWrite(m_interface, MT_FCE_PSE_CTRL, 0x01);
ControlWrite(m_interface, MT_TX_CPU_FROM_FCE_BASE_PTR, 0x400230);
ControlWrite(m_interface, MT_TX_CPU_FROM_FCE_MAX_COUNT, 0x01);
ControlWrite(m_interface, MT_TX_CPU_FROM_FCE_CPU_DESC_IDX, 0x01);
ControlWrite(m_interface, MT_FCE_PDMA_GLOBAL_CONF, 0x44);
ControlWrite(m_interface, MT_FCE_SKIP_FS, 0x03);
WriteToLog("firmware path: %s", firmwarePath);
if (!firmwarePath || *firmwarePath == '\0')
{
WriteToLog("But the string is empty!");
return 256;
}
std::ifstream fs(firmwarePath, std::ios::binary);
if (fs.fail())
return 235;
WriteToLog("Opening file...");
std::vector<uint8_t> firmware(std::istreambuf_iterator<char>(fs), {});
WriteToLog("File opened!");
fs.close();
WriteToLog("writing %lu bytes...", firmware.size());
FwHeader *header = reinterpret_cast<FwHeader *>(firmware.data());
uint8_t *ilmStart = reinterpret_cast<uint8_t *>(header) + sizeof(FwHeader);
uint8_t *dlmStart = ilmStart + header->ilmLength;
uint8_t *dlmEnd = dlmStart + header->dlmLength;
WriteToLog("Writing 1st part");
rc = LoadFirmwarePart(MT_MCU_ILM_OFFSET, ilmStart, dlmStart);
if (R_FAILED(rc))
return rc;
WriteToLog("Writing 2nd part");
rc = LoadFirmwarePart(MT_MCU_DLM_OFFSET, dlmStart, dlmEnd);
if (R_FAILED(rc))
return rc;
WriteToLog("Wrote");
return 0;
}
Result XboxOneAdapter::LoadFirmwarePart(uint32_t offset, uint8_t *start, uint8_t *end)
{
// Send firmware in chunks
Result rc = -1;
for (uint8_t *chunk = start; chunk < end; chunk += MT_FW_CHUNK_SIZE)
{
uint32_t address = (uint32_t)(offset + chunk - start);
uint32_t remaining = (uint32_t)(end - chunk);
uint16_t length = remaining > MT_FW_CHUNK_SIZE ? MT_FW_CHUNK_SIZE : remaining;
rc = ControlWrite(m_interface, MT_FCE_DMA_ADDR, address, MT_VEND_WRITE_CFG);
if (R_FAILED(rc))
return rc;
rc = ControlWrite(m_interface, MT_FCE_DMA_LEN, length << 16, MT_VEND_WRITE_CFG);
if (R_FAILED(rc))
return rc;
uint8_t data[length + 8]{0x00, 0x38, 0x00, 0x10};
for (int i = 0; i != length; ++i)
{
data[i + 4] = chunk[i];
}
rc = m_outPipe->Write(data, sizeof(data));
if (R_FAILED(rc))
return rc;
}
return rc;
}
Result XboxOneAdapter::ControlWrite(IUSBInterface *interface, uint16_t address, uint32_t value, VendorRequest request)
{
Result rc;
if (request == MT_VEND_DEV_MODE)
{
rc = interface->ControlTransfer(0x40, request, address, 0, 0, static_cast<const void *>(nullptr));
}
else
{
rc = interface->ControlTransfer(0x40, request, address, 0, sizeof(uint32_t), &value);
}
return rc;
}
void XboxOneAdapter::LoadConfig(const ControllerConfig *config, const char *path)
{
_xboxoneadapterConfig = *config;
strcpy(firmwarePath, path);
}
ControllerConfig *XboxOneAdapter::GetConfig()
{
return &_xboxoneadapterConfig;
}

View File

@ -1,48 +0,0 @@
#pragma once
#include "IController.h"
#include "Controllers/XboxOneController.h"
//References used:
//https://github.com/quantus/xbox-one-controller-protocol
//https://cs.chromium.org/chromium/src/device/gamepad/xbox_controller_mac.mm
enum VendorRequest : uint8_t
{
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
{
private:
IUSBEndpoint *m_inPipePacket = nullptr;
IUSBEndpoint *m_inPipe = nullptr;
IUSBEndpoint *m_outPipe = nullptr;
IUSBInterface *m_interface = nullptr;
public:
XboxOneAdapter(std::unique_ptr<IUSBDevice> &&interface);
virtual ~XboxOneAdapter() override;
virtual Result Initialize() override;
virtual void Exit() override;
Result OpenInterfaces();
void CloseInterfaces();
virtual ControllerType GetType() override { return CONTROLLER_XBOXONEW; }
Result LoadFirmwarePart(uint32_t offset, uint8_t *start, uint8_t *end);
Result SendInitBytes();
Result ControlWrite(IUSBInterface *interface, uint16_t address, uint32_t value, VendorRequest request = MT_VEND_MULTI_WRITE);
static void LoadConfig(const ControllerConfig *config, const char *path);
virtual ControllerConfig *GetConfig() override;
};

View File

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

View File

@ -1,51 +0,0 @@
#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
#define MT_FCE_DMA_ADDR 0x0230
#define MT_FCE_DMA_LEN 0x0234
#define MT_USB_DMA_CFG 0x0238
#define MT_USB_U3DMA_CFG 0x9018
#define MT_FCE_PSE_CTRL 0x0800
#define MT_TX_CPU_FROM_FCE_BASE_PTR 0x09a0
#define MT_TX_CPU_FROM_FCE_MAX_COUNT 0x09a4
#define MT_TX_CPU_FROM_FCE_CPU_DESC_IDX 0x09a8
#define MT_FCE_PDMA_GLOBAL_CONF 0x09c4
#define MT_FCE_SKIP_FS 0x0a6c
struct FwHeader
{
uint32_t ilmLength;
uint32_t dlmLength;
uint16_t buildVersion;
uint16_t firmwareVersion;
uint32_t padding;
char buildTime[16];
} __attribute__((packed));
union DmaConfig {
struct
{
uint32_t rxBulkAggTimeout : 8;
uint32_t rxBulkAggLimit : 8;
uint32_t udmaTxWlDrop : 1;
uint32_t wakeupEnabled : 1;
uint32_t rxDropOrPad : 1;
uint32_t txClear : 1;
uint32_t txopHalt : 1;
uint32_t rxBulkAggEnabled : 1;
uint32_t rxBulkEnabled : 1;
uint32_t txBulkEnabled : 1;
uint32_t epOutValid : 6;
uint32_t rxBusy : 1;
uint32_t txBusy : 1;
} __attribute__((packed));
uint32_t value;
};

View File

@ -1,6 +1,6 @@
#include "Controllers/XboxOneController.h"
#include <cmath>
#include "../../Sysmodule/source/log.h"
//#include "../../Sysmodule/source/log.h"
static ControllerConfig _xboxoneControllerConfig{};
@ -202,8 +202,6 @@ Result XboxOneController::SendInitBytes()
rc = m_outPipe->Write(init_packets[i].Packet, init_packets[i].Length);
if (R_FAILED(rc))
break;
else
WriteToLog("Sent a specific init packet %i for controller v%u p%u", i, vendor, product);
}
return rc;
}

View File

@ -38,7 +38,7 @@ include $(DEVKITPRO)/libnx/switch_rules
# NACP building is skipped as well.
#---------------------------------------------------------------------------------
TARGET := sys-con
SOURCES := source ../ControllerSwitch ../ControllerLib ../ControllerLib/Controllers ../ControllerLib/Controllers/XboxOneAdapter ../inih
SOURCES := source ../ControllerSwitch ../ControllerLib ../ControllerLib/Controllers ../inih
DATA := data
INCLUDES := include ../ControllerSwitch ../ControllerLib ../inih
#ROMFS := romfs

View File

@ -14,7 +14,6 @@
#define XBOXCONFIG "config_xboxorig.ini"
#define XBOX360CONFIG "config_xbox360.ini"
#define XBOXONECONFIG "config_xboxone.ini"
#define XBOXONEADAPTERCONFIG "config_xboxoneadapter.ini"
#define DUALSHOCK3CONFIG "config_dualshock3.ini"
#define DUALSHOCK4CONFIG "config_dualshock4.ini"
@ -195,11 +194,6 @@ void LoadAllConfigs()
else
WriteToLog("Failed to read from xbox one config!");
if (R_SUCCEEDED(_ReadFromConfig(CONFIG_PATH XBOXONEADAPTERCONFIG)))
XboxOneAdapter::LoadConfig(&temp_config, firmwarePath);
else
WriteToLog("Failed to read from xbox one adapter config!");
if (R_SUCCEEDED(_ReadFromConfig(CONFIG_PATH XBOX360CONFIG)))
{
Xbox360Controller::LoadConfig(&temp_config);
@ -227,7 +221,6 @@ bool CheckForFileChanges()
static time_t xboxConfigLastModified;
static time_t xbox360ConfigLastModified;
static time_t xboxOneConfigLastModified;
static time_t xboxOneAdapterConfigLastModified;
static time_t dualshock3ConfigLastModified;
static time_t dualshock4ConfigLastModified;
struct stat result;
@ -273,11 +266,5 @@ bool CheckForFileChanges()
dualshock4ConfigLastModified = result.st_mtime;
filesChanged = true;
}
if (stat(CONFIG_PATH XBOXONEADAPTERCONFIG, &result) == 0)
if (xboxOneAdapterConfigLastModified != result.st_mtime)
{
xboxOneAdapterConfigLastModified = result.st_mtime;
filesChanged = true;
}
return filesChanged;
}