]> sigrok.org Git - sigrok-util.git/blame - source/drv-api.c
new-driver: *.c: Only #include protocol.h.
[sigrok-util.git] / source / drv-api.c
CommitLineData
a65d66c0 1/*
4b527a01 2 * This file is part of the libsigrok project.
a65d66c0
BV
3 *
4 * Copyright (C) ${year} ${author} <${email}>
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
a65d66c0
BV
20#include "protocol.h"
21
2ef7b331 22SR_PRIV struct sr_dev_driver ${lib}_driver_info;
a65d66c0
BV
23static struct sr_dev_driver *di = &${lib}_driver_info;
24
a65d66c0
BV
25/* Properly close and free all devices. */
26static int clear_instances(void)
27{
28 struct sr_dev_inst *sdi;
29 struct drv_context *drvc;
30 struct dev_context *devc;
31 GSList *l;
32
81fbb7e1
BV
33 if (!(drvc = di->priv))
34 return SR_OK;
35
a65d66c0
BV
36 for (l = drvc->instances; l; l = l->next) {
37 if (!(sdi = l->data))
38 continue;
39 if (!(devc = sdi->priv))
40 continue;
41
42 /* TODO */
43
44 sr_dev_inst_free(sdi);
45 }
46
47 g_slist_free(drvc->instances);
48 drvc->instances = NULL;
49
50 return SR_OK;
51}
52
436a8443 53static int hw_init(struct sr_context *sr_ctx)
a65d66c0 54{
3aef82b3 55 return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN);
a65d66c0
BV
56}
57
58static GSList *hw_scan(GSList *options)
59{
60 struct drv_context *drvc;
61 GSList *devices;
62
63 (void)options;
126eded0 64
a65d66c0
BV
65 devices = NULL;
66 drvc = di->priv;
67 drvc->instances = NULL;
68
69 /* TODO */
70
71 return devices;
72}
73
74static GSList *hw_dev_list(void)
75{
76 struct drv_context *drvc;
77
78 drvc = di->priv;
79
80 return drvc->instances;
81}
82
83static int hw_dev_open(struct sr_dev_inst *sdi)
84{
3aef82b3
UH
85 (void)sdi;
86
a65d66c0
BV
87 /* TODO */
88
89 return SR_OK;
90}
91
92static int hw_dev_close(struct sr_dev_inst *sdi)
93{
3aef82b3
UH
94 (void)sdi;
95
a65d66c0
BV
96 /* TODO */
97
98 return SR_OK;
99}
100
101static int hw_cleanup(void)
102{
a65d66c0
BV
103 clear_instances();
104
105 /* TODO */
106
107 return SR_OK;
108}
109
3aef82b3
UH
110static int hw_config_get(int id, const void **value,
111 const struct sr_dev_inst *sdi)
a65d66c0 112{
3aef82b3
UH
113 (void)sdi;
114 (void)value;
115
116 switch (id) {
a65d66c0
BV
117 /* TODO */
118 default:
119 return SR_ERR_ARG;
120 }
121
122 return SR_OK;
123}
124
3aef82b3
UH
125static int hw_config_set(int id, const void *value,
126 const struct sr_dev_inst *sdi)
a65d66c0 127{
3aef82b3
UH
128 (void)value;
129
a65d66c0
BV
130 int ret;
131
3016358e 132 if (sdi->status != SR_ST_ACTIVE) {
f3f6a561 133 sr_err("Device inactive, can't set config options.");
a65d66c0 134 return SR_ERR;
3016358e 135 }
a65d66c0
BV
136
137 ret = SR_OK;
3aef82b3 138 switch (id) {
a65d66c0
BV
139 /* TODO */
140 default:
3aef82b3 141 sr_err("Unknown hardware capability: %d.", id);
a65d66c0
BV
142 ret = SR_ERR_ARG;
143 }
144
145 return ret;
146}
147
3aef82b3
UH
148static int hw_config_list(int key, const void **data,
149 const struct sr_dev_inst *sdi)
150{
151 (void)sdi;
152 (void)data;
153
154 switch (key) {
155 default:
156 return SR_ERR_ARG;
157 }
158
159 return SR_OK;
160}
161
a65d66c0 162static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
126eded0 163 void *cb_data)
a65d66c0 164{
3aef82b3
UH
165 (void)sdi;
166 (void)cb_data;
167
a65d66c0
BV
168 /* TODO */
169
170 return SR_OK;
171}
172
ea80dfa3 173static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
a65d66c0 174{
a65d66c0
BV
175 (void)cb_data;
176
3016358e 177 if (sdi->status != SR_ST_ACTIVE) {
cd27b91a 178 sr_err("Device inactive, can't stop acquisition.");
a65d66c0 179 return SR_ERR;
3016358e 180 }
a65d66c0
BV
181
182 /* TODO */
183
184 return SR_OK;
185}
186
187SR_PRIV struct sr_dev_driver ${lib}_driver_info = {
188 .name = "${short}",
189 .longname = "${name}",
190 .api_version = 1,
191 .init = hw_init,
192 .cleanup = hw_cleanup,
193 .scan = hw_scan,
194 .dev_list = hw_dev_list,
195 .dev_clear = clear_instances,
3aef82b3
UH
196 .config_get = hw_config_get,
197 .config_set = hw_config_set,
198 .config_list = hw_config_list,
a65d66c0
BV
199 .dev_open = hw_dev_open,
200 .dev_close = hw_dev_close,
a65d66c0
BV
201 .dev_acquisition_start = hw_dev_acquisition_start,
202 .dev_acquisition_stop = hw_dev_acquisition_stop,
203 .priv = NULL,
204};