]> sigrok.org Git - libsigrok.git/commitdiff
kingst-la2016: adjust config param checks, threshold range check
authorGerhard Sittig <redacted>
Sun, 30 Jan 2022 10:32:32 +0000 (11:32 +0100)
committerGerhard Sittig <redacted>
Sun, 6 Feb 2022 17:53:53 +0000 (18:53 +0100)
After scan() completed the conn= can no longer be unknown. The firmware
was loaded and became effective (and communication was tested) before we
get to the config getter. Check PWM period and duty cycle value ranges
in the config setter.

Use symbolic names in the threshold voltage range check when protocol.c
forwards the configured value to the device.

src/hardware/kingst-la2016/api.c
src/hardware/kingst-la2016/protocol.c

index d5cb8678e1d2294ae7925032b9c67a3416399b76..2d90a9f9caf6029b38d7b1ff87ce069a50761374 100644 (file)
@@ -770,16 +770,7 @@ static int config_get(uint32_t key, GVariant **data,
 
        switch (key) {
        case SR_CONF_CONN:
-               if (!sdi->conn)
-                       return SR_ERR_ARG;
                usb = sdi->conn;
-               if (usb->address == 0xff) {
-                       /*
-                        * Device still needs to re-enumerate after firmware
-                        * upload, so we don't know its (future) address.
-                        */
-                       return SR_ERR;
-               }
                *data = g_variant_new_printf("%d.%d", usb->bus, usb->address);
                break;
        case SR_CONF_SAMPLERATE:
@@ -817,6 +808,7 @@ static int config_set(uint32_t key, GVariant *data,
        int ret, cg_type;
        size_t logic_idx, analog_idx;
        struct pwm_setting *pwm;
+       double value_f;
        double low, high;
        int idx;
 
@@ -844,13 +836,19 @@ static int config_set(uint32_t key, GVariant *data,
                                return ret;
                        break;
                case SR_CONF_OUTPUT_FREQUENCY:
-                       pwm->freq = g_variant_get_double(data);
+                       value_f = g_variant_get_double(data);
+                       if (value_f <= 0.0 || value_f > MAX_PWM_FREQ)
+                               return SR_ERR_ARG;
+                       pwm->freq = value_f;
                        ret = la2016_write_pwm_config(sdi, analog_idx);
                        if (ret != SR_OK)
                                return ret;
                        break;
                case SR_CONF_DUTY_CYCLE:
-                       pwm->duty = g_variant_get_double(data);
+                       value_f = g_variant_get_double(data);
+                       if (value_f <= 0.0 || value_f > 100.0)
+                               return SR_ERR_ARG;
+                       pwm->duty = value_f;
                        ret = la2016_write_pwm_config(sdi, analog_idx);
                        if (ret != SR_OK)
                                return ret;
index 3f9156c49b29c3c47c9500d8eb56bce59d173e67..dc1a24a5193b6f0a96933e9f15443480b0eb2c5b 100644 (file)
@@ -344,10 +344,10 @@ static int set_threshold_voltage(const struct sr_dev_inst *sdi, float voltage)
        devc = sdi->priv;
 
        /* Clamp threshold setting to valid range for LA2016. */
-       if (voltage > 4.0) {
-               voltage = 4.0;
-       } else if (voltage < -4.0) {
-               voltage = -4.0;
+       if (voltage > LA2016_THR_VOLTAGE_MAX) {
+               voltage = LA2016_THR_VOLTAGE_MAX;
+       } else if (voltage < -LA2016_THR_VOLTAGE_MAX) {
+               voltage = -LA2016_THR_VOLTAGE_MAX;
        }
 
        /*