diff options
| author | 2024-01-07 09:05:12 -0600 | |
|---|---|---|
| committer | 2024-01-11 19:35:04 -0600 | |
| commit | b5dac5f525e8d5884506ebd98a530e237b518480 (patch) | |
| tree | 6ceee925ba897dc3450bdad209982f0be4bc3f7a /src/hid_core/resources/npad | |
| parent | Merge pull request #12653 from liamwhite/once-more (diff) | |
| download | yuzu-b5dac5f525e8d5884506ebd98a530e237b518480.tar.gz yuzu-b5dac5f525e8d5884506ebd98a530e237b518480.tar.xz yuzu-b5dac5f525e8d5884506ebd98a530e237b518480.zip | |
service: hid: Create abstracted pad structure
Diffstat (limited to 'src/hid_core/resources/npad')
| -rw-r--r-- | src/hid_core/resources/npad/npad.cpp | 8 | ||||
| -rw-r--r-- | src/hid_core/resources/npad/npad_data.cpp | 2 | ||||
| -rw-r--r-- | src/hid_core/resources/npad/npad_types.h | 99 | ||||
| -rw-r--r-- | src/hid_core/resources/npad/npad_vibration.cpp | 80 | ||||
| -rw-r--r-- | src/hid_core/resources/npad/npad_vibration.h | 34 |
5 files changed, 218 insertions, 5 deletions
diff --git a/src/hid_core/resources/npad/npad.cpp b/src/hid_core/resources/npad/npad.cpp index 1f8a0f8ab..97537a2e2 100644 --- a/src/hid_core/resources/npad/npad.cpp +++ b/src/hid_core/resources/npad/npad.cpp | |||
| @@ -193,7 +193,7 @@ void NPad::InitNewlyAddedController(u64 aruid, Core::HID::NpadIdType npad_id) { | |||
| 193 | case Core::HID::NpadStyleIndex::None: | 193 | case Core::HID::NpadStyleIndex::None: |
| 194 | ASSERT(false); | 194 | ASSERT(false); |
| 195 | break; | 195 | break; |
| 196 | case Core::HID::NpadStyleIndex::ProController: | 196 | case Core::HID::NpadStyleIndex::Fullkey: |
| 197 | shared_memory->fullkey_color.attribute = ColorAttribute::Ok; | 197 | shared_memory->fullkey_color.attribute = ColorAttribute::Ok; |
| 198 | shared_memory->fullkey_color.fullkey = body_colors.fullkey; | 198 | shared_memory->fullkey_color.fullkey = body_colors.fullkey; |
| 199 | shared_memory->battery_level_dual = battery_level.dual.battery_level; | 199 | shared_memory->battery_level_dual = battery_level.dual.battery_level; |
| @@ -491,7 +491,7 @@ void NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | |||
| 491 | case Core::HID::NpadStyleIndex::None: | 491 | case Core::HID::NpadStyleIndex::None: |
| 492 | ASSERT(false); | 492 | ASSERT(false); |
| 493 | break; | 493 | break; |
| 494 | case Core::HID::NpadStyleIndex::ProController: | 494 | case Core::HID::NpadStyleIndex::Fullkey: |
| 495 | case Core::HID::NpadStyleIndex::NES: | 495 | case Core::HID::NpadStyleIndex::NES: |
| 496 | case Core::HID::NpadStyleIndex::SNES: | 496 | case Core::HID::NpadStyleIndex::SNES: |
| 497 | case Core::HID::NpadStyleIndex::N64: | 497 | case Core::HID::NpadStyleIndex::N64: |
| @@ -1292,7 +1292,7 @@ Core::HID::SixAxisSensorProperties& NPad::GetSixaxisProperties( | |||
| 1292 | u64 aruid, const Core::HID::SixAxisSensorHandle& sixaxis_handle) { | 1292 | u64 aruid, const Core::HID::SixAxisSensorHandle& sixaxis_handle) { |
| 1293 | auto& controller = GetControllerFromHandle(aruid, sixaxis_handle); | 1293 | auto& controller = GetControllerFromHandle(aruid, sixaxis_handle); |
| 1294 | switch (sixaxis_handle.npad_type) { | 1294 | switch (sixaxis_handle.npad_type) { |
| 1295 | case Core::HID::NpadStyleIndex::ProController: | 1295 | case Core::HID::NpadStyleIndex::Fullkey: |
| 1296 | case Core::HID::NpadStyleIndex::Pokeball: | 1296 | case Core::HID::NpadStyleIndex::Pokeball: |
| 1297 | return controller.shared_memory->sixaxis_fullkey_properties; | 1297 | return controller.shared_memory->sixaxis_fullkey_properties; |
| 1298 | case Core::HID::NpadStyleIndex::Handheld: | 1298 | case Core::HID::NpadStyleIndex::Handheld: |
| @@ -1315,7 +1315,7 @@ const Core::HID::SixAxisSensorProperties& NPad::GetSixaxisProperties( | |||
| 1315 | u64 aruid, const Core::HID::SixAxisSensorHandle& sixaxis_handle) const { | 1315 | u64 aruid, const Core::HID::SixAxisSensorHandle& sixaxis_handle) const { |
| 1316 | const auto& controller = GetControllerFromHandle(aruid, sixaxis_handle); | 1316 | const auto& controller = GetControllerFromHandle(aruid, sixaxis_handle); |
| 1317 | switch (sixaxis_handle.npad_type) { | 1317 | switch (sixaxis_handle.npad_type) { |
| 1318 | case Core::HID::NpadStyleIndex::ProController: | 1318 | case Core::HID::NpadStyleIndex::Fullkey: |
| 1319 | case Core::HID::NpadStyleIndex::Pokeball: | 1319 | case Core::HID::NpadStyleIndex::Pokeball: |
| 1320 | return controller.shared_memory->sixaxis_fullkey_properties; | 1320 | return controller.shared_memory->sixaxis_fullkey_properties; |
| 1321 | case Core::HID::NpadStyleIndex::Handheld: | 1321 | case Core::HID::NpadStyleIndex::Handheld: |
diff --git a/src/hid_core/resources/npad/npad_data.cpp b/src/hid_core/resources/npad/npad_data.cpp index c7e9760cb..29ad5cb08 100644 --- a/src/hid_core/resources/npad/npad_data.cpp +++ b/src/hid_core/resources/npad/npad_data.cpp | |||
| @@ -151,7 +151,7 @@ Core::HID::NpadStyleSet NPadData::GetSupportedNpadStyleSet() const { | |||
| 151 | bool NPadData::IsNpadStyleIndexSupported(Core::HID::NpadStyleIndex style_index) const { | 151 | bool NPadData::IsNpadStyleIndexSupported(Core::HID::NpadStyleIndex style_index) const { |
| 152 | Core::HID::NpadStyleTag style = {supported_npad_style_set}; | 152 | Core::HID::NpadStyleTag style = {supported_npad_style_set}; |
| 153 | switch (style_index) { | 153 | switch (style_index) { |
| 154 | case Core::HID::NpadStyleIndex::ProController: | 154 | case Core::HID::NpadStyleIndex::Fullkey: |
| 155 | return style.fullkey.As<bool>(); | 155 | return style.fullkey.As<bool>(); |
| 156 | case Core::HID::NpadStyleIndex::Handheld: | 156 | case Core::HID::NpadStyleIndex::Handheld: |
| 157 | return style.handheld.As<bool>(); | 157 | return style.handheld.As<bool>(); |
diff --git a/src/hid_core/resources/npad/npad_types.h b/src/hid_core/resources/npad/npad_types.h index a02f9cf16..074dd40cf 100644 --- a/src/hid_core/resources/npad/npad_types.h +++ b/src/hid_core/resources/npad/npad_types.h | |||
| @@ -252,4 +252,103 @@ enum class NpadLagerType : u32 { | |||
| 252 | U, | 252 | U, |
| 253 | }; | 253 | }; |
| 254 | 254 | ||
| 255 | // nn::hidtypes::FeatureType | ||
| 256 | struct FeatureType { | ||
| 257 | union { | ||
| 258 | u64 raw{}; | ||
| 259 | BitField<0, 1, u64> has_left_analog_stick; | ||
| 260 | BitField<1, 1, u64> has_right_analog_stick; | ||
| 261 | BitField<2, 1, u64> has_left_joy_six_axis_sensor; | ||
| 262 | BitField<3, 1, u64> has_right_joy_six_axis_sensor; | ||
| 263 | BitField<4, 1, u64> has_fullkey_joy_six_axis_sensor; | ||
| 264 | BitField<5, 1, u64> has_left_lra_vibration_device; | ||
| 265 | BitField<6, 1, u64> has_right_lra_vibration_device; | ||
| 266 | BitField<7, 1, u64> has_gc_vibration_device; | ||
| 267 | BitField<8, 1, u64> has_erm_vibration_device; | ||
| 268 | BitField<9, 1, u64> has_left_joy_rail_bus; | ||
| 269 | BitField<10, 1, u64> has_right_joy_rail_bus; | ||
| 270 | BitField<11, 1, u64> has_internal_bus; | ||
| 271 | BitField<12, 1, u64> is_palma; | ||
| 272 | BitField<13, 1, u64> has_nfc; | ||
| 273 | BitField<14, 1, u64> has_ir_sensor; | ||
| 274 | BitField<15, 1, u64> is_analog_stick_calibration_supported; | ||
| 275 | BitField<16, 1, u64> is_six_axis_Sensor_user_calibration_supported; | ||
| 276 | BitField<17, 1, u64> has_left_right_joy_battery; | ||
| 277 | BitField<18, 1, u64> has_fullkey_battery; | ||
| 278 | BitField<19, 1, u64> is_disconnect_controller_if_battery_none; | ||
| 279 | BitField<20, 1, u64> has_controller_color; | ||
| 280 | BitField<21, 1, u64> has_grip_color; | ||
| 281 | BitField<22, 1, u64> has_identification_code; | ||
| 282 | BitField<23, 1, u64> has_bluetooth_address; | ||
| 283 | BitField<24, 1, u64> has_mcu; | ||
| 284 | BitField<25, 1, u64> has_notification_led; | ||
| 285 | BitField<26, 1, u64> has_directional_buttons; | ||
| 286 | BitField<27, 1, u64> has_indicator_led; | ||
| 287 | BitField<28, 1, u64> is_button_config_embedded_supported; | ||
| 288 | BitField<29, 1, u64> is_button_config_full_supported; | ||
| 289 | BitField<30, 1, u64> is_button_config_left_supported; | ||
| 290 | BitField<31, 1, u64> is_button_config_right_supported; | ||
| 291 | BitField<32, 1, u64> is_usb_hid_device; | ||
| 292 | BitField<33, 1, u64> is_kuina_device; | ||
| 293 | BitField<34, 1, u64> is_direct_usb_to_bt_switching_device; | ||
| 294 | BitField<35, 1, u64> is_normalize_analog_stick_with_inner_cross; | ||
| 295 | }; | ||
| 296 | }; | ||
| 297 | static_assert(sizeof(FeatureType) == 8, "FeatureType is an invalid size"); | ||
| 298 | |||
| 299 | // This is nn::hid::AssignmentStyle | ||
| 300 | struct AssignmentStyle { | ||
| 301 | union { | ||
| 302 | u32 raw{}; | ||
| 303 | BitField<0, 1, u32> is_external_assigned; | ||
| 304 | BitField<1, 1, u32> is_external_left_assigned; | ||
| 305 | BitField<2, 1, u32> is_external_right_assigned; | ||
| 306 | BitField<3, 1, u32> is_handheld_assigned; | ||
| 307 | BitField<4, 1, u32> is_handheld_left_assigned; | ||
| 308 | BitField<5, 1, u32> is_handheld_right_assigned; | ||
| 309 | }; | ||
| 310 | }; | ||
| 311 | static_assert(sizeof(AssignmentStyle) == 4, "AssignmentStyle is an invalid size"); | ||
| 312 | |||
| 313 | // This is nn::hid::server::IAbstractedPad::InternalFlags | ||
| 314 | struct InternalFlags { | ||
| 315 | union { | ||
| 316 | u32 raw{}; | ||
| 317 | BitField<0, 1, u32> is_bound; | ||
| 318 | BitField<1, 1, u32> is_connected; | ||
| 319 | BitField<2, 1, u32> is_battery_low_ovln_required; | ||
| 320 | BitField<3, 1, u32> is_battery_low_ovln_delay_required; | ||
| 321 | BitField<4, 1, u32> is_sample_recieved; | ||
| 322 | BitField<5, 1, u32> is_virtual_input; | ||
| 323 | BitField<6, 1, u32> is_wired; | ||
| 324 | BitField<8, 1, u32> use_center_clamp; | ||
| 325 | BitField<9, 1, u32> has_virtual_six_axis_sensor_acceleration; | ||
| 326 | BitField<10, 1, u32> has_virtual_six_axis_sensor_angle; | ||
| 327 | BitField<11, 1, u32> is_debug_pad; | ||
| 328 | }; | ||
| 329 | }; | ||
| 330 | static_assert(sizeof(InternalFlags) == 4, "InternalFlags is an invalid size"); | ||
| 331 | |||
| 332 | /// This is nn::hid::server::IAbstractedPad | ||
| 333 | struct IAbstractedPad { | ||
| 334 | InternalFlags internal_flags; | ||
| 335 | u64 controller_id; | ||
| 336 | u32 controller_number; | ||
| 337 | u64 low_battery_display_delay_time; | ||
| 338 | u64 low_battery_display_delay_interval; | ||
| 339 | FeatureType feature_set; | ||
| 340 | FeatureType disabled_feature_set; | ||
| 341 | AssignmentStyle assignment_style; | ||
| 342 | Core::HID::NpadStyleIndex device_type; | ||
| 343 | Core::HID::NpadInterfaceType interface_type; | ||
| 344 | Core::HID::NpadPowerInfo power_info; | ||
| 345 | u32 pad_state; | ||
| 346 | u32 button_mask; | ||
| 347 | u32 system_button_mask; | ||
| 348 | u8 indicator; | ||
| 349 | std::vector<f32> virtual_six_axis_sensor_acceleration; | ||
| 350 | std::vector<f32> virtual_six_axis_sensor_angle; | ||
| 351 | u64 xcd_handle; | ||
| 352 | u64 color; | ||
| 353 | }; | ||
| 255 | } // namespace Service::HID | 354 | } // namespace Service::HID |
diff --git a/src/hid_core/resources/npad/npad_vibration.cpp b/src/hid_core/resources/npad/npad_vibration.cpp new file mode 100644 index 000000000..3bdd55dec --- /dev/null +++ b/src/hid_core/resources/npad/npad_vibration.cpp | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #include "hid_core/hid_result.h" | ||
| 5 | #include "hid_core/resources/npad/npad_vibration.h" | ||
| 6 | |||
| 7 | namespace Service::HID { | ||
| 8 | |||
| 9 | NpadVibration::NpadVibration() {} | ||
| 10 | |||
| 11 | NpadVibration::~NpadVibration() = default; | ||
| 12 | |||
| 13 | Result NpadVibration::Activate() { | ||
| 14 | std::scoped_lock lock{mutex}; | ||
| 15 | |||
| 16 | const f32 master_volume = 1.0f; // nn::settings::system::GetVibrationMasterVolume(); | ||
| 17 | // if (master_volume < 0.0f || master_volume > 1.0f) { | ||
| 18 | // return ResultVibrationStrenghtOutOfRange; | ||
| 19 | // } | ||
| 20 | |||
| 21 | volume = master_volume; | ||
| 22 | return ResultSuccess; | ||
| 23 | } | ||
| 24 | |||
| 25 | Result NpadVibration::Deactivate() { | ||
| 26 | return ResultSuccess; | ||
| 27 | } | ||
| 28 | |||
| 29 | Result NpadVibration::SetVibrationMasterVolume(f32 master_volume) { | ||
| 30 | std::scoped_lock lock{mutex}; | ||
| 31 | |||
| 32 | if (master_volume < 0.0f && master_volume > 1.0f) { | ||
| 33 | return ResultVibrationStrenghtOutOfRange; | ||
| 34 | } | ||
| 35 | |||
| 36 | volume = master_volume; | ||
| 37 | // nn::settings::system::SetVibrationMasterVolume(master_volume); | ||
| 38 | |||
| 39 | return ResultSuccess; | ||
| 40 | } | ||
| 41 | |||
| 42 | Result NpadVibration::GetVibrationVolume(f32& out_volume) const { | ||
| 43 | std::scoped_lock lock{mutex}; | ||
| 44 | out_volume = volume; | ||
| 45 | return ResultSuccess; | ||
| 46 | } | ||
| 47 | |||
| 48 | Result NpadVibration::GetVibrationMasterVolume(f32& out_volume) const { | ||
| 49 | std::scoped_lock lock{mutex}; | ||
| 50 | |||
| 51 | const f32 master_volume = 1.0f; // nn::settings::system::GetVibrationMasterVolume(); | ||
| 52 | // if (master_volume < 0.0f || master_volume > 1.0f) { | ||
| 53 | // return ResultVibrationStrenghtOutOfRange; | ||
| 54 | // } | ||
| 55 | |||
| 56 | out_volume = master_volume; | ||
| 57 | return ResultSuccess; | ||
| 58 | } | ||
| 59 | |||
| 60 | Result NpadVibration::BeginPermitVibrationSession(u64 aruid) { | ||
| 61 | std::scoped_lock lock{mutex}; | ||
| 62 | session_aruid = aruid; | ||
| 63 | volume = 1.0; | ||
| 64 | return ResultSuccess; | ||
| 65 | } | ||
| 66 | |||
| 67 | Result NpadVibration::EndPermitVibrationSession() { | ||
| 68 | std::scoped_lock lock{mutex}; | ||
| 69 | |||
| 70 | const f32 master_volume = 1.0f; // nn::settings::system::GetVibrationMasterVolume(); | ||
| 71 | // if (master_volume < 0.0f || master_volume > 1.0f) { | ||
| 72 | // return ResultVibrationStrenghtOutOfRange; | ||
| 73 | // } | ||
| 74 | |||
| 75 | volume = master_volume; | ||
| 76 | session_aruid = 0; | ||
| 77 | return ResultSuccess; | ||
| 78 | } | ||
| 79 | |||
| 80 | } // namespace Service::HID | ||
diff --git a/src/hid_core/resources/npad/npad_vibration.h b/src/hid_core/resources/npad/npad_vibration.h new file mode 100644 index 000000000..0748aeffc --- /dev/null +++ b/src/hid_core/resources/npad/npad_vibration.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <mutex> | ||
| 7 | |||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "core/hle/result.h" | ||
| 10 | |||
| 11 | namespace Service::HID { | ||
| 12 | |||
| 13 | class NpadVibration final { | ||
| 14 | public: | ||
| 15 | explicit NpadVibration(); | ||
| 16 | ~NpadVibration(); | ||
| 17 | |||
| 18 | Result Activate(); | ||
| 19 | Result Deactivate(); | ||
| 20 | |||
| 21 | Result SetVibrationMasterVolume(f32 master_volume); | ||
| 22 | Result GetVibrationVolume(f32& out_volume) const; | ||
| 23 | Result GetVibrationMasterVolume(f32& out_volume) const; | ||
| 24 | |||
| 25 | Result BeginPermitVibrationSession(u64 aruid); | ||
| 26 | Result EndPermitVibrationSession(); | ||
| 27 | |||
| 28 | private: | ||
| 29 | f32 volume{}; | ||
| 30 | u64 session_aruid{}; | ||
| 31 | mutable std::mutex mutex; | ||
| 32 | }; | ||
| 33 | |||
| 34 | } // namespace Service::HID | ||