From: Gerhard Sittig Date: Sun, 30 Jan 2022 10:32:32 +0000 (+0100) Subject: kingst-la2016: adjust config param checks, threshold range check X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=c35baf6eb0b0b2bc7b1240809775eca1927ca199 kingst-la2016: adjust config param checks, threshold range check 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. --- diff --git a/src/hardware/kingst-la2016/api.c b/src/hardware/kingst-la2016/api.c index d5cb8678..2d90a9f9 100644 --- a/src/hardware/kingst-la2016/api.c +++ b/src/hardware/kingst-la2016/api.c @@ -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; diff --git a/src/hardware/kingst-la2016/protocol.c b/src/hardware/kingst-la2016/protocol.c index 3f9156c4..dc1a24a5 100644 --- a/src/hardware/kingst-la2016/protocol.c +++ b/src/hardware/kingst-la2016/protocol.c @@ -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; } /*