From 56c410b94199d364741a56d885f1682ddb1f2eb8 Mon Sep 17 00:00:00 2001 From: cepetr Date: Mon, 25 Nov 2024 09:10:29 +0100 Subject: [PATCH] feat(core/prodtest): add wpc control commands [no changelog] --- core/embed/projects/prodtest/main.c | 74 +++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/core/embed/projects/prodtest/main.c b/core/embed/projects/prodtest/main.c index 806f5fd4dc..3906c625d1 100644 --- a/core/embed/projects/prodtest/main.c +++ b/core/embed/projects/prodtest/main.c @@ -79,6 +79,7 @@ #ifdef USE_POWERCTL #include "../../sys/powerctl/npm1300/npm1300.h" +#include "../../sys/powerctl/stwlc38/stwlc38.h" #endif #ifdef USE_STORAGE_HWKEY @@ -939,6 +940,75 @@ void test_pmic(const char *args) { } } +void test_wpc(const char *args) { + stwlc38_init(); + + if (strcmp(args, "EN") == 0) { + if (!stwlc38_enable(true)) { + vcp_println("ERROR # STWLC38 not initialized"); + return; + } + vcp_println("OK"); + } else if (strcmp(args, "DIS") == 0) { + if (!stwlc38_enable(false)) { + vcp_println("ERROR # STWLC38 not initialized"); + return; + } + vcp_println("OK"); + } else if (strcmp(args, "VEN") == 0) { + if (!stwlc38_enable_vout(true)) { + vcp_println("ERROR # STWLC38 not initialized"); + return; + } + vcp_println("OK"); + } else if (strcmp(args, "VDIS") == 0) { + if (!stwlc38_enable_vout(false)) { + vcp_println("ERROR # STWLC38 not initialized"); + return; + } + vcp_println("OK"); + } else if (strncmp(args, "MEASURE", 7) == 0) { + stwlc38_report_t report; + + int seconds = atoi(&args[7]); + uint32_t ticks = hal_ticks_ms(); + + vcp_println( + "time; ready; vout_ready; vrect; vout; icur; tmeas; opfreq; ntc"); + do { + if (!stwlc38_get_report(&report)) { + vcp_println("ERROR # STWLC38 not initialized"); + return; + } else { + vcp_print("%09d; ", ticks); + vcp_print("%d; ", report.ready ? 1 : 0); + vcp_print("%d; ", report.vout_ready ? 1 : 0); + vcp_print("%d.%03d; ", (int)report.vrect, + (int)abs(report.vrect * 1000) % 1000); + vcp_print("%d.%03d; ", (int)report.vout, + (int)(report.vout * 1000) % 1000); + vcp_print("%d.%03d; ", (int)report.icur, + (int)abs(report.icur * 1000) % 1000); + vcp_print("%d.%03d; ", (int)report.tmeas, + (int)abs(report.tmeas * 1000) % 1000); + vcp_print("%d; ", report.opfreq); + vcp_print("%d.%03d; ", (int)report.ntc, + (int)abs(report.ntc * 1000) % 1000); + + vcp_println(""); + } + + while (!ticks_expired(ticks + 1000)) { + }; + + ticks += 1000; + + } while (seconds-- > 0); + + vcp_println("OK # Measurement finished"); + } +} + #define BACKLIGHT_NORMAL 150 int main(void) { @@ -1106,6 +1176,10 @@ int main(void) { test_pmic(line + 5); } else if (startswith(line, "PMIC")) { test_pmic(line + 4); + } else if (startswith(line, "WPC ")) { + test_wpc(line + 4); + } else if (startswith(line, "WPC")) { + test_wpc(line + 3); } else { vcp_println("UNKNOWN"); }