Skip to content

Commit

Permalink
sensor: bq274xx: fix few parameter calculations
Browse files Browse the repository at this point in the history
Fix the calculation for designenergy_mwh, as right now it's using a
float casted straight to an int, which results in the factor rounded
from 3.7 to 3. Also rework both that and taperrate so that they don't
use floating point.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
  • Loading branch information
fabiobaltieri committed Jul 6, 2023
1 parent 0b2802a commit d27cdc8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/sensor/bq274xx/bq274xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ static int bq274xx_gauge_configure(const struct device *dev)
terminatevolt_msb, terminatevolt_lsb, taperrate_msb, taperrate_lsb;
uint8_t block[BQ27XXX_DM_SZ];

designenergy_mwh = (uint16_t)3.7 * config->design_capacity;
taperrate = (uint16_t)config->design_capacity / (0.1 * config->taper_current);
designenergy_mwh = (uint32_t)config->design_capacity * 3700 / 1000;
taperrate = config->design_capacity * 10 / config->taper_current;

/* Unseal the battery control register */
ret = bq274xx_ctrl_reg_write(dev, BQ274XX_UNSEAL_KEY);
Expand Down

0 comments on commit d27cdc8

Please sign in to comment.