diff options
| author | 2023-01-24 09:29:37 -0500 | |
|---|---|---|
| committer | 2023-01-24 09:29:37 -0500 | |
| commit | a68af583ea378b48e2ed5a19f519a815ba89e40f (patch) | |
| tree | 2983c14a7d4bc2797259c7d97462a439bec629f3 /src/input_common/helpers/joycon_protocol/generic_functions.cpp | |
| parent | Merge pull request #9555 from abouvier/catch2-update (diff) | |
| parent | core: hid: Make use of SCOPE_EXIT and SCOPE_GUARD where applicable (diff) | |
| download | yuzu-a68af583ea378b48e2ed5a19f519a815ba89e40f.tar.gz yuzu-a68af583ea378b48e2ed5a19f519a815ba89e40f.tar.xz yuzu-a68af583ea378b48e2ed5a19f519a815ba89e40f.zip | |
Merge pull request #9492 from german77/joycon_release
Input_common: Implement custom joycon driver v2
Diffstat (limited to 'src/input_common/helpers/joycon_protocol/generic_functions.cpp')
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/generic_functions.cpp | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/src/input_common/helpers/joycon_protocol/generic_functions.cpp b/src/input_common/helpers/joycon_protocol/generic_functions.cpp new file mode 100644 index 000000000..52bb8b61a --- /dev/null +++ b/src/input_common/helpers/joycon_protocol/generic_functions.cpp | |||
| @@ -0,0 +1,125 @@ | |||
| 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/generic_functions.h" | ||
| 6 | |||
| 7 | namespace InputCommon::Joycon { | ||
| 8 | |||
| 9 | GenericProtocol::GenericProtocol(std::shared_ptr<JoyconHandle> handle) | ||
| 10 | : JoyconCommonProtocol(std::move(handle)) {} | ||
| 11 | |||
| 12 | DriverResult GenericProtocol::EnablePassiveMode() { | ||
| 13 | ScopedSetBlocking sb(this); | ||
| 14 | return SetReportMode(ReportMode::SIMPLE_HID_MODE); | ||
| 15 | } | ||
| 16 | |||
| 17 | DriverResult GenericProtocol::EnableActiveMode() { | ||
| 18 | ScopedSetBlocking sb(this); | ||
| 19 | return SetReportMode(ReportMode::STANDARD_FULL_60HZ); | ||
| 20 | } | ||
| 21 | |||
| 22 | DriverResult GenericProtocol::GetDeviceInfo(DeviceInfo& device_info) { | ||
| 23 | ScopedSetBlocking sb(this); | ||
| 24 | std::vector<u8> output; | ||
| 25 | |||
| 26 | const auto result = SendSubCommand(SubCommand::REQ_DEV_INFO, {}, output); | ||
| 27 | |||
| 28 | device_info = {}; | ||
| 29 | if (result == DriverResult::Success) { | ||
| 30 | memcpy(&device_info, output.data(), sizeof(DeviceInfo)); | ||
| 31 | } | ||
| 32 | |||
| 33 | return result; | ||
| 34 | } | ||
| 35 | |||
| 36 | DriverResult GenericProtocol::GetControllerType(ControllerType& controller_type) { | ||
| 37 | return GetDeviceType(controller_type); | ||
| 38 | } | ||
| 39 | |||
| 40 | DriverResult GenericProtocol::EnableImu(bool enable) { | ||
| 41 | ScopedSetBlocking sb(this); | ||
| 42 | const std::array<u8, 1> buffer{static_cast<u8>(enable ? 1 : 0)}; | ||
| 43 | return SendSubCommand(SubCommand::ENABLE_IMU, buffer); | ||
| 44 | } | ||
| 45 | |||
| 46 | DriverResult GenericProtocol::SetImuConfig(GyroSensitivity gsen, GyroPerformance gfrec, | ||
| 47 | AccelerometerSensitivity asen, | ||
| 48 | AccelerometerPerformance afrec) { | ||
| 49 | ScopedSetBlocking sb(this); | ||
| 50 | const std::array<u8, 4> buffer{static_cast<u8>(gsen), static_cast<u8>(asen), | ||
| 51 | static_cast<u8>(gfrec), static_cast<u8>(afrec)}; | ||
| 52 | return SendSubCommand(SubCommand::SET_IMU_SENSITIVITY, buffer); | ||
| 53 | } | ||
| 54 | |||
| 55 | DriverResult GenericProtocol::GetBattery(u32& battery_level) { | ||
| 56 | // This function is meant to request the high resolution battery status | ||
| 57 | battery_level = 0; | ||
| 58 | return DriverResult::NotSupported; | ||
| 59 | } | ||
| 60 | |||
| 61 | DriverResult GenericProtocol::GetColor(Color& color) { | ||
| 62 | ScopedSetBlocking sb(this); | ||
| 63 | std::vector<u8> buffer; | ||
| 64 | const auto result = ReadSPI(CalAddr::COLOR_DATA, 12, buffer); | ||
| 65 | |||
| 66 | color = {}; | ||
| 67 | if (result == DriverResult::Success) { | ||
| 68 | color.body = static_cast<u32>((buffer[0] << 16) | (buffer[1] << 8) | buffer[2]); | ||
| 69 | color.buttons = static_cast<u32>((buffer[3] << 16) | (buffer[4] << 8) | buffer[5]); | ||
| 70 | color.left_grip = static_cast<u32>((buffer[6] << 16) | (buffer[7] << 8) | buffer[8]); | ||
| 71 | color.right_grip = static_cast<u32>((buffer[9] << 16) | (buffer[10] << 8) | buffer[11]); | ||
| 72 | } | ||
| 73 | |||
| 74 | return result; | ||
| 75 | } | ||
| 76 | |||
| 77 | DriverResult GenericProtocol::GetSerialNumber(SerialNumber& serial_number) { | ||
| 78 | ScopedSetBlocking sb(this); | ||
| 79 | std::vector<u8> buffer; | ||
| 80 | const auto result = ReadSPI(CalAddr::SERIAL_NUMBER, 16, buffer); | ||
| 81 | |||
| 82 | serial_number = {}; | ||
| 83 | if (result == DriverResult::Success) { | ||
| 84 | memcpy(serial_number.data(), buffer.data() + 1, sizeof(SerialNumber)); | ||
| 85 | } | ||
| 86 | |||
| 87 | return result; | ||
| 88 | } | ||
| 89 | |||
| 90 | DriverResult GenericProtocol::GetTemperature(u32& temperature) { | ||
| 91 | // Not all devices have temperature sensor | ||
| 92 | temperature = 25; | ||
| 93 | return DriverResult::NotSupported; | ||
| 94 | } | ||
| 95 | |||
| 96 | DriverResult GenericProtocol::GetVersionNumber(FirmwareVersion& version) { | ||
| 97 | DeviceInfo device_info{}; | ||
| 98 | |||
| 99 | const auto result = GetDeviceInfo(device_info); | ||
| 100 | version = device_info.firmware; | ||
| 101 | |||
| 102 | return result; | ||
| 103 | } | ||
| 104 | |||
| 105 | DriverResult GenericProtocol::SetHomeLight() { | ||
| 106 | ScopedSetBlocking sb(this); | ||
| 107 | static constexpr std::array<u8, 3> buffer{0x0f, 0xf0, 0x00}; | ||
| 108 | return SendSubCommand(SubCommand::SET_HOME_LIGHT, buffer); | ||
| 109 | } | ||
| 110 | |||
| 111 | DriverResult GenericProtocol::SetLedBusy() { | ||
| 112 | return DriverResult::NotSupported; | ||
| 113 | } | ||
| 114 | |||
| 115 | DriverResult GenericProtocol::SetLedPattern(u8 leds) { | ||
| 116 | ScopedSetBlocking sb(this); | ||
| 117 | const std::array<u8, 1> buffer{leds}; | ||
| 118 | return SendSubCommand(SubCommand::SET_PLAYER_LIGHTS, buffer); | ||
| 119 | } | ||
| 120 | |||
| 121 | DriverResult GenericProtocol::SetLedBlinkPattern(u8 leds) { | ||
| 122 | return SetLedPattern(static_cast<u8>(leds << 4)); | ||
| 123 | } | ||
| 124 | |||
| 125 | } // namespace InputCommon::Joycon | ||