X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fmotech-lps-30x%2Fapi.c;h=19f530de1c9a31d7b26e32ef7b1f6dd7d7ef15e6;hb=41812aca436805b0614f2a8f31cf2f8ce494aea0;hp=f118ebe33bb7593eae4e6d313800527008232122;hpb=91219afc75c9aa1d0c5e2da5c03343c1e43eb6df;p=libsigrok.git diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index f118ebe3..19f530de 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -27,7 +27,6 @@ #include #include #include - #include "protocol.h" /* Forward declarations */ @@ -59,27 +58,27 @@ static const uint32_t scanopts[] = { static const uint32_t devopts[] = { /* Device class */ SR_CONF_POWER_SUPPLY, - /* Aquisition modes. */ + /* Acquisition modes. */ SR_CONF_CONTINUOUS, SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET, /* Device configuration */ - SR_CONF_OUTPUT_CHANNEL_CONFIG | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, + SR_CONF_CHANNEL_CONFIG | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, }; /** Hardware capabilities channel 1, 2. */ static const uint32_t devopts_ch12[] = { - SR_CONF_OUTPUT_VOLTAGE | SR_CONF_GET, - SR_CONF_OUTPUT_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, - SR_CONF_OUTPUT_CURRENT | SR_CONF_GET, - SR_CONF_OUTPUT_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, - SR_CONF_OUTPUT_ENABLED | SR_CONF_GET | SR_CONF_SET, + SR_CONF_VOLTAGE | SR_CONF_GET, + SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, + SR_CONF_CURRENT | SR_CONF_GET, + SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, + SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET, }; /** Hardware capabilities channel 3. (LPS-304/305 only). */ static const uint32_t devopts_ch3[] = { - SR_CONF_OUTPUT_VOLTAGE | SR_CONF_GET, - SR_CONF_OUTPUT_ENABLED | SR_CONF_GET | SR_CONF_SET, + SR_CONF_VOLTAGE | SR_CONF_GET, + SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET, }; static const char *channel_modes[] = { @@ -88,7 +87,7 @@ static const char *channel_modes[] = { "Track2", }; -static struct lps_modelspec models[] = { +static const struct lps_modelspec models[] = { { LPS_UNKNOWN, "Dummy", 0, { @@ -134,9 +133,9 @@ static struct lps_modelspec models[] = { }, }; -static int init_lps301(struct sr_context *sr_ctx) +static int init_lps301(struct sr_dev_driver *di, struct sr_context *sr_ctx) { - return std_init(sr_ctx, &motech_lps_301_driver_info, LOG_PREFIX); + return std_init(sr_ctx, di, LOG_PREFIX); } /** Send command to device with va_list. @@ -441,11 +440,10 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o goto exit_err; } - g_strstrip(buf); verstr = buf + 4; } - else /* Bug in device FW 1.17: Quering version string fails while output is active. + else /* Bug in device FW 1.17: Querying version string fails while output is active. Therefore just print an error message, but do not exit with error. */ sr_err("Failed to query for hardware version: %d %s", errno, strerror(errno)); @@ -470,8 +468,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o /* Setup channels and channel groups. */ for (cnt = 0; cnt < models[modelid].num_channels; cnt++) { snprintf(channel, sizeof(channel), "CH%d", cnt + 1); - ch = sr_channel_new(cnt, SR_CHANNEL_ANALOG, TRUE, channel); - sdi->channels = g_slist_append(sdi->channels, ch); + ch = sr_channel_new(sdi, cnt, SR_CHANNEL_ANALOG, TRUE, channel); devc->channel_status[cnt].info = g_slist_append(NULL, ch); @@ -504,8 +501,7 @@ exit_err: serial_close(serial); sr_serial_dev_inst_free(serial); } - if (devc) - g_free(devc); + g_free(devc); if (sdi) sr_dev_inst_free(sdi); @@ -513,19 +509,14 @@ exit_err: } /** Scan for LPS-301 device. */ -static GSList *scan_lps301(GSList *options) +static GSList *scan_lps301(struct sr_dev_driver *di, GSList *options) { - return do_scan(LPS_301, &motech_lps_301_driver_info, options); + return do_scan(LPS_301, di, options); } -static GSList *doDevList(struct sr_dev_driver *drv) +static GSList *dev_list_lps301(const struct sr_dev_driver *di) { - return ((struct drv_context *)(drv->priv))->instances; -} - -static GSList *dev_list_lps301(void) -{ - return doDevList(&motech_lps_301_driver_info); + return ((struct drv_context *)(di->context))->instances; } static void dev_clear_private(struct dev_context* devc) @@ -539,14 +530,14 @@ static void dev_clear_private(struct dev_context* devc) g_timer_destroy(devc->elapsed_msec); } -static int dev_clear_lps301(void) +static int dev_clear_lps301(const struct sr_dev_driver *di) { - return std_dev_clear(&motech_lps_301_driver_info, (std_dev_clear_callback)dev_clear_private); + return std_dev_clear(di, (std_dev_clear_callback)dev_clear_private); } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - return dev_clear_lps301(); + return dev_clear_lps301(di); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, @@ -570,7 +561,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s case SR_CONF_LIMIT_MSEC: *data = g_variant_new_uint64(devc->limit_msec); break; - case SR_CONF_OUTPUT_CHANNEL_CONFIG: + case SR_CONF_CHANNEL_CONFIG: *data = g_variant_new_string(channel_modes[devc->tracking_mode]); break; default: @@ -581,19 +572,19 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s ch = cg->channels->data; ch_idx = ch->index; switch (key) { - case SR_CONF_OUTPUT_VOLTAGE: + case SR_CONF_VOLTAGE: *data = g_variant_new_double(devc->channel_status[ch_idx].output_voltage_last); break; - case SR_CONF_OUTPUT_VOLTAGE_TARGET: + case SR_CONF_VOLTAGE_TARGET: *data = g_variant_new_double(devc->channel_status[ch_idx].output_voltage_max); break; - case SR_CONF_OUTPUT_CURRENT: + case SR_CONF_CURRENT: *data = g_variant_new_double(devc->channel_status[ch_idx].output_current_last); break; - case SR_CONF_OUTPUT_CURRENT_LIMIT: + case SR_CONF_CURRENT_LIMIT: *data = g_variant_new_double(devc->channel_status[ch_idx].output_current_max); break; - case SR_CONF_OUTPUT_ENABLED: + case SR_CONF_ENABLED: *data = g_variant_new_boolean(devc->channel_status[ch_idx].output_enabled); break; default: @@ -630,24 +621,15 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd /* No channel group: global options. */ switch (key) { case SR_CONF_LIMIT_MSEC: - if (g_variant_get_uint64(data) == 0) { - sr_err("LIMIT_MSEC can't be 0."); - return SR_ERR; - } devc->limit_msec = g_variant_get_uint64(data); - sr_dbg("Setting time limit to %" PRIu64 "ms.", - devc->limit_msec); break; case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; - case SR_CONF_OUTPUT_CHANNEL_CONFIG: + case SR_CONF_CHANNEL_CONFIG: sval = g_variant_get_string(data, NULL); found = FALSE; - for (idx = 0; idx < (int)ARRAY_SIZE(channel_modes); idx++) - { + for (idx = 0; idx < (int)ARRAY_SIZE(channel_modes); idx++) { if (!strcmp(sval, channel_modes[idx])) { found = TRUE; if (devc->tracking_mode == idx) @@ -659,9 +641,8 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd if (devc->model->modelid <= LPS_303) /* Only first setting possible for smaller models. */ break; } - if (!found) { + if (!found) return SR_ERR_ARG; - } break; default: return SR_ERR_NA; @@ -673,7 +654,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd ch_idx = ch->index; switch (key) { - case SR_CONF_OUTPUT_VOLTAGE_TARGET: + case SR_CONF_VOLTAGE_TARGET: dval = g_variant_get_double(data); if (dval < 0 || dval > devc->model->channels[ch_idx].voltage[1]) return SR_ERR_ARG; @@ -694,7 +675,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd else return lps_cmd_ok(sdi->conn, "VSET%d %05.3f", ch_idx+1, dval); break; - case SR_CONF_OUTPUT_CURRENT_LIMIT: + case SR_CONF_CURRENT_LIMIT: dval = g_variant_get_double(data); if (dval < 0 || dval > devc->model->channels[ch_idx].current[1]) return SR_ERR_ARG; @@ -703,7 +684,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd devc->channel_status[ch_idx].output_current_max = dval; return lps_cmd_ok(sdi->conn, "ISET%d %05.4f", ch_idx+1, dval); break; - case SR_CONF_OUTPUT_ENABLED: + case SR_CONF_ENABLED: bval = g_variant_get_boolean(data); if (bval == devc->channel_status[ch_idx].output_enabled) /* Nothing to do. */ break; @@ -735,35 +716,33 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * GVariant *gvar; GVariantBuilder gvb; - (void)data; - /* Driver options, no device instance necessary. */ switch (key) { case SR_CONF_SCAN_OPTIONS: *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); + scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); return SR_OK; case SR_CONF_DEVICE_OPTIONS: if (sdi != NULL) break; *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); + drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); return SR_OK; default: - if (sdi == NULL) + if (!sdi) return SR_ERR_ARG; - devc = sdi->priv; + break; } /* Device options, independent from channel groups. */ - if (cg == NULL) { + if (!cg) { switch (key) { case SR_CONF_DEVICE_OPTIONS: *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); return SR_OK; - case SR_CONF_OUTPUT_CHANNEL_CONFIG: + case SR_CONF_CHANNEL_CONFIG: if (devc->model->modelid <= LPS_303) { /* The 1-channel models. */ *data = g_variant_new_strv(channel_modes, 1); @@ -772,7 +751,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * *data = g_variant_new_strv(channel_modes, ARRAY_SIZE(channel_modes)); } return SR_OK; - break; default: return SR_ERR_NA; } @@ -790,7 +768,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, devopts_ch3, ARRAY_SIZE(devopts_ch3), sizeof(uint32_t)); break; - case SR_CONF_OUTPUT_VOLTAGE_TARGET: + case SR_CONF_VOLTAGE_TARGET: g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); /* Min, max, step. */ for (i = 0; i < 3; i++) { @@ -799,7 +777,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * } *data = g_variant_builder_end(&gvb); break; - case SR_CONF_OUTPUT_CURRENT_LIMIT: + case SR_CONF_CURRENT_LIMIT: g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); /* Min, max, step. */ for (i = 0; i < 3; i++) { @@ -871,5 +849,5 @@ SR_PRIV struct sr_dev_driver motech_lps_301_driver_info = { .dev_close = std_serial_dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, - .priv = NULL, + .context = NULL, };