/*
- * This file is part of the sigrok project.
+ * This file is part of the libsigrok project.
*
* Copyright (C) 2010 Sven Peter <sven@fail0verflow.com>
* Copyright (C) 2010 Haxx Enterprises <bushing@gmail.com>
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <libusb.h>
#include <stdio.h>
-#include "sigrok.h"
-#include "sigrok-internal.h"
+#include <libusb.h>
+#include "libsigrok.h"
+#include "libsigrok-internal.h"
#include "gl_usb.h"
+#include "protocol.h"
#define CTRL_IN (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN | \
LIBUSB_RECIPIENT_INTERFACE)
#define CTRL_OUT (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT | \
LIBUSB_RECIPIENT_INTERFACE)
+#define EP1_BULK_IN (LIBUSB_ENDPOINT_IN | 1)
-const int PACKET_CTRL_LEN = 2;
-const int PACKET_INT_LEN = 2;
-const int PACKET_BULK_LEN = 64;
-const int INTERFACE = 0;
-const int ENDPOINT_INT_IN = 0x81; /* Endpoint 0x81 address for IN */
-const int ENDPOINT_INT_OUT = 0x01; /* Endpoint 1 address for OUT */
-const int ENDPOINT_BULK_IN = 0x81; /* Endpoint 0x81 address for IN */
-const int ENDPOINT_BULK_OUT = 0x02; /* Endpoint 1 address for OUT */
-const int TIMEOUT = 5000; /* Timeout in ms */
+#define TIMEOUT 5000 /* Timeout in ms */
enum {
REQ_READBULK = 0x82,
REQ_WRITEDATA,
};
-static struct libusb_device_handle *g_devh = NULL;
-
-int gl_write_address(libusb_device_handle *devh, unsigned int address)
+static int gl_write_address(libusb_device_handle *devh, unsigned int address)
{
unsigned char packet[8] = { address & 0xFF };
int ret;
ret = libusb_control_transfer(devh, CTRL_OUT, 0xc, REQ_WRITEADDR,
0, packet, 1, TIMEOUT);
if (ret != 1)
- sr_err("%s: libusb_control_transfer returned %d\n",
- __func__, ret);
+ sr_err("%s: %s.", __func__, libusb_error_name(ret));
return ret;
}
-int gl_write_data(libusb_device_handle *devh, unsigned int val)
+static int gl_write_data(libusb_device_handle *devh, unsigned int val)
{
unsigned char packet[8] = { val & 0xFF };
int ret;
ret = libusb_control_transfer(devh, CTRL_OUT, 0xc, REQ_WRITEDATA,
0, packet, 1, TIMEOUT);
if (ret != 1)
- sr_err("%s: libusb_control_transfer returned %d\n",
- __func__, ret);
+ sr_err("%s: %s.", __func__, libusb_error_name(ret));
return ret;
}
-int gl_read_data(libusb_device_handle *devh)
+static int gl_read_data(libusb_device_handle *devh)
{
unsigned char packet[8] = { 0 };
int ret;
ret = libusb_control_transfer(devh, CTRL_IN, 0xc, REQ_READDATA,
0, packet, 1, TIMEOUT);
if (ret != 1)
- sr_err("%s: libusb_control_transfer returned %d, val=%hhx\n",
- __func__, ret, packet[0]);
+ sr_err("%s: %s, val=%hhx.", __func__,
+ libusb_error_name(ret), packet[0]);
return (ret == 1) ? packet[0] : ret;
}
-int gl_read_bulk(libusb_device_handle *devh, void *buffer, unsigned int size)
+SR_PRIV int gl_read_bulk(libusb_device_handle *devh, void *buffer,
+ unsigned int size)
{
unsigned char packet[8] =
{ 0, 0, 0, 0, size & 0xff, (size & 0xff00) >> 8,
ret = libusb_control_transfer(devh, CTRL_OUT, 0x4, REQ_READBULK,
0, packet, 8, TIMEOUT);
if (ret != 8)
- sr_err("%s: libusb_control_transfer returned %d\n",
- __func__, ret);
+ sr_err("%s: libusb_control_transfer: %s.", __func__,
+ libusb_error_name(ret));
- ret = libusb_bulk_transfer(devh, ENDPOINT_BULK_IN, buffer, size,
+ ret = libusb_bulk_transfer(devh, EP1_BULK_IN, buffer, size,
&transferred, TIMEOUT);
if (ret < 0)
- sr_err("Bulk read error %d\n", ret);
+ sr_err("%s: libusb_bulk_transfer: %s.", __func__,
+ libusb_error_name(ret));
return transferred;
}
-int gl_reg_write(libusb_device_handle *devh, unsigned int reg,
+SR_PRIV int gl_reg_write(libusb_device_handle *devh, unsigned int reg,
unsigned int val)
{
int ret;
return ret;
}
-int gl_reg_read(libusb_device_handle *devh, unsigned int reg)
+SR_PRIV int gl_reg_read(libusb_device_handle *devh, unsigned int reg)
{
int ret;