]> sigrok.org Git - sigrok-util.git/blame - source/drv-api.c
new-driver: Update for recent changes.
[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 23
87604b0c 24static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
a65d66c0 25{
5b10d8fd 26 return std_init(sr_ctx, di, LOG_PREFIX);
a65d66c0
BV
27}
28
87604b0c 29static GSList *scan(struct sr_dev_driver *di, GSList *options)
a65d66c0
BV
30{
31 struct drv_context *drvc;
32 GSList *devices;
33
34 (void)options;
126eded0 35
a65d66c0 36 devices = NULL;
f03716cf 37 drvc = di->context;
a65d66c0
BV
38 drvc->instances = NULL;
39
87c5b243
BV
40 /* TODO: scan for devices, either based on a SR_CONF_CONN option
41 * or on a USB scan. */
a65d66c0
BV
42
43 return devices;
44}
45
87604b0c 46static GSList *dev_list(const struct sr_dev_driver *di)
a65d66c0 47{
f03716cf 48 return ((struct drv_context *)(di->context))->instances;
a65d66c0
BV
49}
50
87604b0c 51static int dev_clear(const struct sr_dev_driver *di)
87c5b243
BV
52{
53 return std_dev_clear(di, NULL);
54}
55
56static int dev_open(struct sr_dev_inst *sdi)
a65d66c0 57{
3aef82b3
UH
58 (void)sdi;
59
87c5b243
BV
60 /* TODO: get handle from sdi->conn and open it. */
61
62 sdi->status = SR_ST_ACTIVE;
a65d66c0
BV
63
64 return SR_OK;
65}
66
87c5b243 67static int dev_close(struct sr_dev_inst *sdi)
a65d66c0 68{
3aef82b3
UH
69 (void)sdi;
70
87c5b243
BV
71 /* TODO: get handle from sdi->conn and close it. */
72
73 sdi->status = SR_ST_INACTIVE;
a65d66c0
BV
74
75 return SR_OK;
76}
77
87604b0c 78static int cleanup(const struct sr_dev_driver *di)
a65d66c0 79{
87604b0c 80 dev_clear(di);
a65d66c0 81
87c5b243 82 /* TODO: free other driver resources, if any. */
a65d66c0
BV
83
84 return SR_OK;
85}
86
12a98d0a 87static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
d73e0933 88 const struct sr_channel_group *cg)
a65d66c0 89{
87c5b243
BV
90 int ret;
91
3aef82b3 92 (void)sdi;
87c5b243 93 (void)data;
d73e0933 94 (void)cg;
3aef82b3 95
87c5b243
BV
96 ret = SR_OK;
97 switch (key) {
a65d66c0
BV
98 /* TODO */
99 default:
87c5b243 100 return SR_ERR_NA;
a65d66c0
BV
101 }
102
87c5b243 103 return ret;
a65d66c0
BV
104}
105
12a98d0a 106static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
d73e0933 107 const struct sr_channel_group *cg)
a65d66c0
BV
108{
109 int ret;
110
87c5b243 111 (void)data;
d73e0933 112 (void)cg;
87c5b243
BV
113
114 if (sdi->status != SR_ST_ACTIVE)
115 return SR_ERR_DEV_CLOSED;
a65d66c0
BV
116
117 ret = SR_OK;
87c5b243 118 switch (key) {
a65d66c0
BV
119 /* TODO */
120 default:
87c5b243 121 ret = SR_ERR_NA;
a65d66c0
BV
122 }
123
124 return ret;
125}
126
12a98d0a 127static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
d73e0933 128 const struct sr_channel_group *cg)
3aef82b3 129{
87c5b243
BV
130 int ret;
131
3aef82b3
UH
132 (void)sdi;
133 (void)data;
d73e0933 134 (void)cg;
3aef82b3 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,
12a98d0a 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,
f03716cf 189 .context = NULL,
a65d66c0 190};