22
22
23
23
#include <jtag/interface.h>
24
24
#include <jtag/commands.h>
25
- #include <usb.h>
26
- #include "usb_common.h"
25
+ #include "libusb_helper.h"
27
26
28
27
#define USB_VID 0x15ba
29
28
#define USB_PID 0x001e
@@ -75,7 +74,7 @@ static void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_c
75
74
76
75
/* ARM-JTAG-EW lowlevel functions */
77
76
struct armjtagew {
78
- struct usb_dev_handle * usb_handle ;
77
+ struct libusb_device_handle * usb_handle ;
79
78
};
80
79
81
80
static struct armjtagew * armjtagew_usb_open (void );
@@ -684,35 +683,37 @@ static int armjtagew_tap_execute(void)
684
683
685
684
static struct armjtagew * armjtagew_usb_open (void )
686
685
{
687
- usb_init ();
688
-
689
686
const uint16_t vids [] = { USB_VID , 0 };
690
687
const uint16_t pids [] = { USB_PID , 0 };
691
- struct usb_dev_handle * dev ;
692
- if (jtag_usb_open (vids , pids , & dev ) != ERROR_OK )
688
+ struct libusb_device_handle * dev ;
689
+
690
+ if (jtag_libusb_open (vids , pids , NULL , & dev , NULL ) != ERROR_OK )
693
691
return NULL ;
694
692
695
693
struct armjtagew * result = malloc (sizeof (struct armjtagew ));
696
694
result -> usb_handle = dev ;
697
695
698
696
#if 0
699
- /* usb_set_configuration required under win32 */
700
- usb_set_configuration (dev , dev -> config [0 ].bConfigurationValue );
697
+ /* libusb_set_configuration required under win32 */
698
+ struct libusb_config_descriptor * config ;
699
+ struct libusb_device * usb_dev = libusb_get_device (dev );
700
+ libusb_get_config_descriptor (usb_dev , 0 , & config );
701
+ libusb_set_configuration (dev , config -> bConfigurationValue );
701
702
#endif
702
- usb_claim_interface (dev , 0 );
703
+ libusb_claim_interface (dev , 0 );
703
704
#if 0
704
705
/*
705
706
* This makes problems under Mac OS X. And is not needed
706
707
* under Windows. Hopefully this will not break a linux build
707
708
*/
708
- usb_set_altinterface (dev , 0 );
709
+ libusb_set_interface_alt_setting (dev , 0 , 0 );
709
710
#endif
710
711
return result ;
711
712
}
712
713
713
714
static void armjtagew_usb_close (struct armjtagew * armjtagew )
714
715
{
715
- usb_close (armjtagew -> usb_handle );
716
+ libusb_close (armjtagew -> usb_handle );
716
717
free (armjtagew );
717
718
}
718
719
@@ -725,13 +726,13 @@ static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, in
725
726
if (result == out_length ) {
726
727
result = armjtagew_usb_read (armjtagew , in_length );
727
728
if (result != in_length ) {
728
- LOG_ERROR ("usb_bulk_read failed (requested=%d, result=%d)" ,
729
+ LOG_ERROR ("jtag_libusb_bulk_read failed (requested=%d, result=%d)" ,
729
730
in_length ,
730
731
result );
731
732
return -1 ;
732
733
}
733
734
} else {
734
- LOG_ERROR ("usb_bulk_write failed (requested=%d, result=%d)" , out_length , result );
735
+ LOG_ERROR ("jtag_libusb_bulk_write failed (requested=%d, result=%d)" , out_length , result );
735
736
return -1 ;
736
737
}
737
738
return 0 ;
@@ -741,6 +742,7 @@ static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, in
741
742
static int armjtagew_usb_write (struct armjtagew * armjtagew , int out_length )
742
743
{
743
744
int result ;
745
+ int transferred ;
744
746
745
747
if (out_length > ARMJTAGEW_OUT_BUFFER_SIZE ) {
746
748
LOG_ERROR ("armjtagew_write illegal out_length=%d (max=%d)" ,
@@ -749,29 +751,34 @@ static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
749
751
return -1 ;
750
752
}
751
753
752
- result = usb_bulk_write (armjtagew -> usb_handle , ARMJTAGEW_EPT_BULK_OUT ,
753
- (char * )usb_out_buffer , out_length , ARMJTAGEW_USB_TIMEOUT );
754
+ result = jtag_libusb_bulk_write (armjtagew -> usb_handle , ARMJTAGEW_EPT_BULK_OUT ,
755
+ (char * )usb_out_buffer , out_length , ARMJTAGEW_USB_TIMEOUT , & transferred );
754
756
755
757
LOG_DEBUG_IO ("armjtagew_usb_write, out_length = %d, result = %d" , out_length , result );
756
758
757
759
#ifdef _DEBUG_USB_COMMS_
758
760
armjtagew_debug_buffer (usb_out_buffer , out_length );
759
761
#endif
760
- return result ;
762
+ if (result != ERROR_OK )
763
+ return -1 ;
764
+ return transferred ;
761
765
}
762
766
763
767
/* Read data from USB into in_buffer. */
764
768
static int armjtagew_usb_read (struct armjtagew * armjtagew , int exp_in_length )
765
769
{
766
- int result = usb_bulk_read (armjtagew -> usb_handle , ARMJTAGEW_EPT_BULK_IN ,
767
- (char * )usb_in_buffer , exp_in_length , ARMJTAGEW_USB_TIMEOUT );
770
+ int transferred ;
771
+ int result = jtag_libusb_bulk_read (armjtagew -> usb_handle , ARMJTAGEW_EPT_BULK_IN ,
772
+ (char * )usb_in_buffer , exp_in_length , ARMJTAGEW_USB_TIMEOUT , & transferred );
768
773
769
774
LOG_DEBUG_IO ("armjtagew_usb_read, result = %d" , result );
770
775
771
776
#ifdef _DEBUG_USB_COMMS_
772
777
armjtagew_debug_buffer (usb_in_buffer , result );
773
778
#endif
774
- return result ;
779
+ if (result != ERROR_OK )
780
+ return -1 ;
781
+ return transferred ;
775
782
}
776
783
777
784
#ifdef _DEBUG_USB_COMMS_
0 commit comments