]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/hantek-4032l/api.c
use common channel group allocation/release code
[libsigrok.git] / src / hardware / hantek-4032l / api.c
index 6ee46dee0642972ce16bb954fdcd705d93234d38..7e823f8c7935cb9eb1422fcc6e1fdb5b389f991c 100644 (file)
@@ -167,7 +167,7 @@ static const uint64_t samplerates_hw[] = {
        SR_MHZ(320),
 };
 
-SR_PRIV struct sr_dev_driver hantek_4032l_driver_info;
+static struct sr_dev_driver hantek_4032l_driver_info;
 
 static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
@@ -233,10 +233,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
                struct sr_channel_group *channel_groups[2];
                for (int j = 0; j < 2; j++) {
-                       cg = g_malloc0(sizeof(struct sr_channel_group));
+                       cg = sr_channel_group_new(sdi, NULL, NULL);
                        cg->name = g_strdup_printf("%c", 'A' + j);
                        channel_groups[j] = cg;
-                       sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
                }
 
                /* Assemble channel list and add channel to channel groups. */
@@ -515,7 +514,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        else
                cmd_pkt->sample_rate = devc->sample_rate;
 
-       /* Set pwm channel values. */
+       /* Set PWM channel values. */
        devc->cmd_pkt.pwm_a = h4032l_voltage2pwm(devc->cur_threshold[0]);
        devc->cmd_pkt.pwm_b = h4032l_voltage2pwm(devc->cur_threshold[1]);
 
@@ -587,25 +586,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
                        channel = channel->next;
                }
 
-               /* Compress range mask value and apply range settings. */
-               if (range_mask) {
-                       cmd_pkt->trigger[0].flags.data_range_enabled = 1;
-                       cmd_pkt->trigger[0].data_range_mask |= (range_mask);
-
-                       uint32_t new_range_value = 0;
-                       uint32_t bit_mask = 1;
-                       while (range_mask) {
-                               if ((range_mask & 1) != 0) {
-                                       new_range_value <<= 1;
-                                       if ((range_value & 1) != 0)
-                                               new_range_value |= bit_mask;
-                                       bit_mask <<= 1;
-                               }
-                               range_mask >>= 1;
-                               range_value >>= 1;
-                       }
-                       cmd_pkt->trigger[0].data_range_max |= range_value;
-               }
+               cmd_pkt->trigger[0].flags.data_range_enabled = 1;
+               cmd_pkt->trigger[0].data_range_mask |= range_mask;
+               cmd_pkt->trigger[0].data_range_max = range_value;
        }
 
        usb_source_add(sdi->session, drvc->sr_ctx, 1000,
@@ -621,7 +604,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
        return h4032l_stop(sdi);
 }
 
-SR_PRIV struct sr_dev_driver hantek_4032l_driver_info = {
+static struct sr_dev_driver hantek_4032l_driver_info = {
        .name = "hantek-4032l",
        .longname = "Hantek 4032L",
        .api_version = 1,