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