X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fkingst-la2016%2Fapi.c;h=3dee6c862ced9019bb67b4108f5003b3f89ba103;hb=0fbb464bdf0951228d4430794263bb48bc668821;hp=d9cb9b19e0ebf6e95dc7f3f346c458a784c60627;hpb=66a24ab57caebf6ba3abc57ee085a6fd0df37616;p=libsigrok.git diff --git a/src/hardware/kingst-la2016/api.c b/src/hardware/kingst-la2016/api.c index d9cb9b19..3dee6c86 100644 --- a/src/hardware/kingst-la2016/api.c +++ b/src/hardware/kingst-la2016/api.c @@ -1,6 +1,7 @@ /* * This file is part of the libsigrok project. * + * Copyright (C) 2022 Gerhard Sittig * Copyright (C) 2020 Florian Schmidt * Copyright (C) 2013 Marcus Comstedt * Copyright (C) 2013 Bert Vermeulen @@ -43,7 +44,6 @@ static const uint32_t drvopts[] = { }; static const uint32_t devopts[] = { - /* TODO: SR_CONF_CONTINUOUS, */ SR_CONF_CONN | SR_CONF_GET, SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, @@ -53,6 +53,7 @@ static const uint32_t devopts[] = { #endif SR_CONF_TRIGGER_MATCH | SR_CONF_LIST, SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET, + SR_CONF_CONTINUOUS | SR_CONF_GET | SR_CONF_SET, }; static const uint32_t devopts_cg_logic[] = { @@ -517,9 +518,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) * this device. */ devc->fw_uploaded = 0; + devc->usb_pid = pid; if (des.iProduct != LA2016_IPRODUCT_INDEX) { sr_info("Uploading MCU firmware to '%s'.", conn_id); - ret = la2016_upload_firmware(sdi, ctx, dev, pid); + ret = la2016_upload_firmware(sdi, ctx, dev, FALSE); if (ret != SR_OK) { sr_err("MCU firmware upload failed."); kingst_la2016_free_sdi(sdi); @@ -529,6 +531,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) usb->address = 0xff; renum_devices = g_slist_append(renum_devices, sdi); continue; + } else { + ret = la2016_upload_firmware(sdi, NULL, NULL, TRUE); + if (ret != SR_OK) { + sr_err("MCU firmware filename check failed."); + kingst_la2016_free_sdi(sdi); + continue; + } } /* @@ -618,6 +627,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) devc->sw_limits.limit_samples = 0; devc->capture_ratio = 50; devc->samplerate = devc->model->samplerate; + if (!devc->model->memory_bits) + devc->continuous = TRUE; devc->threshold_voltage_idx = LOGIC_THRESHOLD_IDX_DFLT; if (ARRAY_SIZE(devc->pwm_setting) >= 1) { devc->pwm_setting[0].enabled = FALSE; @@ -671,6 +682,8 @@ static int dev_close(struct sr_dev_inst *sdi) if (!usb->devhdl) return SR_ERR_BUG; + la2016_release_resources(sdi); + if (WITH_DEINIT_IN_CLOSE) la2016_deinit_hardware(sdi); @@ -811,6 +824,9 @@ static int config_get(uint32_t key, GVariant **data, *data = std_gvar_tuple_double(voltage, voltage); break; #endif /* WITH_THRESHOLD_DEVCFG */ + case SR_CONF_CONTINUOUS: + *data = g_variant_new_boolean(devc->continuous); + break; default: return SR_ERR_NA; } @@ -827,6 +843,7 @@ static int config_set(uint32_t key, GVariant *data, struct pwm_setting *pwm; double value_f; int idx; + gboolean on; devc = sdi->priv; @@ -906,6 +923,12 @@ static int config_set(uint32_t key, GVariant *data, devc->threshold_voltage_idx = idx; break; #endif /* WITH_THRESHOLD_DEVCFG */ + case SR_CONF_CONTINUOUS: + on = g_variant_get_boolean(data); + if (!devc->model->memory_bits && !on) + return SR_ERR_ARG; + devc->continuous = on; + break; default: return SR_ERR_NA; } @@ -974,8 +997,10 @@ static int config_list(uint32_t key, GVariant **data, *data = std_gvar_samplerates(ARRAY_AND_SIZE(rates_500mhz)); else if (devc->model->samplerate == SR_MHZ(200)) *data = std_gvar_samplerates(ARRAY_AND_SIZE(rates_200mhz)); - else + else if (devc->model->samplerate == SR_MHZ(100)) *data = std_gvar_samplerates(ARRAY_AND_SIZE(rates_100mhz)); + else + return SR_ERR_BUG; break; case SR_CONF_LIMIT_SAMPLES: *data = std_gvar_tuple_u64(0, LA2016_NUM_SAMPLES_MAX); @@ -1001,6 +1026,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct drv_context *drvc; struct sr_context *ctx; struct dev_context *devc; + size_t unitsize; double voltage; int ret; @@ -1010,12 +1036,21 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) devc = sdi->priv; if (!devc->feed_queue) { + if (devc->model->channel_count == 32) + unitsize = sizeof(uint32_t); + else if (devc->model->channel_count == 16) + unitsize = sizeof(uint16_t); + else + return SR_ERR_ARG; devc->feed_queue = feed_queue_logic_alloc(sdi, - LA2016_CONVBUFFER_SIZE, sizeof(uint16_t)); + LA2016_CONVBUFFER_SIZE, unitsize); if (!devc->feed_queue) { sr_err("Cannot allocate buffer for session feed."); return SR_ERR_MALLOC; } + devc->packets_per_chunk = TRANSFER_PACKET_LENGTH; + devc->packets_per_chunk--; + devc->packets_per_chunk /= unitsize + sizeof(uint8_t); } sr_sw_limits_acquisition_start(&devc->sw_limits);