diff options
Diffstat (limited to 'src/input_common/helpers')
| -rw-r--r-- | src/input_common/helpers/joycon_driver.cpp | 43 | ||||
| -rw-r--r-- | src/input_common/helpers/joycon_driver.h | 3 | ||||
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/calibration.cpp | 22 | ||||
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/calibration.h | 10 | ||||
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/poller.cpp | 22 | ||||
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/poller.h | 4 | ||||
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/ringcon.cpp | 132 | ||||
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/ringcon.h | 38 |
8 files changed, 270 insertions, 4 deletions
diff --git a/src/input_common/helpers/joycon_driver.cpp b/src/input_common/helpers/joycon_driver.cpp index 5d0aeabf5..c0a03fe2e 100644 --- a/src/input_common/helpers/joycon_driver.cpp +++ b/src/input_common/helpers/joycon_driver.cpp | |||
| @@ -52,12 +52,18 @@ DriverResult JoyconDriver::InitializeDevice() { | |||
| 52 | error_counter = 0; | 52 | error_counter = 0; |
| 53 | hidapi_handle->packet_counter = 0; | 53 | hidapi_handle->packet_counter = 0; |
| 54 | 54 | ||
| 55 | // Reset external device status | ||
| 56 | starlink_connected = false; | ||
| 57 | ring_connected = false; | ||
| 58 | amiibo_detected = false; | ||
| 59 | |||
| 55 | // Set HW default configuration | 60 | // Set HW default configuration |
| 56 | vibration_enabled = true; | 61 | vibration_enabled = true; |
| 57 | motion_enabled = true; | 62 | motion_enabled = true; |
| 58 | hidbus_enabled = false; | 63 | hidbus_enabled = false; |
| 59 | nfc_enabled = false; | 64 | nfc_enabled = false; |
| 60 | passive_enabled = false; | 65 | passive_enabled = false; |
| 66 | irs_enabled = false; | ||
| 61 | gyro_sensitivity = Joycon::GyroSensitivity::DPS2000; | 67 | gyro_sensitivity = Joycon::GyroSensitivity::DPS2000; |
| 62 | gyro_performance = Joycon::GyroPerformance::HZ833; | 68 | gyro_performance = Joycon::GyroPerformance::HZ833; |
| 63 | accelerometer_sensitivity = Joycon::AccelerometerSensitivity::G8; | 69 | accelerometer_sensitivity = Joycon::AccelerometerSensitivity::G8; |
| @@ -66,6 +72,7 @@ DriverResult JoyconDriver::InitializeDevice() { | |||
| 66 | // Initialize HW Protocols | 72 | // Initialize HW Protocols |
| 67 | calibration_protocol = std::make_unique<CalibrationProtocol>(hidapi_handle); | 73 | calibration_protocol = std::make_unique<CalibrationProtocol>(hidapi_handle); |
| 68 | generic_protocol = std::make_unique<GenericProtocol>(hidapi_handle); | 74 | generic_protocol = std::make_unique<GenericProtocol>(hidapi_handle); |
| 75 | ring_protocol = std::make_unique<RingConProtocol>(hidapi_handle); | ||
| 69 | rumble_protocol = std::make_unique<RumbleProtocol>(hidapi_handle); | 76 | rumble_protocol = std::make_unique<RumbleProtocol>(hidapi_handle); |
| 70 | 77 | ||
| 71 | // Get fixed joycon info | 78 | // Get fixed joycon info |
| @@ -172,9 +179,23 @@ void JoyconDriver::OnNewData(std::span<u8> buffer) { | |||
| 172 | .accelerometer_sensitivity = accelerometer_sensitivity, | 179 | .accelerometer_sensitivity = accelerometer_sensitivity, |
| 173 | }; | 180 | }; |
| 174 | 181 | ||
| 182 | // TODO: Remove this when calibration is properly loaded and not calculated | ||
| 183 | if (ring_connected && report_mode == InputReport::STANDARD_FULL_60HZ) { | ||
| 184 | InputReportActive data{}; | ||
| 185 | memcpy(&data, buffer.data(), sizeof(InputReportActive)); | ||
| 186 | calibration_protocol->GetRingCalibration(ring_calibration, data.ring_input); | ||
| 187 | } | ||
| 188 | |||
| 189 | const RingStatus ring_status{ | ||
| 190 | .is_enabled = ring_connected, | ||
| 191 | .default_value = ring_calibration.default_value, | ||
| 192 | .max_value = ring_calibration.max_value, | ||
| 193 | .min_value = ring_calibration.min_value, | ||
| 194 | }; | ||
| 195 | |||
| 175 | switch (report_mode) { | 196 | switch (report_mode) { |
| 176 | case InputReport::STANDARD_FULL_60HZ: | 197 | case InputReport::STANDARD_FULL_60HZ: |
| 177 | joycon_poller->ReadActiveMode(buffer, motion_status); | 198 | joycon_poller->ReadActiveMode(buffer, motion_status, ring_status); |
| 178 | break; | 199 | break; |
| 179 | case InputReport::NFC_IR_MODE_60HZ: | 200 | case InputReport::NFC_IR_MODE_60HZ: |
| 180 | joycon_poller->ReadNfcIRMode(buffer, motion_status); | 201 | joycon_poller->ReadNfcIRMode(buffer, motion_status); |
| @@ -204,6 +225,26 @@ void JoyconDriver::SetPollingMode() { | |||
| 204 | generic_protocol->EnableImu(false); | 225 | generic_protocol->EnableImu(false); |
| 205 | } | 226 | } |
| 206 | 227 | ||
| 228 | if (ring_protocol->IsEnabled()) { | ||
| 229 | ring_connected = false; | ||
| 230 | ring_protocol->DisableRingCon(); | ||
| 231 | } | ||
| 232 | |||
| 233 | if (hidbus_enabled && supported_features.hidbus) { | ||
| 234 | auto result = ring_protocol->EnableRingCon(); | ||
| 235 | if (result == DriverResult::Success) { | ||
| 236 | result = ring_protocol->StartRingconPolling(); | ||
| 237 | } | ||
| 238 | if (result == DriverResult::Success) { | ||
| 239 | ring_connected = true; | ||
| 240 | disable_input_thread = false; | ||
| 241 | return; | ||
| 242 | } | ||
| 243 | ring_connected = false; | ||
| 244 | ring_protocol->DisableRingCon(); | ||
| 245 | LOG_ERROR(Input, "Error enabling Ringcon"); | ||
| 246 | } | ||
| 247 | |||
| 207 | if (passive_enabled && supported_features.passive) { | 248 | if (passive_enabled && supported_features.passive) { |
| 208 | const auto result = generic_protocol->EnablePassiveMode(); | 249 | const auto result = generic_protocol->EnablePassiveMode(); |
| 209 | if (result == DriverResult::Success) { | 250 | if (result == DriverResult::Success) { |
diff --git a/src/input_common/helpers/joycon_driver.h b/src/input_common/helpers/joycon_driver.h index 48ba859f4..dc5d60221 100644 --- a/src/input_common/helpers/joycon_driver.h +++ b/src/input_common/helpers/joycon_driver.h | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | #include "input_common/helpers/joycon_protocol/generic_functions.h" | 12 | #include "input_common/helpers/joycon_protocol/generic_functions.h" |
| 13 | #include "input_common/helpers/joycon_protocol/joycon_types.h" | 13 | #include "input_common/helpers/joycon_protocol/joycon_types.h" |
| 14 | #include "input_common/helpers/joycon_protocol/poller.h" | 14 | #include "input_common/helpers/joycon_protocol/poller.h" |
| 15 | #include "input_common/helpers/joycon_protocol/ringcon.h" | ||
| 15 | #include "input_common/helpers/joycon_protocol/rumble.h" | 16 | #include "input_common/helpers/joycon_protocol/rumble.h" |
| 16 | 17 | ||
| 17 | namespace InputCommon::Joycon { | 18 | namespace InputCommon::Joycon { |
| @@ -86,6 +87,7 @@ private: | |||
| 86 | std::unique_ptr<CalibrationProtocol> calibration_protocol = nullptr; | 87 | std::unique_ptr<CalibrationProtocol> calibration_protocol = nullptr; |
| 87 | std::unique_ptr<GenericProtocol> generic_protocol = nullptr; | 88 | std::unique_ptr<GenericProtocol> generic_protocol = nullptr; |
| 88 | std::unique_ptr<JoyconPoller> joycon_poller = nullptr; | 89 | std::unique_ptr<JoyconPoller> joycon_poller = nullptr; |
| 90 | std::unique_ptr<RingConProtocol> ring_protocol = nullptr; | ||
| 89 | std::unique_ptr<RumbleProtocol> rumble_protocol = nullptr; | 91 | std::unique_ptr<RumbleProtocol> rumble_protocol = nullptr; |
| 90 | 92 | ||
| 91 | // Connection status | 93 | // Connection status |
| @@ -118,6 +120,7 @@ private: | |||
| 118 | JoyStickCalibration left_stick_calibration{}; | 120 | JoyStickCalibration left_stick_calibration{}; |
| 119 | JoyStickCalibration right_stick_calibration{}; | 121 | JoyStickCalibration right_stick_calibration{}; |
| 120 | MotionCalibration motion_calibration{}; | 122 | MotionCalibration motion_calibration{}; |
| 123 | RingCalibration ring_calibration{}; | ||
| 121 | 124 | ||
| 122 | // Fixed joycon info | 125 | // Fixed joycon info |
| 123 | FirmwareVersion version{}; | 126 | FirmwareVersion version{}; |
diff --git a/src/input_common/helpers/joycon_protocol/calibration.cpp b/src/input_common/helpers/joycon_protocol/calibration.cpp index 5c29af545..ce1ff7061 100644 --- a/src/input_common/helpers/joycon_protocol/calibration.cpp +++ b/src/input_common/helpers/joycon_protocol/calibration.cpp | |||
| @@ -128,6 +128,28 @@ DriverResult CalibrationProtocol::GetImuCalibration(MotionCalibration& calibrati | |||
| 128 | return result; | 128 | return result; |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | DriverResult CalibrationProtocol::GetRingCalibration(RingCalibration& calibration, | ||
| 132 | s16 current_value) { | ||
| 133 | // TODO: Get default calibration form ring itself | ||
| 134 | if (ring_data_max == 0 && ring_data_min == 0) { | ||
| 135 | ring_data_max = current_value + 800; | ||
| 136 | ring_data_min = current_value - 800; | ||
| 137 | ring_data_default = current_value; | ||
| 138 | } | ||
| 139 | if (ring_data_max < current_value) { | ||
| 140 | ring_data_max = current_value; | ||
| 141 | } | ||
| 142 | if (ring_data_min > current_value) { | ||
| 143 | ring_data_min = current_value; | ||
| 144 | } | ||
| 145 | calibration = { | ||
| 146 | .default_value = ring_data_default, | ||
| 147 | .max_value = ring_data_max, | ||
| 148 | .min_value = ring_data_min, | ||
| 149 | }; | ||
| 150 | return DriverResult::Success; | ||
| 151 | } | ||
| 152 | |||
| 131 | void CalibrationProtocol::ValidateCalibration(JoyStickCalibration& calibration) { | 153 | void CalibrationProtocol::ValidateCalibration(JoyStickCalibration& calibration) { |
| 132 | constexpr u16 DefaultStickCenter{2048}; | 154 | constexpr u16 DefaultStickCenter{2048}; |
| 133 | constexpr u16 DefaultStickRange{1740}; | 155 | constexpr u16 DefaultStickRange{1740}; |
diff --git a/src/input_common/helpers/joycon_protocol/calibration.h b/src/input_common/helpers/joycon_protocol/calibration.h index 38214eed4..32ddef4b8 100644 --- a/src/input_common/helpers/joycon_protocol/calibration.h +++ b/src/input_common/helpers/joycon_protocol/calibration.h | |||
| @@ -46,9 +46,19 @@ public: | |||
| 46 | */ | 46 | */ |
| 47 | DriverResult GetImuCalibration(MotionCalibration& calibration); | 47 | DriverResult GetImuCalibration(MotionCalibration& calibration); |
| 48 | 48 | ||
| 49 | /** | ||
| 50 | * Calculates on run time the proper calibration of the ring controller | ||
| 51 | * @returns RingCalibration of the ring sensor | ||
| 52 | */ | ||
| 53 | DriverResult GetRingCalibration(RingCalibration& calibration, s16 current_value); | ||
| 54 | |||
| 49 | private: | 55 | private: |
| 50 | void ValidateCalibration(JoyStickCalibration& calibration); | 56 | void ValidateCalibration(JoyStickCalibration& calibration); |
| 51 | void ValidateCalibration(MotionCalibration& calibration); | 57 | void ValidateCalibration(MotionCalibration& calibration); |
| 58 | |||
| 59 | s16 ring_data_max = 0; | ||
| 60 | s16 ring_data_default = 0; | ||
| 61 | s16 ring_data_min = 0; | ||
| 52 | }; | 62 | }; |
| 53 | 63 | ||
| 54 | } // namespace InputCommon::Joycon | 64 | } // namespace InputCommon::Joycon |
diff --git a/src/input_common/helpers/joycon_protocol/poller.cpp b/src/input_common/helpers/joycon_protocol/poller.cpp index 341479c0c..cb76e1e06 100644 --- a/src/input_common/helpers/joycon_protocol/poller.cpp +++ b/src/input_common/helpers/joycon_protocol/poller.cpp | |||
| @@ -16,7 +16,8 @@ void JoyconPoller::SetCallbacks(const Joycon::JoyconCallbacks& callbacks_) { | |||
| 16 | callbacks = std::move(callbacks_); | 16 | callbacks = std::move(callbacks_); |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | void JoyconPoller::ReadActiveMode(std::span<u8> buffer, const MotionStatus& motion_status) { | 19 | void JoyconPoller::ReadActiveMode(std::span<u8> buffer, const MotionStatus& motion_status, |
| 20 | const RingStatus& ring_status) { | ||
| 20 | InputReportActive data{}; | 21 | InputReportActive data{}; |
| 21 | memcpy(&data, buffer.data(), sizeof(InputReportActive)); | 22 | memcpy(&data, buffer.data(), sizeof(InputReportActive)); |
| 22 | 23 | ||
| @@ -36,6 +37,10 @@ void JoyconPoller::ReadActiveMode(std::span<u8> buffer, const MotionStatus& moti | |||
| 36 | break; | 37 | break; |
| 37 | } | 38 | } |
| 38 | 39 | ||
| 40 | if (ring_status.is_enabled) { | ||
| 41 | UpdateRing(data.ring_input, ring_status); | ||
| 42 | } | ||
| 43 | |||
| 39 | callbacks.on_battery_data(data.battery_status); | 44 | callbacks.on_battery_data(data.battery_status); |
| 40 | } | 45 | } |
| 41 | 46 | ||
| @@ -62,13 +67,26 @@ void JoyconPoller::ReadPassiveMode(std::span<u8> buffer) { | |||
| 62 | 67 | ||
| 63 | void JoyconPoller::ReadNfcIRMode(std::span<u8> buffer, const MotionStatus& motion_status) { | 68 | void JoyconPoller::ReadNfcIRMode(std::span<u8> buffer, const MotionStatus& motion_status) { |
| 64 | // This mode is compatible with the active mode | 69 | // This mode is compatible with the active mode |
| 65 | ReadActiveMode(buffer, motion_status); | 70 | ReadActiveMode(buffer, motion_status, {}); |
| 66 | } | 71 | } |
| 67 | 72 | ||
| 68 | void JoyconPoller::UpdateColor(const Color& color) { | 73 | void JoyconPoller::UpdateColor(const Color& color) { |
| 69 | callbacks.on_color_data(color); | 74 | callbacks.on_color_data(color); |
| 70 | } | 75 | } |
| 71 | 76 | ||
| 77 | void JoyconPoller::UpdateRing(s16 value, const RingStatus& ring_status) { | ||
| 78 | float normalized_value = static_cast<float>(value - ring_status.default_value); | ||
| 79 | if (normalized_value > 0) { | ||
| 80 | normalized_value = normalized_value / | ||
| 81 | static_cast<float>(ring_status.max_value - ring_status.default_value); | ||
| 82 | } | ||
| 83 | if (normalized_value < 0) { | ||
| 84 | normalized_value = normalized_value / | ||
| 85 | static_cast<float>(ring_status.default_value - ring_status.min_value); | ||
| 86 | } | ||
| 87 | callbacks.on_ring_data(normalized_value); | ||
| 88 | } | ||
| 89 | |||
| 72 | void JoyconPoller::UpdateActiveLeftPadInput(const InputReportActive& input, | 90 | void JoyconPoller::UpdateActiveLeftPadInput(const InputReportActive& input, |
| 73 | const MotionStatus& motion_status) { | 91 | const MotionStatus& motion_status) { |
| 74 | static constexpr std::array<Joycon::PadButton, 11> left_buttons{ | 92 | static constexpr std::array<Joycon::PadButton, 11> left_buttons{ |
diff --git a/src/input_common/helpers/joycon_protocol/poller.h b/src/input_common/helpers/joycon_protocol/poller.h index fff681d0a..68b14b8ba 100644 --- a/src/input_common/helpers/joycon_protocol/poller.h +++ b/src/input_common/helpers/joycon_protocol/poller.h | |||
| @@ -28,12 +28,14 @@ public: | |||
| 28 | void ReadPassiveMode(std::span<u8> buffer); | 28 | void ReadPassiveMode(std::span<u8> buffer); |
| 29 | 29 | ||
| 30 | /// Handles data from active packages | 30 | /// Handles data from active packages |
| 31 | void ReadActiveMode(std::span<u8> buffer, const MotionStatus& motion_status); | 31 | void ReadActiveMode(std::span<u8> buffer, const MotionStatus& motion_status, |
| 32 | const RingStatus& ring_status); | ||
| 32 | 33 | ||
| 33 | /// Handles data from nfc or ir packages | 34 | /// Handles data from nfc or ir packages |
| 34 | void ReadNfcIRMode(std::span<u8> buffer, const MotionStatus& motion_status); | 35 | void ReadNfcIRMode(std::span<u8> buffer, const MotionStatus& motion_status); |
| 35 | 36 | ||
| 36 | void UpdateColor(const Color& color); | 37 | void UpdateColor(const Color& color); |
| 38 | void UpdateRing(s16 value, const RingStatus& ring_status); | ||
| 37 | 39 | ||
| 38 | private: | 40 | private: |
| 39 | void UpdateActiveLeftPadInput(const InputReportActive& input, | 41 | void UpdateActiveLeftPadInput(const InputReportActive& input, |
diff --git a/src/input_common/helpers/joycon_protocol/ringcon.cpp b/src/input_common/helpers/joycon_protocol/ringcon.cpp new file mode 100644 index 000000000..2d137b85d --- /dev/null +++ b/src/input_common/helpers/joycon_protocol/ringcon.cpp | |||
| @@ -0,0 +1,132 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "common/logging/log.h" | ||
| 5 | #include "input_common/helpers/joycon_protocol/ringcon.h" | ||
| 6 | |||
| 7 | namespace InputCommon::Joycon { | ||
| 8 | |||
| 9 | RingConProtocol::RingConProtocol(std::shared_ptr<JoyconHandle> handle) | ||
| 10 | : JoyconCommonProtocol(handle) {} | ||
| 11 | |||
| 12 | DriverResult RingConProtocol::EnableRingCon() { | ||
| 13 | LOG_DEBUG(Input, "Enable Ringcon"); | ||
| 14 | DriverResult result{DriverResult::Success}; | ||
| 15 | SetBlocking(); | ||
| 16 | |||
| 17 | if (result == DriverResult::Success) { | ||
| 18 | result = SetReportMode(ReportMode::STANDARD_FULL_60HZ); | ||
| 19 | } | ||
| 20 | if (result == DriverResult::Success) { | ||
| 21 | result = EnableMCU(true); | ||
| 22 | } | ||
| 23 | if (result == DriverResult::Success) { | ||
| 24 | const MCUConfig config{ | ||
| 25 | .command = MCUCommand::ConfigureMCU, | ||
| 26 | .sub_command = MCUSubCommand::SetDeviceMode, | ||
| 27 | .mode = MCUMode::Standby, | ||
| 28 | .crc = {}, | ||
| 29 | }; | ||
| 30 | result = ConfigureMCU(config); | ||
| 31 | } | ||
| 32 | |||
| 33 | SetNonBlocking(); | ||
| 34 | return result; | ||
| 35 | } | ||
| 36 | |||
| 37 | DriverResult RingConProtocol::DisableRingCon() { | ||
| 38 | LOG_DEBUG(Input, "Disable RingCon"); | ||
| 39 | DriverResult result{DriverResult::Success}; | ||
| 40 | SetBlocking(); | ||
| 41 | |||
| 42 | if (result == DriverResult::Success) { | ||
| 43 | result = EnableMCU(false); | ||
| 44 | } | ||
| 45 | |||
| 46 | is_enabled = false; | ||
| 47 | |||
| 48 | SetNonBlocking(); | ||
| 49 | return result; | ||
| 50 | } | ||
| 51 | |||
| 52 | DriverResult RingConProtocol::StartRingconPolling() { | ||
| 53 | LOG_DEBUG(Input, "Enable Ringcon"); | ||
| 54 | bool is_connected = false; | ||
| 55 | DriverResult result{DriverResult::Success}; | ||
| 56 | SetBlocking(); | ||
| 57 | |||
| 58 | if (result == DriverResult::Success) { | ||
| 59 | result = WaitSetMCUMode(ReportMode::STANDARD_FULL_60HZ, MCUMode::Standby); | ||
| 60 | } | ||
| 61 | if (result == DriverResult::Success) { | ||
| 62 | result = IsRingConnected(is_connected); | ||
| 63 | } | ||
| 64 | if (result == DriverResult::Success && is_connected) { | ||
| 65 | LOG_INFO(Input, "Ringcon detected"); | ||
| 66 | result = ConfigureRing(); | ||
| 67 | } | ||
| 68 | if (result == DriverResult::Success) { | ||
| 69 | is_enabled = true; | ||
| 70 | } | ||
| 71 | |||
| 72 | SetNonBlocking(); | ||
| 73 | return result; | ||
| 74 | } | ||
| 75 | |||
| 76 | DriverResult RingConProtocol::IsRingConnected(bool& is_connected) { | ||
| 77 | LOG_DEBUG(Input, "IsRingConnected"); | ||
| 78 | constexpr std::size_t max_tries = 28; | ||
| 79 | std::vector<u8> output; | ||
| 80 | std::size_t tries = 0; | ||
| 81 | is_connected = false; | ||
| 82 | |||
| 83 | do { | ||
| 84 | std::vector<u8> empty_data(0); | ||
| 85 | const auto result = SendSubCommand(SubCommand::UNKNOWN_RINGCON, empty_data, output); | ||
| 86 | |||
| 87 | if (result != DriverResult::Success) { | ||
| 88 | return result; | ||
| 89 | } | ||
| 90 | |||
| 91 | if (tries++ >= max_tries) { | ||
| 92 | return DriverResult::NoDeviceDetected; | ||
| 93 | } | ||
| 94 | } while (output[14] != 0x59 || output[16] != 0x20); | ||
| 95 | |||
| 96 | is_connected = true; | ||
| 97 | return DriverResult::Success; | ||
| 98 | } | ||
| 99 | |||
| 100 | DriverResult RingConProtocol::ConfigureRing() { | ||
| 101 | LOG_DEBUG(Input, "ConfigureRing"); | ||
| 102 | constexpr std::size_t max_tries = 28; | ||
| 103 | DriverResult result{DriverResult::Success}; | ||
| 104 | std::vector<u8> output; | ||
| 105 | std::size_t tries = 0; | ||
| 106 | |||
| 107 | do { | ||
| 108 | std::vector<u8> ring_config{0x06, 0x03, 0x25, 0x06, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x16, | ||
| 109 | 0xED, 0x34, 0x36, 0x00, 0x00, 0x00, 0x0A, 0x64, 0x0B, 0xE6, | ||
| 110 | 0xA9, 0x22, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 111 | 0x00, 0x00, 0x90, 0xA8, 0xE1, 0x34, 0x36}; | ||
| 112 | result = SendSubCommand(SubCommand::UNKNOWN_RINGCON3, ring_config, output); | ||
| 113 | |||
| 114 | if (result != DriverResult::Success) { | ||
| 115 | return result; | ||
| 116 | } | ||
| 117 | if (tries++ >= max_tries) { | ||
| 118 | return DriverResult::NoDeviceDetected; | ||
| 119 | } | ||
| 120 | } while (output[14] != 0x5C); | ||
| 121 | |||
| 122 | std::vector<u8> ringcon_data{0x04, 0x01, 0x01, 0x02}; | ||
| 123 | result = SendSubCommand(SubCommand::UNKNOWN_RINGCON2, ringcon_data, output); | ||
| 124 | |||
| 125 | return result; | ||
| 126 | } | ||
| 127 | |||
| 128 | bool RingConProtocol::IsEnabled() { | ||
| 129 | return is_enabled; | ||
| 130 | } | ||
| 131 | |||
| 132 | } // namespace InputCommon::Joycon | ||
diff --git a/src/input_common/helpers/joycon_protocol/ringcon.h b/src/input_common/helpers/joycon_protocol/ringcon.h new file mode 100644 index 000000000..0c25de23e --- /dev/null +++ b/src/input_common/helpers/joycon_protocol/ringcon.h | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | // Based on dkms-hid-nintendo implementation, CTCaer joycon toolkit and dekuNukem reverse | ||
| 5 | // engineering https://github.com/nicman23/dkms-hid-nintendo/blob/master/src/hid-nintendo.c | ||
| 6 | // https://github.com/CTCaer/jc_toolkit | ||
| 7 | // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering | ||
| 8 | |||
| 9 | #pragma once | ||
| 10 | |||
| 11 | #include <vector> | ||
| 12 | |||
| 13 | #include "input_common/helpers/joycon_protocol/common_protocol.h" | ||
| 14 | #include "input_common/helpers/joycon_protocol/joycon_types.h" | ||
| 15 | |||
| 16 | namespace InputCommon::Joycon { | ||
| 17 | |||
| 18 | class RingConProtocol final : private JoyconCommonProtocol { | ||
| 19 | public: | ||
| 20 | RingConProtocol(std::shared_ptr<JoyconHandle> handle); | ||
| 21 | |||
| 22 | DriverResult EnableRingCon(); | ||
| 23 | |||
| 24 | DriverResult DisableRingCon(); | ||
| 25 | |||
| 26 | DriverResult StartRingconPolling(); | ||
| 27 | |||
| 28 | bool IsEnabled(); | ||
| 29 | |||
| 30 | private: | ||
| 31 | DriverResult IsRingConnected(bool& is_connected); | ||
| 32 | |||
| 33 | DriverResult ConfigureRing(); | ||
| 34 | |||
| 35 | bool is_enabled{}; | ||
| 36 | }; | ||
| 37 | |||
| 38 | } // namespace InputCommon::Joycon | ||