You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/07/09 21:39:24 UTC

[GitHub] kasjer closed pull request #1244: Battery property write

kasjer closed pull request #1244: Battery property write
URL: https://github.com/apache/mynewt-core/pull/1244
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/hw/battery/src/battery_shell.c b/hw/battery/src/battery_shell.c
index 1de5097c5a..fb734c797d 100644
--- a/hw/battery/src/battery_shell.c
+++ b/hw/battery/src/battery_shell.c
@@ -52,6 +52,13 @@ static const struct shell_cmd_help bat_read_help =
         .params = bat_read_params,
 };
 
+static const struct shell_cmd_help bat_write_help =
+{
+        .summary = "write battery properties",
+        .usage = "read <prop> <value>",
+        .params = NULL,
+};
+
 static const struct shell_cmd_help bat_list_help =
 {
         .summary = "list battery properties",
@@ -97,6 +104,7 @@ static void cmd_bat_help(void)
     console_printf("  monitor [<prop>] [off]\n");
     console_printf("  list\n");
     console_printf("  read [<prop>] | all\n");
+    console_printf("  write <prop> <value>\n");
 
     console_printf("Examples:\n");
     console_printf("  list\n");
@@ -104,6 +112,7 @@ static void cmd_bat_help(void)
     console_printf("  monitor off\n");
     console_printf("  read Voltage\n");
     console_printf("  read all\n");
+    console_printf("  write VoltageLoAlarmSet\n");
 }
 
 static const char *bat_status[] = {
@@ -215,6 +224,69 @@ static int cmd_bat_read(int argc, char **argv)
     return rc;
 }
 
+static int
+get_min_max(const struct battery_property *prop, long long *min, long long *max)
+{
+    int rc = 0;
+
+    if (prop->bp_type == BATTERY_PROP_VOLTAGE_NOW) {
+        *min = 0;
+        *max = 10000;
+    } else if (prop->bp_type == BATTERY_PROP_TEMP_NOW) {
+        *min = -128;
+        *max = 127;
+    } else {
+        rc = -1;
+    }
+    return rc;
+}
+
+static int
+cmd_bat_write(int argc, char ** argv)
+{
+    int rc = 0;
+    long long min;
+    long long max;
+    struct battery_property *prop;
+    long long int val;
+
+    if (argc < 3) {
+        console_printf("Invalid number of arguments, use write <prop> <value>\n");
+        goto err;
+    }
+
+    prop = battery_find_property_by_name(bat, argv[1]);
+    if (prop == NULL) {
+        console_printf("Invalid property name %s\n", argv[1]);
+        goto err;
+    }
+    if (get_min_max(prop, &min, &max)) {
+        console_printf("Property %s can not be set\n", argv[1]);
+        goto err;
+    }
+    val = parse_ll_bounds(argv[2], min, max, &rc);
+    if (rc) {
+        console_printf("Property value not in range <%lld, %lld>\n", min, max);
+        rc = 0;
+        goto err;
+    }
+    if (prop->bp_type == BATTERY_PROP_VOLTAGE_NOW &&
+            (prop->bp_flags & BATTERY_PROPERTY_FLAGS_ALARM_THREASH) != 0) {
+        battery_prop_set_value_uint32(prop, (uint32_t)val);
+    } else if (prop->bp_type == BATTERY_PROP_TEMP_NOW &&
+            (prop->bp_flags & BATTERY_PROPERTY_FLAGS_ALARM_THREASH) != 0) {
+        battery_prop_set_value_float(prop, val);
+    } else {
+        console_printf("Property %s can't be written!\n", argv[1]);
+    }
+    if (!prop->bp_valid) {
+        console_printf("Error writing property!\n");
+        goto err;
+    }
+err:
+    return rc;
+}
+
 static int cmd_bat_list(int argc, char **argv)
 {
     int i;
@@ -299,6 +371,7 @@ static int cmd_bat_monitor(int argc, char **argv)
 static const struct shell_cmd bat_cli_commands[] =
 {
         { "read", cmd_bat_read, HELP(bat_read_help) },
+        { "write", cmd_bat_write, HELP(bat_write_help) },
         { "list", cmd_bat_list, HELP(bat_list_help) },
         { "pollrate", cmd_bat_poll_rate, HELP(bat_poll_rate_help) },
         { "monitor", cmd_bat_monitor, HELP(bat_monitor_help) },
diff --git a/hw/drivers/bq27z561/include/bq27z561/bq27z561.h b/hw/drivers/bq27z561/include/bq27z561/bq27z561.h
index 95d78490b4..b92e0ce082 100644
--- a/hw/drivers/bq27z561/include/bq27z561/bq27z561.h
+++ b/hw/drivers/bq27z561/include/bq27z561/bq27z561.h
@@ -69,6 +69,14 @@
 #define BQ27Z561_REG_DCAP       (0x3C)
 #define BQ27Z561_REG_MFRG_ACC   (0x3E)
 #define BQ27Z561_REG_CHKSUM     (0x60)
+#define BQ27Z561_REG_VOLT_HI_SET_TH (0x62)
+#define BQ27Z561_REG_VOLT_HI_CLR_TH (0x64)
+#define BQ27Z561_REG_VOLT_LO_SET_TH (0x66)
+#define BQ27Z561_REG_VOLT_LO_CLR_TH (0x68)
+#define BQ27Z561_REG_TEMP_HI_SET_TH (0x6A)
+#define BQ27Z561_REG_TEMP_HI_CLR_TH (0x6B)
+#define BQ27Z561_REG_TEMP_LO_SET_TH (0x6C)
+#define BQ27Z561_REG_TEMP_LO_CLR_TH (0x6D)
 
 
 /* Alt Manufacturer Command List */
@@ -221,6 +229,60 @@ int bq27z561_get_time_to_empty(struct bq27z561 *dev, uint16_t *tte);
  */
 int bq27z561_get_temp(struct bq27z561 *dev, float *temp_c);
 
+/**
+ * bq27z561 set low temperature set threshold
+ *
+ * Sets low temperature value that triggers interrupt
+ *
+ * @param dev pointer to device
+ * @param temp_c temperature, in C
+ *
+ * @return int 0: success, -1 error
+ */
+int bq27z561_set_temp_lo_set_threshold(struct bq27z561 *dev,
+        int8_t temp_c);
+
+/**
+ * bq27z561 set low temperature clear threshold
+ *
+ * When interrupt is active and temperature goes above this threshold interrupt
+ * is cleared.
+ *
+ * @param dev pointer to device
+ * @param temp_c temperature, in C
+ *
+ * @return int 0: success, -1 error
+ */
+int bq27z561_set_temp_lo_clear_threshold(struct bq27z561 *dev,
+        int16_t temp_c);
+
+/**
+ * bq27z561 set high temperature set threshold
+ *
+ * Sets high temperature value that triggers interrupt
+ *
+ * @param dev pointer to device
+ * @param voltage voltage, in mV
+ *
+ * @return int 0: success, -1 error
+ */
+int bq27z561_set_temp_hi_set_threshold(struct bq27z561 *dev,
+        int8_t temp_c);
+
+/**
+ * bq27z561 set high temperature clear threshold
+ *
+ * When interrupt is active and temperature goes below this threshold interrupt
+ * is cleared.
+ *
+ * @param dev pointer to device
+ * @param voltage voltage, in mV
+ *
+ * @return int 0: success, -1 error
+ */
+int bq27z561_set_temp_hi_clear_threshold(struct bq27z561 *dev,
+        int16_t temp_c);
+
 /**
  * bq27z561 get voltage
  *
@@ -233,6 +295,60 @@ int bq27z561_get_temp(struct bq27z561 *dev, float *temp_c);
  */
 int bq27z561_get_voltage(struct bq27z561 *dev, uint16_t *voltage);
 
+/**
+ * bq27z561 set low voltage set threshold
+ *
+ * Sets low voltage value that triggers interrupt
+ *
+ * @param dev pointer to device
+ * @param voltage voltage, in mV
+ *
+ * @return int 0: success, -1 error
+ */
+int bq27z561_set_voltage_lo_set_threshold(struct bq27z561 *dev,
+        uint16_t voltage);
+
+/**
+ * bq27z561 set low voltage clear threshold
+ *
+ * When interrupt is active and voltage goes above this threshold interrupt
+ * is cleared.
+ *
+ * @param dev pointer to device
+ * @param voltage voltage, in mV
+ *
+ * @return int 0: success, -1 error
+ */
+int bq27z561_set_voltage_lo_clr_threshold(struct bq27z561 *dev,
+        uint16_t voltage);
+
+/**
+ * bq27z561 set high voltage set threshold
+ *
+ * Sets high voltage value that triggers interrupt
+ *
+ * @param dev pointer to device
+ * @param voltage voltage, in mV
+ *
+ * @return int 0: success, -1 error
+ */
+int bq27z561_set_voltage_hi_set_threshold(struct bq27z561 *dev,
+        uint16_t voltage);
+
+/**
+ * bq27z561 set high voltage clear threshold
+ *
+ * When interrupt is active and voltage goes below this threshold interrupt
+ * is cleared.
+ *
+ * @param dev pointer to device
+ * @param voltage voltage, in mV
+ *
+ * @return int 0: success, -1 error
+ */
+int bq27z561_set_voltage_hi_clr_threshold(struct bq27z561 *dev,
+        uint16_t voltage);
+
 /**
  * bq27z561 get batt status
  *
diff --git a/hw/drivers/bq27z561/src/bq27z561.c b/hw/drivers/bq27z561/src/bq27z561.c
index 7da212eb1e..003b285add 100644
--- a/hw/drivers/bq27z561/src/bq27z561.c
+++ b/hw/drivers/bq27z561/src/bq27z561.c
@@ -128,6 +128,33 @@ bq27z561_itf_unlock(struct bq27z561_itf *bi)
     os_mutex_release(bi->itf_lock);
 }
 
+int
+bq27z561_rd_std_reg_byte(struct bq27z561 *dev, uint8_t reg, uint8_t *val)
+{
+    int rc;
+    struct hal_i2c_master_data i2c;
+
+    i2c.address = dev->bq27_itf.itf_addr;
+    i2c.len = 1;
+    i2c.buffer = &reg;
+
+    rc = hal_i2c_master_write(dev->bq27_itf.itf_num, &i2c, OS_TICKS_PER_SEC, 0);
+    if (rc != 0) {
+        BQ27Z561_ERROR("I2C reg read (wr) failed 0x%02X\n", reg);
+        return rc;
+    }
+
+    i2c.len = 1;
+    i2c.buffer = (uint8_t *)val;
+    rc = hal_i2c_master_read(dev->bq27_itf.itf_num, &i2c, OS_TICKS_PER_SEC, 1);
+    if (rc != 0) {
+        BQ27Z561_ERROR("I2C reg read (rd) failed 0x%02X\n", reg);
+        return rc;
+    }
+
+    return 0;
+}
+
 int
 bq27z561_rd_std_reg_word(struct bq27z561 *dev, uint8_t reg, uint16_t *val)
 {
@@ -165,6 +192,29 @@ bq27z561_rd_std_reg_word(struct bq27z561 *dev, uint8_t reg, uint16_t *val)
     return rc;
 }
 
+static int
+bq27z561_wr_std_reg_byte(struct bq27z561 *dev, uint8_t reg, uint8_t val)
+{
+    int rc;
+    uint8_t buf[2];
+    struct hal_i2c_master_data i2c;
+
+    buf[0] = reg;
+    buf[1] = val;
+
+    i2c.address = dev->bq27_itf.itf_num;
+    i2c.len     = 2;
+    i2c.buffer  = buf;
+
+    rc = hal_i2c_master_write(dev->bq27_itf.itf_num, &i2c, OS_TICKS_PER_SEC, 1);
+    if (rc != 0) {
+        BQ27Z561_ERROR("I2C reg write 0x%02X failed\n", reg);
+        return rc;
+    }
+
+    return 0;
+}
+
 static int
 bq27z561_wr_std_reg_word(struct bq27z561 *dev, uint8_t reg, uint16_t val)
 {
@@ -535,12 +585,181 @@ bq27z561_get_temp(struct bq27z561 *dev, float *temp_c)
     return rc;
 }
 
+int
+bq27z561_get_temp_lo_set_threshold(struct bq27z561 *dev, int8_t *temp_c)
+{
+    int rc;
+
+    rc = bq27z561_rd_std_reg_byte(dev, BQ27Z561_REG_TEMP_LO_SET_TH,
+            (uint8_t *)temp_c);
+
+    return rc;
+}
+
+int
+bq27z561_set_temp_lo_set_threshold(struct bq27z561 *dev, int8_t temp_c)
+{
+    int rc;
+    uint8_t temp = (uint8_t)(temp_c);
+
+    rc = bq27z561_wr_std_reg_byte(dev, BQ27Z561_REG_TEMP_LO_SET_TH, temp);
+
+    return rc;
+}
+
+int
+bq27z561_get_temp_lo_clr_threshold(struct bq27z561 *dev, int8_t *temp_c)
+{
+    int rc;
+
+    rc = bq27z561_rd_std_reg_byte(dev, BQ27Z561_REG_TEMP_LO_CLR_TH,
+            (uint8_t *)temp_c);
+
+    return rc;
+}
+
+int
+bq27z561_set_temp_lo_clr_threshold(struct bq27z561 *dev, int8_t temp_c)
+{
+    int rc;
+
+    rc = bq27z561_wr_std_reg_byte(dev, BQ27Z561_REG_TEMP_LO_CLR_TH,
+            (uint8_t)temp_c);
+
+    return rc;
+}
+
+int
+bq27z561_get_temp_hi_set_threshold(struct bq27z561 *dev, int8_t *temp_c)
+{
+    int rc;
+
+    rc = bq27z561_rd_std_reg_byte(dev, BQ27Z561_REG_TEMP_HI_SET_TH,
+            (uint8_t *)temp_c);
+
+    return rc;
+}
+
+int
+bq27z561_set_temp_hi_set_threshold(struct bq27z561 *dev, int8_t temp_c)
+{
+    int rc;
+
+    rc = bq27z561_wr_std_reg_byte(dev, BQ27Z561_REG_TEMP_HI_SET_TH,
+            (uint8_t)temp_c);
+
+    return rc;
+}
+
+int
+bq27z561_get_temp_hi_clr_threshold(struct bq27z561 *dev, int8_t *temp_c)
+{
+    int rc;
+
+    rc = bq27z561_rd_std_reg_byte(dev, BQ27Z561_REG_TEMP_HI_CLR_TH,
+            (uint8_t *)temp_c);
+
+    return rc;
+}
+
+int
+bq27z561_set_temp_hi_clr_threshold(struct bq27z561 *dev, int8_t temp_c)
+{
+    int rc;
+
+    rc = bq27z561_wr_std_reg_byte(dev, BQ27Z561_REG_TEMP_HI_CLR_TH,
+            (uint8_t)temp_c);
+
+    return rc;
+}
+
 int
 bq27z561_get_voltage(struct bq27z561 *dev, uint16_t *voltage)
 {
     int rc;
 
     rc = bq27z561_rd_std_reg_word(dev, BQ27Z561_REG_VOLT, voltage);
+
+    return rc;
+}
+
+int
+bq27z561_get_voltage_lo_set_threshold(struct bq27z561 *dev, uint16_t *voltage)
+{
+    int rc;
+
+    rc = bq27z561_rd_std_reg_word(dev, BQ27Z561_REG_VOLT_LO_SET_TH, voltage);
+
+    return rc;
+}
+
+int
+bq27z561_set_voltage_lo_set_threshold(struct bq27z561 *dev, uint16_t voltage)
+{
+    int rc;
+
+    rc = bq27z561_wr_std_reg_word(dev, BQ27Z561_REG_VOLT_LO_SET_TH, voltage);
+
+    return rc;
+}
+
+int
+bq27z561_get_voltage_lo_clr_threshold(struct bq27z561 *dev, uint16_t *voltage)
+{
+    int rc;
+
+    rc = bq27z561_rd_std_reg_word(dev, BQ27Z561_REG_VOLT_LO_CLR_TH, voltage);
+
+    return rc;
+}
+
+int
+bq27z561_set_voltage_lo_clr_threshold(struct bq27z561 *dev, uint16_t voltage)
+{
+    int rc;
+
+    rc = bq27z561_wr_std_reg_word(dev, BQ27Z561_REG_VOLT_LO_CLR_TH, voltage);
+
+    return rc;
+}
+
+int
+bq27z561_get_voltage_hi_set_threshold(struct bq27z561 *dev, uint16_t *voltage)
+{
+    int rc;
+
+    rc = bq27z561_rd_std_reg_word(dev, BQ27Z561_REG_VOLT_HI_SET_TH, voltage);
+
+    return rc;
+}
+
+int
+bq27z561_set_voltage_hi_set_threshold(struct bq27z561 *dev, uint16_t voltage)
+{
+    int rc;
+
+    rc = bq27z561_rd_std_reg_word(dev, BQ27Z561_REG_VOLT_HI_SET_TH, &voltage);
+
+    return rc;
+}
+
+int
+bq27z561_get_voltage_hi_clr_threshold(struct bq27z561 *dev, uint16_t *voltage)
+{
+    int rc;
+
+    rc = bq27z561_rd_std_reg_word(dev, BQ27Z561_REG_VOLT_HI_CLR_TH, voltage);
+
+    return rc;
+}
+
+int
+bq27z561_set_voltage_hi_clr_threshold(struct bq27z561 *dev, uint16_t voltage)
+{
+    int rc;
+
+    rc = bq27z561_wr_std_reg_word(dev, BQ27Z561_REG_VOLT_HI_CLR_TH, voltage);
+
     return rc;
 }
 
@@ -708,6 +927,26 @@ bq27z561_battery_property_get(struct battery_driver *driver,
         rc = bq27z561_get_voltage((struct bq27z561 *) driver->bd_driver_data,
                                   &val.bpv_u16);
         property->bp_value.bpv_voltage = val.bpv_u16;
+    } else if (property->bp_type == BATTERY_PROP_VOLTAGE_NOW &&
+            property->bp_flags == BATTERY_PROPERTY_FLAGS_LOW_ALARM_SET_THRESHOLD) {
+            rc = bq27z561_get_voltage_lo_set_threshold(
+                    (struct bq27z561 *) driver->bd_driver_data, &val.bpv_u16);
+            property->bp_value.bpv_voltage = val.bpv_u16;
+    } else if (property->bp_type == BATTERY_PROP_VOLTAGE_NOW &&
+            property->bp_flags == BATTERY_PROPERTY_FLAGS_LOW_ALARM_CLEAR_THRESHOLD) {
+            rc = bq27z561_get_voltage_lo_clr_threshold(
+                    (struct bq27z561 *) driver->bd_driver_data, &val.bpv_u16);
+            property->bp_value.bpv_voltage = val.bpv_u16;
+    } else if (property->bp_type == BATTERY_PROP_VOLTAGE_NOW &&
+            property->bp_flags == BATTERY_PROPERTY_FLAGS_HIGH_ALARM_SET_THRESHOLD) {
+            rc = bq27z561_get_voltage_hi_set_threshold(
+                    (struct bq27z561 *) driver->bd_driver_data, &val.bpv_u16);
+            property->bp_value.bpv_voltage = val.bpv_u16;
+    } else if (property->bp_type == BATTERY_PROP_VOLTAGE_NOW &&
+            property->bp_flags == BATTERY_PROPERTY_FLAGS_HIGH_ALARM_CLEAR_THRESHOLD) {
+            rc = bq27z561_get_voltage_hi_clr_threshold(
+                    (struct bq27z561 *) driver->bd_driver_data, &val.bpv_u16);
+            property->bp_value.bpv_voltage = val.bpv_u16;
     } else if (property->bp_type == BATTERY_PROP_STATUS &&
                property->bp_flags == 0) {
         rc = bq27z561_get_batt_status((struct bq27z561 *) driver->bd_driver_data,
@@ -754,6 +993,26 @@ bq27z561_battery_property_get(struct battery_driver *driver,
         rc = bq27z561_get_temp(
                 (struct bq27z561 *) driver->bd_driver_data, &val.bpv_flt);
         property->bp_value.bpv_temperature = val.bpv_flt;
+    } else if (property->bp_type == BATTERY_PROP_TEMP_NOW &&
+            property->bp_flags == BATTERY_PROPERTY_FLAGS_LOW_ALARM_SET_THRESHOLD) {
+            rc = bq27z561_get_temp_lo_set_threshold(
+                    (struct bq27z561 *) driver->bd_driver_data, &val.bpv_i8);
+            property->bp_value.bpv_temperature = val.bpv_i8;
+    } else if (property->bp_type == BATTERY_PROP_TEMP_NOW &&
+            property->bp_flags == BATTERY_PROPERTY_FLAGS_LOW_ALARM_CLEAR_THRESHOLD) {
+            rc = bq27z561_get_temp_lo_clr_threshold(
+                    (struct bq27z561 *) driver->bd_driver_data, &val.bpv_i8);
+            property->bp_value.bpv_temperature = val.bpv_i8;
+    } else if (property->bp_type == BATTERY_PROP_TEMP_NOW &&
+            property->bp_flags == BATTERY_PROPERTY_FLAGS_HIGH_ALARM_SET_THRESHOLD) {
+            rc = bq27z561_get_temp_hi_set_threshold(
+                    (struct bq27z561 *) driver->bd_driver_data, &val.bpv_i8);
+            property->bp_value.bpv_temperature = val.bpv_i8;
+    } else if (property->bp_type == BATTERY_PROP_TEMP_NOW &&
+            property->bp_flags == BATTERY_PROPERTY_FLAGS_HIGH_ALARM_CLEAR_THRESHOLD) {
+            rc = bq27z561_get_temp_hi_clr_threshold(
+                    (struct bq27z561 *) driver->bd_driver_data, &val.bpv_i8);
+            property->bp_value.bpv_temperature = val.bpv_i8;
     } else {
         rc = -1;
         assert(0);
@@ -773,7 +1032,50 @@ bq27z561_battery_property_set(struct battery_driver *driver,
 {
     int rc = 0;
 
-    /* TODO: Not yet implemented */
+    if (property->bp_type == BATTERY_PROP_VOLTAGE_NOW &&
+        property->bp_flags == BATTERY_PROPERTY_FLAGS_LOW_ALARM_SET_THRESHOLD) {
+        rc = bq27z561_set_voltage_lo_set_threshold(
+                (struct bq27z561 *)driver->bd_driver_data,
+                property->bp_value.bpv_voltage);
+    } else if (property->bp_type == BATTERY_PROP_VOLTAGE_NOW &&
+               property->bp_flags == BATTERY_PROPERTY_FLAGS_LOW_ALARM_CLEAR_THRESHOLD) {
+        rc = bq27z561_set_voltage_lo_clr_threshold(
+                (struct bq27z561 *)driver->bd_driver_data,
+                property->bp_value.bpv_voltage);
+    } else if (property->bp_type == BATTERY_PROP_VOLTAGE_NOW &&
+               property->bp_flags == BATTERY_PROPERTY_FLAGS_HIGH_ALARM_SET_THRESHOLD) {
+        rc = bq27z561_set_voltage_hi_set_threshold(
+                (struct bq27z561 *)driver->bd_driver_data,
+                property->bp_value.bpv_voltage);
+    } else if (property->bp_type == BATTERY_PROP_VOLTAGE_NOW &&
+               property->bp_flags == BATTERY_PROPERTY_FLAGS_HIGH_ALARM_CLEAR_THRESHOLD) {
+        rc = bq27z561_set_voltage_hi_clr_threshold(
+                (struct bq27z561 *)driver->bd_driver_data,
+                property->bp_value.bpv_voltage);
+    } else if (property->bp_type == BATTERY_PROP_TEMP_NOW &&
+            property->bp_flags == BATTERY_PROPERTY_FLAGS_LOW_ALARM_SET_THRESHOLD) {
+            rc = bq27z561_set_temp_lo_set_threshold(
+                    (struct bq27z561 *) driver->bd_driver_data,
+                    (int8_t)property->bp_value.bpv_temperature);
+    } else if (property->bp_type == BATTERY_PROP_TEMP_NOW &&
+                   property->bp_flags == BATTERY_PROPERTY_FLAGS_LOW_ALARM_CLEAR_THRESHOLD) {
+            rc = bq27z561_set_temp_lo_clr_threshold(
+                    (struct bq27z561 *) driver->bd_driver_data,
+                    (int16_t)property->bp_value.bpv_temperature);
+    } else if (property->bp_type == BATTERY_PROP_TEMP_NOW &&
+                   property->bp_flags == BATTERY_PROPERTY_FLAGS_HIGH_ALARM_SET_THRESHOLD) {
+            rc = bq27z561_set_temp_hi_set_threshold(
+                    (struct bq27z561 *) driver->bd_driver_data,
+                    (int16_t)property->bp_value.bpv_temperature);
+    } else if (property->bp_type == BATTERY_PROP_TEMP_NOW &&
+                   property->bp_flags == BATTERY_PROPERTY_FLAGS_HIGH_ALARM_CLEAR_THRESHOLD) {
+            rc = bq27z561_set_temp_hi_clr_threshold(
+                    (struct bq27z561 *) driver->bd_driver_data,
+                    (int16_t)property->bp_value.bpv_temperature);
+    } else {
+        rc = -1;
+        assert(0);
+    }
     return rc;
 }
 
@@ -807,7 +1109,22 @@ static const struct battery_driver_property bq27z561_battery_properties[] = {
     { BATTERY_PROP_TIME_TO_EMPTY_NOW, 0, "TimeToEmpty" },
     { BATTERY_PROP_TIME_TO_FULL_NOW, 0, "TimeToFull" },
     { BATTERY_PROP_CYCLE_COUNT, 0, "CycleCount" },
-    /* TODO: Add threshold properties supported by fuel gauge in hardware */
+    { BATTERY_PROP_VOLTAGE_NOW,
+            BATTERY_PROPERTY_FLAGS_LOW_ALARM_SET_THRESHOLD, "LoVoltAlarmSet" },
+    { BATTERY_PROP_VOLTAGE_NOW,
+            BATTERY_PROPERTY_FLAGS_LOW_ALARM_CLEAR_THRESHOLD, "LoVoltAlarmClear" },
+    { BATTERY_PROP_VOLTAGE_NOW,
+            BATTERY_PROPERTY_FLAGS_HIGH_ALARM_SET_THRESHOLD, "HiVoltAlarmSet" },
+    { BATTERY_PROP_VOLTAGE_NOW,
+            BATTERY_PROPERTY_FLAGS_HIGH_ALARM_CLEAR_THRESHOLD, "HiVoltAlarmClear" },
+    { BATTERY_PROP_TEMP_NOW,
+            BATTERY_PROPERTY_FLAGS_LOW_ALARM_SET_THRESHOLD, "LoTempAlarmSet" },
+    { BATTERY_PROP_TEMP_NOW,
+            BATTERY_PROPERTY_FLAGS_LOW_ALARM_CLEAR_THRESHOLD, "LoTempAlarmClear" },
+    { BATTERY_PROP_TEMP_NOW,
+            BATTERY_PROPERTY_FLAGS_HIGH_ALARM_SET_THRESHOLD, "LoTempAlarmSet" },
+    { BATTERY_PROP_TEMP_NOW,
+            BATTERY_PROPERTY_FLAGS_HIGH_ALARM_CLEAR_THRESHOLD, "HiTempAlarmClear" },
     { BATTERY_PROP_NONE },
 };
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services