Skip to content

Drivers: max17055: retrieve the current value #93034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions drivers/sensor/maxim/max17055/max17055.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ static int max17055_channel_get(const struct device *dev,
valp->val1 = tmp / 1000000;
valp->val2 = tmp % 1000000;
break;
case SENSOR_CHAN_CURRENT: {
int current_ma;

current_ma = current_to_ma(config->rsense_mohms, priv->current);
set_millis(valp, current_ma);
break;
}
case SENSOR_CHAN_GAUGE_AVG_CURRENT: {
int current_ma;

Expand Down Expand Up @@ -255,6 +262,13 @@ static int max17055_sample_fetch(const struct device *dev,
}
}

if (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_CURRENT) {
ret = max17055_reg_read(dev, CURRENT, &priv->current);
if (ret < 0) {
return ret;
}
}

if (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_GAUGE_AVG_CURRENT) {
ret = max17055_reg_read(dev, AVG_CURRENT, &priv->avg_current);
if (ret < 0) {
Expand Down
3 changes: 3 additions & 0 deletions drivers/sensor/maxim/max17055/max17055.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum {
REP_SOC = 0x6,
INT_TEMP = 0x8,
VCELL = 0x9,
CURRENT = 0xa,
AVG_CURRENT = 0xb,
FULL_CAP_REP = 0x10,
TTE = 0x11,
Expand Down Expand Up @@ -49,6 +50,8 @@ struct max17055_data {
uint16_t voltage;
/* Current cell open circuit voltage in units of 1.25/16mV */
uint16_t ocv;
/* Current in units of 1.5625uV / Rsense */
int16_t current;
/* Average current in units of 1.5625uV / Rsense */
int16_t avg_current;
/* Remaining capacity as a %age */
Expand Down