diff options
| author | 2022-12-20 14:30:03 -0600 | |
|---|---|---|
| committer | 2023-01-19 18:05:21 -0600 | |
| commit | 594b2ade6d8d829c65166aebe12f5eb3463a6fe9 (patch) | |
| tree | d6d8013f6252cc9051429f39da255fe6937c8346 /src/input_common/helpers/joycon_protocol/generic_functions.h | |
| parent | input_common: Add joycon low level functions (diff) | |
| download | yuzu-594b2ade6d8d829c65166aebe12f5eb3463a6fe9.tar.gz yuzu-594b2ade6d8d829c65166aebe12f5eb3463a6fe9.tar.xz yuzu-594b2ade6d8d829c65166aebe12f5eb3463a6fe9.zip | |
input_common: Add support for joycon generic functions
Diffstat (limited to 'src/input_common/helpers/joycon_protocol/generic_functions.h')
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/generic_functions.h | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/input_common/helpers/joycon_protocol/generic_functions.h b/src/input_common/helpers/joycon_protocol/generic_functions.h new file mode 100644 index 000000000..c3e2ccadc --- /dev/null +++ b/src/input_common/helpers/joycon_protocol/generic_functions.h | |||
| @@ -0,0 +1,108 @@ | |||
| 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 "input_common/helpers/joycon_protocol/common_protocol.h" | ||
| 12 | #include "input_common/helpers/joycon_protocol/joycon_types.h" | ||
| 13 | |||
| 14 | namespace InputCommon::Joycon { | ||
| 15 | |||
| 16 | /// Joycon driver functions that easily implemented | ||
| 17 | class GenericProtocol final : private JoyconCommonProtocol { | ||
| 18 | public: | ||
| 19 | GenericProtocol(std::shared_ptr<JoyconHandle> handle); | ||
| 20 | |||
| 21 | /// Enables passive mode. This mode only sends button data on change. Sticks will return digital | ||
| 22 | /// data instead of analog. Motion will be disabled | ||
| 23 | DriverResult EnablePassiveMode(); | ||
| 24 | |||
| 25 | /// Enables active mode. This mode will return the current status every 5-15ms | ||
| 26 | DriverResult EnableActiveMode(); | ||
| 27 | |||
| 28 | /** | ||
| 29 | * Sends a request to obtain the joycon firmware and mac from handle | ||
| 30 | * @returns controller device info | ||
| 31 | */ | ||
| 32 | DriverResult GetDeviceInfo(DeviceInfo& controller_type); | ||
| 33 | |||
| 34 | /** | ||
| 35 | * Sends a request to obtain the joycon type from handle | ||
| 36 | * @returns controller type of the joycon | ||
| 37 | */ | ||
| 38 | DriverResult GetControllerType(ControllerType& controller_type); | ||
| 39 | |||
| 40 | /** | ||
| 41 | * Enables motion input | ||
| 42 | * @param enable if true motion data will be enabled | ||
| 43 | */ | ||
| 44 | DriverResult EnableImu(bool enable); | ||
| 45 | |||
| 46 | /** | ||
| 47 | * Configures the motion sensor with the specified parameters | ||
| 48 | * @param gsen gyroscope sensor sensitvity in degrees per second | ||
| 49 | * @param gfrec gyroscope sensor frequency in hertz | ||
| 50 | * @param asen accelerometer sensitivity in G force | ||
| 51 | * @param afrec accelerometer frequency in hertz | ||
| 52 | */ | ||
| 53 | DriverResult SetImuConfig(GyroSensitivity gsen, GyroPerformance gfrec, | ||
| 54 | AccelerometerSensitivity asen, AccelerometerPerformance afrec); | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Request battery level from the device | ||
| 58 | * @returns battery level | ||
| 59 | */ | ||
| 60 | DriverResult GetBattery(u32& battery_level); | ||
| 61 | |||
| 62 | /** | ||
| 63 | * Request joycon colors from the device | ||
| 64 | * @returns colors of the body and buttons | ||
| 65 | */ | ||
| 66 | DriverResult GetColor(Color& color); | ||
| 67 | |||
| 68 | /** | ||
| 69 | * Request joycon serial number from the device | ||
| 70 | * @returns 16 byte serial number | ||
| 71 | */ | ||
| 72 | DriverResult GetSerialNumber(SerialNumber& serial_number); | ||
| 73 | |||
| 74 | /** | ||
| 75 | * Request joycon serial number from the device | ||
| 76 | * @returns 16 byte serial number | ||
| 77 | */ | ||
| 78 | DriverResult GetTemperature(u32& temperature); | ||
| 79 | |||
| 80 | /** | ||
| 81 | * Request joycon serial number from the device | ||
| 82 | * @returns 16 byte serial number | ||
| 83 | */ | ||
| 84 | DriverResult GetVersionNumber(FirmwareVersion& version); | ||
| 85 | |||
| 86 | /** | ||
| 87 | * Sets home led behaviour | ||
| 88 | */ | ||
| 89 | DriverResult SetHomeLight(); | ||
| 90 | |||
| 91 | /** | ||
| 92 | * Sets home led into a slow breathing state | ||
| 93 | */ | ||
| 94 | DriverResult SetLedBusy(); | ||
| 95 | |||
| 96 | /** | ||
| 97 | * Sets the 4 player leds on the joycon on a solid state | ||
| 98 | * @params bit flag containing the led state | ||
| 99 | */ | ||
| 100 | DriverResult SetLedPattern(u8 leds); | ||
| 101 | |||
| 102 | /** | ||
| 103 | * Sets the 4 player leds on the joycon on a blinking state | ||
| 104 | * @returns bit flag containing the led state | ||
| 105 | */ | ||
| 106 | DriverResult SetLedBlinkPattern(u8 leds); | ||
| 107 | }; | ||
| 108 | } // namespace InputCommon::Joycon | ||