yuzu/src/core/hle/service/hid/controllers/debug_pad.h

94 lines
2.7 KiB
C++
Raw Normal View History

2018-10-05 16:23:21 +02:00
// Copyright 2018 yuzu emulator team
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
2018-10-06 05:14:42 +02:00
2018-10-05 16:23:21 +02:00
#include <array>
2018-10-18 13:01:55 +02:00
#include "common/bit_field.h"
2018-10-05 16:23:21 +02:00
#include "common/common_funcs.h"
#include "common/common_types.h"
#include "common/swap.h"
#include "core/frontend/input.h"
2018-10-05 16:23:21 +02:00
#include "core/hle/service/hid/controllers/controller_base.h"
#include "core/settings.h"
2018-10-05 16:23:21 +02:00
namespace Service::HID {
class Controller_DebugPad final : public ControllerBase {
public:
2018-10-06 05:14:42 +02:00
Controller_DebugPad();
~Controller_DebugPad() override;
2018-10-05 16:23:21 +02:00
// Called when the controller is initialized
2019-09-21 10:43:43 +02:00
void OnInit(Core::System& system) override;
2018-10-05 16:23:21 +02:00
// When the controller is released
void OnRelease() override;
// When the controller is requesting an update for the shared memory
void OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, std::size_t size) override;
2018-10-05 16:23:21 +02:00
// Called when input devices should be loaded
void OnLoadInputDevices() override;
private:
struct AnalogStick {
s32_le x;
s32_le y;
};
static_assert(sizeof(AnalogStick) == 0x8);
2018-10-18 13:01:55 +02:00
struct PadState {
union {
u32_le raw{};
BitField<0, 1, u32> a;
BitField<1, 1, u32> b;
BitField<2, 1, u32> x;
BitField<3, 1, u32> y;
BitField<4, 1, u32> l;
BitField<5, 1, u32> r;
BitField<6, 1, u32> zl;
BitField<7, 1, u32> zr;
BitField<8, 1, u32> plus;
BitField<9, 1, u32> minus;
BitField<10, 1, u32> d_left;
BitField<11, 1, u32> d_up;
BitField<12, 1, u32> d_right;
BitField<13, 1, u32> d_down;
2018-10-18 13:01:55 +02:00
};
};
static_assert(sizeof(PadState) == 0x4, "PadState is an invalid size");
struct Attributes {
union {
u32_le raw{};
BitField<0, 1, u32> connected;
2018-10-18 13:01:55 +02:00
};
};
static_assert(sizeof(Attributes) == 0x4, "Attributes is an invalid size");
2018-10-05 16:23:21 +02:00
struct PadStates {
s64_le sampling_number;
s64_le sampling_number2;
2018-10-18 13:01:55 +02:00
Attributes attribute;
PadState pad_state;
2018-10-05 16:23:21 +02:00
AnalogStick r_stick;
AnalogStick l_stick;
};
static_assert(sizeof(PadStates) == 0x28, "PadStates is an invalid state");
struct SharedMemory {
CommonHeader header;
std::array<PadStates, 17> pad_states;
INSERT_PADDING_BYTES(0x138);
};
static_assert(sizeof(SharedMemory) == 0x400, "SharedMemory is an invalid size");
SharedMemory shared_memory{};
std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID>
buttons;
std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID>
analogs;
2018-10-05 16:23:21 +02:00
};
2018-10-06 05:14:42 +02:00
} // namespace Service::HID