+ devc->sent_frame_samples = 0;
+
+ /* Setup triggers */
+ if ((trigger = sr_session_trigger_get(sdi->session))) {
+ int pre_trigger_samples = 0;
+ if (devc->limit_samples > 0)
+ pre_trigger_samples = (devc->capture_ratio * devc->limit_samples) / 100;
+ devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
+ if (!devc->stl)
+ return SR_ERR_MALLOC;
+
+ /* Disable all analog channels since using them when there are logic
+ * triggers set up would require having pre-trigger sample buffers
+ * for analog sample data.
+ */
+ for (l = sdi->channels; l; l = l->next) {
+ ch = l->data;
+ if (ch->type == SR_CHANNEL_ANALOG)
+ ch->enabled = FALSE;
+ }
+ }
+ devc->trigger_fired = FALSE;
+
+ /*
+ * Determine the numbers of logic and analog channels that are
+ * involved in the acquisition. Determine an offset and a mask to
+ * remove excess logic data content before datafeed submission.
+ */
+ devc->enabled_logic_channels = 0;
+ devc->enabled_analog_channels = 0;
+ for (l = sdi->channels; l; l = l->next) {
+ ch = l->data;
+ if (!ch->enabled)
+ continue;
+ if (ch->type == SR_CHANNEL_ANALOG) {
+ devc->enabled_analog_channels++;
+ continue;
+ }
+ if (ch->type != SR_CHANNEL_LOGIC)
+ continue;
+ /*
+ * TODO: Need we create a channel map here, such that the
+ * session datafeed packets will have a dense representation
+ * of the enabled channels' data? For example store channels
+ * D3 and D5 in bit positions 0 and 1 respectively, when all
+ * other channels are disabled? The current implementation
+ * generates a sparse layout, might provide data for logic
+ * channels that are disabled while it might suppress data
+ * from enabled channels at the same time.
+ */
+ devc->enabled_logic_channels++;
+ }
+ devc->first_partial_logic_index = devc->enabled_logic_channels / 8;
+ bitpos = devc->enabled_logic_channels % 8;
+ mask = (1 << bitpos) - 1;
+ devc->first_partial_logic_mask = mask;
+ sr_dbg("num logic %zu, partial off %zu, mask 0x%02x.",
+ devc->enabled_logic_channels,
+ devc->first_partial_logic_index,
+ devc->first_partial_logic_mask);