]> sigrok.org Git - libsigrok.git/blob - src/hardware/hung-chang-dso-2100/api.c
sr_dev_close(): Set status to SR_ST_INACTIVE.
[libsigrok.git] / src / hardware / hung-chang-dso-2100 / api.c
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2015 Daniel Glöckner <daniel-gl@gmx.net>
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 #include <config.h>
21 #include <ieee1284.h>
22 #include <string.h>
23 #include "protocol.h"
24
25 static const uint32_t scanopts[] = {
26         SR_CONF_CONN,
27 };
28
29 static const uint32_t drvopts[] = {
30         SR_CONF_OSCILLOSCOPE,
31 };
32
33 static const uint32_t devopts[] = {
34         SR_CONF_CONN | SR_CONF_GET,
35         SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET,
36         SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
37         SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
38         SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
39         SR_CONF_BUFFERSIZE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
40 };
41
42 static const uint32_t cgopts[] = {
43         SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
44         SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
45         SR_CONF_PROBE_FACTOR | SR_CONF_GET | SR_CONF_SET,
46 };
47
48 static const uint64_t samplerates[] = {
49         SR_MHZ(100), SR_MHZ(50),  SR_MHZ(25),   SR_MHZ(20),
50         SR_MHZ(10),  SR_MHZ(5),   SR_KHZ(2500), SR_MHZ(2),
51         SR_MHZ(1),   SR_KHZ(500), SR_KHZ(250),  SR_KHZ(200),
52         SR_KHZ(100), SR_KHZ(50),  SR_KHZ(25),   SR_KHZ(20),
53         SR_KHZ(10),  SR_KHZ(5),   SR_HZ(2500),  SR_KHZ(2),
54         SR_KHZ(1),   SR_HZ(500),  SR_HZ(250),   SR_HZ(200),
55         SR_HZ(100),  SR_HZ(50),   SR_HZ(25),    SR_HZ(20)
56 };
57
58 /* must be in sync with readout_steps[] in protocol.c */
59 static const uint64_t buffersizes[] = {
60         2 * 500, 3 * 500, 4 * 500, 5 * 500,
61         6 * 500, 7 * 500, 8 * 500, 9 * 500, 10 * 500,
62         12 * 500 - 2, 14 * 500 - 2, 16 * 500 - 2,
63         18 * 500 - 2, 20 * 500 - 2, 10240 - 2
64 };
65
66 static const uint64_t vdivs[][2] = {
67         { 10, 1000 },
68         { 20, 1000 },
69         { 50, 1000 },
70         { 100, 1000 },
71         { 200, 1000 },
72         { 500, 1000 },
73         { 1, 1 },
74         { 2, 1 },
75         { 5, 1 },
76 };
77
78 /* Bits 4 and 5 enable relays that add /10 filters to the chain
79  * Bits 0 and 1 select an output from a resistor array */
80 static const uint8_t vdivs_map[] = {
81         0x01, 0x02, 0x03, 0x21, 0x22, 0x23, 0x31, 0x32, 0x33
82 };
83
84
85 static const char *trigger_sources[] = {
86         "A", "B", "EXT"
87 };
88
89 static const uint8_t trigger_sources_map[] = {
90         0x00, 0x80, 0x40
91 };
92
93 static const char *trigger_slopes[] = {
94         "f", "r"
95 };
96
97 static const char *coupling[] = {
98         "DC", "AC", "GND"
99 };
100
101 static const uint8_t coupling_map[] = {
102         0x00, 0x08, 0x04
103 };
104
105 static GSList *scan_port(GSList *devices, struct parport *port)
106 {
107         struct sr_dev_inst *sdi;
108         struct sr_channel *ch;
109         struct sr_channel_group *cg;
110         struct dev_context *devc;
111         int i;
112
113         if (ieee1284_open(port, 0, &i) != E1284_OK) {
114                 sr_err("Can't open parallel port %s", port->name);
115                 goto fail1;
116         }
117
118         if ((i & (CAP1284_RAW | CAP1284_BYTE)) != (CAP1284_RAW | CAP1284_BYTE)) {
119                 sr_err("Parallel port %s does not provide low-level bidirection access",
120                        port->name);
121                 goto fail2;
122         }
123
124         if (ieee1284_claim(port) != E1284_OK) {
125                 sr_err("Parallel port %s already in use", port->name);
126                 goto fail2;
127         }
128
129         if (!hung_chang_dso_2100_check_id(port))
130                 goto fail3;
131
132         sdi = g_malloc0(sizeof(struct sr_dev_inst));
133         sdi->status = SR_ST_INACTIVE;
134         sdi->vendor = g_strdup("Hung-Chang");
135         sdi->model = g_strdup("DSO-2100");
136         sdi->inst_type = 0; /* FIXME */
137         sdi->conn = port;
138         ieee1284_ref(port);
139
140         for (i = 0; i < NUM_CHANNELS; i++) {
141                 cg = g_malloc0(sizeof(struct sr_channel_group));
142                 cg->name = g_strdup(trigger_sources[i]);
143                 ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, FALSE, trigger_sources[i]);
144                 cg->channels = g_slist_append(cg->channels, ch);
145                 sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
146         }
147
148         devc = g_malloc0(sizeof(struct dev_context));
149         devc->enabled_channel = g_slist_append(NULL, NULL);
150         devc->channel = 0;
151         devc->rate = 0;
152         devc->probe[0] = 10;
153         devc->probe[1] = 10;
154         devc->cctl[0] = 0x31; /* 1V/div, DC coupling, trigger on channel A*/
155         devc->cctl[1] = 0x31; /* 1V/div, DC coupling, no tv sync trigger */
156         devc->edge = 0;
157         devc->tlevel = 0x80;
158         devc->pos[0] = 0x80;
159         devc->pos[1] = 0x80;
160         devc->offset[0] = 0x80;
161         devc->offset[1] = 0x80;
162         devc->gain[0] = 0x80;
163         devc->gain[1] = 0x80;
164         devc->frame_limit = 0;
165         devc->last_step = 0; /* buffersize = 1000 */
166         sdi->priv = devc;
167
168         devices = g_slist_append(devices, sdi);
169
170 fail3:
171         ieee1284_release(port);
172 fail2:
173         ieee1284_close(port);
174 fail1:
175         return devices;
176 }
177
178 static GSList *scan(struct sr_dev_driver *di, GSList *options)
179 {
180         struct parport_list ports;
181         struct sr_config *src;
182         const char *conn = NULL;
183         GSList *devices, *option;
184         gboolean port_found;
185         int i;
186
187
188         for (option = options; option; option = option->next) {
189                 src = option->data;
190                 if (src->key == SR_CONF_CONN) {
191                         conn = g_variant_get_string(src->data, NULL);
192                         break;
193                 }
194         }
195
196         if (!conn)
197                 return NULL;
198
199         if (ieee1284_find_ports(&ports, 0) != E1284_OK)
200                 return NULL;
201
202         devices = NULL;
203         port_found = FALSE;
204         for (i = 0; i < ports.portc; i++)
205                 if (!strcmp(ports.portv[i]->name, conn)) {
206                         port_found = TRUE;
207                         devices = scan_port(devices, ports.portv[i]);
208                 }
209
210         if (!port_found) {
211                 sr_err("Parallel port %s not found. Valid names are:", conn);
212                 for (i = 0; i < ports.portc; i++)
213                         sr_err("\t%s", ports.portv[i]->name);
214         }
215
216         ieee1284_free_ports(&ports);
217
218         return std_scan_complete(di, devices);
219 }
220
221 static void clear_private(void *priv)
222 {
223         struct dev_context *devc = priv;
224
225         g_slist_free(devc->enabled_channel);
226 }
227
228 static int dev_clear(const struct sr_dev_driver *di)
229 {
230         struct drv_context *drvc = di->context;
231         struct sr_dev_inst *sdi;
232         GSList *l;
233
234         if (drvc) {
235                 for (l = drvc->instances; l; l = l->next) {
236                         sdi = l->data;
237                         ieee1284_unref(sdi->conn);
238                 }
239         }
240
241         return std_dev_clear(di, clear_private);
242 }
243
244 static int dev_open(struct sr_dev_inst *sdi)
245 {
246         struct dev_context *devc = sdi->priv;
247         int i;
248
249         if (ieee1284_open(sdi->conn, 0, &i) != E1284_OK)
250                 goto fail1;
251
252         if (ieee1284_claim(sdi->conn) != E1284_OK)
253                 goto fail2;
254
255         if (ieee1284_data_dir(sdi->conn, 1) != E1284_OK)
256                 goto fail3;
257
258         if (hung_chang_dso_2100_move_to(sdi, 1))
259                 goto fail3;
260
261         devc->samples = g_try_malloc(1000 * sizeof(*devc->samples));
262         if (!devc->samples)
263                 goto fail3;
264
265         return SR_OK;
266
267 fail3:
268         hung_chang_dso_2100_reset_port(sdi->conn);
269         ieee1284_release(sdi->conn);
270 fail2:
271         ieee1284_close(sdi->conn);
272 fail1:
273         return SR_ERR;
274 }
275
276 static int dev_close(struct sr_dev_inst *sdi)
277 {
278         struct dev_context *devc = sdi->priv;
279
280         g_free(devc->samples);
281         hung_chang_dso_2100_reset_port(sdi->conn);
282         ieee1284_release(sdi->conn);
283         ieee1284_close(sdi->conn);
284
285         return SR_OK;
286 }
287
288 static int find_in_array(GVariant *data, const GVariantType *type,
289                          const void *arr, int n)
290 {
291         const char * const *sarr;
292         const char *s;
293         const uint64_t *u64arr;
294         const uint8_t *u8arr;
295         uint64_t u64;
296         uint8_t u8;
297         int i;
298
299         if (!g_variant_is_of_type(data, type))
300                 return -1;
301
302         switch (g_variant_classify(data)) {
303         case G_VARIANT_CLASS_STRING:
304                 s = g_variant_get_string(data, NULL);
305                 sarr = arr;
306
307                 for (i = 0; i < n; i++)
308                         if (!strcmp(s, sarr[i]))
309                                 return i;
310                 break;
311         case G_VARIANT_CLASS_UINT64:
312                 u64 = g_variant_get_uint64(data);
313                 u64arr = arr;
314
315                 for (i = 0; i < n; i++)
316                         if (u64 == u64arr[i])
317                                 return i;
318                 break;
319         case G_VARIANT_CLASS_BYTE:
320                 u8 = g_variant_get_byte(data);
321                 u8arr = arr;
322
323                 for (i = 0; i < n; i++)
324                         if (u8 == u8arr[i])
325                                 return i;
326         default:
327                 break;
328         }
329
330         return -1;
331 }
332
333 static int reverse_map(uint8_t u, const uint8_t *arr, int n)
334 {
335         GVariant *v = g_variant_new_byte(u);
336         int i = find_in_array(v, G_VARIANT_TYPE_BYTE, arr, n);
337         g_variant_unref(v);
338         return i;
339 }
340
341 static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
342                 const struct sr_channel_group *cg)
343 {
344         struct dev_context *devc = sdi->priv;
345         struct parport *port;
346         int ret, i, ch = -1;
347
348         if (cg) /* sr_config_get will validate cg using config_list */
349                 ch = ((struct sr_channel *)cg->channels->data)->index;
350
351         ret = SR_OK;
352         switch (key) {
353         case SR_CONF_CONN:
354                 port = sdi->conn;
355                 *data = g_variant_new_string(port->name);
356                 break;
357         case SR_CONF_LIMIT_FRAMES:
358                 *data = g_variant_new_uint64(devc->frame_limit);
359                 break;
360         case SR_CONF_SAMPLERATE:
361                 *data = g_variant_new_uint64(samplerates[devc->rate]);
362                 break;
363         case SR_CONF_TRIGGER_SOURCE:
364                 i = reverse_map(devc->cctl[0] & 0xC0, trigger_sources_map,
365                                 ARRAY_SIZE(trigger_sources_map));
366                 if (i == -1)
367                         ret = SR_ERR;
368                 else
369                         *data = g_variant_new_string(trigger_sources[i]);
370                 break;
371         case SR_CONF_TRIGGER_SLOPE:
372                 if (devc->edge >= ARRAY_SIZE(trigger_slopes))
373                         ret = SR_ERR;
374                 else
375                         *data = g_variant_new_string(trigger_slopes[devc->edge]);
376                 break;
377         case SR_CONF_BUFFERSIZE:
378                 *data = g_variant_new_uint64(buffersizes[devc->last_step]);
379                 break;
380         case SR_CONF_VDIV:
381                 if (ch == -1) {
382                         ret = SR_ERR_CHANNEL_GROUP;
383                 } else {
384                         i = reverse_map(devc->cctl[ch] & 0x33, vdivs_map,
385                                         ARRAY_SIZE(vdivs_map));
386                         if (i == -1)
387                                 ret = SR_ERR;
388                         else
389                                 *data = g_variant_new("(tt)", vdivs[i][0],
390                                                       vdivs[i][1]);
391                 }
392                 break;
393         case SR_CONF_COUPLING:
394                 if (ch == -1) {
395                         ret = SR_ERR_CHANNEL_GROUP;
396                 } else {
397                         i = reverse_map(devc->cctl[ch] & 0x0C, coupling_map,
398                                         ARRAY_SIZE(coupling_map));
399                         if (i == -1)
400                                 ret = SR_ERR;
401                         else
402                                 *data = g_variant_new_string(coupling[i]);
403                 }
404                 break;
405         case SR_CONF_PROBE_FACTOR:
406                 if (ch == -1)
407                         ret = SR_ERR_CHANNEL_GROUP;
408                 else
409                         *data = g_variant_new_uint64(devc->probe[ch]);
410                 break;
411         default:
412                 ret = SR_ERR_NA;
413         }
414
415         return ret;
416 }
417
418 static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
419                 const struct sr_channel_group *cg)
420 {
421         struct dev_context *devc = sdi->priv;
422         int ret, i, ch = -1;
423         uint64_t u, v;
424
425         if (cg) /* sr_config_set will validate cg using config_list */
426                 ch = ((struct sr_channel *)cg->channels->data)->index;
427
428         ret = SR_OK;
429         switch (key) {
430         case SR_CONF_LIMIT_FRAMES:
431                 devc->frame_limit = g_variant_get_uint64(data);
432                 break;
433         case SR_CONF_SAMPLERATE:
434                 i = find_in_array(data, G_VARIANT_TYPE_UINT64,
435                                   samplerates, ARRAY_SIZE(samplerates));
436                 if (i == -1)
437                         ret = SR_ERR_ARG;
438                 else
439                         devc->rate = i;
440                 break;
441         case SR_CONF_TRIGGER_SOURCE:
442                 i = find_in_array(data, G_VARIANT_TYPE_STRING,
443                                   trigger_sources, ARRAY_SIZE(trigger_sources));
444                 if (i == -1)
445                         ret = SR_ERR_ARG;
446                 else
447                         devc->cctl[0] = (devc->cctl[0] & 0x3F)
448                                       | trigger_sources_map[i];
449                 break;
450         case SR_CONF_TRIGGER_SLOPE:
451                 i = find_in_array(data, G_VARIANT_TYPE_STRING,
452                                   trigger_slopes, ARRAY_SIZE(trigger_slopes));
453                 if (i == -1)
454                         ret = SR_ERR_ARG;
455                 else
456                         devc->edge = i;
457                 break;
458         case SR_CONF_BUFFERSIZE:
459                 i = find_in_array(data, G_VARIANT_TYPE_UINT64,
460                                   buffersizes, ARRAY_SIZE(buffersizes));
461                 if (i == -1)
462                         ret = SR_ERR_ARG;
463                 else
464                         devc->last_step = i;
465                 break;
466         case SR_CONF_VDIV:
467                 if (ch == -1) {
468                         ret = SR_ERR_CHANNEL_GROUP;
469                 } else if (!g_variant_is_of_type(data, G_VARIANT_TYPE("(tt)"))) {
470                         ret = SR_ERR_ARG;
471                 } else {
472                         g_variant_get(data, "(tt)", &u, &v);
473                         for (i = 0; i < (int)ARRAY_SIZE(vdivs); i++)
474                                 if (vdivs[i][0] == u && vdivs[i][1] == v)
475                                         break;
476                         if (i == ARRAY_SIZE(vdivs))
477                                 ret = SR_ERR_ARG;
478                         else
479                                 devc->cctl[ch] = (devc->cctl[ch] & 0xCC)
480                                                | vdivs_map[i];
481                 }
482                 break;
483         case SR_CONF_COUPLING:
484                 if (ch == -1) {
485                         ret = SR_ERR_CHANNEL_GROUP;
486                 } else {
487                         i = find_in_array(data, G_VARIANT_TYPE_STRING,
488                                           coupling, ARRAY_SIZE(coupling));
489                         if (i == -1)
490                                 ret = SR_ERR_ARG;
491                         else
492                                 devc->cctl[ch] = (devc->cctl[ch] & 0xF3)
493                                                | coupling_map[i];
494                 }
495                 break;
496         case SR_CONF_PROBE_FACTOR:
497                 if (ch == -1) {
498                         ret = SR_ERR_CHANNEL_GROUP;
499                 } else {
500                         u = g_variant_get_uint64(data);
501                         if (!u)
502                                 ret = SR_ERR_ARG;
503                         else
504                                 devc->probe[ch] = u;
505                 }
506                 break;
507         default:
508                 ret = SR_ERR_NA;
509         }
510
511         return ret;
512 }
513
514 static int config_channel_set(const struct sr_dev_inst *sdi,
515                               struct sr_channel *ch,
516                               unsigned int changes)
517 {
518         struct dev_context *devc = sdi->priv;
519         uint8_t v;
520
521         if (changes & SR_CHANNEL_SET_ENABLED) {
522                 if (ch->enabled) {
523                         v = devc->channel | (1 << ch->index);
524                         if (v & (v - 1))
525                                 return SR_ERR;
526                         devc->channel = v;
527                         devc->enabled_channel->data = ch;
528                 } else {
529                         devc->channel &= ~(1 << ch->index);
530                 }
531         }
532         return SR_OK;
533 }
534
535 static int config_commit(const struct sr_dev_inst *sdi)
536 {
537         uint8_t state = hung_chang_dso_2100_read_mbox(sdi->conn, 0.02);
538         int ret;
539
540         switch (state) {
541         case 0x03:
542         case 0x14:
543         case 0x21:
544                 /* we will travel the complete config path on our way to state 1 */
545                 break;
546         case 0x00:
547                 state = 0x01;
548                 /* Fallthrough */
549         default:
550                 ret = hung_chang_dso_2100_move_to(sdi, 1);
551                 if (ret != SR_OK)
552                         return ret;
553                 /* Fallthrough */
554         case 0x01:
555                 hung_chang_dso_2100_write_mbox(sdi->conn, 4);
556         }
557         ret = hung_chang_dso_2100_move_to(sdi, 1);
558         if (ret != SR_OK)
559                 return ret;
560         return hung_chang_dso_2100_move_to(sdi, state);
561 }
562
563 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
564                 const struct sr_channel_group *cg)
565 {
566         GVariantBuilder gvb;
567         GVariant *gvar, *rational[2];
568         GSList *l;
569         int i;
570
571         switch (key) {
572                 case SR_CONF_SCAN_OPTIONS:
573         case SR_CONF_DEVICE_OPTIONS:
574                 break;
575         case SR_CONF_SAMPLERATE:
576         case SR_CONF_TRIGGER_SOURCE:
577         case SR_CONF_TRIGGER_SLOPE:
578         case SR_CONF_BUFFERSIZE:
579                 if (!sdi || cg)
580                         return SR_ERR_NA;
581                 break;
582         case SR_CONF_VDIV:
583         case SR_CONF_COUPLING:
584                 if (!sdi)
585                         return SR_ERR_NA;
586                 if (!cg)
587                         return SR_ERR_CHANNEL_GROUP;
588                 l = g_slist_find(sdi->channel_groups, cg);
589                 if (!l)
590                         return SR_ERR_ARG;
591                 break;
592         default:
593                 return SR_ERR_NA;
594         }
595
596         switch (key) {
597         case SR_CONF_SCAN_OPTIONS:
598                 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
599                                 scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
600                 break;
601         case SR_CONF_DEVICE_OPTIONS:
602                 if (!sdi)
603                         *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
604                                         drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
605                 else if (!cg)
606                         *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
607                                         devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
608                 else
609                         *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
610                                         cgopts, ARRAY_SIZE(cgopts), sizeof(uint32_t));
611                 break;
612         case SR_CONF_SAMPLERATE:
613                 g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
614                 gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
615                                 samplerates, ARRAY_SIZE(samplerates), sizeof(uint64_t));
616                 g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
617                 *data = g_variant_builder_end(&gvb);
618                 break;
619         case SR_CONF_TRIGGER_SOURCE:
620                 *data = g_variant_new_strv(trigger_sources, ARRAY_SIZE(trigger_sources));
621                 break;
622         case SR_CONF_TRIGGER_SLOPE:
623                 *data = g_variant_new_strv(trigger_slopes, ARRAY_SIZE(trigger_slopes));
624                 break;
625         case SR_CONF_BUFFERSIZE:
626                 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64,
627                                 buffersizes, ARRAY_SIZE(buffersizes), sizeof(uint64_t));
628                 break;
629         case SR_CONF_VDIV:
630                 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
631                 for (i = 0; i < (int)ARRAY_SIZE(vdivs); i++) {
632                         rational[0] = g_variant_new_uint64(vdivs[i][0]);
633                         rational[1] = g_variant_new_uint64(vdivs[i][1]);
634                         gvar = g_variant_new_tuple(rational, 2);
635                         g_variant_builder_add_value(&gvb, gvar);
636                 }
637                 *data = g_variant_builder_end(&gvb);
638                 break;
639         case SR_CONF_COUPLING:
640                 *data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
641                 break;
642         }
643
644         return SR_OK;
645 }
646
647 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
648 {
649         struct dev_context *devc = sdi->priv;
650         int ret;
651
652         if (devc->channel) {
653                 static const float res_array[] = {0.5, 1, 2, 5};
654                 static const uint8_t relays[] = {100, 10, 10, 1};
655                 devc->factor = devc->probe[devc->channel - 1] / 32.0;
656                 devc->factor *= res_array[devc->cctl[devc->channel - 1] & 0x03];
657                 devc->factor /= relays[(devc->cctl[devc->channel - 1] >> 4) & 0x03];
658         }
659         devc->frame = 0;
660         devc->state_known = TRUE;
661         devc->step = 0;
662         devc->adc2 = FALSE;
663         devc->retries = MAX_RETRIES;
664
665         ret = hung_chang_dso_2100_move_to(sdi, 0x21);
666         if (ret != SR_OK)
667                 return ret;
668
669         std_session_send_df_header(sdi);
670
671         sr_session_source_add(sdi->session, -1, 0, 8,
672                               hung_chang_dso_2100_poll, (void *)sdi);
673
674         return SR_OK;
675 }
676
677 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
678 {
679         std_session_send_df_end(sdi);
680         sr_session_source_remove(sdi->session, -1);
681         hung_chang_dso_2100_move_to(sdi, 1);
682
683         return SR_OK;
684 }
685
686 static struct sr_dev_driver hung_chang_dso_2100_driver_info = {
687         .name = "hung-chang-dso-2100",
688         .longname = "Hung-Chang DSO-2100",
689         .api_version = 1,
690         .init = std_init,
691         .cleanup = std_cleanup,
692         .scan = scan,
693         .dev_list = std_dev_list,
694         .dev_clear = dev_clear,
695         .config_get = config_get,
696         .config_set = config_set,
697         .config_channel_set = config_channel_set,
698         .config_commit = config_commit,
699         .config_list = config_list,
700         .dev_open = dev_open,
701         .dev_close = dev_close,
702         .dev_acquisition_start = dev_acquisition_start,
703         .dev_acquisition_stop = dev_acquisition_stop,
704         .context = NULL,
705 };
706 SR_REGISTER_DEV_DRIVER(hung_chang_dso_2100_driver_info);