unleashed-firmware/targets/furi_hal_include/furi_hal_power.h

227 lines
5 KiB
C
Raw Normal View History

/**
* @file furi_hal_power.h
* Power HAL API
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <core/string.h>
#include <core/common_defines.h>
#include <toolbox/property.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Power IC type */
2020-12-22 18:16:32 +00:00
typedef enum {
2021-08-08 18:03:25 +00:00
FuriHalPowerICCharger,
FuriHalPowerICFuelGauge,
} FuriHalPowerIC;
2020-12-22 18:16:32 +00:00
/** Initialize drivers */
void furi_hal_power_init(void);
/** 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(void);
/** Check if gauge requests system shutdown
*
* @return true if system shutdown requested
*/
bool furi_hal_power_is_shutdown_requested(void);
/** Get current insomnia level
*
* @return insomnia level: 0 - no insomnia, >0 - insomnia, bearer count.
*/
uint16_t furi_hal_power_insomnia_level(void);
/** Enter insomnia mode Prevents device from going to sleep
* @warning Internally increases insomnia level Must be paired with
* furi_hal_power_insomnia_exit
*/
void furi_hal_power_insomnia_enter(void);
/** Exit insomnia mode Allow device to go to sleep
* @warning Internally decreases insomnia level. Must be paired with
* furi_hal_power_insomnia_enter
*/
void furi_hal_power_insomnia_exit(void);
2024-01-29 12:35:46 +00:00
/** Check if sleep available
*
* @return true if available
*/
bool furi_hal_power_sleep_available(void);
/** Go to sleep
*/
void furi_hal_power_sleep(void);
/** Get predicted remaining battery capacity in percents
*
* @return remaining battery capacity in percents
*/
uint8_t furi_hal_power_get_pct(void);
/** Get battery health state in percents
*
* @return health in percents
*/
uint8_t furi_hal_power_get_bat_health_pct(void);
/** Get charging status
*
* @return true if charging
*/
bool furi_hal_power_is_charging(void);
/** Get charge complete status
*
* @return true if done charging and connected to charger
*/
bool furi_hal_power_is_charging_done(void);
[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 13:29:51 +00:00
/** Switch MCU to SHUTDOWN */
void furi_hal_power_shutdown(void);
[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 13:29:51 +00:00
/** Poweroff device
*/
void furi_hal_power_off(void);
/** Reset device
*/
FURI_NORETURN void furi_hal_power_reset(void);
/** OTG enable
*/
bool furi_hal_power_enable_otg(void);
/** OTG disable
*/
void furi_hal_power_disable_otg(void);
/** Check OTG status fault
*/
bool furi_hal_power_check_otg_fault(void);
/** Check OTG status and disable it if falt happened
*/
void furi_hal_power_check_otg_status(void);
/** Get OTG status
*
* @return true if enabled
*/
bool furi_hal_power_is_otg_enabled(void);
/** Get battery charge voltage limit in V
*
* @return voltage in V
*/
float furi_hal_power_get_battery_charge_voltage_limit(void);
/** Set battery charge voltage limit in V
*
* Invalid values will be clamped downward to the nearest valid value.
*
[FL-870] Auto-generated firmware documentation take two (#2944) * Add doxygen and doxygen-awesome css, cleanup docs files * Ignore more libraries and remove leftover local variables * Create an actual intro page * .md files linting * Add doxygen action * Fix Doxygen path * Fix doxyfile path * Try to upload * Change docs branch * Add submudules checkout * Disable doxygen on PR * Mention the firmware docs in the readme * More dev docs mentions in the readme * Fix runner group, add tags * Test dev in PR * Disable running on PR * Fix a typo in the doxyfile * Try upload to S3 * Fix local path * Fix S3 ACL * Add delete flag, unifying dev and tags * Update ignored directories * More ignored directories * Even more ignored directories * Fix submodule * Change S3 uploader * Change S3 uploader version * Fix aws sync flags * Fix ACL * Disable ACL * Improve ignores, add WiFi devboard docs * TEMP: generate dev docs * TEMP: generate 0.89.0 docs * Disabling PR trigger * Enable submodules and test build * Enable test build * Disable test build * Change docs directory structure * Fix accidentally committed submodule * Fix submodules * Update links to the developer documentation * Markdown linting * Update workflow, enable test build * Fix doxygen dir path * Update Doxyfile-awesome.cfg * Change paths * Fix upload docs path * Disable pull_request debug trigger * Disable tags building * Remove autolinks and namespaces * Establish basic documentation structure * Add missing changes * Improve stylesheet, move some files * Improve examples * Improve the main page * Improve application dev docs * Improve system programming docs * Improve development tools docs * Improve other docs * Improve application examples * Fix formatting * Fix PVS-studio warnings * Improve visuals * Fix doxygen syntax warnings * Fix broken links * Update doxygen action Co-authored-by: DrunkBatya <drunkbatya.js@gmail.com> Co-authored-by: あく <alleteam@gmail.com> Co-authored-by: Georgii Surkov <georgii.surkov@outlook.com> Co-authored-by: Georgii Surkov <37121527+gsurkov@users.noreply.github.com>
2024-03-06 06:25:21 +00:00
* @param[in] voltage voltage in V
*/
void furi_hal_power_set_battery_charge_voltage_limit(float voltage);
/** Get remaining battery battery capacity in mAh
*
* @return capacity in mAh
*/
uint32_t furi_hal_power_get_battery_remaining_capacity(void);
2020-12-22 18:16:32 +00:00
/** Get full charge battery capacity in mAh
*
* @return capacity in mAh
*/
uint32_t furi_hal_power_get_battery_full_capacity(void);
2020-12-22 18:16:32 +00:00
/** Get battery capacity in mAh from battery profile
*
* @return capacity in mAh
*/
uint32_t furi_hal_power_get_battery_design_capacity(void);
/** Get battery voltage in V
*
[FL-870] Auto-generated firmware documentation take two (#2944) * Add doxygen and doxygen-awesome css, cleanup docs files * Ignore more libraries and remove leftover local variables * Create an actual intro page * .md files linting * Add doxygen action * Fix Doxygen path * Fix doxyfile path * Try to upload * Change docs branch * Add submudules checkout * Disable doxygen on PR * Mention the firmware docs in the readme * More dev docs mentions in the readme * Fix runner group, add tags * Test dev in PR * Disable running on PR * Fix a typo in the doxyfile * Try upload to S3 * Fix local path * Fix S3 ACL * Add delete flag, unifying dev and tags * Update ignored directories * More ignored directories * Even more ignored directories * Fix submodule * Change S3 uploader * Change S3 uploader version * Fix aws sync flags * Fix ACL * Disable ACL * Improve ignores, add WiFi devboard docs * TEMP: generate dev docs * TEMP: generate 0.89.0 docs * Disabling PR trigger * Enable submodules and test build * Enable test build * Disable test build * Change docs directory structure * Fix accidentally committed submodule * Fix submodules * Update links to the developer documentation * Markdown linting * Update workflow, enable test build * Fix doxygen dir path * Update Doxyfile-awesome.cfg * Change paths * Fix upload docs path * Disable pull_request debug trigger * Disable tags building * Remove autolinks and namespaces * Establish basic documentation structure * Add missing changes * Improve stylesheet, move some files * Improve examples * Improve the main page * Improve application dev docs * Improve system programming docs * Improve development tools docs * Improve other docs * Improve application examples * Fix formatting * Fix PVS-studio warnings * Improve visuals * Fix doxygen syntax warnings * Fix broken links * Update doxygen action Co-authored-by: DrunkBatya <drunkbatya.js@gmail.com> Co-authored-by: あく <alleteam@gmail.com> Co-authored-by: Georgii Surkov <georgii.surkov@outlook.com> Co-authored-by: Georgii Surkov <37121527+gsurkov@users.noreply.github.com>
2024-03-06 06:25:21 +00:00
* @param[in] ic FuriHalPowerIc to get measurment
*
* @return voltage in V
*/
2021-08-08 18:03:25 +00:00
float furi_hal_power_get_battery_voltage(FuriHalPowerIC ic);
/** Get battery current in A
*
[FL-870] Auto-generated firmware documentation take two (#2944) * Add doxygen and doxygen-awesome css, cleanup docs files * Ignore more libraries and remove leftover local variables * Create an actual intro page * .md files linting * Add doxygen action * Fix Doxygen path * Fix doxyfile path * Try to upload * Change docs branch * Add submudules checkout * Disable doxygen on PR * Mention the firmware docs in the readme * More dev docs mentions in the readme * Fix runner group, add tags * Test dev in PR * Disable running on PR * Fix a typo in the doxyfile * Try upload to S3 * Fix local path * Fix S3 ACL * Add delete flag, unifying dev and tags * Update ignored directories * More ignored directories * Even more ignored directories * Fix submodule * Change S3 uploader * Change S3 uploader version * Fix aws sync flags * Fix ACL * Disable ACL * Improve ignores, add WiFi devboard docs * TEMP: generate dev docs * TEMP: generate 0.89.0 docs * Disabling PR trigger * Enable submodules and test build * Enable test build * Disable test build * Change docs directory structure * Fix accidentally committed submodule * Fix submodules * Update links to the developer documentation * Markdown linting * Update workflow, enable test build * Fix doxygen dir path * Update Doxyfile-awesome.cfg * Change paths * Fix upload docs path * Disable pull_request debug trigger * Disable tags building * Remove autolinks and namespaces * Establish basic documentation structure * Add missing changes * Improve stylesheet, move some files * Improve examples * Improve the main page * Improve application dev docs * Improve system programming docs * Improve development tools docs * Improve other docs * Improve application examples * Fix formatting * Fix PVS-studio warnings * Improve visuals * Fix doxygen syntax warnings * Fix broken links * Update doxygen action Co-authored-by: DrunkBatya <drunkbatya.js@gmail.com> Co-authored-by: あく <alleteam@gmail.com> Co-authored-by: Georgii Surkov <georgii.surkov@outlook.com> Co-authored-by: Georgii Surkov <37121527+gsurkov@users.noreply.github.com>
2024-03-06 06:25:21 +00:00
* @param[in] ic FuriHalPowerIc to get measurment
*
* @return current in A
*/
2021-08-08 18:03:25 +00:00
float furi_hal_power_get_battery_current(FuriHalPowerIC ic);
/** Get temperature in C
*
[FL-870] Auto-generated firmware documentation take two (#2944) * Add doxygen and doxygen-awesome css, cleanup docs files * Ignore more libraries and remove leftover local variables * Create an actual intro page * .md files linting * Add doxygen action * Fix Doxygen path * Fix doxyfile path * Try to upload * Change docs branch * Add submudules checkout * Disable doxygen on PR * Mention the firmware docs in the readme * More dev docs mentions in the readme * Fix runner group, add tags * Test dev in PR * Disable running on PR * Fix a typo in the doxyfile * Try upload to S3 * Fix local path * Fix S3 ACL * Add delete flag, unifying dev and tags * Update ignored directories * More ignored directories * Even more ignored directories * Fix submodule * Change S3 uploader * Change S3 uploader version * Fix aws sync flags * Fix ACL * Disable ACL * Improve ignores, add WiFi devboard docs * TEMP: generate dev docs * TEMP: generate 0.89.0 docs * Disabling PR trigger * Enable submodules and test build * Enable test build * Disable test build * Change docs directory structure * Fix accidentally committed submodule * Fix submodules * Update links to the developer documentation * Markdown linting * Update workflow, enable test build * Fix doxygen dir path * Update Doxyfile-awesome.cfg * Change paths * Fix upload docs path * Disable pull_request debug trigger * Disable tags building * Remove autolinks and namespaces * Establish basic documentation structure * Add missing changes * Improve stylesheet, move some files * Improve examples * Improve the main page * Improve application dev docs * Improve system programming docs * Improve development tools docs * Improve other docs * Improve application examples * Fix formatting * Fix PVS-studio warnings * Improve visuals * Fix doxygen syntax warnings * Fix broken links * Update doxygen action Co-authored-by: DrunkBatya <drunkbatya.js@gmail.com> Co-authored-by: あく <alleteam@gmail.com> Co-authored-by: Georgii Surkov <georgii.surkov@outlook.com> Co-authored-by: Georgii Surkov <37121527+gsurkov@users.noreply.github.com>
2024-03-06 06:25:21 +00:00
* @param[in] ic FuriHalPowerIc to get measurment
*
* @return temperature in C
*/
2021-08-08 18:03:25 +00:00
float furi_hal_power_get_battery_temperature(FuriHalPowerIC ic);
2020-12-22 18:16:32 +00:00
/** Get USB voltage in V
*
* @return voltage in V
*/
float furi_hal_power_get_usb_voltage(void);
2020-12-18 18:03:28 +00:00
/** Enable 3.3v on external gpio and sd card
*/
void furi_hal_power_enable_external_3_3v(void);
/** Disable 3.3v on external gpio and sd card
*/
void furi_hal_power_disable_external_3_3v(void);
/** Enter supress charge mode.
*
* Use this function when your application need clean power supply.
*/
void furi_hal_power_suppress_charge_enter(void);
/** Exit supress charge mode
*/
void furi_hal_power_suppress_charge_exit(void);
/** Get power information
*
* @param[in] callback callback to provide with new data
* @param[in] sep category separator character
* @param[in] context context to pass to callback
*/
void furi_hal_power_info_get(PropertyValueCallback callback, char sep, void* context);
/** Get power debug information
*
* @param[in] callback callback to provide with new data
* @param[in] context context to pass to callback
*/
void furi_hal_power_debug_get(PropertyValueCallback callback, void* context);
#ifdef __cplusplus
}
#endif