2021-10-03 13:36:05 +03:00
|
|
|
/**
|
|
|
|
* @file furi-hal-power.h
|
|
|
|
* Power HAL API
|
|
|
|
*/
|
|
|
|
|
2020-11-11 09:31:35 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2020-12-02 13:47:13 +03:00
|
|
|
#include <m-string.h>
|
|
|
|
|
|
|
|
#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
|
|
|
|
2021-10-03 13:36:05 +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
|
|
|
|
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
|
|
|
/** Check if deep sleep availble
|
|
|
|
*
|
|
|
|
* @return true if available
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
bool furi_hal_power_deep_sleep_available();
|
[FL-781] FURI, CLI, stdlib: stdout hooks, integration between subsystems, uniform printf usage (#311)
* FURI stdglue: stdout hooks, local and global, ISR safe printf. Uniform newlines for terminal/debug output. Power: prevent sleep while core 2 has not started.
* Furi record, stdglue: check mutex allocation
* remove unused test
* Furi stdglue: buferized output, dynamically allocated state. Furi record: dynamically allocated state. Input dump: proper line ending. Hal VCP: dynamically allocated state.
* Interrupt manager: explicitly init list.
* Makefile: cleanup rules, fix broken dfu upload. F4: add compiler stack protection options.
* BLE: call debug uart callback on transmission complete
* FreeRTOS: add configUSE_NEWLIB_REENTRANT
* API HAL Timebase: fix issue with idle thread stack corruption caused by systick interrupt. BT: cleanup debug info output. FreeRTOS: disable reentry for newlib.
* F4: update stack protection CFLAGS to match used compiller
* F4: disable compiller stack protection because of incompatibility with current compiller
* Makefile: return openocd logs to gdb
* BLE: fixed pin, moar power, ble trace info.
* Prevent sleep when connection is active
* Makefile: return serial port to upload rule, add workaround for mac os
* Furi: prevent usage of stack for cmsis functions.
* F4: add missing includes, add debugger breakpoints
* Applications: per app stack size.
* Furi: honor kernel state in stdglue
* FreeRTOS: remove unused hooks
* Cleanup and format sources
Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2021-01-29 03:09:33 +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
|
|
|
|
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
|
|
|
|
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();
|
|
|
|
|
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
|
|
|
|
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 System voltage in V
|
|
|
|
*
|
|
|
|
* @return voltage in V
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
float furi_hal_power_get_system_voltage();
|
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
|
|
|
/** Get power system component state
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_power_dump_state();
|
2020-12-02 13:47:13 +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
|
|
|
|
2020-12-02 13:47:13 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|