Commits

Anonymous committed 244a410

Additional Fx2 delegates for libusb functions.

  • Participants
  • Parent commits 9354b71

Comments (0)

Files changed (3)

File examples/fx2/cpp/fx2.cpp

 #include "fx2.h"
 
 
-fx2::fx2():dev_handle(NULL),interface(0),alt_setting(0) {
+fx2::fx2():dev_handle(NULL) {
 
  int rv=libusb_init(&libusb_ctx);
  assert(!rv);
 void fx2::open(int vid,int pid) {
     dev_handle=libusb_open_device_with_vid_pid (libusb_ctx,vid,pid);
     assert(dev_handle);
-    int rv=libusb_claim_interface(dev_handle,interface);
+    int rv=libusb_claim_interface(dev_handle,0);
     assert(!rv);
-    rv=libusb_set_interface_alt_setting(dev_handle,interface,alt_setting);
+    interface=0;
+    rv=libusb_set_interface_alt_setting(dev_handle,0,0);
     assert(!rv);
+    alt_setting=0;
+    
 }
 void fx2::set_interface(int iface, int alt){
     assert(dev_handle);
     if (interface != iface) {
-        libusb_release_interface(dev_handle,this->interface);
+        libusb_release_interface(dev_handle,interface);
+        int rv=libusb_claim_interface(dev_handle,iface);
+        assert(!rv);
+        this->interface=iface;
     }
-    int rv=libusb_claim_interface(dev_handle,iface);
+    int rv=libusb_set_interface_alt_setting(dev_handle,interface,alt);
     assert(!rv);
-    rv=libusb_set_interface_alt_setting(dev_handle,iface,alt);
-    assert(!rv);
-    this->interface=iface;
-    this->alt_setting=alt;
+    alt_setting=alt;
 }
 void fx2::close() {
     assert(dev_handle);
     1000);
 }
 
+int fx2::clear_halt(char ep) {
+    assert(dev_handle);
+    return libusb_clear_halt(dev_handle,(unsigned char)ep);
+}
+
+int fx2::reset() {
+    assert(dev_handle);
+    int rv=libusb_reset_device(dev_handle);
+    if (rv==LIBUSB_ERROR_NO_DEVICE) {
+        printf ( "Device Changed.  Closing\n");
+        libusb_close(dev_handle);
+        interface=0;alt_setting=0;
+    }
+    return rv;
+}
+
+int fx2::set_configuration(int configuration) {
+    assert(dev_handle);
+    libusb_release_interface(dev_handle,interface);
+    int rv=libusb_set_configuration(dev_handle,configuration);
+    if (!rv) {
+        libusb_claim_interface(dev_handle,interface);
+    }
+}
 
 
 bool fx2::ep_bulk(char* buf, int size, unsigned char ep, int timeout) {

File examples/fx2/cpp/fx2.h

         bool isopen() { return dev_handle != NULL; }
         void close();
         int do_usb_command(char* buf, int size, unsigned char type, unsigned char request, unsigned short value, unsigned short index, unsigned short length );
+        int clear_halt(char ep);
+        int reset();
+        int set_configuration(int config);
         bool ep_bulk(char* buf, int size, unsigned char ep, int timeout);
 
 };

File examples/fx2/fx2load/__init__.py

  print "loading bix file of length: %d" % len(bix) 
  write_ram( 0, bix,len(bix) );
  reset_device(False)
- print "Closing device after reset"
- f.close();
+ f.close()