2021-10-03 13:36:05 +03:00
|
|
|
/**
|
2022-01-05 19:10:18 +03:00
|
|
|
* @file furi_hal_power.h
|
2021-10-03 13:36:05 +03:00
|
|
|
* Power HAL API
|
|
|
|
*/
|
|
|
|
|
2020-11-11 09:31:35 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2022-11-29 12:08:08 +03:00
|
|
|
#include <core/string.h>
|
|
|
|
#include <toolbox/property.h>
|
2020-12-02 13:47:13 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2020-11-11 09:31:35 +03:00
|
|
|
|
2021-03-24 12:35:33 +03:00
|
|
|
/** Power IC type */
|
2020-12-22 21:16:32 +03:00
|
|
|
typedef enum {
|
2021-08-08 21:03:25 +03:00
|
|
|
FuriHalPowerICCharger,
|
|
|
|
FuriHalPowerICFuelGauge,
|
|
|
|
} FuriHalPowerIC;
|
2020-12-22 21:16:32 +03:00
|
|
|
|
2022-04-19 02:09:11 +03:00
|
|
|
/** Initialize drivers */
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_power_init();
|
2020-11-11 09:31:35 +03:00
|
|
|
|
2022-04-19 02:09:11 +03:00
|
|
|
/** Check if gauge is ok
|
|
|
|
*
|
|
|
|
* Verifies that:
|
|
|
|
* - gauge is alive
|
|
|
|
* - correct profile loaded
|
|
|
|
* - self diagnostic status is good
|
|
|
|
*
|
|
|
|
* @return true if gauge is ok
|
|
|
|
*/
|
|
|
|
bool furi_hal_power_gauge_is_ok();
|
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Get current insomnia level
|
|
|
|
*
|
|
|
|
* @return insomnia level: 0 - no insomnia, >0 - insomnia, bearer count.
|
2021-02-12 20:24:34 +03:00
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
uint16_t furi_hal_power_insomnia_level();
|
2021-02-12 20:24:34 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Enter insomnia mode Prevents device from going to sleep
|
|
|
|
* @warning Internally increases insomnia level Must be paired with
|
|
|
|
* furi_hal_power_insomnia_exit
|
2021-02-12 20:24:34 +03:00
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_power_insomnia_enter();
|
2021-02-12 20:24:34 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Exit insomnia mode Allow device to go to sleep
|
|
|
|
* @warning Internally decreases insomnia level. Must be paired with
|
|
|
|
* furi_hal_power_insomnia_enter
|
2021-02-12 20:24:34 +03:00
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_power_insomnia_exit();
|
2021-02-12 20:24:34 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Check if sleep availble
|
|
|
|
*
|
|
|
|
* @return true if available
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
bool furi_hal_power_sleep_available();
|
2021-03-31 20:55:00 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Go to sleep
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_power_sleep();
|
2021-01-20 10:43:12 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Get predicted remaining battery capacity in percents
|
|
|
|
*
|
|
|
|
* @return remaining battery capacity in percents
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
uint8_t furi_hal_power_get_pct();
|
2020-11-11 09:31:35 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Get battery health state in percents
|
|
|
|
*
|
|
|
|
* @return health in percents
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
uint8_t furi_hal_power_get_bat_health_pct();
|
2021-03-02 19:07:26 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Get charging status
|
|
|
|
*
|
|
|
|
* @return true if charging
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
bool furi_hal_power_is_charging();
|
2020-11-11 09:31:35 +03:00
|
|
|
|
2022-09-26 18:34:59 +03:00
|
|
|
/** Get charge complete status
|
|
|
|
*
|
|
|
|
* @return true if done charging and connected to charger
|
|
|
|
*/
|
|
|
|
bool furi_hal_power_is_charging_done();
|
|
|
|
|
[FL-2399, FL-2261] Tickless sleep shenanigans (#1168)
* Disable USART in sleep
* Restore UART state on suspend/resume
* FuriHal: Enable stop mode and add insomnia to I2C and SPI
* Remove IDLE interrupt
* FuriHal: add FPU isr and disable all FPU interrupt, add core2 stop mode configuration on deep sleep
* FuriHal: tie stop mode debug with debug rtc flag
* FuriHal: adjust flash latency on clock switch, tie mcu debug with RTC debug flag
* FuriHal: move resource init to early stage
* Add EXTI pending check, enable debug traps with compile-time flag
* Wrap sleep debug functions in conditional compilation
* Remove erroneous changed
* Do not use CSS, remove it from everywhere
* Enable/disable USB on VBUS connect (prototype)
* FuriHal: add LPMS and DEEPSLEEP magic, workaround state inconsistency between cores
* FuriHal: honor c1 LMPS
* USB mode switch fix
* Applications: add flags and insomnia bypass system
* Correct spelling
* FuriHal: cleanup insomnia usage, reset sleep flags on wakeup, add shutdown api
* FuriHal: extra check on reinit request
* FuriHal: rename gpio_display_rst pin to gpio_display_rst_n
* FuriHal: add debug HAL
* FuriHal: add some magic to core2 reload procedure, fix issue with crash on ble keyboard exit
* FuriHal: cleanup ble glue, add BLE_GLUE_DEBUG flag
* FuriHal: ble reinit API, move os timer to LPTIM1 for deep sleep capability, shutdown that works
* FuriHal: take insomnia while shutdown
* Remove USB switch on/off on VBUS change
* Better tick skew handling
* Improve tick consistency under load
* Add USB_HP dummy IRQ handler
* Move interrupt check closer to sleep
* Clean up includes
* Re-enable Insomnia globally
* FuriHal: enable CSS
* FuriHal: remove questionable core2 clock shenanigans
* FuriHal: use core1 RCC registers in idle timer config
* FuriHal: return back CSS handlers, add lptim isr dispatching
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
Co-authored-by: nminaylov <nm29719@gmail.com>
2022-04-29 16:29:51 +03:00
|
|
|
/** Switch MCU to SHUTDOWN */
|
|
|
|
void furi_hal_power_shutdown();
|
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Poweroff device
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_power_off();
|
2020-11-11 09:31:35 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Reset device
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_power_reset();
|
2021-04-30 07:51:48 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** OTG enable
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_power_enable_otg();
|
2020-11-11 09:31:35 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** OTG disable
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_power_disable_otg();
|
2020-12-02 13:47:13 +03:00
|
|
|
|
2022-01-21 19:55:44 +03:00
|
|
|
/** Check OTG status and disable it if falt happened
|
|
|
|
*/
|
|
|
|
void furi_hal_power_check_otg_status();
|
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Get OTG status
|
|
|
|
*
|
|
|
|
* @return true if enabled
|
|
|
|
*/
|
2021-09-30 23:03:28 +03:00
|
|
|
bool furi_hal_power_is_otg_enabled();
|
|
|
|
|
2023-02-26 20:23:39 +03:00
|
|
|
/** Get battery charge voltage limit in V
|
2022-12-08 09:57:49 +03:00
|
|
|
*
|
|
|
|
* @return voltage in V
|
|
|
|
*/
|
2023-02-26 20:23:39 +03:00
|
|
|
float furi_hal_power_get_battery_charge_voltage_limit();
|
2022-12-08 09:57:49 +03:00
|
|
|
|
2023-02-26 20:23:39 +03:00
|
|
|
/** Set battery charge voltage limit in V
|
2022-12-08 09:57:49 +03:00
|
|
|
*
|
2023-02-26 20:23:39 +03:00
|
|
|
* Invalid values will be clamped downward to the nearest valid value.
|
2022-12-08 09:57:49 +03:00
|
|
|
*
|
|
|
|
* @param voltage[in] voltage in V
|
|
|
|
*
|
|
|
|
* @return voltage in V
|
|
|
|
*/
|
2023-02-26 20:23:39 +03:00
|
|
|
void furi_hal_power_set_battery_charge_voltage_limit(float voltage);
|
2022-12-08 09:57:49 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Get remaining battery battery capacity in mAh
|
|
|
|
*
|
|
|
|
* @return capacity in mAh
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
uint32_t furi_hal_power_get_battery_remaining_capacity();
|
2020-12-22 21:16:32 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Get full charge battery capacity in mAh
|
|
|
|
*
|
|
|
|
* @return capacity in mAh
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
uint32_t furi_hal_power_get_battery_full_capacity();
|
2020-12-22 21:16:32 +03:00
|
|
|
|
2022-04-07 18:00:45 +03:00
|
|
|
/** Get battery capacity in mAh from battery profile
|
|
|
|
*
|
|
|
|
* @return capacity in mAh
|
|
|
|
*/
|
|
|
|
uint32_t furi_hal_power_get_battery_design_capacity();
|
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Get battery voltage in V
|
|
|
|
*
|
|
|
|
* @param ic FuriHalPowerIc to get measurment
|
|
|
|
*
|
|
|
|
* @return voltage in V
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
float furi_hal_power_get_battery_voltage(FuriHalPowerIC ic);
|
2020-12-02 13:47:13 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Get battery current in A
|
|
|
|
*
|
|
|
|
* @param ic FuriHalPowerIc to get measurment
|
|
|
|
*
|
|
|
|
* @return current in A
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
float furi_hal_power_get_battery_current(FuriHalPowerIC ic);
|
2020-12-02 13:47:13 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Get temperature in C
|
|
|
|
*
|
|
|
|
* @param ic FuriHalPowerIc to get measurment
|
|
|
|
*
|
|
|
|
* @return temperature in C
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
float furi_hal_power_get_battery_temperature(FuriHalPowerIC ic);
|
2020-12-22 21:16:32 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Get USB voltage in V
|
|
|
|
*
|
|
|
|
* @return voltage in V
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
float furi_hal_power_get_usb_voltage();
|
2020-12-18 21:03:28 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Enable 3.3v on external gpio and sd card
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_power_enable_external_3_3v();
|
2021-03-09 14:53:33 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Disable 3.3v on external gpio and sd card
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_power_disable_external_3_3v();
|
2021-03-09 14:53:33 +03:00
|
|
|
|
2021-10-04 10:01:41 +03:00
|
|
|
/** Enter supress charge mode.
|
|
|
|
*
|
|
|
|
* Use this function when your application need clean power supply.
|
|
|
|
*/
|
|
|
|
void furi_hal_power_suppress_charge_enter();
|
|
|
|
|
|
|
|
/** Exit supress charge mode
|
|
|
|
*/
|
|
|
|
void furi_hal_power_suppress_charge_exit();
|
|
|
|
|
2022-11-29 12:08:08 +03:00
|
|
|
/** Get power information
|
2022-04-07 18:00:45 +03:00
|
|
|
*
|
2022-11-29 12:08:08 +03:00
|
|
|
* @param[in] callback callback to provide with new data
|
|
|
|
* @param[in] sep category separator character
|
|
|
|
* @param[in] context context to pass to callback
|
2022-04-07 18:00:45 +03:00
|
|
|
*/
|
2022-11-29 12:08:08 +03:00
|
|
|
void furi_hal_power_info_get(PropertyValueCallback callback, char sep, void* context);
|
2022-04-07 18:00:45 +03:00
|
|
|
|
2022-11-29 12:08:08 +03:00
|
|
|
/** Get power debug information
|
2022-04-07 18:00:45 +03:00
|
|
|
*
|
|
|
|
* @param[in] callback callback to provide with new data
|
|
|
|
* @param[in] context context to pass to callback
|
|
|
|
*/
|
2022-11-29 12:08:08 +03:00
|
|
|
void furi_hal_power_debug_get(PropertyValueCallback callback, void* context);
|
2022-04-07 18:00:45 +03:00
|
|
|
|
2020-12-02 13:47:13 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|