Skip to content

Commit

Permalink
sensor: bq274xx: add support for bq27427
Browse files Browse the repository at this point in the history
The current ID for BQ274XX_DEVICE_ID is actually the one for the
BQ27421. The driver seems to work with the BQ27427 as well, add that
variant as well, rename the existing one and print the currently read ID
when the ID check fails.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
  • Loading branch information
fabiobaltieri committed Jul 6, 2023
1 parent f6b5ec8 commit 0b2802a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions drivers/sensor/bq274xx/bq274xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ static int bq274xx_get_device_type(const struct device *dev, uint16_t *val)
}

ret = bq274xx_cmd_reg_read(dev, BQ274XX_CMD_CONTROL_LOW, val);

if (ret < 0) {
LOG_ERR("Unable to read register");
return -EIO;
Expand Down Expand Up @@ -592,8 +591,9 @@ static int bq274xx_gauge_init(const struct device *dev)
return -EIO;
}

if (id != BQ274XX_DEVICE_ID) {
LOG_ERR("Invalid Device");
if (id != BQ27421_DEVICE_ID &&
id != BQ27427_DEVICE_ID) {
LOG_ERR("Invalid Device ID: 0x%x", id);
return -EINVAL;
}

Expand Down
3 changes: 2 additions & 1 deletion drivers/sensor/bq274xx/bq274xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

/*** General Constant ***/
#define BQ274XX_UNSEAL_KEY 0x8000 /* Secret code to unseal the BQ27441-G1A */
#define BQ274XX_DEVICE_ID 0x0421 /* Default device ID */
#define BQ27421_DEVICE_ID 0x0421
#define BQ27427_DEVICE_ID 0x0427

/*** Standard Commands ***/
#define BQ274XX_CMD_CONTROL_LOW 0x00 /* Control() low register */
Expand Down

0 comments on commit 0b2802a

Please sign in to comment.