1 /* 2 * Copyright 2020 Google LLC 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_DRIVERS_SENSOR_BATTERY_MAX17055_H_ 8 #define ZEPHYR_DRIVERS_SENSOR_BATTERY_MAX17055_H_ 9 10 #include <zephyr/drivers/i2c.h> 11 12 /* Register addresses */ 13 enum { 14 STATUS = 0x0, 15 REP_CAP = 0x5, 16 REP_SOC = 0x6, 17 INT_TEMP = 0x8, 18 VCELL = 0x9, 19 AVG_CURRENT = 0xb, 20 FULL_CAP_REP = 0x10, 21 TTE = 0x11, 22 ICHG_TERM = 0x1e, 23 CYCLES = 0x17, 24 DESIGN_CAP = 0x18, 25 TTF = 0x20, 26 V_EMPTY = 0x3a, 27 FSTAT = 0x3d, 28 D_QACC = 0x45, 29 D_PACC = 0x46, 30 SOFT_WAKEUP = 0x60, 31 HIB_CFG = 0xba, 32 MODEL_CFG = 0xdb, 33 VFOCV = 0xfb, 34 }; 35 36 /* Masks */ 37 enum { 38 FSTAT_DNR = 0x0001, 39 HIB_CFG_CLEAR = 0x0000, 40 MODELCFG_REFRESH = 0x8000, 41 SOFT_WAKEUP_CLEAR = 0x0000, 42 SOFT_WAKEUP_WAKEUP = 0x0090, 43 STATUS_POR = 0x0002, 44 VEMPTY_VE = 0xff80, 45 }; 46 47 struct max17055_data { 48 /* Current cell voltage in units of 1.25/16mV */ 49 uint16_t voltage; 50 /* Current cell open circuit voltage in units of 1.25/16mV */ 51 uint16_t ocv; 52 /* Average current in units of 1.5625uV / Rsense */ 53 int16_t avg_current; 54 /* Remaining capacity as a %age */ 55 uint16_t state_of_charge; 56 /* Internal temperature in units of 1/256 degrees C */ 57 int16_t internal_temp; 58 /* Full charge capacity in 5/Rsense uA */ 59 uint16_t full_cap; 60 /* Remaining capacity in 5/Rsense uA */ 61 uint16_t remaining_cap; 62 /* Time to empty in units of 5.625s */ 63 uint16_t time_to_empty; 64 /* Time to full in units of 5.625s */ 65 uint16_t time_to_full; 66 /* Cycle count in 1/100ths (number of charge/discharge cycles) */ 67 uint16_t cycle_count; 68 /* Design capacity in 5/Rsense uA */ 69 uint16_t design_cap; 70 }; 71 72 struct max17055_config { 73 struct i2c_dt_spec i2c; 74 /* Value of Rsense resistor in milliohms (typically 5 or 10) */ 75 uint16_t rsense_mohms; 76 /* The design capacity (aka label capacity) of the cell in mAh */ 77 uint16_t design_capacity; 78 /* Design voltage of cell in mV */ 79 uint16_t design_voltage; 80 /* Desired voltage of cell in mV */ 81 uint16_t desired_voltage; 82 /* Desired charging current in mA */ 83 uint16_t desired_charging_current; 84 /* The charge termination current in uA */ 85 uint16_t i_chg_term; 86 /* The empty voltage of the cell in mV */ 87 uint16_t v_empty; 88 }; 89 90 #endif 91