mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-11-24 03:07:21 +03:00
Api Hal OS/Power: split insomnia and return to where it belongs. (#393)
This commit is contained in:
parent
5439e232cc
commit
81ace53cc1
@ -39,8 +39,11 @@ void api_hal_power_insomnia_enter();
|
||||
*/
|
||||
void api_hal_power_insomnia_exit();
|
||||
|
||||
/** Check if sleep availble */
|
||||
bool api_hal_power_sleep_available();
|
||||
|
||||
/** Check if deep sleep availble */
|
||||
bool api_hal_power_deep_available();
|
||||
bool api_hal_power_deep_sleep_available();
|
||||
|
||||
/** Go to sleep */
|
||||
void api_hal_power_sleep();
|
||||
|
@ -12,7 +12,16 @@
|
||||
#include <bq27220.h>
|
||||
#include <bq25896.h>
|
||||
|
||||
volatile uint32_t api_hal_power_insomnia = 1;
|
||||
typedef struct {
|
||||
volatile uint32_t insomnia;
|
||||
volatile uint32_t deep_insomnia;
|
||||
} ApiHalPower;
|
||||
|
||||
static volatile ApiHalPower api_hal_power = {
|
||||
.insomnia = 0,
|
||||
.deep_insomnia = 1,
|
||||
};
|
||||
|
||||
const ParamCEDV cedv = {
|
||||
.full_charge_cap = 2100,
|
||||
.design_cap = 2100,
|
||||
@ -48,19 +57,23 @@ void api_hal_power_init() {
|
||||
}
|
||||
|
||||
uint16_t api_hal_power_insomnia_level() {
|
||||
return api_hal_power_insomnia;
|
||||
return api_hal_power.insomnia;
|
||||
}
|
||||
|
||||
void api_hal_power_insomnia_enter() {
|
||||
api_hal_power_insomnia++;
|
||||
api_hal_power.insomnia++;
|
||||
}
|
||||
|
||||
void api_hal_power_insomnia_exit() {
|
||||
api_hal_power_insomnia--;
|
||||
api_hal_power.insomnia--;
|
||||
}
|
||||
|
||||
bool api_hal_power_deep_available() {
|
||||
return api_hal_bt_is_alive() && api_hal_power_insomnia == 0;
|
||||
bool api_hal_power_sleep_available() {
|
||||
return api_hal_power.insomnia == 0;
|
||||
}
|
||||
|
||||
bool api_hal_power_deep_sleep_available() {
|
||||
return api_hal_bt_is_alive() && api_hal_power.deep_insomnia == 0;
|
||||
}
|
||||
|
||||
void api_hal_power_light_sleep() {
|
||||
@ -112,7 +125,7 @@ void api_hal_power_deep_sleep() {
|
||||
}
|
||||
|
||||
void api_hal_power_sleep() {
|
||||
if(api_hal_power_deep_available()) {
|
||||
if(api_hal_power_deep_sleep_available()) {
|
||||
api_hal_power_deep_sleep();
|
||||
} else {
|
||||
api_hal_power_light_sleep();
|
||||
|
@ -99,6 +99,11 @@ static inline uint32_t api_hal_os_sleep(TickType_t expected_idle_ticks) {
|
||||
}
|
||||
|
||||
void vPortSuppressTicksAndSleep(TickType_t expected_idle_ticks) {
|
||||
if(!api_hal_power_sleep_available()) {
|
||||
__WFI();
|
||||
return;
|
||||
}
|
||||
|
||||
// Limit mount of ticks to maximum that timer can count
|
||||
if (expected_idle_ticks > API_HAL_OS_MAX_SLEEP) {
|
||||
expected_idle_ticks = API_HAL_OS_MAX_SLEEP;
|
||||
|
@ -13,7 +13,16 @@
|
||||
#include <bq27220.h>
|
||||
#include <bq25896.h>
|
||||
|
||||
volatile uint32_t api_hal_power_insomnia = 1;
|
||||
typedef struct {
|
||||
volatile uint32_t insomnia;
|
||||
volatile uint32_t deep_insomnia;
|
||||
} ApiHalPower;
|
||||
|
||||
static volatile ApiHalPower api_hal_power = {
|
||||
.insomnia = 0,
|
||||
.deep_insomnia = 1,
|
||||
};
|
||||
|
||||
const ParamCEDV cedv = {
|
||||
.full_charge_cap = 2100,
|
||||
.design_cap = 2100,
|
||||
@ -49,19 +58,23 @@ void api_hal_power_init() {
|
||||
}
|
||||
|
||||
uint16_t api_hal_power_insomnia_level() {
|
||||
return api_hal_power_insomnia;
|
||||
return api_hal_power.insomnia;
|
||||
}
|
||||
|
||||
void api_hal_power_insomnia_enter() {
|
||||
api_hal_power_insomnia++;
|
||||
api_hal_power.insomnia++;
|
||||
}
|
||||
|
||||
void api_hal_power_insomnia_exit() {
|
||||
api_hal_power_insomnia--;
|
||||
api_hal_power.insomnia--;
|
||||
}
|
||||
|
||||
bool api_hal_power_deep_available() {
|
||||
return api_hal_bt_is_alive() && api_hal_power_insomnia == 0;
|
||||
bool api_hal_power_sleep_available() {
|
||||
return api_hal_power.insomnia == 0;
|
||||
}
|
||||
|
||||
bool api_hal_power_deep_sleep_available() {
|
||||
return api_hal_bt_is_alive() && api_hal_power.deep_insomnia == 0;
|
||||
}
|
||||
|
||||
void api_hal_power_light_sleep() {
|
||||
@ -113,7 +126,7 @@ void api_hal_power_deep_sleep() {
|
||||
}
|
||||
|
||||
void api_hal_power_sleep() {
|
||||
if(api_hal_power_deep_available()) {
|
||||
if(api_hal_power_deep_sleep_available()) {
|
||||
api_hal_power_deep_sleep();
|
||||
} else {
|
||||
api_hal_power_light_sleep();
|
||||
@ -186,7 +199,7 @@ float api_hal_power_get_battery_temperature(ApiHalPowerIC ic) {
|
||||
}
|
||||
|
||||
float api_hal_power_get_usb_voltage(){
|
||||
return (float)bq25896_get_vbus_voltage() / 1000.0f;;
|
||||
return (float)bq25896_get_vbus_voltage() / 1000.0f;
|
||||
}
|
||||
|
||||
void api_hal_power_dump_state(string_t buffer) {
|
||||
|
Loading…
Reference in New Issue
Block a user