1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-03-22 19:15:43 +00:00

0.3.0.1: PMIC charging start, prodtest version

This commit is contained in:
tychovrahe 2025-03-14 02:44:37 +01:00
parent b1c37a1f16
commit 59a45ec303
4 changed files with 91 additions and 6 deletions

View File

@ -51,12 +51,49 @@ static void prodtest_pmic_charge_enable(cli_t* cli) {
return;
}
npm1300_report_t report = {0};
cli_trace(cli, "Enabling battery charging @ %dmA...",
npm1300_get_charging_limit());
if (!npm1300_set_charging(true)) {
cli_error(cli, CLI_ERROR, "Failed to enable battery charging.");
return;
while (true) {
if (!npm1300_set_charging(true)) {
cli_error(cli, CLI_ERROR, "Failed to enable battery charging.");
return;
}
systick_delay_ms(10);
if (!npm1300_measure_sync(&report)) {
cli_error(cli, CLI_ERROR, "Failed to get NPM1300 report.");
return;
}
bool charging = ((report.ibat_meas_status >> 2) & 0x03) == 3;
cli_trace(
cli, "Trying to start charging: %d.%03d %d.%03d %d.%03d 0x%02X 0x%02X",
(int)report.vbat, (int)(report.vbat * 1000) % 1000,
(int)report.ibat, (int)abs(report.ibat * 1000) % 1000,
(int)report.ntc_temp, (int)abs(report.ntc_temp * 1000) % 1000,
report.ibat_meas_status, report.buck_status);
if (charging) {
systick_delay_ms(100);
// confirm that we are still charging after some delay
npm1300_measure_sync(&report);
charging = ((report.ibat_meas_status >> 2) & 0x03) == 3;
if (charging) {
break;
}
}
if (cli_aborted(cli)) {
return;
}
}
cli_ok(cli, "");
@ -198,6 +235,52 @@ static void prodtest_pmic_report(cli_t* cli) {
cli_ok(cli, "");
}
//
// static void prodtest_pmic_resurrect(cli_t* cli) {
//
//
// if (cli_arg_count(cli) > 0) {
// cli_error_arg_count(cli);
// return;
// }
//
//
// while (true) {
// npm1300_report_t report;
//
// if (!npm1300_measure_sync(&report)) {
// cli_error(cli, CLI_ERROR, "Failed to get NPM1300 report.");
// return;
// }
//
// npm1300_set_charging(true);
//
// bool ibat_charging = ((report.ibat_meas_status >> 2) & 0x03) == 3;
// if (ibat_charging) {
// cli_trace(cli, "Charging established");
// //break;
// }
//
// cli_progress(
// cli, "%d.%03d %d.%03d %d.%03d %d.%03d %d.%03d 0x%02X 0x%02X",
// (int)report.vbat, (int)(report.vbat * 1000) % 1000,
// (int)report.ibat, (int)abs(report.ibat * 1000) % 1000,
// (int)report.ntc_temp, (int)abs(report.ntc_temp * 1000) % 1000,
// (int)report.vsys, (int)(report.vsys * 1000) % 1000,
// (int)report.die_temp, (int)abs(report.die_temp * 1000) % 1000,
// report.ibat_meas_status, report.buck_status);
//
//
// if (cli_aborted(cli)) {
// return;
// }
//
// }
//
// cli_ok(cli, "");
// }
// clang-format off
PRODTEST_CLI_CMD(
@ -240,6 +323,6 @@ PRODTEST_CLI_CMD(
.func = prodtest_pmic_report,
.info = "Retrieve PMIC report",
.args = "[<count>] [<period>]"
);
);
#endif // USE_POWERCTL

View File

@ -44,7 +44,7 @@ static void prodtest_prodtest_version(cli_t* cli) {
return;
}
cli_ok(cli, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
cli_ok(cli, "%d.%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_BUILD);
}
static void prodtest_prodtest_wipe(cli_t* cli) {

View File

@ -5,7 +5,7 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 3
#define VERSION_PATCH 0
#define VERSION_BUILD 0
#define VERSION_BUILD 1
#define FIX_VERSION_MAJOR 0
#define FIX_VERSION_MINOR 2

View File

@ -612,6 +612,8 @@ static void npm1300_calculate_report(npm1300_driver_t* drv,
// I2C operations for enabling of the charging
static const i2c_op_t npm1300_ops_charging_enable[] = {
NPM_WRITE_CONST(NPM1300_TASKCLEARCHGERR, 1),
NPM_WRITE_CONST(NPM1300_TASKRELEASEERR, 1),
NPM_WRITE_CONST(NPM1300_BCHGENABLESET, NPM1300_BCHGENABLESET_ENABLECHG),
};