mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-22 21:01:40 +03:00
01434265f6
* 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>
213 lines
4.6 KiB
C
213 lines
4.6 KiB
C
/**
|
|
* @file furi_hal_power.h
|
|
* Power HAL API
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <m-string.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/** Power IC type */
|
|
typedef enum {
|
|
FuriHalPowerICCharger,
|
|
FuriHalPowerICFuelGauge,
|
|
} FuriHalPowerIC;
|
|
|
|
/** Initialize drivers */
|
|
void furi_hal_power_init();
|
|
|
|
/** 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();
|
|
|
|
/** Get current insomnia level
|
|
*
|
|
* @return insomnia level: 0 - no insomnia, >0 - insomnia, bearer count.
|
|
*/
|
|
uint16_t furi_hal_power_insomnia_level();
|
|
|
|
/** 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();
|
|
|
|
/** 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();
|
|
|
|
/** Check if sleep availble
|
|
*
|
|
* @return true if available
|
|
*/
|
|
bool furi_hal_power_sleep_available();
|
|
|
|
/** Check if deep sleep availble
|
|
*
|
|
* @return true if available
|
|
*/
|
|
bool furi_hal_power_deep_sleep_available();
|
|
|
|
/** Go to sleep
|
|
*/
|
|
void furi_hal_power_sleep();
|
|
|
|
/** Get predicted remaining battery capacity in percents
|
|
*
|
|
* @return remaining battery capacity in percents
|
|
*/
|
|
uint8_t furi_hal_power_get_pct();
|
|
|
|
/** Get battery health state in percents
|
|
*
|
|
* @return health in percents
|
|
*/
|
|
uint8_t furi_hal_power_get_bat_health_pct();
|
|
|
|
/** Get charging status
|
|
*
|
|
* @return true if charging
|
|
*/
|
|
bool furi_hal_power_is_charging();
|
|
|
|
/** Switch MCU to SHUTDOWN */
|
|
void furi_hal_power_shutdown();
|
|
|
|
/** Poweroff device
|
|
*/
|
|
void furi_hal_power_off();
|
|
|
|
/** Reset device
|
|
*/
|
|
void furi_hal_power_reset();
|
|
|
|
/** OTG enable
|
|
*/
|
|
void furi_hal_power_enable_otg();
|
|
|
|
/** OTG disable
|
|
*/
|
|
void furi_hal_power_disable_otg();
|
|
|
|
/** Check OTG status and disable it if falt happened
|
|
*/
|
|
void furi_hal_power_check_otg_status();
|
|
|
|
/** Get OTG status
|
|
*
|
|
* @return true if enabled
|
|
*/
|
|
bool furi_hal_power_is_otg_enabled();
|
|
|
|
/** Get remaining battery battery capacity in mAh
|
|
*
|
|
* @return capacity in mAh
|
|
*/
|
|
uint32_t furi_hal_power_get_battery_remaining_capacity();
|
|
|
|
/** Get full charge battery capacity in mAh
|
|
*
|
|
* @return capacity in mAh
|
|
*/
|
|
uint32_t furi_hal_power_get_battery_full_capacity();
|
|
|
|
/** Get battery capacity in mAh from battery profile
|
|
*
|
|
* @return capacity in mAh
|
|
*/
|
|
uint32_t furi_hal_power_get_battery_design_capacity();
|
|
|
|
/** Get battery voltage in V
|
|
*
|
|
* @param ic FuriHalPowerIc to get measurment
|
|
*
|
|
* @return voltage in V
|
|
*/
|
|
float furi_hal_power_get_battery_voltage(FuriHalPowerIC ic);
|
|
|
|
/** Get battery current in A
|
|
*
|
|
* @param ic FuriHalPowerIc to get measurment
|
|
*
|
|
* @return current in A
|
|
*/
|
|
float furi_hal_power_get_battery_current(FuriHalPowerIC ic);
|
|
|
|
/** Get temperature in C
|
|
*
|
|
* @param ic FuriHalPowerIc to get measurment
|
|
*
|
|
* @return temperature in C
|
|
*/
|
|
float furi_hal_power_get_battery_temperature(FuriHalPowerIC ic);
|
|
|
|
/** Get System voltage in V
|
|
*
|
|
* @return voltage in V
|
|
*/
|
|
float furi_hal_power_get_system_voltage();
|
|
|
|
/** Get USB voltage in V
|
|
*
|
|
* @return voltage in V
|
|
*/
|
|
float furi_hal_power_get_usb_voltage();
|
|
|
|
/** Get power system component state
|
|
*/
|
|
void furi_hal_power_dump_state();
|
|
|
|
/** Enable 3.3v on external gpio and sd card
|
|
*/
|
|
void furi_hal_power_enable_external_3_3v();
|
|
|
|
/** Disable 3.3v on external gpio and sd card
|
|
*/
|
|
void furi_hal_power_disable_external_3_3v();
|
|
|
|
/** 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();
|
|
|
|
/** Callback type called by furi_hal_power_info_get every time another key-value pair of information is ready
|
|
*
|
|
* @param key[in] power information type identifier
|
|
* @param value[in] power information value
|
|
* @param last[in] whether the passed key-value pair is the last one
|
|
* @param context[in] to pass to callback
|
|
*/
|
|
typedef void (
|
|
*FuriHalPowerInfoCallback)(const char* key, const char* value, bool last, void* context);
|
|
|
|
/** Get power information
|
|
*
|
|
* @param[in] callback callback to provide with new data
|
|
* @param[in] context context to pass to callback
|
|
*/
|
|
void furi_hal_power_info_get(FuriHalPowerInfoCallback callback, void* context);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|