Introduce generic "outputs" DTS binding

Replaces previous "switch" and "pwm-out" bindings and allows to reference
either gpio or pwm handle and specify maximum current.

Also replacing CONFIG_HAS_LOAD and CONFIG_HAS_USB_PWR with DT_ variants.
This commit is contained in:
Martin Jäger
2020-05-06 12:53:26 +02:00
parent 90c1e7fcf5
commit ce7f63b888
29 changed files with 142 additions and 160 deletions
+13 -5
View File
@@ -6,6 +6,10 @@
#include "bat_charger.h"
#ifndef UNIT_TEST
#include <zephyr.h>
#endif
#include <math.h> // for fabs function
#include <stdio.h>
@@ -46,7 +50,7 @@ void battery_conf_init(BatConf *bat, int type, int num_cells, float nominal_capa
bat->voltage_load_reconnect = num_cells * 2.10;
// assumption: Battery selection matching charge controller
bat->internal_resistance = num_cells * (1.95 - 1.80) / LOAD_CURRENT_MAX;
bat->internal_resistance = num_cells * (1.95 - 1.80) / DT_OUTPUTS_LOAD_CURRENT_MAX;
bat->voltage_absolute_min = num_cells * 1.6;
@@ -84,7 +88,8 @@ void battery_conf_init(BatConf *bat, int type, int num_cells, float nominal_capa
bat->voltage_load_reconnect = num_cells * 3.15;
// 5% voltage drop at max current
bat->internal_resistance = bat->voltage_load_disconnect * 0.05 / LOAD_CURRENT_MAX;
bat->internal_resistance = bat->voltage_load_disconnect * 0.05 /
DT_OUTPUTS_LOAD_CURRENT_MAX;
bat->voltage_absolute_min = num_cells * 2.0;
bat->ocv_full = num_cells * 3.4; // will give really nonlinear SOC calculation
@@ -109,7 +114,8 @@ void battery_conf_init(BatConf *bat, int type, int num_cells, float nominal_capa
bat->voltage_load_reconnect = num_cells * 3.6;
// 5% voltage drop at max current
bat->internal_resistance = bat->voltage_load_disconnect * 0.05 / LOAD_CURRENT_MAX;
bat->internal_resistance = bat->voltage_load_disconnect * 0.05 /
DT_OUTPUTS_LOAD_CURRENT_MAX;
bat->voltage_absolute_min = num_cells * 2.5;
@@ -158,9 +164,11 @@ bool battery_conf_check(BatConf *bat_conf)
bat_conf->voltage_recharge > (bat_conf->voltage_load_disconnect + 1) &&
bat_conf->voltage_load_disconnect > (bat_conf->voltage_absolute_min + 0.4) &&
// max. 10% drop
bat_conf->internal_resistance < bat_conf->voltage_load_disconnect * 0.1 / LOAD_CURRENT_MAX &&
bat_conf->internal_resistance < bat_conf->voltage_load_disconnect * 0.1 /
DT_OUTPUTS_LOAD_CURRENT_MAX &&
// max. 3% loss
bat_conf->wire_resistance < bat_conf->topping_voltage * 0.03 / LOAD_CURRENT_MAX &&
bat_conf->wire_resistance < bat_conf->topping_voltage * 0.03 /
DT_OUTPUTS_LOAD_CURRENT_MAX &&
// C/10 or lower current cutoff allowed
bat_conf->topping_current_cutoff < (bat_conf->nominal_capacity / 10.0) &&
bat_conf->topping_current_cutoff > 0.01 &&