]> sigrok.org Git - libsigrok.git/commitdiff
link-mso19: Add trigger_level config option
authorPaul Kasemir <redacted>
Wed, 16 Dec 2020 09:59:34 +0000 (02:59 -0700)
committerSoeren Apel <redacted>
Wed, 16 Oct 2024 22:08:31 +0000 (00:08 +0200)
src/hardware/link-mso19/api.c
src/hardware/link-mso19/protocol.c
src/hardware/link-mso19/protocol.h

index 3a720124875e54c324b6539a0d2a0e20e08e8672..ffcc44968f723d5338620192a6f18d9b10383e9b 100644 (file)
@@ -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;
index 8abb4ae89433dda39589cf0f53efd1ccca529f46..27186655f43eea6dcbbd43b171d9a0377deda79b 100644 (file)
@@ -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;
index 86345f498f73372f8366f4767d856b95236486fa..f6d714d5e060dd17824c7953fe246e376bbf65ec 100644 (file)
@@ -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);