From: Paul Kasemir Date: Wed, 16 Dec 2020 09:59:34 +0000 (-0700) Subject: link-mso19: Add trigger_level config option X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1dce5fe951e9b79b9021eee28ea5d6f7c15dc4f2;p=libsigrok.git link-mso19: Add trigger_level config option --- diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index 3a720124..ffcc4496 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -44,6 +44,7 @@ static const uint32_t devopts[] = { static const uint32_t devopts_cg_analog[] = { SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, + SR_CONF_TRIGGER_LEVEL | SR_CONF_GET | SR_CONF_SET, SR_CONF_PROBE_FACTOR | SR_CONF_GET | SR_CONF_SET, }; @@ -118,6 +119,21 @@ static void mso_update_trigger_slope(struct dev_context *devc) } } +static void mso_limit_trigger_level(struct dev_context *devc) +{ + double max_level = 2.0 * devc->dso_probe_factor; + if (devc->dso_trigger_level < -max_level) { + devc->dso_trigger_adjusted = -max_level; + } else if (devc->dso_trigger_level > max_level) { + devc->dso_trigger_adjusted = max_level; + } else if (devc->dso_trigger_level != devc->dso_trigger_adjusted){ + devc->dso_trigger_adjusted = devc->dso_trigger_level; + } else { + return; + } + sr_info("Adjusted dso trigger level to %f", devc->dso_trigger_adjusted); +} + static GSList* scan_handle_port(GSList *devices, struct sp_port *port) { int usb_vid, usb_pid; @@ -310,6 +326,11 @@ static int config_get(uint32_t key, GVariant **data, else return SR_ERR_NA; break; + case SR_CONF_TRIGGER_LEVEL: + if (!cg_is_analog(cg)) + return SR_ERR_ARG; + *data = g_variant_new_double(devc->dso_trigger_level); + break; default: return SR_ERR_NA; } @@ -373,6 +394,12 @@ static int config_set(uint32_t key, GVariant *data, } mso_update_trigger_slope(devc); break; + case SR_CONF_TRIGGER_LEVEL: + if (!cg_is_analog(cg)) + return SR_ERR_ARG; + devc->dso_trigger_level = g_variant_get_double(data); + mso_limit_trigger_level(devc); + break; case SR_CONF_HORIZ_TRIGGERPOS: pos = g_variant_get_double(data); if (pos < 0 || pos > 255) { @@ -397,6 +424,7 @@ static int config_set(uint32_t key, GVariant *data, if (!tmp_u64) return SR_ERR_ARG; devc->dso_probe_factor = tmp_u64; + mso_limit_trigger_level(devc); break; default: return SR_ERR_NA; diff --git a/src/hardware/link-mso19/protocol.c b/src/hardware/link-mso19/protocol.c index 8abb4ae8..27186655 100644 --- a/src/hardware/link-mso19/protocol.c +++ b/src/hardware/link-mso19/protocol.c @@ -76,10 +76,8 @@ static uint16_t mso_bank_select(const struct dev_context *devc, int bank) SR_PRIV int mso_configure_trigger(const struct sr_dev_inst *sdi) { struct dev_context *devc = sdi->priv; - uint16_t threshold_value = mso_calc_raw_from_mv(devc); + uint16_t threshold_value = mso_calc_trigger_threshold(devc); - // Use 0x200 temporary value till we can properly calculate it. - threshold_value = 0x200; TRIG_UPDATE_THRESH_MSB(devc->ctltrig, threshold_value); uint16_t ops[] = { @@ -168,10 +166,10 @@ SR_PRIV int mso_dac_out(const struct sr_dev_inst *sdi, uint16_t val) return mso_send_control_message(devc->serial, ARRAY_AND_SIZE(ops)); } -SR_PRIV uint16_t mso_calc_raw_from_mv(struct dev_context *devc) +SR_PRIV uint16_t mso_calc_trigger_threshold(struct dev_context *devc) { return (uint16_t) (0x200 - - ((devc->dso_trigger_voltage / devc->dso_probe_factor) / + ((devc->dso_trigger_adjusted / devc->dso_probe_factor) / devc->vbit)); } @@ -427,7 +425,6 @@ SR_PRIV int mso_configure_channels(const struct sr_dev_inst *sdi) devc->la_trigger_mask = 0xFF; //the mask for the LA_TRIGGER (bits set to 0 matter, those set to 1 are ignored). devc->la_trigger = 0x00; //The value of the LA byte that generates a trigger event (in that mode). - devc->dso_trigger_voltage = 3; trigger = sr_session_trigger_get(sdi->session); if (!trigger) return SR_OK; diff --git a/src/hardware/link-mso19/protocol.h b/src/hardware/link-mso19/protocol.h index 86345f49..f6d714d5 100644 --- a/src/hardware/link-mso19/protocol.h +++ b/src/hardware/link-mso19/protocol.h @@ -101,7 +101,8 @@ struct dev_context { uint8_t la_trigger_slope; uint8_t la_trigger; uint8_t la_trigger_mask; - double dso_trigger_voltage; + double dso_trigger_level; + double dso_trigger_adjusted; uint16_t dso_trigger_width; struct mso_prototrig protocol_trigger; uint16_t buffer_n; @@ -122,7 +123,7 @@ SR_PRIV int mso_read_buffer(struct sr_dev_inst *sdi); SR_PRIV int mso_arm(const struct sr_dev_inst *sdi); SR_PRIV int mso_force_capture(struct sr_dev_inst *sdi); SR_PRIV int mso_dac_out(const struct sr_dev_inst *sdi, uint16_t val); -SR_PRIV uint16_t mso_calc_raw_from_mv(struct dev_context *devc); +SR_PRIV uint16_t mso_calc_trigger_threshold(struct dev_context *devc); SR_PRIV int mso_reset_fsm(const struct sr_dev_inst *sdi); SR_PRIV int mso_configure_channels(const struct sr_dev_inst *sdi);