]> sigrok.org Git - libsigrok.git/commitdiff
saleae-logic16: Fix acquisition with fewer than nine channels enabled.
authorBert Vermeulen <redacted>
Thu, 29 May 2014 20:55:52 +0000 (22:55 +0200)
committerBert Vermeulen <redacted>
Thu, 29 May 2014 20:55:52 +0000 (22:55 +0200)
hardware/saleae-logic16/api.c
hardware/saleae-logic16/protocol.c
hardware/saleae-logic16/protocol.h

index dee3d25cfdd952b88620c30e641ed7c0777ee572..8b2db4b49e065b9845e976559d735f70812d034d 100644 (file)
@@ -670,16 +670,6 @@ static int configure_channels(const struct sr_dev_inst *sdi)
                devc->channel_masks[devc->num_channels++] = channel_bit;
        }
 
-       if (devc->cur_channels & ~0xff) {
-               devc->unitsize = 2;
-       } else {
-#ifdef WORDS_BIGENDIAN
-               for (i = 0; i < devc->num_channels; i++)
-                       devc->channel_masks[i] >>= 8;
-#endif
-               devc->unitsize = 1;
-       }
-
        return SR_OK;
 }
 
index 288c7de5d2f5217640d310149152e4555fdc764d..8b430d90c01e91e5d62ce2c87af853faaa19376f 100644 (file)
@@ -632,9 +632,8 @@ static void resubmit_transfer(struct libusb_transfer *transfer)
        sr_err("%s: %s", __func__, libusb_error_name(ret));
 }
 
-static size_t convert_sample_data_16(struct dev_context *devc,
-                                    uint8_t *dest, size_t destcnt,
-                                    const uint8_t *src, size_t srccnt)
+static size_t convert_sample_data(struct dev_context *devc,
+               uint8_t *dest, size_t destcnt, const uint8_t *src, size_t srccnt)
 {
        uint16_t *channel_data;
        int i, cur_channel;
@@ -675,60 +674,6 @@ static size_t convert_sample_data_16(struct dev_context *devc,
        return ret;
 }
 
-static size_t convert_sample_data_8(struct dev_context *devc,
-                                   uint8_t *dest, size_t destcnt,
-                                   const uint8_t *src, size_t srccnt)
-{
-       uint8_t *channel_data;
-       int i, cur_channel;
-       size_t ret = 0;
-       uint16_t sample;
-       uint8_t channel_mask;
-
-       srccnt /= 2;
-
-       channel_data = (uint8_t *)devc->channel_data;
-       cur_channel = devc->cur_channel;
-
-       while (srccnt--) {
-               sample = src[0] | (src[1] << 8);
-               src += 2;
-
-               channel_mask = devc->channel_masks[cur_channel];
-
-               for (i = 15; i >= 0; --i, sample >>= 1)
-                       if (sample & 1)
-                               channel_data[i] |= channel_mask;
-
-               if (++cur_channel == devc->num_channels) {
-                       cur_channel = 0;
-                       if (destcnt < 16) {
-                               sr_err("Conversion buffer too small!");
-                               break;
-                       }
-                       memcpy(dest, channel_data, 16);
-                       memset(channel_data, 0, 16);
-                       dest += 16;
-                       ret += 16;
-                       destcnt -= 16;
-               }
-       }
-
-       devc->cur_channel = cur_channel;
-
-       return ret;
-}
-
-static size_t convert_sample_data(struct dev_context *devc,
-                                 uint8_t *dest, size_t destcnt,
-                                 const uint8_t *src, size_t srccnt,
-                                 int unitsize)
-{
-       return (unitsize == 2 ?
-               convert_sample_data_16(devc, dest, destcnt, src, srccnt) :
-               convert_sample_data_8(devc, dest, destcnt, src, srccnt));
-}
-
 SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer)
 {
        gboolean packet_has_error = FALSE;
@@ -791,8 +736,7 @@ SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer)
        }
 
        new_samples = convert_sample_data(devc, devc->convbuffer,
-                       devc->convbuffer_size, transfer->buffer,
-                       transfer->actual_length, devc->unitsize);
+                       devc->convbuffer_size, transfer->buffer, transfer->actual_length);
 
        if (new_samples > 0) {
                if (devc->trigger_fired) {
@@ -802,14 +746,14 @@ SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer)
                        if (devc->limit_samples &&
                                        new_samples > devc->limit_samples - devc->sent_samples)
                                new_samples = devc->limit_samples - devc->sent_samples;
-                       logic.length = new_samples * devc->unitsize;
-                       logic.unitsize = devc->unitsize;
+                       logic.length = new_samples * 2;
+                       logic.unitsize = 2;
                        logic.data = devc->convbuffer;
                        sr_session_send(devc->cb_data, &packet);
                        devc->sent_samples += new_samples;
                } else {
                        trigger_offset = soft_trigger_logic_check(devc->stl,
-                                       devc->convbuffer, new_samples * devc->unitsize);
+                                       devc->convbuffer, new_samples * 2);
                        if (trigger_offset > -1) {
                                packet.type = SR_DF_LOGIC;
                                packet.payload = &logic;
@@ -817,9 +761,9 @@ SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer)
                                if (devc->limit_samples &&
                                                num_samples > devc->limit_samples - devc->sent_samples)
                                        num_samples = devc->limit_samples - devc->sent_samples;
-                               logic.length = num_samples * devc->unitsize;
-                               logic.unitsize = devc->unitsize;
-                               logic.data = devc->convbuffer + trigger_offset * devc->unitsize;
+                               logic.length = num_samples * 2;
+                               logic.unitsize = 2;
+                               logic.data = devc->convbuffer + trigger_offset * 2;
                                sr_session_send(devc->cb_data, &packet);
                                devc->sent_samples += num_samples;
 
index 8557a3e3a2b2f1da01c067bb9aa69fa9118478b2..8a1ded823900e7ae41c194f355d1a73b5f07fb15 100644 (file)
@@ -66,7 +66,8 @@ struct dev_context {
        int64_t sent_samples;
        int submitted_transfers;
        int empty_transfer_count;
-       int num_channels, cur_channel, unitsize;
+       int num_channels;
+       int cur_channel;
        uint16_t channel_masks[16];
        uint16_t channel_data[16];
        uint8_t *convbuffer;