FL-339: cli diagnostic interface for power subsystem. (#256)
* Core, API: add externs for c++ * Makefile: improve debug speed, flash with openocd, cleanup f2 config * Power: add cli diagnostic. * Local: fix api hal externs * Local: fix externs in main and flipper_hal * F2: power state dump stabs * Bootloader flashing with openocd * F3: move bq drivers to libs * temporary do not build drivers on local * temporary do not build drivers on f2 Co-authored-by: aanper <mail@s3f.ru>
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
#include "main.h"
|
||||
#include "stdbool.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// this defined in xx_hal_gpio.c, so...
|
||||
#define GPIO_NUMBER (16U)
|
||||
|
||||
@@ -67,3 +71,7 @@ static inline bool hal_gpio_read(const GpioPin* gpio) {
|
||||
bool hal_gpio_read_sd_detect(void);
|
||||
|
||||
void enable_cc1101_irq();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,20 +1,20 @@
|
||||
#include <api-hal-power.h>
|
||||
#include <adc.h>
|
||||
#include <math.h>
|
||||
|
||||
#define BATTERY_MIN_VOLTAGE 3.2f
|
||||
#define BATTERY_MAX_VOLTAGE 4.0f
|
||||
#define BATTERY_MIN_VOLTAGE 3.4f
|
||||
#define BATTERY_MAX_VOLTAGE 4.1f
|
||||
|
||||
void api_hal_power_init() {}
|
||||
|
||||
uint8_t api_hal_power_get_pct() {
|
||||
float value;
|
||||
HAL_ADC_Start(&hadc1);
|
||||
if(HAL_ADC_PollForConversion(&hadc1, 1000) != HAL_TIMEOUT) {
|
||||
value = HAL_ADC_GetValue(&hadc1);
|
||||
float value = api_hal_power_get_battery_voltage();
|
||||
|
||||
if (value == NAN || value < BATTERY_MIN_VOLTAGE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
value = ((float)value / 10 * 2 - BATTERY_MIN_VOLTAGE) /
|
||||
(BATTERY_MAX_VOLTAGE - BATTERY_MIN_VOLTAGE);
|
||||
value = (value - BATTERY_MIN_VOLTAGE) / (BATTERY_MAX_VOLTAGE - BATTERY_MIN_VOLTAGE) * 100;
|
||||
|
||||
if(value > 100) {
|
||||
value = 100;
|
||||
@@ -32,3 +32,33 @@ void api_hal_power_off() {}
|
||||
void api_hal_power_enable_otg() {}
|
||||
|
||||
void api_hal_power_disable_otg() {}
|
||||
|
||||
float api_hal_power_get_battery_voltage() {
|
||||
ADC_ChannelConfTypeDef sConfig = {0};
|
||||
sConfig.Channel = ADC_CHANNEL_4;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
|
||||
sConfig.SingleDiff = ADC_SINGLE_ENDED;
|
||||
sConfig.OffsetNumber = ADC_OFFSET_NONE;
|
||||
sConfig.Offset = 0;
|
||||
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
float value = NAN;
|
||||
HAL_ADC_Start(&hadc1);
|
||||
if(HAL_ADC_PollForConversion(&hadc1, 1000) != HAL_TIMEOUT) {
|
||||
// adc range / 12 bits * adc_value * divider ratio * sampling drag correction
|
||||
value = 3.3f / 4096.0f * HAL_ADC_GetValue(&hadc1) * 2 * 1.3;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
float api_hal_power_get_battery_current() {
|
||||
return NAN;
|
||||
}
|
||||
|
||||
void api_hal_power_dump_state(string_t buffer) {
|
||||
string_cat_printf(buffer, "Not supported");
|
||||
}
|
||||
|
Reference in New Issue
Block a user