lc709203f.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 RWTH Aachen
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
22 #ifndef LC709203F_H
23 #define LC709203F_H
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #include "periph/i2c.h"
30 #include "periph/gpio.h"
31 
37 typedef enum {
38  AUTO_MODE = 0x0,
39  CHARGE_MODE = 0x1,
40  DISCHARGE_MODE = 0xffff
49 typedef enum {
50  BAT_PROFILE_1 = 0,
51  BAT_PROFILE_2 = 1
60 typedef enum {
61  OPERATIONAL_MODE = 1,
62  SLEEP_MODE = 2
71 typedef enum {
72  I2C_MODE = 0,
73  THERMISTOR_MODE = 1
82 typedef void (*lc709203f_cb_t)(void *arg);
83 
88 typedef struct {
89  gpio_t alarm_pin;
91  uint8_t addr;
95 enum {
99 };
100 
106 typedef struct {
108  uint8_t addr;
109  uint8_t scale;
112  void *arg;
113 } lc709203f_t;
121 #define LC709203F_REG_CELL_VOLTAGE 0x09
122 #define LC709203F_REG_RSOC 0x0d
123 #define LC709203F_REG_ITE 0x0f
124 #define LC709203F_REG_ID 0x11
125 #define LC709203F_REG_CELL_TEMP 0x08
126 #define LC709203F_REG_STATUS 0x16
127 #define LC709203F_REG_POWER_MODE 0x15
128 #define LC709203F_REG_ALARM_VOLTAGE 0x14
129 #define LC709203F_REG_ALARM_RSOC 0x13
130 #define LC709203F_REG_CHANGE_PARAMETER 0x12
131 #define LC709203F_REG_APT 0x0c
132 #define LC709203F_REG_APA 0x0b
133 #define LC709203F_REG_CURRENT_DIRECTION 0x0a
134 #define LC709203F_REG_THERMISTOR 0x06
135 #define LC709203F_REG_BEFORE_RSOC 0x04
136 #define LC709203F_REG_INITIAL_RSOC 0x07
139 #define LC709203F_CRC_POLYNOMIAL 0x07
150 int lc709203f_init(lc709203f_t *dev, const lc709203f_params_t *params);
151 
159 int16_t lc709203f_get_voltage(const lc709203f_t *dev);
160 
168 int16_t lc709203f_get_rsoc(const lc709203f_t *dev);
169 
177 int16_t lc709203f_get_ite(const lc709203f_t *dev);
178 
186 int16_t lc709203f_get_id(const lc709203f_t *dev);
187 
195 int16_t lc709203f_get_cell_temp(const lc709203f_t *dev);
196 
206 
216 
225 int16_t lc709203f_get_alarm_low_voltage(const lc709203f_t *dev);
226 
235 int16_t lc709203f_get_alarm_low_rsoc(const lc709203f_t *dev);
236 
245 
254 int16_t lc709203f_get_apt(const lc709203f_t *dev);
255 
264 int16_t lc709203f_get_apa(const lc709203f_t *dev);
265 
276 
284 int16_t lc709203f_get_thermistor_b(const lc709203f_t *dev);
285 
291 void lc709203f_set_rsoc_before(const lc709203f_t *dev);
292 
299 void lc709203f_set_thermistor_b(const lc709203f_t *dev, const unsigned int value);
300 
306 void lc709203f_set_rsoc_initial(const lc709203f_t *dev);
307 
317 int8_t lc709203f_set_cell_temp(const lc709203f_t *dev, const unsigned int value);
318 
326 
333 void lc709203f_set_apa(const lc709203f_t *dev, const uint8_t value);
334 
341 void lc709203f_set_apt(const lc709203f_t *dev, const unsigned int value);
342 
350 
357 void lc709203f_set_alarm_low_rsoc(const lc709203f_t *dev, const uint8_t value);
358 
365 void lc709203f_set_alarm_low_cell_voltage(const lc709203f_t *dev, const unsigned int value);
366 
373 void lc709203f_set_power_mode(const lc709203f_t *dev, const lc709203f_power_mode_t value);
374 
382 
383 #ifdef __cplusplus
384 }
385 #endif
386 
387 #endif /* LC709203F_H */
388 
lc709203f_cb_t
void(* lc709203f_cb_t)(void *arg)
Typedef for the Callback function.
Definition: lc709203f.h:82
lc709203f_t::bus
i2c_t bus
I2C bus to use.
Definition: lc709203f.h:107
LC709203F_NOI2C
@ LC709203F_NOI2C
error using the I2C bus
Definition: lc709203f.h:97
lc709203f_t
Device descriptor for the fuel gauge.
Definition: lc709203f.h:106
lc709203f_set_cell_temp
int8_t lc709203f_set_cell_temp(const lc709203f_t *dev, const unsigned int value)
Sets cell temperature in I2C-mode.
lc709203f_set_power_mode
void lc709203f_set_power_mode(const lc709203f_t *dev, const lc709203f_power_mode_t value)
Sets power mode.
lc709203f_get_change_of_parameter
int16_t lc709203f_get_change_of_parameter(const lc709203f_t *dev)
reads Change of the Parameter register, Battery Profile selection
lc709203f_set_apt
void lc709203f_set_apt(const lc709203f_t *dev, const unsigned int value)
Sets value to adjust temperature measurement delay timing (adjusmtent pack thermistor)
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
lc709203f_power_mode_t
lc709203f_power_mode_t
Power mode choices.
Definition: lc709203f.h:60
lc709203f_set_rsoc_before
void lc709203f_set_rsoc_before(const lc709203f_t *dev)
Executes RSOC initialization with sampled maximum voltage.
lc709203f_get_power_mode
lc709203f_power_mode_t lc709203f_get_power_mode(const lc709203f_t *dev)
reads IC Power Mode register
lc709203f_get_status_bit
lc709203f_temp_obtaining_mode_t lc709203f_get_status_bit(const lc709203f_t *dev)
reads status bit register (Temperature obtaining mode)
lc709203f_set_thermistor_b
void lc709203f_set_thermistor_b(const lc709203f_t *dev, const unsigned int value)
Sets B constant of the Thermistor.
lc709203f_set_apa
void lc709203f_set_apa(const lc709203f_t *dev, const uint8_t value)
Sets parasitic impedance (adjustment pack application)
lc709203f_t::addr
uint8_t addr
I2C Address of fuel gauge.
Definition: lc709203f.h:108
lc709203f_t::scale
uint8_t scale
scale for returned values
Definition: lc709203f.h:109
lc709203f_params_t::alarm_pin
gpio_t alarm_pin
Pin which is connected to the interrupt pin of the sensor.
Definition: lc709203f.h:89
lc709203f_current_direction_t
lc709203f_current_direction_t
Current direction modes.
Definition: lc709203f.h:37
lc709203f_set_rsoc_initial
void lc709203f_set_rsoc_initial(const lc709203f_t *dev)
Executes RSOC initialization.
LC709203F_CELL_TEMP_INVALID
@ LC709203F_CELL_TEMP_INVALID
Cell temp invalid.
Definition: lc709203f.h:98
lc709203f_get_apt
int16_t lc709203f_get_apt(const lc709203f_t *dev)
reads APT (Adjustment Pack Thermistor) value to adjust temperature measurement delay timing.
lc709203f_set_change_of_parameter
void lc709203f_set_change_of_parameter(const lc709203f_t *dev, const lc709203f_battery_profile_t value)
Sets battery profile.
lc709203f_temp_obtaining_mode_t
lc709203f_temp_obtaining_mode_t
Temperature obtaining mode options.
Definition: lc709203f.h:71
lc709203f_get_thermistor_b
int16_t lc709203f_get_thermistor_b(const lc709203f_t *dev)
reads Thermistor-B register (Thermistor B constant to be measured)
lc709203f_t::cb
lc709203f_cb_t cb
callback method
Definition: lc709203f.h:111
lc709203f_params_t::addr
uint8_t addr
I2C Address of the fuel gauge.
Definition: lc709203f.h:91
lc709203f_params_t
Parameter struct for driver initialization.
Definition: lc709203f.h:88
lc709203f_get_cell_temp
int16_t lc709203f_get_cell_temp(const lc709203f_t *dev)
reads cell temperature from sensor
lc709203f_get_rsoc
int16_t lc709203f_get_rsoc(const lc709203f_t *dev)
reads battery state of charge from Sensor
lc709203f_get_alarm_low_voltage
int16_t lc709203f_get_alarm_low_voltage(const lc709203f_t *dev)
reads Alarm Low Cell Voltage Register
lc709203f_get_ite
int16_t lc709203f_get_ite(const lc709203f_t *dev)
reads battery indicator to empty from Sensor
lc709203f_get_voltage
int16_t lc709203f_get_voltage(const lc709203f_t *dev)
reads battery voltage from Sensor
lc709203f_set_alarm_low_cell_voltage
void lc709203f_set_alarm_low_cell_voltage(const lc709203f_t *dev, const unsigned int value)
Sets threshold for low cell voltage alert.
lc709203f_set_alarm_low_rsoc
void lc709203f_set_alarm_low_rsoc(const lc709203f_t *dev, const uint8_t value)
Sets threshold for low rsoc alert.
lc709203f_t::params
lc709203f_params_t params
param struct with static settings etc
Definition: lc709203f.h:110
gpio.h
Low-level GPIO peripheral driver interface definitions.
lc709203f_get_apa
int16_t lc709203f_get_apa(const lc709203f_t *dev)
reads APA (Adjustment Pack Application) in 1mOhm steps value to adjust temperature measurement delay ...
lc709203f_set_status_bit
void lc709203f_set_status_bit(const lc709203f_t *dev, const lc709203f_temp_obtaining_mode_t value)
Sets temperature obtaining method.
LC709203F_OK
@ LC709203F_OK
all went as expected
Definition: lc709203f.h:96
lc709203f_battery_profile_t
lc709203f_battery_profile_t
Battery Profile Options.
Definition: lc709203f.h:49
lc709203f_get_current_direction
lc709203f_current_direction_t lc709203f_get_current_direction(const lc709203f_t *dev)
reads Current Direction Register
lc709203f_set_current_direction
void lc709203f_set_current_direction(const lc709203f_t *dev, const lc709203f_current_direction_t direction)
Sets current direction.
lc709203f_get_id
int16_t lc709203f_get_id(const lc709203f_t *dev)
reads Sensor id
i2c.h
Low-level I2C peripheral driver interface definition.
lc709203f_get_alarm_low_rsoc
int16_t lc709203f_get_alarm_low_rsoc(const lc709203f_t *dev)
reads Alarm Low RSOC Register
lc709203f_t::arg
void * arg
additional arguments for the callback method
Definition: lc709203f.h:112
lc709203f_params_t::bus
i2c_t bus
I2C bus to use.
Definition: lc709203f.h:90