X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fpipistrello-ols%2Fapi.c;h=a2b01dce199b648f874dfa17355003ae19b584cf;hb=91b77e6b1d126b6406978386ec325f1c6d5bffd8;hp=3e02bc2868ed3e0636dbcafe97cc8e66da1d3e0f;hpb=dcd438ee3523098201c7937e75e55775da3b506f;p=libsigrok.git
diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c
index 3e02bc28..a2b01dce 100644
--- a/src/hardware/pipistrello-ols/api.c
+++ b/src/hardware/pipistrello-ols/api.c
@@ -17,6 +17,7 @@
* along with this program. If not, see .
*/
+#include
#include "protocol.h"
static const uint32_t devopts[] = {
@@ -65,7 +66,6 @@ SR_PRIV const char *p_ols_channel_names[] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",
"13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23",
"24", "25", "26", "27", "28", "29", "30", "31",
- NULL,
};
/* Default supported samplerates, can be overridden by device metadata. */
@@ -94,7 +94,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
(void)options;
- drvc = di->priv;
+ drvc = di->context;
devices = NULL;
@@ -111,10 +111,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
devc->flag_reg = 0;
/* Allocate memory for the incoming ftdi data. */
- if (!(devc->ftdi_buf = g_try_malloc0(FTDI_BUF_SIZE))) {
- sr_err("ftdi_buf malloc failed.");
- goto err_free_devc;
- }
+ devc->ftdi_buf = g_malloc0(FTDI_BUF_SIZE);
/* Allocate memory for the FTDI context (ftdic) and initialize it. */
if (!(devc->ftdic = ftdi_new())) {
@@ -198,17 +195,11 @@ err_free_ftdic:
ftdi_free(devc->ftdic); /* NOT free() or g_free()! */
err_free_ftdi_buf:
g_free(devc->ftdi_buf);
-err_free_devc:
g_free(devc);
return NULL;
}
-static GSList *dev_list(const struct sr_dev_driver *di)
-{
- return ((struct drv_context *)(di->priv))->instances;
-}
-
static void clear_helper(void *priv)
{
struct dev_context *devc;
@@ -224,11 +215,6 @@ static int dev_clear(const struct sr_dev_driver *di)
return std_dev_clear(di, clear_helper);
}
-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)
{
@@ -303,10 +289,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
break;
case SR_CONF_CAPTURE_RATIO:
devc->capture_ratio = g_variant_get_uint64(data);
- if (devc->capture_ratio < 0 || devc->capture_ratio > 100) {
- devc->capture_ratio = 0;
+ if (devc->capture_ratio < 0 || devc->capture_ratio > 100)
ret = SR_ERR;
- } else
+ else
ret = SR_OK;
break;
case SR_CONF_EXTERNAL_CLOCK:
@@ -540,8 +525,7 @@ static int disable_trigger(const struct sr_dev_inst *sdi, int stage)
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)
{
struct dev_context *devc;
uint32_t samplecount, readcount, delaycount;
@@ -581,7 +565,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
* buffer.
*/
sr_dbg("max_samples = %d", devc->max_samples);
- sr_dbg("limit_samples = %d", devc->limit_samples);
+ sr_dbg("limit_samples = %" PRIu64, devc->limit_samples);
samplecount = MIN(devc->max_samples, devc->limit_samples);
sr_dbg("Samplecount = %d", samplecount);
@@ -694,20 +678,18 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
devc->cnt_bytes = devc->cnt_samples = devc->cnt_samples_rle = 0;
memset(devc->sample, 0, 4);
- /* Send header packet to the session bus. */
- std_session_send_df_header(cb_data, LOG_PREFIX);
+ std_session_send_df_header(sdi, LOG_PREFIX);
/* Hook up a dummy handler to receive data from the device. */
- sr_session_source_add(sdi->session, 0, G_IO_IN, 10, p_ols_receive_data,
- cb_data);
+ sr_session_source_add(sdi->session, -1, 0, 10, p_ols_receive_data,
+ (struct sr_dev_inst *)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 dev_context *devc;
- struct sr_datafeed_packet packet;
devc = sdi->priv;
@@ -718,12 +700,9 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
write_shortcommand(devc, CMD_RESET);
write_shortcommand(devc, CMD_RESET);
- sr_session_source_remove(sdi->session, 0);
+ 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(cb_data, &packet);
+ std_session_send_df_end(sdi, LOG_PREFIX);
return SR_OK;
}
@@ -733,9 +712,9 @@ SR_PRIV struct sr_dev_driver p_ols_driver_info = {
.longname = "Pipistrello OLS",
.api_version = 1,
.init = init,
- .cleanup = cleanup,
+ .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,
@@ -744,5 +723,5 @@ SR_PRIV struct sr_dev_driver p_ols_driver_info = {
.dev_close = dev_close,
.dev_acquisition_start = dev_acquisition_start,
.dev_acquisition_stop = dev_acquisition_stop,
- .priv = NULL,
+ .context = NULL,
};