diff --git a/firmware/target/arm/stm32/echoplayer/power-echoplayer.c b/firmware/target/arm/stm32/echoplayer/power-echoplayer.c index e001a3a6f2..3482d884eb 100644 --- a/firmware/target/arm/stm32/echoplayer/power-echoplayer.c +++ b/firmware/target/arm/stm32/echoplayer/power-echoplayer.c @@ -19,6 +19,11 @@ * ****************************************************************************/ #include "power.h" +#include "mutex.h" +#include "gpio-stm32h7.h" + +static struct mutex power_1v8_lock; +static int power_1v8_refcount; unsigned short battery_level_disksafe = 3500; unsigned short battery_level_shutoff = 3400; @@ -35,9 +40,29 @@ unsigned short percent_to_volt_charge[11] = 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196 }; +/* API for enabling 1V8 regulator */ +void echoplayer_enable_1v8_regulator(bool enable) +{ + mutex_lock(&power_1v8_lock); + + if (enable) + { + if (power_1v8_refcount++ == 0) + gpio_set_level(GPIO_POWER_1V8, 1); + } + else + { + if (--power_1v8_refcount == 0) + gpio_set_level(GPIO_POWER_1V8, 0); + } + + mutex_unlock(&power_1v8_lock); +} + /* Power management */ void power_init(void) { + mutex_init(&power_1v8_lock); } void power_off(void) diff --git a/firmware/target/arm/stm32/echoplayer/power-echoplayer.h b/firmware/target/arm/stm32/echoplayer/power-echoplayer.h new file mode 100644 index 0000000000..555b55c034 --- /dev/null +++ b/firmware/target/arm/stm32/echoplayer/power-echoplayer.h @@ -0,0 +1,28 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2026 by Aidan MacDonald + * + * 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 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef __POWER_ECHOPLAYER_H__ +#define __POWER_ECHOPLAYER_H__ + +#include + +void echoplayer_enable_1v8_regulator(bool enable); + +#endif /* __POWER_ECHOPLAYER_H__ */