]> sigrok.org Git - libsigrok.git/blob - src/hardware/kern-scale/api.c
kern-scale: Initial driver skeleton.
[libsigrok.git] / src / hardware / kern-scale / api.c
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2015 Uwe Hermann <uwe@hermann-uwe.de>
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 2 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, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #include "protocol.h"
22
23 SR_PRIV struct sr_dev_driver kern_scale_driver_info;
24
25 static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
26 {
27         return std_init(sr_ctx, di, LOG_PREFIX);
28 }
29
30 static GSList *scan(struct sr_dev_driver *di, GSList *options)
31 {
32         struct drv_context *drvc;
33         GSList *devices;
34
35         (void)options;
36
37         devices = NULL;
38         drvc = di->context;
39         drvc->instances = NULL;
40
41         return devices;
42 }
43
44 static GSList *dev_list(const struct sr_dev_driver *di)
45 {
46         return ((struct drv_context *)(di->context))->instances;
47 }
48
49 static int dev_clear(const struct sr_dev_driver *di)
50 {
51         return std_dev_clear(di, NULL);
52 }
53
54 static int dev_open(struct sr_dev_inst *sdi)
55 {
56         (void)sdi;
57
58         sdi->status = SR_ST_ACTIVE;
59
60         return SR_OK;
61 }
62
63 static int dev_close(struct sr_dev_inst *sdi)
64 {
65         (void)sdi;
66
67         sdi->status = SR_ST_INACTIVE;
68
69         return SR_OK;
70 }
71
72 static int cleanup(const struct sr_dev_driver *di)
73 {
74         dev_clear(di);
75
76         return SR_OK;
77 }
78
79 static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
80                 const struct sr_channel_group *cg)
81 {
82         int ret;
83
84         (void)sdi;
85         (void)data;
86         (void)cg;
87
88         ret = SR_OK;
89         switch (key) {
90         default:
91                 return SR_ERR_NA;
92         }
93
94         return ret;
95 }
96
97 static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
98                 const struct sr_channel_group *cg)
99 {
100         int ret;
101
102         (void)data;
103         (void)cg;
104
105         if (sdi->status != SR_ST_ACTIVE)
106                 return SR_ERR_DEV_CLOSED;
107
108         ret = SR_OK;
109         switch (key) {
110         default:
111                 ret = SR_ERR_NA;
112         }
113
114         return ret;
115 }
116
117 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
118                 const struct sr_channel_group *cg)
119 {
120         int ret;
121
122         (void)sdi;
123         (void)data;
124         (void)cg;
125
126         ret = SR_OK;
127         switch (key) {
128         default:
129                 return SR_ERR_NA;
130         }
131
132         return ret;
133 }
134
135 static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
136 {
137         (void)sdi;
138         (void)cb_data;
139
140         if (sdi->status != SR_ST_ACTIVE)
141                 return SR_ERR_DEV_CLOSED;
142
143         return SR_OK;
144 }
145
146 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
147 {
148         (void)cb_data;
149
150         if (sdi->status != SR_ST_ACTIVE)
151                 return SR_ERR_DEV_CLOSED;
152
153         return SR_OK;
154 }
155
156 SR_PRIV struct sr_dev_driver kern_scale_driver_info = {
157         .name = "kern-scale",
158         .longname = "KERN Scale",
159         .api_version = 1,
160         .init = init,
161         .cleanup = cleanup,
162         .scan = scan,
163         .dev_list = dev_list,
164         .dev_clear = dev_clear,
165         .config_get = config_get,
166         .config_set = config_set,
167         .config_list = config_list,
168         .dev_open = dev_open,
169         .dev_close = dev_close,
170         .dev_acquisition_start = dev_acquisition_start,
171         .dev_acquisition_stop = dev_acquisition_stop,
172         .context = NULL,
173 };