]> sigrok.org Git - sigrok-util.git/blame - source/drv-api.c
new-driver: Update templates to new API
[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 25
87c5b243 26static int init(struct sr_context *sr_ctx)
a65d66c0 27{
87c5b243 28 return std_hw_init(sr_ctx, di, LOG_PREFIX);
a65d66c0
BV
29}
30
87c5b243 31static GSList *scan(GSList *options)
a65d66c0
BV
32{
33 struct drv_context *drvc;
34 GSList *devices;
35
36 (void)options;
126eded0 37
a65d66c0
BV
38 devices = NULL;
39 drvc = di->priv;
40 drvc->instances = NULL;
41
87c5b243
BV
42 /* TODO: scan for devices, either based on a SR_CONF_CONN option
43 * or on a USB scan. */
a65d66c0
BV
44
45 return devices;
46}
47
87c5b243 48static GSList *dev_list(void)
a65d66c0
BV
49{
50 struct drv_context *drvc;
51
52 drvc = di->priv;
53
54 return drvc->instances;
55}
56
87c5b243
BV
57static int dev_clear(void)
58{
59 return std_dev_clear(di, NULL);
60}
61
62static int dev_open(struct sr_dev_inst *sdi)
a65d66c0 63{
3aef82b3
UH
64 (void)sdi;
65
87c5b243
BV
66 /* TODO: get handle from sdi->conn and open it. */
67
68 sdi->status = SR_ST_ACTIVE;
a65d66c0
BV
69
70 return SR_OK;
71}
72
87c5b243 73static int dev_close(struct sr_dev_inst *sdi)
a65d66c0 74{
3aef82b3
UH
75 (void)sdi;
76
87c5b243
BV
77 /* TODO: get handle from sdi->conn and close it. */
78
79 sdi->status = SR_ST_INACTIVE;
a65d66c0
BV
80
81 return SR_OK;
82}
83
87c5b243 84static int cleanup(void)
a65d66c0 85{
87c5b243 86 dev_clear();
a65d66c0 87
87c5b243 88 /* TODO: free other driver resources, if any. */
a65d66c0
BV
89
90 return SR_OK;
91}
92
87c5b243 93static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
a65d66c0 94{
87c5b243
BV
95 int ret;
96
3aef82b3 97 (void)sdi;
87c5b243 98 (void)data;
3aef82b3 99
87c5b243
BV
100 ret = SR_OK;
101 switch (key) {
a65d66c0
BV
102 /* TODO */
103 default:
87c5b243 104 return SR_ERR_NA;
a65d66c0
BV
105 }
106
87c5b243 107 return ret;
a65d66c0
BV
108}
109
87c5b243 110static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
a65d66c0
BV
111{
112 int ret;
113
87c5b243
BV
114 (void)data;
115
116 if (sdi->status != SR_ST_ACTIVE)
117 return SR_ERR_DEV_CLOSED;
a65d66c0
BV
118
119 ret = SR_OK;
87c5b243 120 switch (key) {
a65d66c0
BV
121 /* TODO */
122 default:
87c5b243 123 ret = SR_ERR_NA;
a65d66c0
BV
124 }
125
126 return ret;
127}
128
87c5b243 129static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
3aef82b3 130{
87c5b243
BV
131 int ret;
132
3aef82b3
UH
133 (void)sdi;
134 (void)data;
135
87c5b243 136 ret = SR_OK;
3aef82b3 137 switch (key) {
87c5b243 138 /* TODO */
3aef82b3 139 default:
87c5b243 140 return SR_ERR_NA;
3aef82b3
UH
141 }
142
87c5b243 143 return ret;
3aef82b3
UH
144}
145
87c5b243 146static int dev_acquisition_start(const struct sr_dev_inst *sdi,
126eded0 147 void *cb_data)
a65d66c0 148{
3aef82b3
UH
149 (void)sdi;
150 (void)cb_data;
151
87c5b243
BV
152 if (sdi->status != SR_ST_ACTIVE)
153 return SR_ERR_DEV_CLOSED;
154
155 /* TODO: configure hardware, reset acquisition state, set up
156 * callbacks and send header packet. */
a65d66c0
BV
157
158 return SR_OK;
159}
160
87c5b243 161static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
a65d66c0 162{
a65d66c0
BV
163 (void)cb_data;
164
87c5b243
BV
165 if (sdi->status != SR_ST_ACTIVE)
166 return SR_ERR_DEV_CLOSED;
a65d66c0 167
87c5b243 168 /* TODO: stop acquisition. */
a65d66c0
BV
169
170 return SR_OK;
171}
172
173SR_PRIV struct sr_dev_driver ${lib}_driver_info = {
174 .name = "${short}",
175 .longname = "${name}",
176 .api_version = 1,
87c5b243
BV
177 .init = init,
178 .cleanup = cleanup,
179 .scan = scan,
180 .dev_list = dev_list,
181 .dev_clear = dev_clear,
182 .config_get = config_get,
183 .config_set = config_set,
184 .config_list = config_list,
185 .dev_open = dev_open,
186 .dev_close = dev_close,
187 .dev_acquisition_start = dev_acquisition_start,
188 .dev_acquisition_stop = dev_acquisition_stop,
a65d66c0
BV
189 .priv = NULL,
190};