Compare commits
1 Commits
hidbus
...
ring_proto
Author | SHA1 | Date | |
---|---|---|---|
0495a13e31 |
@ -14,22 +14,11 @@ constexpr Result VibrationInvalidStyleIndex{ErrorModule::HID, 122};
|
|||||||
constexpr Result VibrationInvalidNpadId{ErrorModule::HID, 123};
|
constexpr Result VibrationInvalidNpadId{ErrorModule::HID, 123};
|
||||||
constexpr Result VibrationDeviceIndexOutOfRange{ErrorModule::HID, 124};
|
constexpr Result VibrationDeviceIndexOutOfRange{ErrorModule::HID, 124};
|
||||||
constexpr Result InvalidSixAxisFusionRange{ErrorModule::HID, 423};
|
constexpr Result InvalidSixAxisFusionRange{ErrorModule::HID, 423};
|
||||||
|
|
||||||
constexpr Result ResultMcuInvalidHandle{ErrorModule::HID, 541};
|
|
||||||
constexpr Result ResultMcuNotEnabled{ErrorModule::HID, 542};
|
|
||||||
constexpr Result ResultMcuNoDeviceConnected{ErrorModule::HID, 543};
|
|
||||||
constexpr Result ResultMcuUnknown544{ErrorModule::HID, 544};
|
|
||||||
constexpr Result ResultMcuUnknown546{ErrorModule::HID, 546};
|
|
||||||
constexpr Result ResultMcuUnknown548{ErrorModule::HID, 548};
|
|
||||||
|
|
||||||
constexpr Result NpadIsDualJoycon{ErrorModule::HID, 601};
|
constexpr Result NpadIsDualJoycon{ErrorModule::HID, 601};
|
||||||
constexpr Result NpadIsSameType{ErrorModule::HID, 602};
|
constexpr Result NpadIsSameType{ErrorModule::HID, 602};
|
||||||
constexpr Result InvalidNpadId{ErrorModule::HID, 709};
|
constexpr Result InvalidNpadId{ErrorModule::HID, 709};
|
||||||
constexpr Result NpadNotConnected{ErrorModule::HID, 710};
|
constexpr Result NpadNotConnected{ErrorModule::HID, 710};
|
||||||
constexpr Result InvalidArraySize{ErrorModule::HID, 715};
|
constexpr Result InvalidArraySize{ErrorModule::HID, 715};
|
||||||
|
|
||||||
constexpr Result ResultControllerUpdateFailed{ErrorModule::HID, 3201};
|
|
||||||
|
|
||||||
constexpr Result InvalidPalmaHandle{ErrorModule::HID, 3302};
|
constexpr Result InvalidPalmaHandle{ErrorModule::HID, 3302};
|
||||||
|
|
||||||
} // namespace Service::HID
|
} // namespace Service::HID
|
||||||
@ -40,17 +29,3 @@ constexpr Result InvalidProcessorState{ErrorModule::Irsensor, 78};
|
|||||||
constexpr Result InvalidIrCameraHandle{ErrorModule::Irsensor, 204};
|
constexpr Result InvalidIrCameraHandle{ErrorModule::Irsensor, 204};
|
||||||
|
|
||||||
} // namespace Service::IRS
|
} // namespace Service::IRS
|
||||||
|
|
||||||
namespace Service::HIDBUS {
|
|
||||||
|
|
||||||
constexpr Result ResultNotEnabled{ErrorModule::HIDBUS, 1};
|
|
||||||
constexpr Result ResultControllerUpdateFailed{ErrorModule::HIDBUS, 3};
|
|
||||||
constexpr Result ResultInvalidBusHandle{ErrorModule::HIDBUS, 4};
|
|
||||||
constexpr Result ResultNoDeviceConnected{ErrorModule::HIDBUS, 5};
|
|
||||||
constexpr Result ResultUknown6{ErrorModule::HIDBUS, 6};
|
|
||||||
constexpr Result ResultPollingRecieveDataNotAvailable{ErrorModule::HIDBUS, 7};
|
|
||||||
constexpr Result ResultDeviceEnabledNotSet{ErrorModule::HIDBUS, 8};
|
|
||||||
constexpr Result ResultBusHandleAlreadyInitialized{ErrorModule::HIDBUS, 10};
|
|
||||||
constexpr Result ResultInvalidBusType{ErrorModule::HIDBUS, 11};
|
|
||||||
|
|
||||||
} // namespace Service::HID
|
|
@ -12,8 +12,6 @@
|
|||||||
#include "core/hle/kernel/k_shared_memory.h"
|
#include "core/hle/kernel/k_shared_memory.h"
|
||||||
#include "core/hle/kernel/k_transfer_memory.h"
|
#include "core/hle/kernel/k_transfer_memory.h"
|
||||||
#include "core/hle/service/hid/hidbus.h"
|
#include "core/hle/service/hid/hidbus.h"
|
||||||
#include "core/hle/service/hid/errors.h"
|
|
||||||
#include "core/hle/service/hid/controllers/npad.h"
|
|
||||||
#include "core/hle/service/hid/hidbus/ringcon.h"
|
#include "core/hle/service/hid/hidbus/ringcon.h"
|
||||||
#include "core/hle/service/hid/hidbus/starlink.h"
|
#include "core/hle/service/hid/hidbus/starlink.h"
|
||||||
#include "core/hle/service/hid/hidbus/stubbed.h"
|
#include "core/hle/service/hid/hidbus/stubbed.h"
|
||||||
@ -49,9 +47,56 @@ HidBus::HidBus(Core::System& system_)
|
|||||||
|
|
||||||
RegisterHandlers(functions);
|
RegisterHandlers(functions);
|
||||||
|
|
||||||
|
// Register update callbacks
|
||||||
|
hidbus_update_event = Core::Timing::CreateEvent(
|
||||||
|
"Hidbus::UpdateCallback",
|
||||||
|
[this](std::uintptr_t user_data, s64 time,
|
||||||
|
std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
|
||||||
|
const auto guard = LockService();
|
||||||
|
UpdateHidbus(user_data, ns_late);
|
||||||
|
return std::nullopt;
|
||||||
|
});
|
||||||
|
|
||||||
|
system_.CoreTiming().ScheduleLoopingEvent(hidbus_update_ns, hidbus_update_ns,
|
||||||
|
hidbus_update_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
HidBus::~HidBus() {
|
HidBus::~HidBus() {
|
||||||
|
system.CoreTiming().UnscheduleEvent(hidbus_update_event, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HidBus::UpdateHidbus(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) {
|
||||||
|
if (is_hidbus_enabled) {
|
||||||
|
for (std::size_t i = 0; i < devices.size(); ++i) {
|
||||||
|
if (!devices[i].is_device_initializated) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto& device = devices[i].device;
|
||||||
|
device->OnUpdate();
|
||||||
|
auto& cur_entry = hidbus_status.entries[devices[i].handle.internal_index];
|
||||||
|
cur_entry.is_polling_mode = device->IsPollingMode();
|
||||||
|
cur_entry.polling_mode = device->GetPollingMode();
|
||||||
|
cur_entry.is_enabled = device->IsEnabled();
|
||||||
|
|
||||||
|
u8* shared_memory = system.Kernel().GetHidBusSharedMem().GetPointer();
|
||||||
|
std::memcpy(shared_memory + (i * sizeof(HidbusStatusManagerEntry)), &hidbus_status,
|
||||||
|
sizeof(HidbusStatusManagerEntry));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::size_t> HidBus::GetDeviceIndexFromHandle(BusHandle handle) const {
|
||||||
|
for (std::size_t i = 0; i < devices.size(); ++i) {
|
||||||
|
const auto& device_handle = devices[i].handle;
|
||||||
|
if (handle.abstracted_pad_id == device_handle.abstracted_pad_id &&
|
||||||
|
handle.internal_index == device_handle.internal_index &&
|
||||||
|
handle.player_number == device_handle.player_number &&
|
||||||
|
handle.bus_type_id == device_handle.bus_type_id &&
|
||||||
|
handle.is_valid == device_handle.is_valid) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HidBus::GetBusHandle(HLERequestContext& ctx) {
|
void HidBus::GetBusHandle(HLERequestContext& ctx) {
|
||||||
@ -69,9 +114,38 @@ void HidBus::GetBusHandle(HLERequestContext& ctx) {
|
|||||||
LOG_INFO(Service_HID, "called, npad_id={}, bus_type={}, applet_resource_user_id={}",
|
LOG_INFO(Service_HID, "called, npad_id={}, bus_type={}, applet_resource_user_id={}",
|
||||||
parameters.npad_id, parameters.bus_type, parameters.applet_resource_user_id);
|
parameters.npad_id, parameters.bus_type, parameters.applet_resource_user_id);
|
||||||
|
|
||||||
if (parameters.bus_type >= BusType::MaxBusType) {
|
bool is_handle_found = 0;
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
std::size_t handle_index = 0;
|
||||||
rb.Push(HIDBUS::ResultInvalidBusType);
|
|
||||||
|
for (std::size_t i = 0; i < devices.size(); i++) {
|
||||||
|
const auto& handle = devices[i].handle;
|
||||||
|
if (!handle.is_valid) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (static_cast<Core::HID::NpadIdType>(handle.player_number) == parameters.npad_id &&
|
||||||
|
handle.bus_type_id == static_cast<u8>(parameters.bus_type)) {
|
||||||
|
is_handle_found = true;
|
||||||
|
handle_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle not found. Create a new one
|
||||||
|
if (!is_handle_found) {
|
||||||
|
for (std::size_t i = 0; i < devices.size(); i++) {
|
||||||
|
if (devices[i].handle.is_valid) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
devices[i].handle = {
|
||||||
|
.abstracted_pad_id = static_cast<u8>(i),
|
||||||
|
.internal_index = static_cast<u8>(i),
|
||||||
|
.player_number = static_cast<u8>(parameters.npad_id),
|
||||||
|
.bus_type_id = static_cast<u8>(parameters.bus_type),
|
||||||
|
.is_valid = true,
|
||||||
|
};
|
||||||
|
handle_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct OutData {
|
struct OutData {
|
||||||
@ -81,8 +155,10 @@ void HidBus::GetBusHandle(HLERequestContext& ctx) {
|
|||||||
};
|
};
|
||||||
static_assert(sizeof(OutData) == 0x10, "OutData has incorrect size.");
|
static_assert(sizeof(OutData) == 0x10, "OutData has incorrect size.");
|
||||||
|
|
||||||
OutData out_data{};
|
const OutData out_data{
|
||||||
out_data.is_valid = GetBusHandleImpl(out_data.handle, parameters.npad_id, parameters.bus_type);
|
.is_valid = true,
|
||||||
|
.handle = devices[handle_index].handle,
|
||||||
|
};
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 6};
|
IPC::ResponseBuilder rb{ctx, 6};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(ResultSuccess);
|
||||||
@ -99,10 +175,21 @@ void HidBus::IsExternalDeviceConnected(HLERequestContext& ctx) {
|
|||||||
bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index,
|
bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index,
|
||||||
bus_handle_.player_number, bus_handle_.is_valid);
|
bus_handle_.player_number, bus_handle_.is_valid);
|
||||||
|
|
||||||
auto result = TranslateHidErrorToHidBusError(ResultSuccess);
|
const auto device_index = GetDeviceIndexFromHandle(bus_handle_);
|
||||||
|
|
||||||
|
if (device_index) {
|
||||||
|
const auto& device = devices[device_index.value()].device;
|
||||||
|
const bool is_attached = device->IsDeviceActivated();
|
||||||
|
|
||||||
|
IPC::ResponseBuilder rb{ctx, 3};
|
||||||
|
rb.Push(ResultSuccess);
|
||||||
|
rb.Push(is_attached);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_ERROR(Service_HID, "Invalid handle");
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(result);
|
rb.Push(ResultUnknown);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,6 +204,40 @@ void HidBus::Initialize(HLERequestContext& ctx) {
|
|||||||
bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index,
|
bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index,
|
||||||
bus_handle_.player_number, bus_handle_.is_valid, applet_resource_user_id);
|
bus_handle_.player_number, bus_handle_.is_valid, applet_resource_user_id);
|
||||||
|
|
||||||
|
is_hidbus_enabled = true;
|
||||||
|
|
||||||
|
const auto device_index = GetDeviceIndexFromHandle(bus_handle_);
|
||||||
|
|
||||||
|
if (device_index) {
|
||||||
|
const auto entry_index = devices[device_index.value()].handle.internal_index;
|
||||||
|
auto& cur_entry = hidbus_status.entries[entry_index];
|
||||||
|
|
||||||
|
if (bus_handle_.internal_index == 0 && Settings::values.enable_ring_controller) {
|
||||||
|
MakeDevice<RingController>(bus_handle_);
|
||||||
|
devices[device_index.value()].is_device_initializated = true;
|
||||||
|
devices[device_index.value()].device->ActivateDevice();
|
||||||
|
cur_entry.is_in_focus = true;
|
||||||
|
cur_entry.is_connected = true;
|
||||||
|
cur_entry.is_connected_result = ResultSuccess;
|
||||||
|
cur_entry.is_enabled = false;
|
||||||
|
cur_entry.is_polling_mode = false;
|
||||||
|
} else {
|
||||||
|
MakeDevice<HidbusStubbed>(bus_handle_);
|
||||||
|
devices[device_index.value()].is_device_initializated = true;
|
||||||
|
cur_entry.is_in_focus = true;
|
||||||
|
cur_entry.is_connected = false;
|
||||||
|
cur_entry.is_connected_result = ResultSuccess;
|
||||||
|
cur_entry.is_enabled = false;
|
||||||
|
cur_entry.is_polling_mode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::memcpy(system.Kernel().GetHidBusSharedMem().GetPointer(), &hidbus_status,
|
||||||
|
sizeof(hidbus_status));
|
||||||
|
|
||||||
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
rb.Push(ResultSuccess);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LOG_ERROR(Service_HID, "Invalid handle");
|
LOG_ERROR(Service_HID, "Invalid handle");
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
@ -135,6 +256,27 @@ void HidBus::Finalize(HLERequestContext& ctx) {
|
|||||||
bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index,
|
bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index,
|
||||||
bus_handle_.player_number, bus_handle_.is_valid, applet_resource_user_id);
|
bus_handle_.player_number, bus_handle_.is_valid, applet_resource_user_id);
|
||||||
|
|
||||||
|
const auto device_index = GetDeviceIndexFromHandle(bus_handle_);
|
||||||
|
|
||||||
|
if (device_index) {
|
||||||
|
const auto entry_index = devices[device_index.value()].handle.internal_index;
|
||||||
|
auto& cur_entry = hidbus_status.entries[entry_index];
|
||||||
|
auto& device = devices[device_index.value()].device;
|
||||||
|
devices[device_index.value()].is_device_initializated = false;
|
||||||
|
device->DeactivateDevice();
|
||||||
|
|
||||||
|
cur_entry.is_in_focus = true;
|
||||||
|
cur_entry.is_connected = false;
|
||||||
|
cur_entry.is_connected_result = ResultSuccess;
|
||||||
|
cur_entry.is_enabled = false;
|
||||||
|
cur_entry.is_polling_mode = false;
|
||||||
|
std::memcpy(system.Kernel().GetHidBusSharedMem().GetPointer(), &hidbus_status,
|
||||||
|
sizeof(hidbus_status));
|
||||||
|
|
||||||
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
rb.Push(ResultSuccess);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LOG_ERROR(Service_HID, "Invalid handle");
|
LOG_ERROR(Service_HID, "Invalid handle");
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
@ -163,6 +305,16 @@ void HidBus::EnableExternalDevice(HLERequestContext& ctx) {
|
|||||||
parameters.bus_handle.player_number, parameters.bus_handle.is_valid, parameters.inval,
|
parameters.bus_handle.player_number, parameters.bus_handle.is_valid, parameters.inval,
|
||||||
parameters.applet_resource_user_id);
|
parameters.applet_resource_user_id);
|
||||||
|
|
||||||
|
const auto device_index = GetDeviceIndexFromHandle(parameters.bus_handle);
|
||||||
|
|
||||||
|
if (device_index) {
|
||||||
|
auto& device = devices[device_index.value()].device;
|
||||||
|
device->Enable(parameters.enable);
|
||||||
|
|
||||||
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
rb.Push(ResultSuccess);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LOG_ERROR(Service_HID, "Invalid handle");
|
LOG_ERROR(Service_HID, "Invalid handle");
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
@ -180,29 +332,21 @@ void HidBus::GetExternalDeviceId(HLERequestContext& ctx) {
|
|||||||
bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index,
|
bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index,
|
||||||
bus_handle_.player_number, bus_handle_.is_valid);
|
bus_handle_.player_number, bus_handle_.is_valid);
|
||||||
|
|
||||||
u32 device_id{};
|
const auto device_index = GetDeviceIndexFromHandle(bus_handle_);
|
||||||
auto result = SetEventForSendCommandAsycResult2();
|
|
||||||
if (result.IsSuccess()) {
|
|
||||||
if (1) {
|
|
||||||
result = HIDBUS::ResultInvalidBusHandle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.IsSuccess()) {
|
if (device_index) {
|
||||||
// result = GetExternalDeviceIdImpl();
|
const auto& device = devices[device_index.value()].device;
|
||||||
}
|
u32 device_id = device->GetDeviceId();
|
||||||
|
|
||||||
if (result.IsSuccess()) {
|
|
||||||
IPC::ResponseBuilder rb{ctx, 3};
|
IPC::ResponseBuilder rb{ctx, 3};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(ResultSuccess);
|
||||||
rb.Push<u32>(device_id);
|
rb.Push<u32>(device_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = TranslateHidErrorToHidBusError(result);
|
LOG_ERROR(Service_HID, "Invalid handle");
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(result);
|
rb.Push(ResultUnknown);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HidBus::SendCommandAsync(HLERequestContext& ctx) {
|
void HidBus::SendCommandAsync(HLERequestContext& ctx) {
|
||||||
@ -216,6 +360,16 @@ void HidBus::SendCommandAsync(HLERequestContext& ctx) {
|
|||||||
data.size(), bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id,
|
data.size(), bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id,
|
||||||
bus_handle_.internal_index, bus_handle_.player_number, bus_handle_.is_valid);
|
bus_handle_.internal_index, bus_handle_.player_number, bus_handle_.is_valid);
|
||||||
|
|
||||||
|
const auto device_index = GetDeviceIndexFromHandle(bus_handle_);
|
||||||
|
|
||||||
|
if (device_index) {
|
||||||
|
auto& device = devices[device_index.value()].device;
|
||||||
|
device->SetCommand(data);
|
||||||
|
|
||||||
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
rb.Push(ResultSuccess);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LOG_ERROR(Service_HID, "Invalid handle");
|
LOG_ERROR(Service_HID, "Invalid handle");
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
@ -233,6 +387,18 @@ void HidBus::GetSendCommandAsynceResult(HLERequestContext& ctx) {
|
|||||||
bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index,
|
bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index,
|
||||||
bus_handle_.player_number, bus_handle_.is_valid);
|
bus_handle_.player_number, bus_handle_.is_valid);
|
||||||
|
|
||||||
|
const auto device_index = GetDeviceIndexFromHandle(bus_handle_);
|
||||||
|
|
||||||
|
if (device_index) {
|
||||||
|
const auto& device = devices[device_index.value()].device;
|
||||||
|
const std::vector<u8> data = device->GetReply();
|
||||||
|
const u64 data_size = ctx.WriteBuffer(data);
|
||||||
|
|
||||||
|
IPC::ResponseBuilder rb{ctx, 4};
|
||||||
|
rb.Push(ResultSuccess);
|
||||||
|
rb.Push<u64>(data_size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LOG_ERROR(Service_HID, "Invalid handle");
|
LOG_ERROR(Service_HID, "Invalid handle");
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
@ -250,6 +416,16 @@ void HidBus::SetEventForSendCommandAsycResult(HLERequestContext& ctx) {
|
|||||||
bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index,
|
bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index,
|
||||||
bus_handle_.player_number, bus_handle_.is_valid);
|
bus_handle_.player_number, bus_handle_.is_valid);
|
||||||
|
|
||||||
|
const auto device_index = GetDeviceIndexFromHandle(bus_handle_);
|
||||||
|
|
||||||
|
if (device_index) {
|
||||||
|
const auto& device = devices[device_index.value()].device;
|
||||||
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
||||||
|
rb.Push(ResultSuccess);
|
||||||
|
rb.PushCopyObjects(device->GetSendCommandAsycEvent());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LOG_ERROR(Service_HID, "Invalid handle");
|
LOG_ERROR(Service_HID, "Invalid handle");
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(ResultUnknown);
|
rb.Push(ResultUnknown);
|
||||||
@ -291,6 +467,17 @@ void HidBus::EnableJoyPollingReceiveMode(HLERequestContext& ctx) {
|
|||||||
t_mem_handle, polling_mode_, bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id,
|
t_mem_handle, polling_mode_, bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id,
|
||||||
bus_handle_.internal_index, bus_handle_.player_number, bus_handle_.is_valid);
|
bus_handle_.internal_index, bus_handle_.player_number, bus_handle_.is_valid);
|
||||||
|
|
||||||
|
const auto device_index = GetDeviceIndexFromHandle(bus_handle_);
|
||||||
|
|
||||||
|
if (device_index) {
|
||||||
|
auto& device = devices[device_index.value()].device;
|
||||||
|
device->SetPollingMode(polling_mode_);
|
||||||
|
device->SetTransferMemoryAddress(t_mem->GetSourceAddress());
|
||||||
|
|
||||||
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
rb.Push(ResultSuccess);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LOG_ERROR(Service_HID, "Invalid handle");
|
LOG_ERROR(Service_HID, "Invalid handle");
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
@ -308,6 +495,16 @@ void HidBus::DisableJoyPollingReceiveMode(HLERequestContext& ctx) {
|
|||||||
bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index,
|
bus_handle_.abstracted_pad_id, bus_handle_.bus_type_id, bus_handle_.internal_index,
|
||||||
bus_handle_.player_number, bus_handle_.is_valid);
|
bus_handle_.player_number, bus_handle_.is_valid);
|
||||||
|
|
||||||
|
const auto device_index = GetDeviceIndexFromHandle(bus_handle_);
|
||||||
|
|
||||||
|
if (device_index) {
|
||||||
|
auto& device = devices[device_index.value()].device;
|
||||||
|
device->DisablePollingMode();
|
||||||
|
|
||||||
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
rb.Push(ResultSuccess);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LOG_ERROR(Service_HID, "Invalid handle");
|
LOG_ERROR(Service_HID, "Invalid handle");
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
@ -324,59 +521,4 @@ void HidBus::SetStatusManagerType(HLERequestContext& ctx) {
|
|||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(ResultSuccess);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
bool HidBus::GetBusHandleImpl(BusHandle& handle, Core::HID::NpadIdType npad_id, BusType bus_type) {
|
|
||||||
ASSERT_MSG(&handle != nullptr, "Handle is null");
|
|
||||||
|
|
||||||
if (!Controller_NPad::IsNpadIdValid(npad_id)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bus_type == BusType::LeftJoyRail || bus_type == BusType::RightJoyRail) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bus_type == BusType::InternalBus) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Result TranslateHidErrorToHidBusError(Result result) {
|
|
||||||
if (result.IsSuccess()) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
if (result.module != ErrorModule::HID) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
if (result == ResultMcuNotEnabled) {
|
|
||||||
return HIDBUS::ResultNotEnabled;
|
|
||||||
}
|
|
||||||
if (result == ResultMcuNoDeviceConnected) {
|
|
||||||
return HIDBUS::ResultNoDeviceConnected;
|
|
||||||
}
|
|
||||||
if (result == ResultMcuUnknown544) {
|
|
||||||
return HIDBUS::ResultUknown6;
|
|
||||||
}
|
|
||||||
if ((result.description & 0x1FFB) == 0x221) {
|
|
||||||
return HIDBUS::ResultPollingRecieveDataNotAvailable;
|
|
||||||
}
|
|
||||||
if (result == ResultMcuInvalidHandle) {
|
|
||||||
return HIDBUS::ResultInvalidBusHandle;
|
|
||||||
}
|
|
||||||
if (result == ResultMcuUnknown546) {
|
|
||||||
return HIDBUS::ResultDeviceEnabledNotSet;
|
|
||||||
}
|
|
||||||
if (result == ResultMcuUnknown548) {
|
|
||||||
return HIDBUS::ResultInvalidBusHandle;
|
|
||||||
}
|
|
||||||
if (result == ResultControllerUpdateFailed) {
|
|
||||||
return HIDBUS::ResultControllerUpdateFailed;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Service::HID
|
} // namespace Service::HID
|
||||||
|
@ -108,12 +108,21 @@ private:
|
|||||||
void DisableJoyPollingReceiveMode(HLERequestContext& ctx);
|
void DisableJoyPollingReceiveMode(HLERequestContext& ctx);
|
||||||
void SetStatusManagerType(HLERequestContext& ctx);
|
void SetStatusManagerType(HLERequestContext& ctx);
|
||||||
|
|
||||||
bool GetBusHandleImpl(BusHandle& handle, Core::HID::NpadIdType npad_id, BusType bus_type);
|
void UpdateHidbus(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
||||||
Result TranslateHidErrorToHidBusError(Result result);
|
std::optional<std::size_t> GetDeviceIndexFromHandle(BusHandle handle) const;
|
||||||
Result SetEventForSendCommandAsycResult2();
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void MakeDevice(BusHandle handle) {
|
||||||
|
const auto device_index = GetDeviceIndexFromHandle(handle);
|
||||||
|
if (device_index) {
|
||||||
|
devices[device_index.value()].device = std::make_unique<T>(system, service_context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_hidbus_enabled{false};
|
||||||
HidbusStatusManager hidbus_status{};
|
HidbusStatusManager hidbus_status{};
|
||||||
|
std::array<HidbusDevice, max_number_of_handles> devices{};
|
||||||
|
std::shared_ptr<Core::Timing::EventType> hidbus_update_event;
|
||||||
KernelHelpers::ServiceContext service_context;
|
KernelHelpers::ServiceContext service_context;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -388,6 +388,32 @@ enum class ExternalDeviceId : u16 {
|
|||||||
Starlink = 0x2800,
|
Starlink = 0x2800,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Most missing command names are leftovers from other firmware versions
|
||||||
|
enum class RingConCommand : u32 {
|
||||||
|
GetFirmwareVersion = 0x00020000,
|
||||||
|
ReadId = 0x00020100,
|
||||||
|
JoyPolling = 0x00020101,
|
||||||
|
Unknown1 = 0x00020104,
|
||||||
|
c20105 = 0x00020105,
|
||||||
|
Unknown2 = 0x00020204,
|
||||||
|
Unknown3 = 0x00020304,
|
||||||
|
Unknown4 = 0x00020404,
|
||||||
|
ReadUnkCal = 0x00020504,
|
||||||
|
ReadFactoryCal = 0x00020A04,
|
||||||
|
Unknown5 = 0x00021104,
|
||||||
|
Unknown6 = 0x00021204,
|
||||||
|
Unknown7 = 0x00021304,
|
||||||
|
ReadUserCal = 0x00021A04,
|
||||||
|
ReadRepCount = 0x00023104,
|
||||||
|
ReadTotalPushCount = 0x00023204,
|
||||||
|
ResetRepCount = 0x04013104,
|
||||||
|
Unknown8 = 0x04011104,
|
||||||
|
Unknown9 = 0x04011204,
|
||||||
|
Unknown10 = 0x04011304,
|
||||||
|
SaveCalData = 0x10011A04,
|
||||||
|
Error = 0xFFFFFFFF,
|
||||||
|
};
|
||||||
|
|
||||||
enum class DriverResult {
|
enum class DriverResult {
|
||||||
Success,
|
Success,
|
||||||
WrongReply,
|
WrongReply,
|
||||||
@ -687,6 +713,57 @@ struct RingStatus {
|
|||||||
s16 min_value;
|
s16 min_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
struct RingCommandData {
|
||||||
|
u8 data_type;
|
||||||
|
RingConCommand command;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(RingCommandData) == 0x5, "RingCommandData is an invalid size");
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
struct RingFactoryCalibration {
|
||||||
|
s32_le os_max;
|
||||||
|
s32_le hk_max;
|
||||||
|
s32_le zero_min;
|
||||||
|
s32_le zero_max;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(RingFactoryCalibration) == 0x10, "RingFactoryCalibration is an invalid size");
|
||||||
|
|
||||||
|
struct RingCalibrationValue {
|
||||||
|
s16 value;
|
||||||
|
u16 crc;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(RingCalibrationValue) == 0x4, "RingCalibrationValue is an invalid size");
|
||||||
|
|
||||||
|
struct RingUserCalibration {
|
||||||
|
RingCalibrationValue os_max;
|
||||||
|
RingCalibrationValue hk_max;
|
||||||
|
RingCalibrationValue zero;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(RingUserCalibration) == 0xC, "RingUserCalibration is an invalid size");
|
||||||
|
|
||||||
|
struct RingReadId {
|
||||||
|
u16 id_l_x0;
|
||||||
|
u16 id_l_x0_2;
|
||||||
|
u16 id_l_x4;
|
||||||
|
u16 id_h_x0;
|
||||||
|
u16 id_h_x0_2;
|
||||||
|
u16 id_h_x4;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(RingReadId) == 0xC, "RingReadId is an invalid size");
|
||||||
|
|
||||||
|
struct RingCommandReply {
|
||||||
|
DriverResult result;
|
||||||
|
RingConCommand command;
|
||||||
|
FirmwareVersion firmware;
|
||||||
|
RingFactoryCalibration factory_calibration;
|
||||||
|
RingUserCalibration user_calibration;
|
||||||
|
RingReadId read_id;
|
||||||
|
u8 c20105;
|
||||||
|
u8 total_push_count;
|
||||||
|
u8 total_rep_count;
|
||||||
|
};
|
||||||
|
|
||||||
struct VibrationPacket {
|
struct VibrationPacket {
|
||||||
OutputReport output_report;
|
OutputReport output_report;
|
||||||
u8 packet_counter;
|
u8 packet_counter;
|
||||||
|
@ -108,6 +108,65 @@ DriverResult RingConProtocol::ConfigureRing() {
|
|||||||
return SendSubCommand(SubCommand::ENABLE_EXTERNAL_POLLING, ringcon_data);
|
return SendSubCommand(SubCommand::ENABLE_EXTERNAL_POLLING, ringcon_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DriverResult RingConProtocol::SendCommand(RingConCommand command) {
|
||||||
|
SubCommandResponce output{};
|
||||||
|
RingCommandData data{
|
||||||
|
.data_type = 0x04, // This seems to be always 4 for this command
|
||||||
|
.command = command,
|
||||||
|
};
|
||||||
|
RingCommandReply reply{
|
||||||
|
.result = DriverResult::Success,
|
||||||
|
.command = command,
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<u8, sizeof(RingCommandData)> raw_data{};
|
||||||
|
memcpy(raw_data.data(), &data, sizeof(RingCommandData));
|
||||||
|
const DriverResult result = SendSubCommand(SubCommand::SET_EXTERNAL_CONFIG, raw_data, output);
|
||||||
|
|
||||||
|
if (result != DriverResult::Success) {
|
||||||
|
reply.result = result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (command) {
|
||||||
|
case RingConCommand::GetFirmwareVersion:
|
||||||
|
memcpy(&reply.firmware, output.command_data.data() + 6, sizeof(FirmwareVersion));
|
||||||
|
break;
|
||||||
|
case RingConCommand::ReadId:
|
||||||
|
memcpy(&reply.read_id, output.command_data.data() + 6,
|
||||||
|
sizeof(RingReadId));
|
||||||
|
break;
|
||||||
|
case RingConCommand::c20105:
|
||||||
|
reply.c20105 = output.command_data[6];
|
||||||
|
break;
|
||||||
|
case RingConCommand::ReadUnkCal:
|
||||||
|
break;
|
||||||
|
case RingConCommand::ReadFactoryCal:
|
||||||
|
memcpy(&reply.factory_calibration, output.command_data.data() + 6,
|
||||||
|
sizeof(RingFactoryCalibration));
|
||||||
|
break;
|
||||||
|
case RingConCommand::ReadUserCal:
|
||||||
|
memcpy(&reply.user_calibration, output.command_data.data() + 6, sizeof(RingUserCalibration));
|
||||||
|
break;
|
||||||
|
case RingConCommand::ReadRepCount:
|
||||||
|
reply.total_rep_count = output.command_data[6];
|
||||||
|
break;
|
||||||
|
case RingConCommand::ReadTotalPushCount:
|
||||||
|
reply.total_push_count = output.command_data[6];
|
||||||
|
break;
|
||||||
|
case RingConCommand::ResetRepCount:
|
||||||
|
break;
|
||||||
|
case RingConCommand::SaveCalData:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
reply.result = DriverResult::NotSupported;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool RingConProtocol::IsEnabled() const {
|
bool RingConProtocol::IsEnabled() const {
|
||||||
return is_enabled;
|
return is_enabled;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,9 @@ public:
|
|||||||
|
|
||||||
DriverResult StartRingconPolling();
|
DriverResult StartRingconPolling();
|
||||||
|
|
||||||
|
// Hidbus can send individual commands to the ring each one with an unique reply
|
||||||
|
DriverResult SendCommand(RingConCommand command);
|
||||||
|
|
||||||
bool IsEnabled() const;
|
bool IsEnabled() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user