From: Andrej Valek Date: Sun, 29 Apr 2018 20:07:09 +0000 (+0200) Subject: hantek-4032l: Unify style. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=28f2d07fe5c88508b957860044355ee9b284a3ac;p=libsigrok.git hantek-4032l: Unify style. Signed-off-by: Andrej Valek --- diff --git a/src/hardware/hantek-4032l/api.c b/src/hardware/hantek-4032l/api.c index cf01e299..55b764e1 100644 --- a/src/hardware/hantek-4032l/api.c +++ b/src/hardware/hantek-4032l/api.c @@ -164,8 +164,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) struct sr_usb_dev_inst *usb = NULL; for (l = conn_devices; l; l = l->next) { usb = l->data; - if (usb->bus == libusb_get_bus_number(devlist[i]) - && usb->address == libusb_get_device_address(devlist[i])) + if (usb->bus == libusb_get_bus_number(devlist[i]) && + usb->address == libusb_get_device_address(devlist[i])) break; } if (!l) @@ -338,35 +338,36 @@ static int config_set(uint32_t key, GVariant *data, return SR_ERR_SAMPLERATE; } cmd_pkt->sample_rate = i; - - return SR_OK; + break; } case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - return SR_OK; + break; case SR_CONF_LIMIT_SAMPLES: { uint64_t number_samples = g_variant_get_uint64(data); number_samples += 511; number_samples &= 0xfffffe00; - if (number_samples < 2048 - || number_samples > 64 * 1024 * 1024) { + if (number_samples < 2048 || + number_samples > 64 * 1024 * 1024) { sr_err("Invalid sample range 2k...64M: %" PRIu64 ".", number_samples); return SR_ERR; } cmd_pkt->sample_size = number_samples; - return SR_OK; + break; } case SR_CONF_VOLTAGE_THRESHOLD: { double d1, d2; g_variant_get(data, "(dd)", &d1, &d2); devc->cmd_pkt.pwm_a = h4032l_voltage2pwm(d1); devc->cmd_pkt.pwm_b = h4032l_voltage2pwm(d2); - return SR_OK; + break; } + default: + return SR_ERR_NA; } - return SR_ERR_NA; + return SR_OK; } static int config_list(uint32_t key, GVariant **data, @@ -400,6 +401,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct sr_trigger *trigger = sr_session_trigger_get(sdi->session); struct h4032l_cmd_pkt *cmd_pkt = &devc->cmd_pkt; + /* Initialize variables. */ devc->acq_aborted = FALSE; /* Calculate packet ratio. */ diff --git a/src/hardware/hantek-4032l/protocol.c b/src/hardware/hantek-4032l/protocol.c index fb18e897..84a5608a 100644 --- a/src/hardware/hantek-4032l/protocol.c +++ b/src/hardware/hantek-4032l/protocol.c @@ -125,13 +125,12 @@ void LIBUSB_CALL h4032l_usb_callback(struct libusb_transfer *transfer) */ status = (struct h4032l_status_packet *)transfer->buffer; sr_dbg("FPGA version: 0x%x.", status->fpga_version); - if (status->magic != H4032L_STATUS_PACKET_MAGIC) { + if (status->magic != H4032L_STATUS_PACKET_MAGIC) devc->status = H4032L_STATUS_RESPONSE_STATUS; - } else if (status->status == 2) { + else if (status->status == 2) devc->status = H4032L_STATUS_RESPONSE_STATUS_CONTINUE; - } else { + else devc->status = H4032L_STATUS_RESPONSE_STATUS_RETRY; - } break; case H4032L_STATUS_RESPONSE_STATUS_RETRY: devc->status = H4032L_STATUS_CMD_STATUS; @@ -157,7 +156,8 @@ void LIBUSB_CALL h4032l_usb_callback(struct libusb_transfer *transfer) buffer++; /* Fallthrough. */ case H4032L_STATUS_TRANSFER: - number_samples = (devc->remaining_samples < max_samples) ? devc->remaining_samples : max_samples; + number_samples = (devc->remaining_samples < max_samples) ? + devc->remaining_samples : max_samples; devc->remaining_samples -= number_samples; packet.type = SR_DF_LOGIC; packet.payload = &logic; @@ -166,7 +166,7 @@ void LIBUSB_CALL h4032l_usb_callback(struct libusb_transfer *transfer) logic.data = buffer; sr_session_send(sdi, &packet); sr_dbg("Remaining: %d %08X %08X.", devc->remaining_samples, - buffer[0], buffer[1]); + buffer[0], buffer[1]); if (devc->remaining_samples == 0) { std_session_send_df_end(sdi); usb_source_remove(sdi->session, drvc->sr_ctx); @@ -185,8 +185,8 @@ void LIBUSB_CALL h4032l_usb_callback(struct libusb_transfer *transfer) 2 | LIBUSB_ENDPOINT_OUT, (unsigned char *)&devc->cmd_pkt, sizeof(struct h4032l_cmd_pkt), - h4032l_usb_callback, (void *)sdi, - H4032L_USB_TIMEOUT); + h4032l_usb_callback, + (void *)sdi, H4032L_USB_TIMEOUT); } else { /* Setup new USB poll packet, reuse transfer object. */ sr_dbg("Poll: %d.", devc->status); @@ -245,7 +245,8 @@ SR_PRIV int h4032l_start(const struct sr_dev_inst *sdi) if ((ret = libusb_control_transfer(usb->devhdl, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT, CMD_RESET, 0x00, 0x00, buffer, ARRAY_SIZE(buffer), H4032L_USB_TIMEOUT)) < 0) { - sr_err("Failed to send vendor request %s.", libusb_error_name(ret)); + sr_err("Failed to send vendor request %s.", + libusb_error_name(ret)); return SR_ERR; } @@ -265,7 +266,8 @@ SR_PRIV int h4032l_start(const struct sr_dev_inst *sdi) (void *)sdi, H4032L_USB_TIMEOUT); if ((ret = libusb_submit_transfer(transfer)) != 0) { - sr_err("Failed to submit transfer: %s.", libusb_error_name(ret)); + sr_err("Failed to submit transfer: %s.", + libusb_error_name(ret)); libusb_free_transfer(transfer); return SR_ERR; } @@ -301,8 +303,9 @@ SR_PRIV int h4032l_dev_open(struct sr_dev_inst *sdi) if ((sdi->status == SR_ST_INITIALIZING) || (sdi->status == SR_ST_INACTIVE)) { /* Check device by its physical USB bus/port address. */ - usb_get_port_path(devlist[i], connection_id, - sizeof(connection_id)); + if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0) + continue; + if (strcmp(sdi->connection_id, connection_id)) /* This is not the one. */ continue; @@ -315,7 +318,7 @@ SR_PRIV int h4032l_dev_open(struct sr_dev_inst *sdi) * upload, so we don't know the address yet. */ usb->address = - libusb_get_device_address(devlist[i]); + libusb_get_device_address(devlist[i]); } else { sr_err("Failed to open device: %s.", libusb_error_name(ret)); diff --git a/src/hardware/hantek-4032l/protocol.h b/src/hardware/hantek-4032l/protocol.h index 8ebcbaa8..b95b711f 100644 --- a/src/hardware/hantek-4032l/protocol.h +++ b/src/hardware/hantek-4032l/protocol.h @@ -39,28 +39,28 @@ #define H4032L_END_PACKET_MAGIC 0x4D3C037F enum h4032l_trigger_edge_type { - H4032L_TRIGGER_EDGE_TYPE_RISE = 0, + H4032L_TRIGGER_EDGE_TYPE_RISE, H4032L_TRIGGER_EDGE_TYPE_FALL, H4032L_TRIGGER_EDGE_TYPE_TOGGLE, H4032L_TRIGGER_EDGE_TYPE_DISABLED }; enum h4032l_trigger_data_range_type { - H4032L_TRIGGER_DATA_RANGE_TYPE_MAX = 0, + H4032L_TRIGGER_DATA_RANGE_TYPE_MAX, H4032L_TRIGGER_DATA_RANGE_TYPE_MIN_OR_MAX, H4032L_TRIGGER_DATA_RANGE_TYPE_OUT_OF_RANGE, H4032L_TRIGGER_DATA_RANGE_TYPE_WITHIN_RANGE }; enum h4032l_trigger_time_range_type { - H4032L_TRIGGER_TIME_RANGE_TYPE_MAX = 0, + H4032L_TRIGGER_TIME_RANGE_TYPE_MAX, H4032L_TRIGGER_TIME_RANGE_TYPE_MIN_OR_MAX, H4032L_TRIGGER_TIME_RANGE_TYPE_OUT_OF_RANGE, H4032L_TRIGGER_TIME_RANGE_TYPE_WITHIN_RANGE }; enum h4032l_trigger_data_selection { - H4032L_TRIGGER_DATA_SELECTION_NEXT = 0, + H4032L_TRIGGER_DATA_SELECTION_NEXT, H4032L_TRIGGER_DATA_SELECTION_CURRENT, H4032L_TRIGGER_DATA_SELECTION_PREV }; @@ -74,7 +74,7 @@ enum h4032l_status { H4032L_STATUS_RESPONSE_STATUS_CONTINUE, H4032L_STATUS_CMD_GET, H4032L_STATUS_FIRST_TRANSFER, - H4032L_STATUS_TRANSFER, + H4032L_STATUS_TRANSFER }; #pragma pack(push,2)