X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fcenter-3xx%2Fapi.c;h=4591ae967dc7d0e5e85fede5b37c6dae5a343dc6;hb=HEAD;hp=40e8dbd66efc40f0402360edbf529bb662bc01a0;hpb=c2fdcc25a47c4c8f25e3ea96ea36a674a151e839;p=libsigrok.git diff --git a/src/hardware/center-3xx/api.c b/src/hardware/center-3xx/api.c index 40e8dbd6..76d234ff 100644 --- a/src/hardware/center-3xx/api.c +++ b/src/hardware/center-3xx/api.c @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * along with this program; if not, see . */ #include @@ -40,8 +39,8 @@ static const char *channel_names[] = { "T1", "T2", "T3", "T4", }; -SR_PRIV struct sr_dev_driver center_309_driver_info; -SR_PRIV struct sr_dev_driver voltcraft_k204_driver_info; +static struct sr_dev_driver center_309_driver_info; +static struct sr_dev_driver voltcraft_k204_driver_info; SR_PRIV const struct center_dev_info center_devs[] = { { @@ -60,20 +59,14 @@ static GSList *center_scan(const char *conn, const char *serialcomm, int idx) { int i; struct sr_dev_inst *sdi; - struct drv_context *drvc; struct dev_context *devc; struct sr_serial_dev_inst *serial; - GSList *devices; serial = sr_serial_dev_inst_new(conn, serialcomm); if (serial_open(serial, SERIAL_RDWR) != SR_OK) return NULL; - drvc = center_devs[idx].di->context; - devices = NULL; - serial_flush(serial); - sr_info("Found device on port %s.", conn); sdi = g_malloc0(sizeof(struct sr_dev_inst)); @@ -84,17 +77,13 @@ static GSList *center_scan(const char *conn, const char *serialcomm, int idx) sdi->inst_type = SR_INST_SERIAL; sdi->conn = serial; sdi->priv = devc; - sdi->driver = center_devs[idx].di; for (i = 0; i < center_devs[idx].num_channels; i++) sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]); - drvc->instances = g_slist_append(drvc->instances, sdi); - devices = g_slist_append(devices, sdi); - serial_close(serial); - return devices; + return g_slist_append(NULL, sdi); } static GSList *scan(GSList *options, int idx) @@ -118,55 +107,30 @@ static GSList *scan(GSList *options, int idx) if (!conn) return NULL; - if (serialcomm) { - /* Use the provided comm specs. */ + if (serialcomm) devices = center_scan(conn, serialcomm, idx); - } else { - /* Try the default. */ + else devices = center_scan(conn, center_devs[idx].conn, idx); - } - return devices; + return std_scan_complete(center_devs[idx].di, devices); } -static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_set(uint32_t key, GVariant *data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; (void)cg; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; return sr_sw_limits_config_set(&devc->sw_limits, key, data); } -static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_list(uint32_t key, GVariant **data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - (void)cg; - - switch (key) { - case SR_CONF_SCAN_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); - break; - case SR_CONF_DEVICE_OPTIONS: - if (!sdi) - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); - else - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); - break; - default: - return SR_ERR_NA; - } - - return SR_OK; + return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts); } static int dev_acquisition_start(const struct sr_dev_inst *sdi, int idx) @@ -174,16 +138,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, int idx) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; sr_sw_limits_acquisition_start(&devc->sw_limits); - std_session_send_df_header(sdi, LOG_PREFIX); + std_session_send_df_header(sdi); - /* Poll every 500ms, or whenever some data comes in. */ serial = sdi->conn; serial_source_add(sdi->session, serial, G_IO_IN, 500, center_devs[idx].receive_data, (void *)sdi); @@ -191,12 +151,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, int idx) return SR_OK; } -static int dev_acquisition_stop(struct sr_dev_inst *sdi) -{ - return std_serial_dev_acquisition_stop(sdi, - std_serial_dev_close, sdi->conn, LOG_PREFIX); -} - /* Driver-specific API function wrappers */ #define HW_SCAN(X) \ static GSList *scan_##X(struct sr_dev_driver *d, GSList *options) { \ @@ -209,7 +163,7 @@ static int dev_acquisition_start_##X(const struct sr_dev_inst *sdi \ #define DRV(ID, ID_UPPER, NAME, LONGNAME) \ HW_SCAN(ID_UPPER) \ HW_DEV_ACQUISITION_START(ID_UPPER) \ -SR_PRIV struct sr_dev_driver ID##_driver_info = { \ +static struct sr_dev_driver ID##_driver_info = { \ .name = NAME, \ .longname = LONGNAME, \ .api_version = 1, \ @@ -217,15 +171,17 @@ SR_PRIV struct sr_dev_driver ID##_driver_info = { \ .cleanup = std_cleanup, \ .scan = scan_##ID_UPPER, \ .dev_list = std_dev_list, \ + .dev_clear = std_dev_clear, \ .config_get = NULL, \ .config_set = config_set, \ .config_list = config_list, \ .dev_open = std_serial_dev_open, \ .dev_close = std_serial_dev_close, \ .dev_acquisition_start = dev_acquisition_start_##ID_UPPER, \ - .dev_acquisition_stop = dev_acquisition_stop, \ + .dev_acquisition_stop = std_serial_dev_acquisition_stop, \ .context = NULL, \ -}; +}; \ +SR_REGISTER_DEV_DRIVER(ID##_driver_info); DRV(center_309, CENTER_309, "center-309", "Center 309") DRV(voltcraft_k204, VOLTCRAFT_K204, "voltcraft-k204", "Voltcraft K204")