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