]> sigrok.org Git - libsigrok.git/blame - src/hardware/tondaj-sl-814/api.c
Drop unneeded std_session_send_df_header() comments.
[libsigrok.git] / src / hardware / tondaj-sl-814 / api.c
CommitLineData
aa2af324 1/*
50985c20 2 * This file is part of the libsigrok project.
aa2af324
UH
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
6ec6c43b 21#include <config.h>
c073af80 22#include <fcntl.h>
aa2af324 23#include <glib.h>
c1aae900 24#include <libsigrok/libsigrok.h>
aa2af324
UH
25#include "libsigrok-internal.h"
26#include "protocol.h"
27
19ee7dff
BV
28#define SERIALCOMM "9600/8e1"
29
a0e0bb41 30static const uint32_t scanopts[] = {
1953564a
BV
31 SR_CONF_CONN,
32 SR_CONF_SERIALCOMM,
c073af80
UH
33};
34
f254bc4b 35static const uint32_t devopts[] = {
1953564a 36 SR_CONF_SOUNDLEVELMETER,
1953564a 37 SR_CONF_CONTINUOUS,
5827f61b 38 SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
c073af80
UH
39};
40
aa2af324 41SR_PRIV struct sr_dev_driver tondaj_sl_814_driver_info;
aa2af324 42
4f840ce9 43static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
aa2af324 44{
f6beaac5 45 return std_init(sr_ctx, di, LOG_PREFIX);
aa2af324
UH
46}
47
4f840ce9 48static GSList *scan(struct sr_dev_driver *di, GSList *options)
aa2af324
UH
49{
50 struct drv_context *drvc;
c073af80
UH
51 struct dev_context *devc;
52 struct sr_dev_inst *sdi;
1987b8d6 53 struct sr_config *src;
c073af80
UH
54 GSList *devices, *l;
55 const char *conn, *serialcomm;
a5e44c32 56 struct sr_serial_dev_inst *serial;
aa2af324 57
41812aca 58 drvc = di->context;
aa2af324
UH
59 drvc->instances = NULL;
60
4b97c74e
UH
61 devices = NULL;
62
c073af80
UH
63 conn = serialcomm = NULL;
64 for (l = options; l; l = l->next) {
1987b8d6 65 if (!(src = l->data)) {
c073af80
UH
66 sr_err("Invalid option data, skipping.");
67 continue;
68 }
1987b8d6 69 switch (src->key) {
1953564a 70 case SR_CONF_CONN:
afdf6d6a 71 conn = g_variant_get_string(src->data, NULL);
c073af80 72 break;
1953564a 73 case SR_CONF_SERIALCOMM:
06c45a66 74 serialcomm = g_variant_get_string(src->data, NULL);
c073af80
UH
75 break;
76 default:
1987b8d6 77 sr_err("Unknown option %d, skipping.", src->key);
c073af80
UH
78 break;
79 }
80 }
80bc6632 81 if (!conn)
c073af80 82 return NULL;
19ee7dff
BV
83 if (!serialcomm)
84 serialcomm = SERIALCOMM;
c073af80 85
aac29cc1 86 sdi = g_malloc0(sizeof(struct sr_dev_inst));
0af636be
UH
87 sdi->status = SR_ST_INACTIVE;
88 sdi->vendor = g_strdup("Tondaj");
89 sdi->model = g_strdup("SL-814");
f57d8ffe 90 devc = g_malloc0(sizeof(struct dev_context));
c073af80 91
91219afc 92 serial = sr_serial_dev_inst_new(conn, serialcomm);
c073af80 93
7ef93fb0 94 if (serial_open(serial, SERIAL_RDWR) != SR_OK)
c073af80 95 return NULL;
19ee7dff 96
a5e44c32
UH
97 sdi->inst_type = SR_INST_SERIAL;
98 sdi->conn = serial;
99
c073af80
UH
100 sdi->priv = devc;
101 sdi->driver = di;
5e23fcab 102 sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
c073af80
UH
103 drvc->instances = g_slist_append(drvc->instances, sdi);
104 devices = g_slist_append(devices, sdi);
aa2af324
UH
105
106 return devices;
107}
108
4f840ce9 109static GSList *dev_list(const struct sr_dev_driver *di)
aa2af324 110{
41812aca 111 return ((struct drv_context *)(di->context))->instances;
aa2af324
UH
112}
113
4f840ce9 114static int cleanup(const struct sr_dev_driver *di)
aa2af324 115{
a6630742 116 return std_dev_clear(di, NULL);
aa2af324
UH
117}
118
584560f1 119static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
53b4680f 120 const struct sr_channel_group *cg)
aa2af324 121{
c073af80 122 struct dev_context *devc;
aa2af324 123
53b4680f 124 (void)cg;
8f996b89 125
e73ffd42
BV
126 if (sdi->status != SR_ST_ACTIVE)
127 return SR_ERR_DEV_CLOSED;
aa2af324 128
c073af80
UH
129 devc = sdi->priv;
130
584560f1 131 switch (key) {
1953564a 132 case SR_CONF_LIMIT_SAMPLES:
afdf6d6a 133 devc->limit_samples = g_variant_get_uint64(data);
c073af80 134 break;
aa2af324 135 default:
bd6fbf62 136 return SR_ERR_NA;
aa2af324
UH
137 }
138
c073af80 139 return SR_OK;
aa2af324
UH
140}
141
584560f1 142static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
53b4680f 143 const struct sr_channel_group *cg)
a1c743fc 144{
a1c743fc 145 (void)sdi;
53b4680f 146 (void)cg;
a1c743fc
BV
147
148 switch (key) {
0d485e30 149 case SR_CONF_SCAN_OPTIONS:
584560f1 150 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
a0e0bb41 151 scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
0d485e30 152 break;
9a6517d1 153 case SR_CONF_DEVICE_OPTIONS:
584560f1 154 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
f254bc4b 155 devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
9a6517d1 156 break;
a1c743fc 157 default:
bd6fbf62 158 return SR_ERR_NA;
a1c743fc
BV
159 }
160
161 return SR_OK;
162}
163
6078d2c9 164static int dev_acquisition_start(const struct sr_dev_inst *sdi,
aa2af324
UH
165 void *cb_data)
166{
c073af80 167 struct dev_context *devc;
a5e44c32 168 struct sr_serial_dev_inst *serial;
c073af80 169
e73ffd42
BV
170 if (sdi->status != SR_ST_ACTIVE)
171 return SR_ERR_DEV_CLOSED;
172
c073af80
UH
173 devc = sdi->priv;
174 devc->cb_data = cb_data;
175
29a27196 176 std_session_send_df_header(cb_data, LOG_PREFIX);
c073af80 177
c073af80 178 /* Poll every 500ms, or whenever some data comes in. */
a5e44c32 179 serial = sdi->conn;
102f1239 180 serial_source_add(sdi->session, serial, G_IO_IN, 500,
c073af80 181 tondaj_sl_814_receive_data, (void *)sdi);
aa2af324
UH
182
183 return SR_OK;
184}
185
6078d2c9 186static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
aa2af324 187{
d43b0908
BV
188 return std_serial_dev_acquisition_stop(sdi, cb_data, std_serial_dev_close,
189 sdi->conn, LOG_PREFIX);
aa2af324
UH
190}
191
192SR_PRIV struct sr_dev_driver tondaj_sl_814_driver_info = {
193 .name = "tondaj-sl-814",
194 .longname = "Tondaj SL-814",
195 .api_version = 1,
6078d2c9
UH
196 .init = init,
197 .cleanup = cleanup,
198 .scan = scan,
199 .dev_list = dev_list,
a6630742 200 .dev_clear = NULL,
6fab7b8f 201 .config_get = NULL,
035a1078 202 .config_set = config_set,
a1c743fc 203 .config_list = config_list,
854434de 204 .dev_open = std_serial_dev_open,
bf2c987f 205 .dev_close = std_serial_dev_close,
6078d2c9
UH
206 .dev_acquisition_start = dev_acquisition_start,
207 .dev_acquisition_stop = dev_acquisition_stop,
41812aca 208 .context = NULL,
aa2af324 209};