core/hid: Update structs to 13.1.0

This commit is contained in:
german77 2021-10-27 18:06:13 -05:00 committed by Narr the Reg
parent c085e54316
commit 2d3a63b289
12 changed files with 107 additions and 50 deletions

View File

@ -231,7 +231,12 @@ enum class NpadButton : u64 {
RightSR = 1U << 27, RightSR = 1U << 27,
Palma = 1U << 28, Palma = 1U << 28,
Verification = 1U << 29,
HandheldLeftB = 1U << 30, HandheldLeftB = 1U << 30,
LagonCLeft = 1U << 31,
LagonCUp = 1ULL << 32,
LagonCRight = 1ULL << 33,
LagonCDown = 1ULL << 34,
}; };
DECLARE_ENUM_FLAG_OPERATORS(NpadButton); DECLARE_ENUM_FLAG_OPERATORS(NpadButton);
@ -278,7 +283,12 @@ struct NpadButtonState {
BitField<27, 1, u64> right_sr; BitField<27, 1, u64> right_sr;
BitField<28, 1, u64> palma; BitField<28, 1, u64> palma;
BitField<29, 1, u64> verification;
BitField<30, 1, u64> handheld_left_b; BitField<30, 1, u64> handheld_left_b;
BitField<31, 1, u64> lagon_c_left;
BitField<32, 1, u64> lagon_c_up;
BitField<33, 1, u64> lagon_c_right;
BitField<34, 1, u64> lagon_c_down;
}; };
}; };
static_assert(sizeof(NpadButtonState) == 0x8, "NpadButtonState has incorrect size."); static_assert(sizeof(NpadButtonState) == 0x8, "NpadButtonState has incorrect size.");

View File

@ -20,7 +20,7 @@ InputInterpreter::InputInterpreter(Core::System& system)
InputInterpreter::~InputInterpreter() = default; InputInterpreter::~InputInterpreter() = default;
void InputInterpreter::PollInput() { void InputInterpreter::PollInput() {
const u32 button_state = npad.GetAndResetPressState(); const u64 button_state = npad.GetAndResetPressState();
previous_index = current_index; previous_index = current_index;
current_index = (current_index + 1) % button_states.size(); current_index = (current_index + 1) % button_states.size();
@ -32,7 +32,7 @@ void InputInterpreter::ResetButtonStates() {
previous_index = 0; previous_index = 0;
current_index = 0; current_index = 0;
button_states[0] = 0xFFFFFFFF; button_states[0] = 0xFFFFFFFFFFFFFFFF;
for (std::size_t i = 1; i < button_states.size(); ++i) { for (std::size_t i = 1; i < button_states.size(); ++i) {
button_states[i] = 0; button_states[i] = 0;
@ -40,22 +40,22 @@ void InputInterpreter::ResetButtonStates() {
} }
bool InputInterpreter::IsButtonPressed(Core::HID::NpadButton button) const { bool InputInterpreter::IsButtonPressed(Core::HID::NpadButton button) const {
return (button_states[current_index] & static_cast<u32>(button)) != 0; return (button_states[current_index] & static_cast<u64>(button)) != 0;
} }
bool InputInterpreter::IsButtonPressedOnce(Core::HID::NpadButton button) const { bool InputInterpreter::IsButtonPressedOnce(Core::HID::NpadButton button) const {
const bool current_press = (button_states[current_index] & static_cast<u32>(button)) != 0; const bool current_press = (button_states[current_index] & static_cast<u64>(button)) != 0;
const bool previous_press = (button_states[previous_index] & static_cast<u32>(button)) != 0; const bool previous_press = (button_states[previous_index] & static_cast<u64>(button)) != 0;
return current_press && !previous_press; return current_press && !previous_press;
} }
bool InputInterpreter::IsButtonHeld(Core::HID::NpadButton button) const { bool InputInterpreter::IsButtonHeld(Core::HID::NpadButton button) const {
u32 held_buttons{button_states[0]}; u64 held_buttons{button_states[0]};
for (std::size_t i = 1; i < button_states.size(); ++i) { for (std::size_t i = 1; i < button_states.size(); ++i) {
held_buttons &= button_states[i]; held_buttons &= button_states[i];
} }
return (held_buttons & static_cast<u32>(button)) != 0; return (held_buttons & static_cast<u64>(button)) != 0;
} }

View File

@ -105,7 +105,7 @@ private:
Service::HID::Controller_NPad& npad; Service::HID::Controller_NPad& npad;
/// Stores 9 consecutive button states polled from HID. /// Stores 9 consecutive button states polled from HID.
std::array<u32, 9> button_states{}; std::array<u64, 9> button_states{};
std::size_t previous_index{}; std::size_t previous_index{};
std::size_t current_index{}; std::size_t current_index{};

View File

@ -30,8 +30,8 @@ void Controller_DebugPad::OnRelease() {}
void Controller_DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, void Controller_DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
std::size_t size) { std::size_t size) {
if (!IsControllerActivated()) { if (!IsControllerActivated()) {
debug_pad_lifo.entry_count = 0; debug_pad_lifo.buffer_count = 0;
debug_pad_lifo.last_entry_index = 0; debug_pad_lifo.buffer_tail = 0;
std::memcpy(data + SHARED_MEMORY_OFFSET, &debug_pad_lifo, sizeof(debug_pad_lifo)); std::memcpy(data + SHARED_MEMORY_OFFSET, &debug_pad_lifo, sizeof(debug_pad_lifo));
return; return;
} }

View File

@ -31,8 +31,8 @@ Controller_Gesture::Controller_Gesture(Core::System& system_) : ControllerBase(s
Controller_Gesture::~Controller_Gesture() = default; Controller_Gesture::~Controller_Gesture() = default;
void Controller_Gesture::OnInit() { void Controller_Gesture::OnInit() {
gesture_lifo.entry_count = 0; gesture_lifo.buffer_count = 0;
gesture_lifo.last_entry_index = 0; gesture_lifo.buffer_tail = 0;
force_update = true; force_update = true;
} }
@ -41,8 +41,8 @@ void Controller_Gesture::OnRelease() {}
void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
std::size_t size) { std::size_t size) {
if (!IsControllerActivated()) { if (!IsControllerActivated()) {
gesture_lifo.entry_count = 0; gesture_lifo.buffer_count = 0;
gesture_lifo.last_entry_index = 0; gesture_lifo.buffer_tail = 0;
std::memcpy(data + SHARED_MEMORY_OFFSET, &gesture_lifo, sizeof(gesture_lifo)); std::memcpy(data + SHARED_MEMORY_OFFSET, &gesture_lifo, sizeof(gesture_lifo));
return; return;
} }

View File

@ -27,8 +27,8 @@ void Controller_Keyboard::OnRelease() {}
void Controller_Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, void Controller_Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
std::size_t size) { std::size_t size) {
if (!IsControllerActivated()) { if (!IsControllerActivated()) {
keyboard_lifo.entry_count = 0; keyboard_lifo.buffer_count = 0;
keyboard_lifo.last_entry_index = 0; keyboard_lifo.buffer_tail = 0;
std::memcpy(data + SHARED_MEMORY_OFFSET, &keyboard_lifo, sizeof(keyboard_lifo)); std::memcpy(data + SHARED_MEMORY_OFFSET, &keyboard_lifo, sizeof(keyboard_lifo));
return; return;
} }

View File

@ -24,11 +24,9 @@ void Controller_Mouse::OnRelease() {}
void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
std::size_t size) { std::size_t size) {
mouse_lifo.timestamp = core_timing.GetCPUTicks();
if (!IsControllerActivated()) { if (!IsControllerActivated()) {
mouse_lifo.entry_count = 0; mouse_lifo.buffer_count = 0;
mouse_lifo.last_entry_index = 0; mouse_lifo.buffer_tail = 0;
std::memcpy(data + SHARED_MEMORY_OFFSET, &mouse_lifo, sizeof(mouse_lifo)); std::memcpy(data + SHARED_MEMORY_OFFSET, &mouse_lifo, sizeof(mouse_lifo));
return; return;
} }

View File

@ -101,7 +101,8 @@ Controller_NPad::Controller_NPad(Core::System& system_,
for (std::size_t i = 0; i < controller_data.size(); ++i) { for (std::size_t i = 0; i < controller_data.size(); ++i) {
auto& controller = controller_data[i]; auto& controller = controller_data[i];
controller.device = system.HIDCore().GetEmulatedControllerByIndex(i); controller.device = system.HIDCore().GetEmulatedControllerByIndex(i);
controller.vibration[Core::HID::DeviceIndex::LeftIndex].latest_vibration_value = DEFAULT_VIBRATION_VALUE; controller.vibration[Core::HID::DeviceIndex::LeftIndex].latest_vibration_value =
DEFAULT_VIBRATION_VALUE;
controller.vibration[Core::HID::DeviceIndex::RightIndex].latest_vibration_value = controller.vibration[Core::HID::DeviceIndex::RightIndex].latest_vibration_value =
DEFAULT_VIBRATION_VALUE; DEFAULT_VIBRATION_VALUE;
Core::HID::ControllerUpdateCallback engine_callback{ Core::HID::ControllerUpdateCallback engine_callback{
@ -178,7 +179,7 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) {
shared_memory.system_properties.use_plus.Assign(1); shared_memory.system_properties.use_plus.Assign(1);
shared_memory.system_properties.use_minus.Assign(1); shared_memory.system_properties.use_minus.Assign(1);
shared_memory.assignment_mode = NpadJoyAssignmentMode::Single; shared_memory.assignment_mode = NpadJoyAssignmentMode::Single;
shared_memory.footer_type = AppletFooterUiType::SwitchProController; shared_memory.applet_footer.type = AppletFooterUiType::SwitchProController;
break; break;
case Core::HID::NpadType::Handheld: case Core::HID::NpadType::Handheld:
shared_memory.style_set.handheld.Assign(1); shared_memory.style_set.handheld.Assign(1);
@ -188,7 +189,7 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) {
shared_memory.system_properties.use_plus.Assign(1); shared_memory.system_properties.use_plus.Assign(1);
shared_memory.system_properties.use_minus.Assign(1); shared_memory.system_properties.use_minus.Assign(1);
shared_memory.assignment_mode = NpadJoyAssignmentMode::Dual; shared_memory.assignment_mode = NpadJoyAssignmentMode::Dual;
shared_memory.footer_type = AppletFooterUiType::HandheldJoyConLeftJoyConRight; shared_memory.applet_footer.type = AppletFooterUiType::HandheldJoyConLeftJoyConRight;
break; break;
case Core::HID::NpadType::JoyconDual: case Core::HID::NpadType::JoyconDual:
shared_memory.style_set.joycon_dual.Assign(1); shared_memory.style_set.joycon_dual.Assign(1);
@ -198,7 +199,7 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) {
shared_memory.system_properties.use_plus.Assign(1); shared_memory.system_properties.use_plus.Assign(1);
shared_memory.system_properties.use_minus.Assign(1); shared_memory.system_properties.use_minus.Assign(1);
shared_memory.assignment_mode = NpadJoyAssignmentMode::Dual; shared_memory.assignment_mode = NpadJoyAssignmentMode::Dual;
shared_memory.footer_type = AppletFooterUiType::JoyDual; shared_memory.applet_footer.type = AppletFooterUiType::JoyDual;
break; break;
case Core::HID::NpadType::JoyconLeft: case Core::HID::NpadType::JoyconLeft:
shared_memory.style_set.joycon_left.Assign(1); shared_memory.style_set.joycon_left.Assign(1);
@ -206,7 +207,7 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) {
shared_memory.system_properties.is_horizontal.Assign(1); shared_memory.system_properties.is_horizontal.Assign(1);
shared_memory.system_properties.use_minus.Assign(1); shared_memory.system_properties.use_minus.Assign(1);
shared_memory.assignment_mode = NpadJoyAssignmentMode::Single; shared_memory.assignment_mode = NpadJoyAssignmentMode::Single;
shared_memory.footer_type = AppletFooterUiType::JoyLeftHorizontal; shared_memory.applet_footer.type = AppletFooterUiType::JoyLeftHorizontal;
break; break;
case Core::HID::NpadType::JoyconRight: case Core::HID::NpadType::JoyconRight:
shared_memory.style_set.joycon_right.Assign(1); shared_memory.style_set.joycon_right.Assign(1);
@ -214,7 +215,7 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) {
shared_memory.system_properties.is_horizontal.Assign(1); shared_memory.system_properties.is_horizontal.Assign(1);
shared_memory.system_properties.use_plus.Assign(1); shared_memory.system_properties.use_plus.Assign(1);
shared_memory.assignment_mode = NpadJoyAssignmentMode::Single; shared_memory.assignment_mode = NpadJoyAssignmentMode::Single;
shared_memory.footer_type = AppletFooterUiType::JoyRightHorizontal; shared_memory.applet_footer.type = AppletFooterUiType::JoyRightHorizontal;
break; break;
case Core::HID::NpadType::GameCube: case Core::HID::NpadType::GameCube:
shared_memory.style_set.gamecube.Assign(1); shared_memory.style_set.gamecube.Assign(1);
@ -919,7 +920,7 @@ void Controller_NPad::DisconnectNpadAtIndex(std::size_t npad_index) {
.right = {}, .right = {},
}; };
shared_memory_entry.assignment_mode = NpadJoyAssignmentMode::Dual; shared_memory_entry.assignment_mode = NpadJoyAssignmentMode::Dual;
shared_memory_entry.footer_type = AppletFooterUiType::None; shared_memory_entry.applet_footer.type = AppletFooterUiType::None;
controller.is_connected = false; controller.is_connected = false;
controller.device->Disconnect(); controller.device->Disconnect();

View File

@ -330,10 +330,43 @@ private:
BitField<13, 1, s32> handheld_lark_nes_left; BitField<13, 1, s32> handheld_lark_nes_left;
BitField<14, 1, s32> handheld_lark_nes_right; BitField<14, 1, s32> handheld_lark_nes_right;
BitField<15, 1, s32> lucia; BitField<15, 1, s32> lucia;
BitField<16, 1, s32> lagon;
BitField<17, 1, s32> lager;
BitField<31, 1, s32> system; BitField<31, 1, s32> system;
}; };
}; };
// This is nn::hid::detail::NfcXcdDeviceHandleStateImpl
struct NfcXcdDeviceHandleStateImpl {
u64 handle;
bool is_available;
bool is_activated;
INSERT_PADDING_BYTES(0x6); // Reserved
u64 sampling_number;
};
static_assert(sizeof(NfcXcdDeviceHandleStateImpl) == 0x18,
"NfcXcdDeviceHandleStateImpl is an invalid size");
// nn::hid::detail::NfcXcdDeviceHandleStateImplAtomicStorage
struct NfcXcdDeviceHandleStateImplAtomicStorage {
u64 sampling_number;
NfcXcdDeviceHandleStateImpl nfc_xcd_device_handle_state;
};
static_assert(sizeof(NfcXcdDeviceHandleStateImplAtomicStorage) == 0x20,
"NfcXcdDeviceHandleStateImplAtomicStorage is an invalid size");
// This is nn::hid::detail::NfcXcdDeviceHandleState
struct NfcXcdDeviceHandleState {
// TODO(german77): Make this struct a ring lifo object
INSERT_PADDING_BYTES(0x8); // Unused
s64 total_buffer_count = max_buffer_size;
s64 buffer_tail{};
s64 buffer_count{};
std::array<NfcXcdDeviceHandleStateImplAtomicStorage, 2> nfc_xcd_device_handle_storage;
};
static_assert(sizeof(NfcXcdDeviceHandleState) == 0x60,
"NfcXcdDeviceHandleState is an invalid size");
// This is nn::hid::system::AppletFooterUiAttributesSet // This is nn::hid::system::AppletFooterUiAttributesSet
struct AppletFooterUiAttributes { struct AppletFooterUiAttributes {
INSERT_PADDING_BYTES(0x4); INSERT_PADDING_BYTES(0x4);
@ -365,6 +398,14 @@ private:
Lagon = 21, Lagon = 21,
}; };
struct AppletFooterUi {
AppletFooterUiAttributes attributes;
AppletFooterUiType type;
INSERT_PADDING_BYTES(0x5B); // Reserved
};
static_assert(sizeof(AppletFooterUi) == 0x60,
"AppletFooterUi is an invalid size");
// This is nn::hid::NpadLarkType // This is nn::hid::NpadLarkType
enum class NpadLarkType : u32 { enum class NpadLarkType : u32 {
Invalid, Invalid,
@ -382,6 +423,11 @@ private:
U, U,
}; };
// This is nn::hid::NpadLagonType
enum class NpadLagonType : u32 {
Invalid,
};
// This is nn::hid::NpadLagerType // This is nn::hid::NpadLagerType
enum class NpadLagerType : u32 { enum class NpadLagerType : u32 {
Invalid, Invalid,
@ -416,17 +462,19 @@ private:
Core::HID::BatteryLevel battery_level_dual; Core::HID::BatteryLevel battery_level_dual;
Core::HID::BatteryLevel battery_level_left; Core::HID::BatteryLevel battery_level_left;
Core::HID::BatteryLevel battery_level_right; Core::HID::BatteryLevel battery_level_right;
AppletFooterUiAttributes footer_attributes; union {
AppletFooterUiType footer_type; NfcXcdDeviceHandleState nfc_xcd_device_handle;
// GetXcdHandleForNpadWithNfc needs to be checked switchbrew doesn't match with HW AppletFooterUi applet_footer;
INSERT_PADDING_BYTES(0x78); // Unknown };
INSERT_PADDING_BYTES(0x20); // Unknown
Lifo<NpadGcTriggerState> gc_trigger_lifo; Lifo<NpadGcTriggerState> gc_trigger_lifo;
NpadLarkType lark_type_l; NpadLarkType lark_type_l_and_main;
NpadLarkType lark_type_r; NpadLarkType lark_type_r;
NpadLuciaType lucia_type; NpadLuciaType lucia_type;
NpadLagonType lagon_type;
NpadLagerType lager_type; NpadLagerType lager_type;
INSERT_PADDING_BYTES( INSERT_PADDING_BYTES(
0x8); // FW 13.x Investigate there is some sort of bitflag related to joycons 0x4); // FW 13.x Investigate there is some sort of bitflag related to joycons
INSERT_PADDING_BYTES(0xc08); // Unknown INSERT_PADDING_BYTES(0xc08); // Unknown
}; };
static_assert(sizeof(NpadInternalState) == 0x5000, "NpadInternalState is an invalid size"); static_assert(sizeof(NpadInternalState) == 0x5000, "NpadInternalState is an invalid size");

View File

@ -30,8 +30,8 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
touch_screen_lifo.timestamp = core_timing.GetCPUTicks(); touch_screen_lifo.timestamp = core_timing.GetCPUTicks();
if (!IsControllerActivated()) { if (!IsControllerActivated()) {
touch_screen_lifo.entry_count = 0; touch_screen_lifo.buffer_count = 0;
touch_screen_lifo.last_entry_index = 0; touch_screen_lifo.buffer_tail = 0;
std::memcpy(data, &touch_screen_lifo, sizeof(touch_screen_lifo)); std::memcpy(data, &touch_screen_lifo, sizeof(touch_screen_lifo));
return; return;
} }

View File

@ -20,8 +20,8 @@ void Controller_XPad::OnRelease() {}
void Controller_XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, void Controller_XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
std::size_t size) { std::size_t size) {
if (!IsControllerActivated()) { if (!IsControllerActivated()) {
basic_xpad_lifo.entry_count = 0; basic_xpad_lifo.buffer_count = 0;
basic_xpad_lifo.last_entry_index = 0; basic_xpad_lifo.buffer_tail = 0;
std::memcpy(data + SHARED_MEMORY_OFFSET, &basic_xpad_lifo, sizeof(basic_xpad_lifo)); std::memcpy(data + SHARED_MEMORY_OFFSET, &basic_xpad_lifo, sizeof(basic_xpad_lifo));
return; return;
} }

View File

@ -8,7 +8,7 @@
#include "common/swap.h" #include "common/swap.h"
namespace Service::HID { namespace Service::HID {
constexpr std::size_t max_entry_size = 17; constexpr std::size_t max_buffer_size = 17;
template <typename State> template <typename State>
struct AtomicStorage { struct AtomicStorage {
@ -19,13 +19,13 @@ struct AtomicStorage {
template <typename State> template <typename State>
struct Lifo { struct Lifo {
s64 timestamp{}; s64 timestamp{};
s64 total_entry_count = max_entry_size; s64 total_buffer_count = max_buffer_size;
s64 last_entry_index{}; s64 buffer_tail{};
s64 entry_count{}; s64 buffer_count{};
std::array<AtomicStorage<State>, max_entry_size> entries{}; std::array<AtomicStorage<State>, max_buffer_size> entries{};
const AtomicStorage<State>& ReadCurrentEntry() const { const AtomicStorage<State>& ReadCurrentEntry() const {
return entries[last_entry_index]; return entries[buffer_tail];
} }
const AtomicStorage<State>& ReadPreviousEntry() const { const AtomicStorage<State>& ReadPreviousEntry() const {
@ -33,21 +33,21 @@ struct Lifo {
} }
std::size_t GetPreviuousEntryIndex() const { std::size_t GetPreviuousEntryIndex() const {
return (last_entry_index + total_entry_count - 1) % total_entry_count; return (buffer_tail + total_buffer_count - 1) % total_buffer_count;
} }
std::size_t GetNextEntryIndex() const { std::size_t GetNextEntryIndex() const {
return (last_entry_index + 1) % total_entry_count; return (buffer_tail + 1) % total_buffer_count;
} }
void WriteNextEntry(const State& new_state) { void WriteNextEntry(const State& new_state) {
if (entry_count < total_entry_count - 1) { if (buffer_count < total_buffer_count - 1) {
entry_count++; buffer_count++;
} }
last_entry_index = GetNextEntryIndex(); buffer_tail = GetNextEntryIndex();
const auto& previous_entry = ReadPreviousEntry(); const auto& previous_entry = ReadPreviousEntry();
entries[last_entry_index].sampling_number = previous_entry.sampling_number + 1; entries[buffer_tail].sampling_number = previous_entry.sampling_number + 1;
entries[last_entry_index].state = new_state; entries[buffer_tail].state = new_state;
} }
}; };