1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-06-26 18:02:35 +00:00

feat(core): add pm stabilization in init function [no changelog]

This commit is contained in:
kopecdav 2025-05-07 17:38:13 +02:00 committed by kopecdav
parent f050136abb
commit 6ba574cd82
3 changed files with 13 additions and 0 deletions

View File

@ -116,6 +116,15 @@ pm_status_t pm_init(bool inherit_state) {
// Enable charging by default // Enable charging by default
drv->charging_enabled = true; drv->charging_enabled = true;
// Poll until fuel_gauge is initialized and first PMIC & WLC measurements
// propagates into power_monitor.
bool state_machine_stabilized;
do{
irq_key_t irq_key = irq_lock();
state_machine_stabilized = drv->state_machine_stabilized;
irq_unlock(irq_key);
}while(!state_machine_stabilized);
drv->initialized = true; drv->initialized = true;
return PM_OK; return PM_OK;

View File

@ -69,6 +69,7 @@ typedef struct {
// Power manager core driver structure // Power manager core driver structure
typedef struct { typedef struct {
bool initialized; bool initialized;
bool state_machine_stabilized;
pm_internal_state_t state; pm_internal_state_t state;
pm_event_t event_flags; pm_event_t event_flags;

View File

@ -115,6 +115,9 @@ void pm_monitor_power_sources(void) {
// Request fresh measurements // Request fresh measurements
npm1300_measure(pm_pmic_data_ready, NULL); npm1300_measure(pm_pmic_data_ready, NULL);
drv->pmic_measurement_ready = false; drv->pmic_measurement_ready = false;
drv->state_machine_stabilized = true;
} }
// PMIC measurement callback // PMIC measurement callback