2 * This file is part of the libsigrok project.
4 * Copyright (C) 2022 Shawn Walker <ac0bi00@gmail.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 //debug print levels are err/warn/info/dbg/spew
28 #include <libsigrok/libsigrok.h>
29 #include "libsigrok-internal.h"
32 //Baud rate is really a don't care because we run USB CDC, dtr must be 1.
33 //flow should be zero since we don't
35 #define SERIALCOMM "115200/8n1/dtr=1/rts=0/flow=0"
37 static const uint32_t scanopts[] = {
38 SR_CONF_CONN, //Required OS name for the port, i.e. /dev/ttyACM0
39 SR_CONF_SERIALCOMM, //Optional config of the port, i.e. 115200/8n1
41 //The host can either provide a std_gvar_samplerates_steps or a std_gvar_samplerates.
42 //The latter is just a long list of every supported rate.
43 //For the steps, pulseview/pv/toolbars/mainbar.cpp will do a min,max,step. If step is
44 //1 then it provides a 1,2,5,10 select otherwise it allows a spin box.
45 //Going with the full list because while the spin box is more flexible, it is harder to read
47 static const uint64_t samplerates[] = {
53 static const uint64_t samplerates[] = {
67 SR_KHZ(160),//max rate of 3 ADC channels that has integer divisor/dividend
69 SR_KHZ(250), //max rate of 2 ADC channels
75 //Give finer granularity near the thresholds of RLE effectiveness
95 static const uint32_t drvopts[] = {
97 SR_CONF_LOGIC_ANALYZER,
100 //SW trigger requires this
101 static const int32_t trigger_matches[] = {
110 static const uint32_t devopts[] = {
111 //CLI prefers LIMIT_SAMPLES to be a list of high,low
112 SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
113 SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
114 SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
115 //pulseview needs a list return to allow sample rate setting
116 SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
119 static struct sr_dev_driver raspberrypi_pico_driver_info;
122 static GSList *scan(struct sr_dev_driver *di, GSList * options)
124 struct sr_config *src;
125 struct sr_dev_inst *sdi;
126 struct sr_serial_dev_inst *serial;
127 struct dev_context *devc;
128 struct sr_channel *ch;
132 const char *conn, *serialcomm;
135 uint8_t num_a, num_d, a_size;
138 conn = serialcomm = NULL;
139 for (l = options; l; l = l->next) {
143 conn = g_variant_get_string(src->data, NULL);
145 case SR_CONF_SERIALCOMM:
146 serialcomm = g_variant_get_string(src->data, NULL);
154 serialcomm = SERIALCOMM;
156 serial = sr_serial_dev_inst_new(conn, serialcomm);
157 sr_info("Opening %s.", conn);
158 if (serial_open(serial, SERIAL_RDWR) != SR_OK) {
159 sr_err("1st serial open fail");
163 sr_info("Resetting device with *s at %s.", conn);
164 send_serial_char(serial, '*');
166 //drain any inflight data
168 sr_warn("Drain reads");
169 len = serial_read_blocking(serial, buf, 32, 100);
170 sr_warn("Drain reads done");
172 sr_dbg("Dropping in flight serial data");
177 num_read = send_serial_w_resp(serial, "i\n", buf, 17);
179 sr_err("1st identify failed");
180 serial_close(serial);
182 if (serial_open(serial, SERIAL_RDWR) != SR_OK) {
183 sr_err("2st serial open fail");
187 sr_err("Send second *");
188 send_serial_char(serial, '*');
190 num_read = send_serial_w_resp(serial, "i\n", buf, 17);
192 sr_err("Second attempt failed");
196 //Expected ID response is SRPICO,AxxyDzz,VV
197 //where xx are number of analog channels, y is bytes per analog sample
198 //and zz is number of digital channels, and VV is two digit version# which must be 02
200 || (strncmp(buf, "SRPICO,A", 8))
203 || (buf[16] != '2')) {
204 sr_err("ERROR:Bad response string %s %d", buf, num_read);
207 a_size = buf[10] - '0';
208 buf[10] = '\0'; //Null to end the str for atois
209 buf[14] = '\0'; //Null to end the str for atois
210 num_a = atoi(&buf[8]);
211 num_d = atoi(&buf[12]);
213 sdi = g_malloc0(sizeof(struct sr_dev_inst));
214 sdi->status = SR_ST_INACTIVE;
215 sdi->vendor = g_strdup("Raspberry Pi");
216 sdi->model = g_strdup("PICO");
217 sdi->version = g_strdup("00");
219 sdi->driver = &raspberrypi_pico_driver_info;
220 sdi->inst_type = SR_INST_SERIAL;
221 sdi->serial_num = g_strdup("N/A");
222 if (((num_a == 0) && (num_d == 0))
223 || (num_a > MAX_ANALOG_CHANNELS)
224 || (num_d > MAX_DIGITAL_CHANNELS)
227 sr_err("ERROR: invalid channel config a %d d %d asz %d",
228 num_a, num_d, a_size);
231 devc = g_malloc0(sizeof(struct dev_context));
232 devc->a_size = a_size;
233 //multiple bytes per analog sample not supported
234 if ((num_a > 0) && (devc->a_size != 1)) {
235 sr_err("Only Analog Size of 1 supported\n\r");
238 devc->num_a_channels = num_a;
239 devc->num_d_channels = num_d;
240 devc->a_chan_mask = ((1 << num_a) - 1);
241 devc->d_chan_mask = ((1 << num_d) - 1);
242 //The number of bytes that each digital sample in the buffers sent to the session.
243 //All logical channels are packed together, where a slice of N channels takes roundup(N/8) bytes
244 //This never changes even if channels are disabled because PV expects disabled channels to still
245 //be accounted for in the packing
246 devc->dig_sample_bytes = ((devc->num_d_channels + 7) / 8);
247 //These are the slice sizes of the data on the wire
248 //1 7 bit field per byte
249 devc->bytes_per_slice = (devc->num_a_channels * devc->a_size);
250 if (devc->num_d_channels > 0) {
251 // logic sent in groups of 7
252 devc->bytes_per_slice += (devc->num_d_channels + 6) / 7;
254 sr_dbg("num channels a %d d %d bps %d dsb %d", num_a, num_d,
255 devc->bytes_per_slice, devc->dig_sample_bytes);
256 //Each analog channel is it's own group
257 //Digital are just channels
258 //Grouping of channels is rather arbitrary as parameters like sample rate and number of samples
259 //apply to all changes. Analog channels do have a scale and offset, but that is applied
260 //without involvement of the session.
261 devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group *) *
262 devc->num_a_channels);
263 for (i = 0; i < devc->num_a_channels; i++) {
264 channel_name = g_strdup_printf("A%d", i);
265 //sdi, index, type, enabled,name
266 ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE,
268 devc->analog_groups[i] =
269 g_malloc0(sizeof(struct sr_channel_group));
270 devc->analog_groups[i]->name = channel_name;
271 devc->analog_groups[i]->channels =
272 g_slist_append(NULL, ch);
273 sdi->channel_groups =
274 g_slist_append(sdi->channel_groups,
275 devc->analog_groups[i]);
278 if (devc->num_d_channels > 0) {
279 for (i = 0; i < devc->num_d_channels; i++) {
280 //Name digital channels starting at D2 to match pico board pin names
281 channel_name = g_strdup_printf("D%d", i + 2);
282 sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
284 g_free(channel_name);
288 //In large sample usages we get the call to receive with large transfers.
289 //Since the CDC serial implemenation can silenty lose data as it gets close to full, allocate
290 //storage for a half buffer which in a worst case scenario has 2x ratio of transmitted bytes
292 //Note: The intent of making this buffer large is to prevent CDC serial buffer overflows.
293 //However, it is likely that if the host is running slow (i.e. it's a raspberry pi model 3) that it becomes
294 //compute bound and doesn't service CDC serial responses in time to not overflow the internal CDC buffers.
295 //And thus no serial buffer is large enough. But, it's only 32K....
296 devc->serial_buffer_size = 32000;
298 sr_dbg("Setting serial buffer size: %i.",
299 devc->serial_buffer_size);
300 devc->cbuf_wrptr = 0;
301 //While slices are sent as a group of one sample across all channels, sigrok wants analog
302 //channel data sent as separate packets.
303 //Logical trace values are packed together.
304 //An RLE byte in normal mode can represent up to 1640 samples.
305 //In D4 an RLE byte can represents up to 640 samples.
306 //Rather than making the sample_buf_size 1640x the size of serial buff, we require that the process loops
307 //push samples to the session as we get anywhere close to full.
309 devc->sample_buf_size = devc->serial_buffer_size;
310 for (i = 0; i < devc->num_a_channels; i++) {
311 devc->a_data_bufs[i] = NULL;
312 devc->a_pretrig_bufs[i] = NULL;
314 devc->d_data_buf = NULL;
315 devc->sample_rate = 5000;
316 devc->capture_ratio = 10;
317 devc->rxstate = RX_IDLE;
319 //Set an initial value as various code relies on an inital value.
320 devc->limit_samples = 1000;
322 if (raspberrypi_pico_get_dev_cfg(sdi) != SR_OK) {
326 sr_err("sr_err level logging enabled");
327 sr_warn("sr_warn level logging enabled");
328 sr_info("sr_info level logging enabled");
329 sr_dbg("sr_dbg level logging enabled");
330 sr_spew("sr_spew level logging enabled");
331 serial_close(serial);
332 return std_scan_complete(di, g_slist_append(NULL, sdi));
338 //Note that on the initial driver load we pull all values into local storage.
339 //Thus gets can return local data, but sets have to issue commands to device.
340 static int config_set(uint32_t key, GVariant * data,
341 const struct sr_dev_inst *sdi,
342 const struct sr_channel_group *cg)
344 struct dev_context *devc;
351 sr_dbg("Got config_set key %d \n", key);
353 case SR_CONF_SAMPLERATE:
354 devc->sample_rate = g_variant_get_uint64(data);
355 sr_dbg("config_set sr %llu\n", devc->sample_rate);
357 case SR_CONF_LIMIT_SAMPLES:
358 devc->limit_samples = g_variant_get_uint64(data);
359 sr_dbg("config_set slimit %lld\n", devc->limit_samples);
361 case SR_CONF_CAPTURE_RATIO:
362 devc->capture_ratio = g_variant_get_uint64(data);
366 sr_err("ERROR:config_set undefine %d\n", key);
373 static int config_get(uint32_t key, GVariant ** data,
374 const struct sr_dev_inst *sdi,
375 const struct sr_channel_group *cg)
377 struct dev_context *devc;
378 sr_dbg("at config_get key %d", key);
385 case SR_CONF_SAMPLERATE:
386 *data = g_variant_new_uint64(devc->sample_rate);
387 sr_spew("sample rate get of %lld", devc->sample_rate);
389 case SR_CONF_CAPTURE_RATIO:
393 *data = g_variant_new_uint64(devc->capture_ratio);
395 case SR_CONF_LIMIT_SAMPLES:
396 sr_spew("config_get limit_samples of %llu",
397 devc->limit_samples);
398 *data = g_variant_new_uint64(devc->limit_samples);
401 sr_spew("unsupported cfg_get key %d", key);
407 static int config_list(uint32_t key, GVariant ** data,
408 const struct sr_dev_inst *sdi,
409 const struct sr_channel_group *cg)
412 //scan or device options are the only ones that can be called without a defined instance
413 if ((key == SR_CONF_SCAN_OPTIONS)
414 || (key == SR_CONF_DEVICE_OPTIONS)) {
415 return STD_CONFIG_LIST(key, data, sdi, cg, scanopts,
420 ("ERROR:\n\r\n\r\n\r Call to config list with null sdi\n\r\n\r");
423 sr_dbg("start config_list with key %X\n", key);
425 case SR_CONF_SAMPLERATE:
426 sr_dbg("Return sample rate list");
428 // std_gvar_samplerates_steps(ARRAY_AND_SIZE
430 std_gvar_samplerates(ARRAY_AND_SIZE
433 //This must be set to get SW trigger support
434 case SR_CONF_TRIGGER_MATCH:
436 std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches));
438 case SR_CONF_LIMIT_SAMPLES:
439 //Really this limit is up to the memory capacity of the host,
440 //and users that pick huge values deserve what they get.
441 //But setting this limit to prevent really crazy things.
442 *data = std_gvar_tuple_u64(1LL, 1000000000LL);
443 sr_dbg("sr_config_list limit samples ");
446 sr_dbg("reached default statement of config_list");
454 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
456 struct sr_serial_dev_inst *serial;
457 struct dev_context *devc;
458 struct sr_channel *ch;
459 struct sr_trigger *trigger;
462 int a_enabled = 0, d_enabled = 0, len;
466 sr_dbg("Enter acq start");
467 sr_dbg("dsbstart %d", devc->dig_sample_bytes);
468 devc->buffer = g_malloc(devc->serial_buffer_size);
469 if (!(devc->buffer)) {
470 sr_err("ERROR:serial buffer malloc fail");
471 return SR_ERR_MALLOC;
473 //Get device in idle state
474 if (serial_drain(serial) != SR_OK) {
475 sr_err("Initial Drain Failed\n\r");
478 send_serial_char(serial, '*');
479 if (serial_drain(serial) != SR_OK) {
480 sr_err("Second Drain Failed\n\r");
484 for (l = sdi->channels; l; l = l->next) {
486 sr_dbg("c %d enabled %d name %s\n", ch->index, ch->enabled,
489 if (ch->name[0] == 'A') {
490 devc->a_chan_mask &= ~(1 << ch->index);
493 (ch->enabled << ch->index);
496 // sr_dbg("A%d en %d mask 0x%X",ch->index,ch->enabled,devc->a_chan_mask);
499 if (ch->name[0] == 'D') {
500 devc->d_chan_mask &= ~(1 << ch->index);
503 (ch->enabled << ch->index);
505 // sr_dbg("D%d en %d mask 0x%X",ch->index,ch->enabled,devc->d_chan_mask);
508 sr_info("Channel enable masks D 0x%X A 0x%X",
509 devc->d_chan_mask, devc->a_chan_mask);
510 sprintf(tmpstr, "%c%d%d\n", ch->name[0], ch->enabled,
512 if (send_serial_w_ack(serial, tmpstr) != SR_OK) {
513 sr_err("ERROR:Channel enable fail");
519 //ensure data channels are continuous
521 for (i = 0; i < 32; i++) {
522 if ((devc->d_chan_mask >> i) & 1) {
525 ("Digital channel mask 0x%X not continous\n\r",
533 //recalculate bytes_per_slice.
534 devc->bytes_per_slice = (a_enabled * devc->a_size);
536 for (i = 0; i < devc->num_d_channels; i += 7) {
537 if (((devc->d_chan_mask) >> i) & (0x7F)) {
538 (devc->bytes_per_slice)++;
541 if ((a_enabled == 0) && (d_enabled == 0)) {
542 sr_err("ERROR:No channels enabled");
545 sr_dbg("bps %d\n", devc->bytes_per_slice);
547 //Apply sample rate limits
548 if ((a_enabled == 3) && (devc->sample_rate > 160000)) {
550 ("ERROR:3 channel ADC sample rate dropped to 160khz");
551 devc->sample_rate = 160000;
553 if ((a_enabled == 2) && (devc->sample_rate > 250000)) {
555 ("ERROR:2 channel ADC sample rate dropped to 250khz");
556 devc->sample_rate = 250000;
558 if ((a_enabled == 1) && (devc->sample_rate > 500000)) {
560 ("ERROR:1 channel ADC sample rate dropped to 500khz");
561 devc->sample_rate = 500000;
563 //Depending on channel configs, rates below 5ksps are possible
564 //but such a low rate can easily stream and this eliminates a lot
566 if (devc->sample_rate < 5000) {
567 sr_err("Sample rate override to min of 5ksps");
568 devc->sample_rate = 5000;
570 if (devc->sample_rate > 120000000) {
571 sr_err("Sample rate override to max of 120Msps");
572 devc->sample_rate = 12000000;
574 //It may take a very large number of samples to notice, but if digital and analog are enabled
575 //and either PIO or ADC are fractional the samples will skew over time.
576 //24Mhz is the max common divisor to the 120Mhz and 48Mhz ADC clock
577 //so force an integer divisor to it.
578 if ((a_enabled > 0) && (d_enabled > 0)) {
579 if (24000000ULL % (devc->sample_rate)) {
580 uint32_t commondivint =
581 24000000ULL / (devc->sample_rate);
582 //Always increment the divisor so that we go down in frequency to avoid max sample rate issues
584 devc->sample_rate = 24000000ULL / commondivint;
585 //Make sure the divisor increement didn't make use go too low.
586 if (devc->sample_rate < 5000) {
587 devc->sample_rate = 50000;
590 ("WARN: Forcing common integer divisor sample rate of %llu div %u\n\r",
591 devc->sample_rate, commondivint);
595 //If we are only digital only or only analog print a warning that the
596 //fractional divisors aren't a true PLL fractional feedback loop and thus
597 //could have sample to sample variation.
599 if (48000000ULL % (devc->sample_rate * a_enabled)) {
601 ("WARN: Non integer ADC divisor of 48Mhz clock for sample rate %llu may cause sample to sample variability.",
606 if (120000000ULL % (devc->sample_rate)) {
608 ("WARN: Non integer PIO divisor of 120Mhz for sample rate %llu may cause sample to sample variability.",
613 sprintf(&tmpstr[0], "R%llu\n", devc->sample_rate);
614 if (send_serial_w_ack(serial, tmpstr) != SR_OK) {
615 sr_err("Sample rate to device failed");
618 sprintf(tmpstr, "L%lld\n", devc->limit_samples);
619 if (send_serial_w_ack(serial, tmpstr) != SR_OK) {
620 sr_err("Sample limit to device failed");
625 devc->sent_samples = 0;
627 devc->bytes_avail = 0;
629 devc->cbuf_wrptr = 0;
631 serial_read_blocking(serial, devc->buffer,
632 devc->serial_buffer_size,
633 serial_timeout(serial, 4));
635 sr_info("Pre-ARM drain had %d characters:", len);
636 devc->buffer[len] = 0;
637 sr_info("%s", devc->buffer);
640 for (i = 0; i < devc->num_a_channels; i++) {
641 devc->a_data_bufs[i] =
642 g_malloc(devc->sample_buf_size * sizeof(float));
643 if (!(devc->a_data_bufs[i])) {
644 sr_err("ERROR:analog buffer malloc fail");
645 return SR_ERR_MALLOC;
648 if (devc->num_d_channels > 0) {
650 g_malloc(devc->sample_buf_size *
651 devc->dig_sample_bytes);
652 if (!(devc->d_data_buf)) {
653 sr_err("ERROR:logic buffer malloc fail");
654 return SR_ERR_MALLOC;
657 devc->pretrig_entries =
658 (devc->capture_ratio * devc->limit_samples) / 100;
659 //While the driver supports the passing of trigger info to the device
660 //it has been found that the sw overhead of supporting triggering and
661 //pretrigger buffer entries etc.. ends up slowing the cores down enough
662 //that the effect continous sample rate isn't much higher than that of sending
663 //untriggered samples across USB. Thus this code will remain but likely may
664 //not be used by the device.
665 if ((trigger = sr_session_trigger_get(sdi->session))) {
666 if (g_slist_length(trigger->stages) > 1)
669 struct sr_trigger_stage *stage;
670 struct sr_trigger_match *match;
672 stage = g_slist_nth_data(trigger->stages, 0);
675 for (l = stage->matches; l; l = l->next) {
679 if (!match->channel->enabled)
681 int idx = match->channel->index;
683 switch(match->match){
684 case SR_TRIGGER_ZERO:
688 case SR_TRIGGER_RISING:
690 case SR_TRIGGER_FALLING:
692 case SR_TRIGGER_EDGE:
697 sr_info("Trigger value idx %d match %d",idx,match->match);
698 //Only set trigger on enabled channels
699 if((val>=0) && ((devc->d_chan_mask>>idx)&1)){
700 sprintf(&tmpstr[0], "t%d%02d\n", val,idx+2);
701 if (send_serial_w_ack(serial, tmpstr) != SR_OK) {
702 sr_err("Trigger cfg to device failed");
708 sprintf(&tmpstr[0], "p%d\n", devc->pretrig_entries);
709 if (send_serial_w_ack(serial, tmpstr) != SR_OK) {
710 sr_err("Pretrig to device failed");
714 soft_trigger_logic_new(sdi, trigger,
715 devc->pretrig_entries);
717 return SR_ERR_MALLOC;
718 devc->trigger_fired = FALSE;
719 if (devc->pretrig_entries > 0) {
720 sr_dbg("Allocating pretrig buffers size %d",
721 devc->pretrig_entries);
722 for (i = 0; i < devc->num_a_channels; i++) {
723 if ((devc->a_chan_mask >> i) & 1) {
724 devc->a_pretrig_bufs[i] =
725 g_malloc0(sizeof(float) *
728 if (!devc->a_pretrig_bufs[i]) {
730 ("ERROR:Analog pretrigger buffer malloc failure, disabling");
731 devc->trigger_fired = TRUE;
734 } //for num_a_channels
736 sr_info("Entering sw triggered mode");
737 //post the receive before starting the device to ensure we are ready to receive data ASAP
738 serial_source_add(sdi->session, serial, G_IO_IN, 200,
739 raspberrypi_pico_receive, (void *) sdi);
740 sprintf(tmpstr, "C\n");
741 if (send_serial_str(serial, tmpstr) != SR_OK)
745 devc->trigger_fired = TRUE;
746 devc->pretrig_entries = 0;
747 sr_info("Entering fixed sample mode");
748 serial_source_add(sdi->session, serial, G_IO_IN, 200,
749 raspberrypi_pico_receive, (void *) sdi);
750 sprintf(tmpstr, "F\n");
751 if (send_serial_str(serial, tmpstr) != SR_OK)
754 std_session_send_df_header(sdi);
756 sr_dbg("dsbstartend %d", devc->dig_sample_bytes);
758 if (devc->trigger_fired)
759 std_session_send_df_trigger(sdi);
760 //Keep this at the end as we don't want to be RX_ACTIVE unless everything is ok
761 devc->rxstate = RX_ACTIVE;
766 //This function is called either by the protocol code if we reached all of the samples
767 //or an error condition, and also by the user clicking stop in pulseview.
768 //It must always be called for any acquistion that was started to free memory.
769 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
771 struct dev_context *devc;
772 struct sr_serial_dev_inst *serial;
773 sr_dbg("****at dev_acquisition_stop");
778 std_session_send_df_end(sdi);
779 //If we reached this while still active it is likely because the stop button was pushed
781 //That is generally some kind of error condition, so we don't try to check the bytenct
782 if (devc->rxstate == RX_ACTIVE) {
783 sr_err("Reached dev_acquisition_stop in RX_ACTIVE");
785 if (devc->rxstate != RX_IDLE) {
786 sr_err("Sending plus to stop device stream\n\r");
787 send_serial_char(serial, '+');
789 //In case we get calls to receive force it to exit
790 devc->rxstate = RX_IDLE;
791 //drain data from device so that it doesn't confuse subsequent commands
794 serial_read_blocking(serial, devc->buffer,
795 devc->serial_buffer_size, 100);
797 sr_err("Dropping %d device bytes\n\r", len);
803 g_free(devc->buffer);
807 for (int i = 0; i < devc->num_a_channels; i++) {
808 if (devc->a_data_bufs[i]) {
809 g_free(devc->a_data_bufs[i]);
810 devc->a_data_bufs[i] = NULL;
814 if (devc->d_data_buf) {
815 g_free(devc->d_data_buf);
816 devc->d_data_buf = NULL;
818 for (int i = 0; i < devc->num_a_channels; i++) {
819 if (devc->a_pretrig_bufs[i])
820 g_free(devc->a_pretrig_bufs[i]);
821 devc->a_pretrig_bufs[i] = NULL;
825 serial_source_remove(sdi->session, serial);
830 static struct sr_dev_driver raspberrypi_pico_driver_info = {
831 .name = "raspberrypi-pico",
832 .longname = "RaspberryPI PICO",
835 .cleanup = std_cleanup,
837 .dev_list = std_dev_list,
838 .dev_clear = std_dev_clear,
839 .config_get = config_get,
840 .config_set = config_set,
841 .config_list = config_list,
842 .dev_open = std_serial_dev_open,
843 .dev_close = std_serial_dev_close,
844 .dev_acquisition_start = dev_acquisition_start,
845 .dev_acquisition_stop = dev_acquisition_stop,
849 SR_REGISTER_DEV_DRIVER(raspberrypi_pico_driver_info);