/* The documentation asks for CC_CFG to be set to 0x19 upon startup */
#define CC_CFG_DEFAULT 0x19
+/* Cell balancing helpers */
+#define CELL_BALANCE(x) (x)
+#define BCELL(x) (0x01 << ((x) - 1))
+
/* Check the bms presence, return 1 if bms was found.
* This is a basic check, it could be anything with the same address ...
return 0;
}
+/* Cell balancing
+ * set corresponds to the cells set number : [1 .. 3]
+ * cell is the cell number within the set : [1 .. 5] or 0 to turn off cell balancing for this set
+ */
+int bq769x0_cell_balance(struct bq769x0_bms_conf* conf, uint8_t set, uint8_t cell)
+{
+ int ret = 0;
+ uint8_t tmp = 0;
+
+ if ((set == 0) || (set > 3)) {
+ return -1;
+ }
+ if (cell > 5) {
+ return -2;
+ }
+ /* Turn off cell balancing for this set */
+ if (cell == 0) {
+ tmp = 0;
+ } else {
+ tmp = BCELL(cell);
+ }
+ ret = bq769x0_bms_set_regs(conf, CELL_BALANCE(set), &tmp, 1);
+ if (ret != 0) {
+ conf->probe_ok = 20;
+ return ret;
+ }
+ return 0;
+}
+
/* Read ADC values.
* type is one of :
uint8_t uvlo, uint8_t ovp, uint8_t ocd, uint8_t scd);
+/* Cell balancing
+ * set corresponds to the cells set number : [1 .. 3]
+ * cell is the cell number within the set : [1 .. 5] or 0 to turn off cell balancing for this set
+ */
+int bq769x0_cell_balance(struct bq769x0_bms_conf* conf, uint8_t set, uint8_t cell);
+
enum bq769x0_bms_adc_values {
ALL = 0,