diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/ptm/psm.cpp | 113 |
1 files changed, 112 insertions, 1 deletions
diff --git a/src/core/hle/service/ptm/psm.cpp b/src/core/hle/service/ptm/psm.cpp index b4b0dd241..a7cfccda3 100644 --- a/src/core/hle/service/ptm/psm.cpp +++ b/src/core/hle/service/ptm/psm.cpp | |||
| @@ -5,13 +5,116 @@ | |||
| 5 | #include <memory> | 5 | #include <memory> |
| 6 | 6 | ||
| 7 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "core/core.h" | ||
| 8 | #include "core/hle/ipc_helpers.h" | 9 | #include "core/hle/ipc_helpers.h" |
| 10 | #include "core/hle/kernel/kernel.h" | ||
| 11 | #include "core/hle/kernel/readable_event.h" | ||
| 12 | #include "core/hle/kernel/writable_event.h" | ||
| 9 | #include "core/hle/service/ptm/psm.h" | 13 | #include "core/hle/service/ptm/psm.h" |
| 10 | #include "core/hle/service/service.h" | 14 | #include "core/hle/service/service.h" |
| 11 | #include "core/hle/service/sm/sm.h" | 15 | #include "core/hle/service/sm/sm.h" |
| 12 | 16 | ||
| 13 | namespace Service::PSM { | 17 | namespace Service::PSM { |
| 14 | 18 | ||
| 19 | class IPsmSession final : public ServiceFramework<IPsmSession> { | ||
| 20 | public: | ||
| 21 | explicit IPsmSession(Core::System& system_) : ServiceFramework{system_, "IPsmSession"} { | ||
| 22 | // clang-format off | ||
| 23 | static const FunctionInfo functions[] = { | ||
| 24 | {0, &IPsmSession::BindStateChangeEvent, "BindStateChangeEvent"}, | ||
| 25 | {1, &IPsmSession::UnbindStateChangeEvent, "UnbindStateChangeEvent"}, | ||
| 26 | {2, &IPsmSession::SetChargerTypeChangeEventEnabled, "SetChargerTypeChangeEventEnabled"}, | ||
| 27 | {3, &IPsmSession::SetPowerSupplyChangeEventEnabled, "SetPowerSupplyChangeEventEnabled"}, | ||
| 28 | {4, &IPsmSession::SetBatteryVoltageStateChangeEventEnabled, "SetBatteryVoltageStateChangeEventEnabled"}, | ||
| 29 | }; | ||
| 30 | // clang-format on | ||
| 31 | |||
| 32 | RegisterHandlers(functions); | ||
| 33 | |||
| 34 | state_change_event = Kernel::WritableEvent::CreateEventPair( | ||
| 35 | system_.Kernel(), "IPsmSession::state_change_event"); | ||
| 36 | } | ||
| 37 | |||
| 38 | ~IPsmSession() override = default; | ||
| 39 | |||
| 40 | void SignalChargerTypeChanged() { | ||
| 41 | if (should_signal && should_signal_charger_type) { | ||
| 42 | state_change_event.writable->Signal(); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | void SignalPowerSupplyChanged() { | ||
| 47 | if (should_signal && should_signal_power_supply) { | ||
| 48 | state_change_event.writable->Signal(); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | void SignalBatteryVoltageStateChanged() { | ||
| 53 | if (should_signal && should_signal_battery_voltage) { | ||
| 54 | state_change_event.writable->Signal(); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | private: | ||
| 59 | void BindStateChangeEvent(Kernel::HLERequestContext& ctx) { | ||
| 60 | LOG_DEBUG(Service_PSM, "called"); | ||
| 61 | |||
| 62 | should_signal = true; | ||
| 63 | |||
| 64 | IPC::ResponseBuilder rb{ctx, 2, 1}; | ||
| 65 | rb.Push(RESULT_SUCCESS); | ||
| 66 | rb.PushCopyObjects(state_change_event.readable); | ||
| 67 | } | ||
| 68 | |||
| 69 | void UnbindStateChangeEvent(Kernel::HLERequestContext& ctx) { | ||
| 70 | LOG_DEBUG(Service_PSM, "called"); | ||
| 71 | |||
| 72 | should_signal = false; | ||
| 73 | |||
| 74 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 75 | rb.Push(RESULT_SUCCESS); | ||
| 76 | } | ||
| 77 | |||
| 78 | void SetChargerTypeChangeEventEnabled(Kernel::HLERequestContext& ctx) { | ||
| 79 | IPC::RequestParser rp{ctx}; | ||
| 80 | const auto state = rp.Pop<bool>(); | ||
| 81 | LOG_DEBUG(Service_PSM, "called, state={}", state); | ||
| 82 | |||
| 83 | should_signal_charger_type = state; | ||
| 84 | |||
| 85 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 86 | rb.Push(RESULT_SUCCESS); | ||
| 87 | } | ||
| 88 | |||
| 89 | void SetPowerSupplyChangeEventEnabled(Kernel::HLERequestContext& ctx) { | ||
| 90 | IPC::RequestParser rp{ctx}; | ||
| 91 | const auto state = rp.Pop<bool>(); | ||
| 92 | LOG_DEBUG(Service_PSM, "called, state={}", state); | ||
| 93 | |||
| 94 | should_signal_power_supply = state; | ||
| 95 | |||
| 96 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 97 | rb.Push(RESULT_SUCCESS); | ||
| 98 | } | ||
| 99 | |||
| 100 | void SetBatteryVoltageStateChangeEventEnabled(Kernel::HLERequestContext& ctx) { | ||
| 101 | IPC::RequestParser rp{ctx}; | ||
| 102 | const auto state = rp.Pop<bool>(); | ||
| 103 | LOG_DEBUG(Service_PSM, "called, state={}", state); | ||
| 104 | |||
| 105 | should_signal_battery_voltage = state; | ||
| 106 | |||
| 107 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 108 | rb.Push(RESULT_SUCCESS); | ||
| 109 | } | ||
| 110 | |||
| 111 | bool should_signal_charger_type{}; | ||
| 112 | bool should_signal_power_supply{}; | ||
| 113 | bool should_signal_battery_voltage{}; | ||
| 114 | bool should_signal{}; | ||
| 115 | Kernel::EventPair state_change_event; | ||
| 116 | }; | ||
| 117 | |||
| 15 | class PSM final : public ServiceFramework<PSM> { | 118 | class PSM final : public ServiceFramework<PSM> { |
| 16 | public: | 119 | public: |
| 17 | explicit PSM(Core::System& system_) : ServiceFramework{system_, "psm"} { | 120 | explicit PSM(Core::System& system_) : ServiceFramework{system_, "psm"} { |
| @@ -24,7 +127,7 @@ public: | |||
| 24 | {4, nullptr, "IsBatteryChargingEnabled"}, | 127 | {4, nullptr, "IsBatteryChargingEnabled"}, |
| 25 | {5, nullptr, "AcquireControllerPowerSupply"}, | 128 | {5, nullptr, "AcquireControllerPowerSupply"}, |
| 26 | {6, nullptr, "ReleaseControllerPowerSupply"}, | 129 | {6, nullptr, "ReleaseControllerPowerSupply"}, |
| 27 | {7, nullptr, "OpenSession"}, | 130 | {7, &PSM::OpenSession, "OpenSession"}, |
| 28 | {8, nullptr, "EnableEnoughPowerChargeEmulation"}, | 131 | {8, nullptr, "EnableEnoughPowerChargeEmulation"}, |
| 29 | {9, nullptr, "DisableEnoughPowerChargeEmulation"}, | 132 | {9, nullptr, "DisableEnoughPowerChargeEmulation"}, |
| 30 | {10, nullptr, "EnableFastBatteryCharging"}, | 133 | {10, nullptr, "EnableFastBatteryCharging"}, |
| @@ -61,6 +164,14 @@ private: | |||
| 61 | rb.PushEnum(charger_type); | 164 | rb.PushEnum(charger_type); |
| 62 | } | 165 | } |
| 63 | 166 | ||
| 167 | void OpenSession(Kernel::HLERequestContext& ctx) { | ||
| 168 | LOG_DEBUG(Service_PSM, "called"); | ||
| 169 | |||
| 170 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | ||
| 171 | rb.Push(RESULT_SUCCESS); | ||
| 172 | rb.PushIpcInterface<IPsmSession>(system); | ||
| 173 | } | ||
| 174 | |||
| 64 | enum class ChargerType : u32 { | 175 | enum class ChargerType : u32 { |
| 65 | Unplugged = 0, | 176 | Unplugged = 0, |
| 66 | RegularCharger = 1, | 177 | RegularCharger = 1, |