]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/ikalogic-scanaplus/api.c
Add sr_dev_acquisition_stop(), factor out SR_ERR_DEV_CLOSED check.
[libsigrok.git] / src / hardware / ikalogic-scanaplus / api.c
index ec649d41f582fd4f8295c99320622e8c7897efa3..439116cc69dc757c9b69cf1fee0c0ed6087ccef9 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
  */
 
 #include <config.h>
@@ -44,10 +43,6 @@ static const char *channel_names[] = {
 /* Note: The IKALOGIC ScanaPLUS always samples at 100MHz. */
 static const uint64_t samplerates[1] = { SR_MHZ(100) };
 
-SR_PRIV struct sr_dev_driver ikalogic_scanaplus_driver_info;
-
-static int dev_acquisition_stop(struct sr_dev_inst *sdi);
-
 static void clear_helper(void *priv)
 {
        struct dev_context *devc;
@@ -65,26 +60,15 @@ static int dev_clear(const struct sr_dev_driver *di)
        return std_dev_clear(di, clear_helper);
 }
 
-static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
-{
-       return std_init(sr_ctx, di, LOG_PREFIX);
-}
-
 static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
        struct sr_dev_inst *sdi;
-       struct drv_context *drvc;
        struct dev_context *devc;
-       GSList *devices;
        unsigned int i;
        int ret;
 
        (void)options;
 
-       drvc = di->context;
-
-       devices = NULL;
-
        /* Allocate memory for our private device context. */
        devc = g_malloc0(sizeof(struct dev_context));
 
@@ -119,22 +103,18 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
        /* Register the device with libsigrok. */
        sdi = g_malloc0(sizeof(struct sr_dev_inst));
-       sdi->status = SR_ST_INITIALIZING;
+       sdi->status = SR_ST_INACTIVE;
        sdi->vendor = g_strdup(USB_VENDOR_NAME);
        sdi->model = g_strdup(USB_MODEL_NAME);
-       sdi->driver = di;
        sdi->priv = devc;
 
        for (i = 0; i < ARRAY_SIZE(channel_names); i++)
                sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_names[i]);
 
-       devices = g_slist_append(devices, sdi);
-       drvc->instances = g_slist_append(drvc->instances, sdi);
-
        /* Close device. We'll reopen it again when we need it. */
        scanaplus_close(devc);
 
-       return devices;
+       return std_scan_complete(di, g_slist_append(NULL, sdi));
 
        scanaplus_close(devc);
 err_free_ftdic:
@@ -149,11 +129,6 @@ err_free_devc:
        return NULL;
 }
 
-static GSList *dev_list(const struct sr_dev_driver *di)
-{
-       return ((struct drv_context *)(di->context))->instances;
-}
-
 static int dev_open(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
@@ -261,11 +236,6 @@ static int dev_close(struct sr_dev_inst *sdi)
        return ret;
 }
 
-static int cleanup(const struct sr_dev_driver *di)
-{
-       return dev_clear(di);
-}
-
 static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
@@ -376,7 +346,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        if ((ret = scanaplus_start_acquisition(devc)) < 0)
                return ret;
 
-       std_session_send_df_header(sdi, LOG_PREFIX);
+       std_session_send_df_header(sdi);
 
        /* Hook up a dummy handler to receive data from the device. */
        sr_session_source_add(sdi->session, -1, 0, 0, scanaplus_receive_data, (void *)sdi);
@@ -386,21 +356,20 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 
 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
 {
-       sr_dbg("Stopping acquisition.");
        sr_session_source_remove(sdi->session, -1);
-       std_session_send_df_end(sdi, LOG_PREFIX);
+       std_session_send_df_end(sdi);
 
        return SR_OK;
 }
 
-SR_PRIV struct sr_dev_driver ikalogic_scanaplus_driver_info = {
+static struct sr_dev_driver ikalogic_scanaplus_driver_info = {
        .name = "ikalogic-scanaplus",
        .longname = "IKALOGIC ScanaPLUS",
        .api_version = 1,
-       .init = init,
-       .cleanup = cleanup,
+       .init = std_init,
+       .cleanup = std_cleanup,
        .scan = scan,
-       .dev_list = dev_list,
+       .dev_list = std_dev_list,
        .dev_clear = dev_clear,
        .config_get = config_get,
        .config_set = config_set,
@@ -411,3 +380,4 @@ SR_PRIV struct sr_dev_driver ikalogic_scanaplus_driver_info = {
        .dev_acquisition_stop = dev_acquisition_stop,
        .context = NULL,
 };
+SR_REGISTER_DEV_DRIVER(ikalogic_scanaplus_driver_info);