From: Paul Kasemir Date: Mon, 12 Dec 2022 19:04:12 +0000 (-0700) Subject: link-mso19: Refactor code style to declare variables first X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4e73d8f65f3e2ec62b93a6fcdbbc1f5bc4f38796;p=libsigrok.git link-mso19: Refactor code style to declare variables first Variables are now declared without any value, and then set later in the code. --- diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index 8d087643..be7e781b 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -160,8 +160,11 @@ static void mso_limit_trigger_level(struct dev_context *devc) static void mso_update_trigger_pos(struct dev_context *devc) { - int pos = (devc->horiz_triggerpos * MSO_NUM_SAMPLES) + 0.5; - uint16_t sign_bit = TRIG_POS_IS_POSITIVE; + int pos; + uint16_t sign_bit; + + pos = (devc->horiz_triggerpos * MSO_NUM_SAMPLES) + 0.5; + sign_bit = TRIG_POS_IS_POSITIVE; if (pos < 0) { pos = -pos; sign_bit = TRIG_POS_IS_NEGATIVE; @@ -184,9 +187,12 @@ static void mso_update_trigger_pos(struct dev_context *devc) static void mso_update_offset_value(struct dev_context *devc) { - double scaled_value = devc->dso_offset / devc->dso_probe_factor; - double limited_value = MIN(2.0, MAX(-2.0, scaled_value)); - int value = devc->dac_offset - (limited_value / devc->offset_vbit); + double scaled_value, limited_value; + int value; + + scaled_value = devc->dso_offset / devc->dso_probe_factor; + limited_value = MIN(2.0, MAX(-2.0, scaled_value)); + value = devc->dac_offset - (limited_value / devc->offset_vbit); value = MIN(DAC_DSO_VALUE_MASK, MAX(0, value)); devc->dso_offset_value = value; devc->dso_offset_adjusted = (devc->dac_offset - value) * @@ -289,11 +295,13 @@ static GSList* scan_handle_port(GSList *devices, struct sp_port *port) static GSList *scan(struct sr_dev_driver *di, GSList *options) { - GSList *devices = NULL; - const char *conn = NULL; - GSList *l; + GSList *devices, *l; + const char *conn; struct sr_config *src; + devices = NULL; + conn = NULL; + for (l = options; l; l = l->next) { src = l->data; switch (src->key) { @@ -581,8 +589,9 @@ static int config_list(uint32_t key, GVariant **data, static int dev_acquisition_start(const struct sr_dev_inst *sdi) { struct dev_context *devc; - int ret = SR_ERR; + int ret; + ret = SR_ERR; devc = sdi->priv; if (mso_configure_channels(sdi) != SR_OK) { diff --git a/src/hardware/link-mso19/protocol.c b/src/hardware/link-mso19/protocol.c index 3f5c99a7..eeff3bf2 100644 --- a/src/hardware/link-mso19/protocol.c +++ b/src/hardware/link-mso19/protocol.c @@ -78,8 +78,11 @@ static uint16_t mso_bank_select(const struct dev_context *devc, int bank) SR_PRIV int mso_configure_trigger(const struct sr_dev_inst *sdi) { - struct dev_context *devc = sdi->priv; - uint16_t threshold_value = mso_calc_trigger_threshold(devc); + struct dev_context *devc; + uint16_t threshold_value; + + devc = sdi->priv; + threshold_value = mso_calc_trigger_threshold(devc); TRIG_UPDATE_THRESH_MSB(devc->ctltrig, threshold_value); @@ -262,9 +265,12 @@ SR_PRIV int mso_clkrate_out(struct sr_serial_dev_inst *serial, uint16_t val) SR_PRIV int mso_configure_rate(const struct sr_dev_inst *sdi, uint32_t rate) { - struct dev_context *devc = sdi->priv; + struct dev_context *devc; unsigned int i; - int ret = SR_ERR; + int ret; + + devc = sdi->priv; + ret = SR_ERR; for (i = 0; i < ARRAY_SIZE(rate_map); i++) { if (rate_map[i].rate == rate) { @@ -283,7 +289,9 @@ SR_PRIV int mso_configure_rate(const struct sr_dev_inst *sdi, uint32_t rate) } static int mso_validate_status(uint8_t val) { - uint8_t action = BITS_STATUS_ACTION(val); + uint8_t action; + + action = BITS_STATUS_ACTION(val); if (action == 0 || action > STATUS_DATA_READY || val & 0xC0) { sr_err("Invalid status byte %.2x", val); @@ -296,9 +304,11 @@ static int mso_validate_status(uint8_t val) { SR_PRIV int mso_read_status(struct sr_serial_dev_inst *serial, uint8_t *status) { uint16_t ops[] = { mso_trans(REG_STATUS, 0) }; - uint8_t buf = 0; + uint8_t buf; int ret; + buf = 0; + sr_dbg("Requesting status."); ret = mso_send_control_message(serial, ARRAY_AND_SIZE(ops)); if (!status || ret != SR_OK) {