]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/kingst-la2016/protocol.c
kingst-la2016: implement alternative simpler threshold voltage config
[libsigrok.git] / src / hardware / kingst-la2016 / protocol.c
index f7e2f208d18d4ee2f5faba7bb95545b13b5a5397..86c90ea99ad164e077218a4b1485cde38be05948 100644 (file)
@@ -95,6 +95,10 @@ static const struct kingst_model models[] = {
 #define RUNSTATE_TRGD_BIT      (1UL << 2)
 #define RUNSTATE_POST_BIT      (1UL << 3)
 
+/* Properties related to the layout of capture data downloads. */
+#define NUM_PACKETS_IN_CHUNK   5
+#define TRANSFER_PACKET_LENGTH 16
+
 static int ctrl_in(const struct sr_dev_inst *sdi,
        uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
        void *data, uint16_t wLength)
@@ -331,19 +335,16 @@ static int enable_fpga_bitstream(const struct sr_dev_inst *sdi)
 
 static int set_threshold_voltage(const struct sr_dev_inst *sdi, float voltage)
 {
-       struct dev_context *devc;
        int ret;
        uint16_t duty_R79, duty_R56;
        uint8_t buf[2 * sizeof(uint16_t)];
        uint8_t *wrptr;
 
-       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;
        }
 
        /*
@@ -387,7 +388,6 @@ static int set_threshold_voltage(const struct sr_dev_inst *sdi, float voltage)
                sr_err("Cannot set threshold voltage %.2fV.", voltage);
                return ret;
        }
-       devc->threshold_voltage = voltage;
 
        return SR_OK;
 }
@@ -514,7 +514,12 @@ static int set_trigger_config(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        struct sr_trigger *trigger;
-       struct trigger_cfg cfg;
+       struct trigger_cfg {
+               uint32_t channels;
+               uint32_t enabled;
+               uint32_t level;
+               uint32_t high_or_falling;
+       } cfg;
        GSList *stages;
        GSList *channel;
        struct sr_trigger_stage *stage1;
@@ -884,15 +889,13 @@ SR_PRIV int la2016_upload_firmware(const struct sr_dev_inst *sdi,
        return SR_OK;
 }
 
-SR_PRIV int la2016_setup_acquisition(const struct sr_dev_inst *sdi)
+SR_PRIV int la2016_setup_acquisition(const struct sr_dev_inst *sdi,
+       double voltage)
 {
-       struct dev_context *devc;
        int ret;
        uint8_t cmd;
 
-       devc = sdi->priv;
-
-       ret = set_threshold_voltage(sdi, devc->threshold_voltage);
+       ret = set_threshold_voltage(sdi, voltage);
        if (ret != SR_OK)
                return ret;