]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/kingst-la2016/protocol.c
kingst-la2016: rephrase USB bulk transfer size padding constraint
[libsigrok.git] / src / hardware / kingst-la2016 / protocol.c
index a49e96ed1301c81c74c6460386aa2635e673a326..6ab72df02ecc517992a758c798fe50a80b97d53b 100644 (file)
@@ -96,7 +96,14 @@ 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. */
+/*
+ * Properties related to the layout of capture data downloads.
+ *
+ * TODO Check the layout of 32 channel models' capture data. Could it be
+ * 3x (u32 + u8) instead of 5x (u16 + u8) perhaps? Same 16 bytes chunk
+ * but fewer packets per chunk and thus per transfer? Which questions
+ * the NUM_PACKETS_IN_CHUNK literal, maybe needs to be a runtime value?
+ */
 #define NUM_PACKETS_IN_CHUNK   5
 #define TRANSFER_PACKET_LENGTH 16
 
@@ -1011,8 +1018,9 @@ static int la2016_start_download(const struct sr_dev_inst *sdi,
        to_read = devc->n_bytes_to_read;
        if (to_read >= LA2016_USB_BUFSZ) /* Multiple transfers. */
                to_read = LA2016_USB_BUFSZ;
-       else /* One transfer. */
-               to_read = (to_read + (LA2016_EP6_PKTSZ-1)) & ~(LA2016_EP6_PKTSZ-1);
+       to_read += LA2016_EP6_PKTSZ - 1;
+       to_read /= LA2016_EP6_PKTSZ;
+       to_read *= LA2016_EP6_PKTSZ;
        buffer = g_try_malloc(to_read);
        if (!buffer) {
                sr_dbg("USB bulk transfer size %d bytes.", (int)to_read);
@@ -1137,8 +1145,9 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer)
                 */
                if (to_read >= LA2016_USB_BUFSZ)
                        to_read = LA2016_USB_BUFSZ;
-               else
-                       to_read = (to_read + (LA2016_EP6_PKTSZ-1)) & ~(LA2016_EP6_PKTSZ-1);
+               to_read += LA2016_EP6_PKTSZ - 1;
+               to_read /= LA2016_EP6_PKTSZ;
+               to_read *= LA2016_EP6_PKTSZ;
                libusb_fill_bulk_transfer(transfer,
                        usb->devhdl, USB_EP_CAPTURE_DATA | LIBUSB_ENDPOINT_IN,
                        transfer->buffer, to_read,