X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fikalogic-scanaplus%2Fapi.c;h=79585f060dfc86f9d71209cd27f2567611bd7f82;hb=f1ba6b4b2c9a8ecf90bb31efb218752aa7e49d1a;hp=3bd1b2733c0fb1e34d08e08398a7b35fae47da86;hpb=5e23fcab889c62864b92aa3ad6902ce3e9f5be49;p=libsigrok.git diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index 3bd1b273..79585f06 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -14,10 +14,10 @@ * 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 #include "protocol.h" #define USB_VENDOR_ID 0x0403 @@ -38,16 +38,10 @@ static const uint32_t devopts[] = { /* Channels are numbered 1-9. */ static const char *channel_names[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", - NULL, }; /* Note: The IKALOGIC ScanaPLUS always samples at 100MHz. */ -static uint64_t samplerates[1] = { SR_MHZ(100) }; - -SR_PRIV struct sr_dev_driver ikalogic_scanaplus_driver_info; -static struct sr_dev_driver *di = &ikalogic_scanaplus_driver_info; - -static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); +static const uint64_t samplerates[1] = { SR_MHZ(100) }; static void clear_helper(void *priv) { @@ -61,31 +55,20 @@ static void clear_helper(void *priv) g_free(devc); } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, clear_helper); } -static int init(struct sr_context *sr_ctx) -{ - return std_init(sr_ctx, di, LOG_PREFIX); -} - -static GSList *scan(GSList *options) +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->priv; - - devices = NULL; - /* Allocate memory for our private device context. */ devc = g_malloc0(sizeof(struct dev_context)); @@ -120,23 +103,18 @@ static GSList *scan(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; channel_names[i]; 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); + for (i = 0; i < ARRAY_SIZE(channel_names); i++) + sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_names[i]); /* 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: @@ -151,11 +129,6 @@ err_free_devc: return NULL; } -static GSList *dev_list(void) -{ - return ((struct drv_context *)(di->priv))->instances; -} - static int dev_open(struct sr_dev_inst *sdi) { struct dev_context *devc; @@ -234,38 +207,21 @@ static int dev_open(struct sr_dev_inst *sdi) sr_dbg("Received ScanaPLUS device ID successfully: %02x %02x %02x.", devc->devid[0], devc->devid[1], devc->devid[2]); - sdi->status = SR_ST_ACTIVE; - return SR_OK; err_dev_open_close_ftdic: scanaplus_close(devc); + return SR_ERR; } static int dev_close(struct sr_dev_inst *sdi) { - int ret; struct dev_context *devc; - ret = SR_OK; devc = sdi->priv; - if (sdi->status == SR_ST_ACTIVE) { - sr_dbg("Status ACTIVE, closing device."); - ret = scanaplus_close(devc); - } else { - sr_spew("Status not ACTIVE, nothing to do."); - } - - sdi->status = SR_ST_INACTIVE; - - return ret; -} - -static int cleanup(void) -{ - return dev_clear(); + return scanaplus_close(devc); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, @@ -293,9 +249,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd (void)cg; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; switch (key) { @@ -352,24 +305,18 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * return SR_OK; } -static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) +static int dev_acquisition_start(const struct sr_dev_inst *sdi) { int ret; struct dev_context *devc; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - - if (!(devc = sdi->priv)) - return SR_ERR_BUG; + devc = sdi->priv; if (!devc->ftdic) return SR_ERR_BUG; /* TODO: Configure channels later (thresholds etc.). */ - devc->cb_data = cb_data; - /* Properly reset internal variables before every new acquisition. */ devc->compressed_bytes_ignored = 0; devc->samples_sent = 0; @@ -381,40 +328,30 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) if ((ret = scanaplus_start_acquisition(devc)) < 0) return ret; - /* Send header packet to the session bus. */ - 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, G_IO_IN, 0, scanaplus_receive_data, (void *)sdi); + sr_session_source_add(sdi->session, -1, 0, 0, scanaplus_receive_data, (void *)sdi); return SR_OK; } -static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) +static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - struct sr_datafeed_packet packet; - - (void)cb_data; - - sr_dbg("Stopping acquisition."); sr_session_source_remove(sdi->session, -1); - - /* Send end packet to the session bus. */ - sr_dbg("Sending SR_DF_END."); - packet.type = SR_DF_END; - sr_session_send(sdi, &packet); + 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, @@ -423,5 +360,6 @@ SR_PRIV struct sr_dev_driver ikalogic_scanaplus_driver_info = { .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, - .priv = NULL, + .context = NULL, }; +SR_REGISTER_DEV_DRIVER(ikalogic_scanaplus_driver_info);