-/* Message logging helpers with subsystem-specific prefix string. */
-#define LOG_PREFIX "ikalogic-scanalogic2: "
-#define sr_log(l, s, args...) sr_log(l, LOG_PREFIX s, ## args)
-#define sr_spew(s, args...) sr_spew(LOG_PREFIX s, ## args)
-#define sr_dbg(s, args...) sr_dbg(LOG_PREFIX s, ## args)
-#define sr_info(s, args...) sr_info(LOG_PREFIX s, ## args)
-#define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args)
-#define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args)
+#define LOG_PREFIX "ikalogic-scanalogic2"
+
+#define VENDOR_NAME "IKALOGIC"
+#define MODEL_NAME "Scanalogic-2"
+
+#define USB_VID_PID "20a0.4123"
+#define USB_INTERFACE 0
+#define USB_TIMEOUT 5000
+
+#define USB_REQUEST_TYPE_IN (LIBUSB_REQUEST_TYPE_CLASS | \
+ LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_IN)
+
+#define USB_REQUEST_TYPE_OUT (LIBUSB_REQUEST_TYPE_CLASS | \
+ LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_OUT)
+
+#define USB_HID_GET_REPORT 0x01
+#define USB_HID_SET_REPORT 0x09
+#define USB_HID_REPORT_TYPE_FEATURE 0x300
+
+#define NUM_SAMPLERATES 11
+#define NUM_CHANNELS 4
+
+/*
+ * Number of sample bytes and samples the device can acquire. Note that the
+ * vendor software can acquire 32736 sample bytes only but the device is capable
+ * to acquire up to 32766 sample bytes.
+ */
+#define MAX_DEV_SAMPLE_BYTES 32766
+#define MAX_DEV_SAMPLES (MAX_INT_SAMPLE_BYTES * 8)
+
+/* Number of sample bytes and samples the driver can acquire. */
+#define MAX_SAMPLE_BYTES (MAX_DEV_SAMPLE_BYTES - 1)
+#define MAX_SAMPLES (MAX_SAMPLE_BYTES * 8)
+
+/* Maximum time that the trigger can be delayed in milliseconds. */
+#define MAX_AFTER_TRIGGER_DELAY 65000
+
+#define PACKET_LENGTH 128
+
+/* Number of sample bytes per packet where a sample byte contains 8 samples. */
+#define PACKET_NUM_SAMPLE_BYTES 124
+
+/* Number of samples per packet. */
+#define PACKET_NUM_SAMPLES (PACKET_NUM_SAMPLE_BYTES * 8)
+
+#define DEFAULT_SAMPLERATE SR_KHZ(1.25)
+
+/*
+ * Time interval between the last status of available data received and the
+ * moment when the next status request will be sent in microseconds.
+ */
+#define WAIT_DATA_READY_INTERVAL 1500000
+
+#define CMD_SAMPLE 0x01
+#define CMD_RESET 0x02
+#define CMD_IDLE 0x07
+#define CMD_INFO 0x0a
+
+#define TRIGGER_CHANNEL_ALL 0x00
+#define TRIGGER_CHANNEL_0 0x01
+#define TRIGGER_CHANNEL_1 0x02
+#define TRIGGER_CHANNEL_2 0x03
+
+#define TRIGGER_TYPE_NEGEDGE 0x00
+#define TRIGGER_TYPE_POSEDGE 0x01
+#define TRIGGER_TYPE_ANYEDGE 0x02
+#define TRIGGER_TYPE_NONE 0x03
+
+#define STATUS_DATA_READY 0x60
+#define STATUS_WAITING_FOR_TRIGGER 0x61
+#define STATUS_SAMPLING 0x62
+#define STATUS_DEVICE_READY 0x63
+
+struct device_info {
+ /* Serial number of the device. */
+ uint32_t serial;
+
+ /* Major version of the firmware. */
+ uint8_t fw_ver_major;
+
+ /* Minor version of the firmware. */
+ uint8_t fw_ver_minor;
+};
+
+enum {
+ STATE_IDLE = 0,
+ STATE_SAMPLE,
+ STATE_WAIT_DATA_READY,
+ STATE_RECEIVE_DATA,
+ STATE_RESET_AND_IDLE,
+ STATE_WAIT_DEVICE_READY
+};