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