2018-01-15 02:24:50 +00:00
|
|
|
// Copyright 2018 yuzu emulator team
|
2015-01-18 23:07:48 +00:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-01-15 09:21:02 +00:00
|
|
|
#include <atomic>
|
2016-09-18 00:38:01 +00:00
|
|
|
#include "common/logging/log.h"
|
2018-01-15 09:21:02 +00:00
|
|
|
#include "core/core_timing.h"
|
|
|
|
#include "core/frontend/input.h"
|
2018-01-15 02:24:50 +00:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
|
|
|
#include "core/hle/kernel/client_port.h"
|
|
|
|
#include "core/hle/kernel/client_session.h"
|
2018-02-07 12:11:17 +00:00
|
|
|
#include "core/hle/kernel/event.h"
|
2018-01-15 02:24:50 +00:00
|
|
|
#include "core/hle/kernel/shared_memory.h"
|
2016-09-21 06:52:38 +00:00
|
|
|
#include "core/hle/service/hid/hid.h"
|
2016-09-20 15:21:23 +00:00
|
|
|
#include "core/hle/service/service.h"
|
2015-03-09 04:14:59 +00:00
|
|
|
|
2015-01-18 23:07:48 +00:00
|
|
|
namespace Service {
|
|
|
|
namespace HID {
|
|
|
|
|
2018-01-15 09:21:02 +00:00
|
|
|
// Updating period for each HID device.
|
|
|
|
// TODO(shinyquagsire23): These need better values.
|
2018-01-17 08:20:25 +00:00
|
|
|
constexpr u64 pad_update_ticks = BASE_CLOCK_RATE / 10000;
|
|
|
|
constexpr u64 accelerometer_update_ticks = BASE_CLOCK_RATE / 10000;
|
|
|
|
constexpr u64 gyroscope_update_ticks = BASE_CLOCK_RATE / 10000;
|
2018-01-15 09:21:02 +00:00
|
|
|
|
2018-01-15 02:24:50 +00:00
|
|
|
class IAppletResource final : public ServiceFramework<IAppletResource> {
|
|
|
|
public:
|
|
|
|
IAppletResource() : ServiceFramework("IAppletResource") {
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"},
|
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
2015-01-18 23:07:48 +00:00
|
|
|
|
2018-01-15 02:24:50 +00:00
|
|
|
shared_mem = Kernel::SharedMemory::Create(
|
|
|
|
nullptr, 0x40000, Kernel::MemoryPermission::ReadWrite, Kernel::MemoryPermission::Read,
|
|
|
|
0, Kernel::MemoryRegion::BASE, "HID:SharedMemory");
|
2018-01-15 09:21:02 +00:00
|
|
|
|
|
|
|
// Register update callbacks
|
|
|
|
pad_update_event = CoreTiming::RegisterEvent(
|
|
|
|
"HID::UpdatePadCallback",
|
|
|
|
[this](u64 userdata, int cycles_late) { UpdatePadCallback(userdata, cycles_late); });
|
|
|
|
|
|
|
|
// TODO(shinyquagsire23): Other update callbacks? (accel, gyro?)
|
|
|
|
|
|
|
|
CoreTiming::ScheduleEvent(pad_update_ticks, pad_update_event);
|
2018-01-15 02:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void GetSharedMemoryHandle(Kernel::HLERequestContext& ctx) {
|
2018-01-24 00:52:18 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
2018-01-15 02:24:50 +00:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushCopyObjects(shared_mem);
|
2018-02-04 22:02:39 +00:00
|
|
|
LOG_DEBUG(Service_HID, "called");
|
2018-01-15 02:24:50 +00:00
|
|
|
}
|
|
|
|
|
2018-01-15 09:21:02 +00:00
|
|
|
void LoadInputDevices() {
|
|
|
|
std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
|
|
|
|
Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END,
|
|
|
|
buttons.begin(), Input::CreateDevice<Input::ButtonDevice>);
|
|
|
|
// TODO(shinyquagsire23): sticks, gyro, touch, mouse, keyboard
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdatePadCallback(u64 userdata, int cycles_late) {
|
|
|
|
SharedMemory* mem = reinterpret_cast<SharedMemory*>(shared_mem->GetPointer());
|
|
|
|
|
|
|
|
if (is_device_reload_pending.exchange(false))
|
|
|
|
LoadInputDevices();
|
|
|
|
|
2018-01-16 10:14:27 +00:00
|
|
|
// Set up controllers as neon red+blue Joy-Con attached to console
|
2018-01-17 02:22:12 +00:00
|
|
|
ControllerHeader& controller_header = mem->controllers[Controller_Handheld].header;
|
|
|
|
controller_header.type = ControllerType_Handheld | ControllerType_JoyconPair;
|
|
|
|
controller_header.single_colors_descriptor = ColorDesc_ColorsNonexistent;
|
|
|
|
controller_header.right_color_body = JOYCON_BODY_NEON_RED;
|
|
|
|
controller_header.right_color_buttons = JOYCON_BUTTONS_NEON_RED;
|
|
|
|
controller_header.left_color_body = JOYCON_BODY_NEON_BLUE;
|
|
|
|
controller_header.left_color_buttons = JOYCON_BUTTONS_NEON_BLUE;
|
2018-01-16 10:14:27 +00:00
|
|
|
|
2018-01-17 02:22:58 +00:00
|
|
|
for (int layoutIdx = 0; layoutIdx < HID_NUM_LAYOUTS; layoutIdx++) {
|
2018-01-16 10:14:27 +00:00
|
|
|
ControllerLayout& layout = mem->controllers[Controller_Handheld].layouts[layoutIdx];
|
2018-01-17 02:22:12 +00:00
|
|
|
layout.header.num_entries = HID_NUM_ENTRIES;
|
|
|
|
layout.header.max_entry_index = HID_NUM_ENTRIES - 1;
|
2018-01-16 10:14:27 +00:00
|
|
|
|
|
|
|
// HID shared memory stores the state of the past 17 samples in a circlular buffer,
|
|
|
|
// each with a timestamp in number of samples since boot.
|
2018-01-17 02:22:12 +00:00
|
|
|
layout.header.timestamp_ticks = CoreTiming::GetTicks();
|
|
|
|
layout.header.latest_entry = (layout.header.latest_entry + 1) % HID_NUM_ENTRIES;
|
2018-01-16 10:14:27 +00:00
|
|
|
|
2018-01-17 02:22:12 +00:00
|
|
|
ControllerInputEntry& entry = layout.entries[layout.header.latest_entry];
|
|
|
|
entry.connection_state = ConnectionState_Connected | ConnectionState_Wired;
|
2018-01-16 10:14:27 +00:00
|
|
|
entry.timestamp++;
|
|
|
|
entry.timestamp_2++; // TODO(shinyquagsire23): Is this always identical to timestamp?
|
|
|
|
|
|
|
|
// TODO(shinyquagsire23): Set up some LUTs for each layout mapping in the future?
|
|
|
|
// For now everything is just the default handheld layout, but split Joy-Con will
|
|
|
|
// rotate the face buttons and directions for certain layouts.
|
|
|
|
ControllerPadState& state = entry.buttons;
|
|
|
|
using namespace Settings::NativeButton;
|
|
|
|
state.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.lstick.Assign(buttons[LStick - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.rstick.Assign(buttons[RStick - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.zl.Assign(buttons[ZL - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.zr.Assign(buttons[ZR - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
|
|
|
|
state.dleft.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.dup.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.dright.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.ddown.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
|
|
|
|
state.lstick_left.Assign(buttons[LStick_Left - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.lstick_up.Assign(buttons[LStick_Up - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.lstick_right.Assign(buttons[LStick_Right - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.lstick_down.Assign(buttons[LStick_Down - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
|
|
|
|
state.rstick_left.Assign(buttons[RStick_Left - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.rstick_up.Assign(buttons[RStick_Up - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.rstick_right.Assign(buttons[RStick_Right - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.rstick_down.Assign(buttons[RStick_Down - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
|
|
|
|
state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus());
|
|
|
|
|
|
|
|
// TODO(shinyquagsire23): Analog stick vals
|
|
|
|
|
2018-01-17 02:22:58 +00:00
|
|
|
// TODO(shinyquagsire23): Update pad info proper, (circular buffers, timestamps,
|
|
|
|
// layouts)
|
2018-01-16 10:14:27 +00:00
|
|
|
}
|
2018-01-15 09:21:02 +00:00
|
|
|
|
|
|
|
// TODO(shinyquagsire23): Update touch info
|
|
|
|
|
|
|
|
// TODO(shinyquagsire23): Signal events
|
|
|
|
|
|
|
|
// Reschedule recurrent event
|
|
|
|
CoreTiming::ScheduleEvent(pad_update_ticks - cycles_late, pad_update_event);
|
|
|
|
}
|
|
|
|
|
2018-01-15 02:24:50 +00:00
|
|
|
// Handle to shared memory region designated to HID service
|
|
|
|
Kernel::SharedPtr<Kernel::SharedMemory> shared_mem;
|
2018-01-15 09:21:02 +00:00
|
|
|
|
|
|
|
// CoreTiming update events
|
|
|
|
CoreTiming::EventType* pad_update_event;
|
|
|
|
|
|
|
|
// Stored input state info
|
|
|
|
std::atomic<bool> is_device_reload_pending{true};
|
|
|
|
std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID>
|
|
|
|
buttons;
|
2018-01-15 02:24:50 +00:00
|
|
|
};
|
|
|
|
|
2018-02-04 22:06:14 +00:00
|
|
|
class IActiveVibrationDeviceList final : public ServiceFramework<IActiveVibrationDeviceList> {
|
|
|
|
public:
|
|
|
|
IActiveVibrationDeviceList() : ServiceFramework("IActiveVibrationDeviceList") {
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, &IActiveVibrationDeviceList::ActivateVibrationDevice, "ActivateVibrationDevice"},
|
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ActivateVibrationDevice(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
LOG_WARNING(Service_HID, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-01-15 02:24:50 +00:00
|
|
|
class Hid final : public ServiceFramework<Hid> {
|
|
|
|
public:
|
|
|
|
Hid() : ServiceFramework("hid") {
|
|
|
|
static const FunctionInfo functions[] = {
|
2018-02-05 03:24:20 +00:00
|
|
|
{0, &Hid::CreateAppletResource, "CreateAppletResource"},
|
|
|
|
{1, &Hid::ActivateDebugPad, "ActivateDebugPad"},
|
2018-02-06 02:53:11 +00:00
|
|
|
{11, &Hid::ActivateTouchScreen, "ActivateTouchScreen"},
|
2018-02-05 03:24:20 +00:00
|
|
|
{66, &Hid::StartSixAxisSensor, "StartSixAxisSensor"},
|
|
|
|
{100, &Hid::SetSupportedNpadStyleSet, "SetSupportedNpadStyleSet"},
|
|
|
|
{102, &Hid::SetSupportedNpadIdType, "SetSupportedNpadIdType"},
|
|
|
|
{103, &Hid::ActivateNpad, "ActivateNpad"},
|
2018-02-07 12:11:17 +00:00
|
|
|
{106, &Hid::AcquireNpadStyleSetUpdateEventHandle,
|
|
|
|
"AcquireNpadStyleSetUpdateEventHandle"},
|
2018-02-06 02:53:11 +00:00
|
|
|
{120, &Hid::SetNpadJoyHoldType, "SetNpadJoyHoldType"},
|
2018-02-07 12:11:17 +00:00
|
|
|
{121, &Hid::GetNpadJoyHoldType, "GetNpadJoyHoldType"},
|
2018-02-05 03:24:20 +00:00
|
|
|
{124, nullptr, "SetNpadJoyAssignmentModeDual"},
|
2018-02-06 07:26:33 +00:00
|
|
|
{128, &Hid::SetNpadHandheldActivationMode, "SetNpadHandheldActivationMode"},
|
2018-02-14 00:05:06 +00:00
|
|
|
{200, &Hid::GetVibrationDeviceInfo, "GetVibrationDeviceInfo"},
|
2018-02-04 22:06:14 +00:00
|
|
|
{203, &Hid::CreateActiveVibrationDeviceList, "CreateActiveVibrationDeviceList"},
|
2018-02-14 00:05:06 +00:00
|
|
|
{206, &Hid::SendVibrationValues, "SendVibrationValues"},
|
2018-01-15 02:24:50 +00:00
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
2018-02-07 12:11:17 +00:00
|
|
|
|
|
|
|
event = Kernel::Event::Create(Kernel::ResetType::OneShot, "hid:EventHandle");
|
2018-01-15 02:24:50 +00:00
|
|
|
}
|
|
|
|
~Hid() = default;
|
|
|
|
|
|
|
|
private:
|
2018-01-22 22:41:31 +00:00
|
|
|
std::shared_ptr<IAppletResource> applet_resource;
|
2018-02-07 12:11:17 +00:00
|
|
|
u32 joy_hold_type{0};
|
|
|
|
Kernel::SharedPtr<Kernel::Event> event;
|
2018-01-22 20:27:55 +00:00
|
|
|
|
2018-01-15 02:24:50 +00:00
|
|
|
void CreateAppletResource(Kernel::HLERequestContext& ctx) {
|
2018-01-22 22:41:31 +00:00
|
|
|
if (applet_resource == nullptr) {
|
|
|
|
applet_resource = std::make_shared<IAppletResource>();
|
2018-01-22 20:27:55 +00:00
|
|
|
}
|
|
|
|
|
2018-01-24 00:52:18 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2018-01-22 22:41:31 +00:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-01-24 00:43:59 +00:00
|
|
|
rb.PushIpcInterface<IAppletResource>(applet_resource);
|
2018-02-04 22:02:39 +00:00
|
|
|
LOG_DEBUG(Service_HID, "called");
|
2018-01-15 02:24:50 +00:00
|
|
|
}
|
2018-02-04 22:06:14 +00:00
|
|
|
|
2018-02-05 03:24:20 +00:00
|
|
|
void ActivateDebugPad(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
LOG_WARNING(Service_HID, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
2018-02-06 02:53:11 +00:00
|
|
|
void ActivateTouchScreen(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
LOG_WARNING(Service_HID, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
2018-02-05 03:24:20 +00:00
|
|
|
void StartSixAxisSensor(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
LOG_WARNING(Service_HID, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
LOG_WARNING(Service_HID, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetSupportedNpadIdType(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
LOG_WARNING(Service_HID, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActivateNpad(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
LOG_WARNING(Service_HID, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
2018-02-07 12:11:17 +00:00
|
|
|
void AcquireNpadStyleSetUpdateEventHandle(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushCopyObjects(event);
|
|
|
|
LOG_WARNING(Service_HID, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
2018-02-06 02:53:11 +00:00
|
|
|
void SetNpadJoyHoldType(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
LOG_WARNING(Service_HID, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
2018-02-07 12:11:17 +00:00
|
|
|
void GetNpadJoyHoldType(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.Push(joy_hold_type);
|
|
|
|
LOG_WARNING(Service_HID, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
2018-02-06 07:26:33 +00:00
|
|
|
void SetNpadHandheldActivationMode(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
LOG_WARNING(Service_HID, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
2018-02-14 00:05:06 +00:00
|
|
|
void GetVibrationDeviceInfo(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.Push<u64>(0);
|
|
|
|
LOG_WARNING(Service_HID, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
2018-02-04 22:06:14 +00:00
|
|
|
void CreateActiveVibrationDeviceList(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushIpcInterface<IActiveVibrationDeviceList>();
|
|
|
|
LOG_DEBUG(Service_HID, "called");
|
|
|
|
}
|
2018-02-14 00:05:06 +00:00
|
|
|
|
|
|
|
void SendVibrationValues(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
LOG_WARNING(Service_HID, "(STUBBED) called");
|
|
|
|
}
|
2018-01-15 02:24:50 +00:00
|
|
|
};
|
2015-01-18 23:07:48 +00:00
|
|
|
|
2017-10-13 01:21:49 +00:00
|
|
|
void ReloadInputDevices() {}
|
2015-01-18 23:07:48 +00:00
|
|
|
|
2018-01-15 02:24:50 +00:00
|
|
|
void InstallInterfaces(SM::ServiceManager& service_manager) {
|
|
|
|
std::make_shared<Hid>()->InstallAsService(service_manager);
|
|
|
|
}
|
|
|
|
|
2015-03-09 04:14:59 +00:00
|
|
|
} // namespace HID
|
|
|
|
} // namespace Service
|