]> sigrok.org Git - sigrok-firmware-fx2lafw.git/blobdiff - fx2lib/examples/fx2/cpp/fx2.h
Import fx2lib into fx2lafw directly.
[sigrok-firmware-fx2lafw.git] / fx2lib / examples / fx2 / cpp / fx2.h
diff --git a/fx2lib/examples/fx2/cpp/fx2.h b/fx2lib/examples/fx2/cpp/fx2.h
new file mode 100644 (file)
index 0000000..bb61613
--- /dev/null
@@ -0,0 +1,61 @@
+/**
+ * Copyright (C) 2009 Ubixum, Inc. 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ **/
+
+#ifndef FX2_H
+#define FX2_H
+
+#include <libusb-1.0/libusb.h>
+
+const int VID=0x04b4;
+const int PID=0x0082;
+
+class fx2 {
+    
+    private:
+        libusb_context* libusb_ctx;
+        libusb_device_handle* dev_handle;
+        int interface,alt_setting;
+        
+    public:
+        fx2();
+        ~fx2();
+        /**
+         * open
+         * vid = vendor id
+         * pid = product id
+         * idx = nth device if there are more than one.
+         *
+         * Opens device with vid,pid and claims alt 0 of interface 0
+         **/
+        void open(int vid=VID,int pid=PID, int idx=0);
+        void set_interface(int interface, int alt_setting);
+        bool isopen() { return dev_handle != NULL; }
+        void close();
+        /**
+         * level n = 0-3
+         */
+        void set_debug_level(int n);
+        int do_usb_command(char* buf, int size, unsigned char type, unsigned char request, unsigned short value, unsigned short index, unsigned short length, int timeout=1000 );
+        int clear_halt(char ep);
+        int reset();
+        int set_configuration(int config);
+        bool ep_bulk(char* buf, int size, unsigned char ep, int timeout);
+
+};
+
+#endif