Skip to content
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

Drivers: Fuel_Gauge: MAX17048: added units to fuel_gauge sample output and Output of voltage is now shown in microVolts #75563

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
15 changes: 7 additions & 8 deletions drivers/fuel_gauge/max17048/max17048.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/* Charge as percentage */
uint8_t charge;
/* Voltage as mV */
Goyalrahul1516 marked this conversation as resolved.
Show resolved Hide resolved
uint16_t voltage;
uint32_t voltage;

/* Time in minutes */
uint16_t time_to_full;
Expand Down Expand Up @@ -72,9 +72,10 @@
/**
* Battery voltage
*/
int max17048_voltage(const struct device *i2c_dev, uint16_t *response)
int max17048_voltage(const struct device *i2c_dev, uint32_t *response)
{
int rc = max17048_adc(i2c_dev, response);
uint16_t raw_voltage;

Check failure on line 77 in drivers/fuel_gauge/max17048/max17048.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

drivers/fuel_gauge/max17048/max17048.c:77 code indent should use tabs where possible

Check warning on line 77 in drivers/fuel_gauge/max17048/max17048.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACE_BEFORE_TAB

drivers/fuel_gauge/max17048/max17048.c:77 please, no space before tabs

Check warning on line 77 in drivers/fuel_gauge/max17048/max17048.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

drivers/fuel_gauge/max17048/max17048.c:77 please, no spaces at the start of a line
int rc = max17048_adc(i2c_dev, &raw_voltage);

Check failure on line 78 in drivers/fuel_gauge/max17048/max17048.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

drivers/fuel_gauge/max17048/max17048.c:78 code indent should use tabs where possible

Check warning on line 78 in drivers/fuel_gauge/max17048/max17048.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACE_BEFORE_TAB

drivers/fuel_gauge/max17048/max17048.c:78 please, no space before tabs

Check warning on line 78 in drivers/fuel_gauge/max17048/max17048.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

drivers/fuel_gauge/max17048/max17048.c:78 please, no spaces at the start of a line

if (rc < 0) {
return rc;
Expand All @@ -85,12 +86,10 @@
* MAX17048-MAX17049.pdf
* Page 10, Table 2. Register Summary: 78.125µV/cell
* Max17048 only supports one cell so we just have to multiply the value by 78.125 to
* obtain µV and then divide the value to obtain V.
* But to avoid floats, instead of using 78.125 we will use 78125 and use this value as
* milli volts instead of volts.
* obtain µV
*/

*response = (uint16_t)((uint32_t)*response * 78125L / 1000000L);
*response = (uint32_t)raw_voltage * 78.125;
return 0;
}

Expand Down Expand Up @@ -120,7 +119,7 @@
* Percentage of the total battery capacity per hour, positive is charging or
* negative if discharging
*/
int max17048_crate(const struct device *i2c_dev, int16_t *response)
int max17048_crate(const struct device *i2c_dev, uint16_t *response)
{
int rc = max17048_read_register(i2c_dev, REGISTER_CRATE, response);

Expand Down
6 changes: 3 additions & 3 deletions samples/fuel_gauge/max17048/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ int main(void)
if (ret < 0) {
printk("Error: cannot get properties\n");
} else {
printk("Time to empty %d\n", vals[0].runtime_to_empty);
printk("Time to empty %d minutes\n", vals[0].runtime_to_empty);

printk("Time to full %d\n", vals[1].runtime_to_full);
printk("Time to full %d minutes\n", vals[1].runtime_to_full);

printk("Charge %d%%\n", vals[2].relative_state_of_charge);

printk("Voltage %d\n", vals[3].voltage);
printk("Voltage %d uV\n", vals[3].voltage);
}

k_sleep(K_MSEC(5000));
Expand Down
Loading