From 0ef7d0634c4edc6e19e3c9c8a8deb2f0f0d9416d Mon Sep 17 00:00:00 2001
From: tychovrahe <brunam@seznam.cz>
Date: Tue, 11 Mar 2025 03:40:11 +0100
Subject: [PATCH] powerctl emulator

---
 core/embed/rust/Cargo.toml                    |  1 +
 core/embed/sys/powerctl/unix/powerctl.c       | 30 +++++++++++++++++++
 core/site_scons/models/T3W1/emulator.py       |  7 +++++
 .../models/T3W1/trezor_t3w1_revA.py           |  1 +
 .../models/T3W1/trezor_t3w1_revB.py           |  1 +
 5 files changed, 40 insertions(+)
 create mode 100644 core/embed/sys/powerctl/unix/powerctl.c

diff --git a/core/embed/rust/Cargo.toml b/core/embed/rust/Cargo.toml
index 3deab49cf7..a887e6c474 100644
--- a/core/embed/rust/Cargo.toml
+++ b/core/embed/rust/Cargo.toml
@@ -43,6 +43,7 @@ backlight = []
 usb = []
 optiga = []
 ble = []
+powerctl = []
 translations = ["crypto"]
 test = [
     "backlight",
diff --git a/core/embed/sys/powerctl/unix/powerctl.c b/core/embed/sys/powerctl/unix/powerctl.c
new file mode 100644
index 0000000000..d5c6732a3d
--- /dev/null
+++ b/core/embed/sys/powerctl/unix/powerctl.c
@@ -0,0 +1,30 @@
+/*
+* This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <trezor_rtl.h>
+
+
+#include <SDL.h>
+
+bool powerctl_hibernate(void) {
+
+  exit(1);
+  return true;
+}
+
diff --git a/core/site_scons/models/T3W1/emulator.py b/core/site_scons/models/T3W1/emulator.py
index 56483240ad..f7580b5c0b 100644
--- a/core/site_scons/models/T3W1/emulator.py
+++ b/core/site_scons/models/T3W1/emulator.py
@@ -58,6 +58,13 @@ def configure(
         features_available.append("touch")
         defines += [("USE_TOUCH", "1")]
 
+    sources += [
+        "embed/sys/powerctl/unix/powerctl.c",
+    ]
+    defines += [("USE_POWERCTL", "1")]
+    paths += ["embed/sys/powerctl/inc"]
+    features_available.append("powerctl")
+
     features_available.append("backlight")
     defines += [("USE_BACKLIGHT", "1")]
 
diff --git a/core/site_scons/models/T3W1/trezor_t3w1_revA.py b/core/site_scons/models/T3W1/trezor_t3w1_revA.py
index 8f94eca4bb..2f266c1759 100644
--- a/core/site_scons/models/T3W1/trezor_t3w1_revA.py
+++ b/core/site_scons/models/T3W1/trezor_t3w1_revA.py
@@ -235,6 +235,7 @@ def configure(
     ]
     paths += ["embed/sys/powerctl/inc"]
     defines += [("USE_POWERCTL", "1")]
+    features_available.append("powerctl")
 
     env.get("ENV")["LINKER_SCRIPT"] = linker_script
 
diff --git a/core/site_scons/models/T3W1/trezor_t3w1_revB.py b/core/site_scons/models/T3W1/trezor_t3w1_revB.py
index 6d81b310fd..73995af447 100644
--- a/core/site_scons/models/T3W1/trezor_t3w1_revB.py
+++ b/core/site_scons/models/T3W1/trezor_t3w1_revB.py
@@ -240,6 +240,7 @@ def configure(
     ]
     paths += ["embed/sys/powerctl/inc"]
     defines += [("USE_POWERCTL", "1")]
+    features_available.append("powerctl")
 
     env.get("ENV")["LINKER_SCRIPT"] = linker_script