usb 2.1.3 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +3 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/usb/bindings.d.ts +4 -0
- package/dist/usb/device.js +5 -0
- package/dist/usb/device.js.map +1 -1
- package/libusb/.gitattributes +2 -6
- package/libusb/.private/appveyor_build.sh +22 -0
- package/libusb/.private/bm.sh +1 -1
- package/libusb/.private/ci-build.sh +67 -0
- package/libusb/.private/post-rewrite.sh +5 -1
- package/libusb/.private/pre-commit.sh +5 -1
- package/libusb/.private/wbs.txt +4 -19
- package/libusb/.travis.yml +32 -23
- package/libusb/AUTHORS +76 -3
- package/libusb/ChangeLog +41 -3
- package/libusb/INSTALL_WIN.txt +22 -44
- package/libusb/Makefile.am +32 -10
- package/libusb/{README.md → README} +2 -2
- package/libusb/README.git +3 -3
- package/libusb/Xcode/common.xcconfig +23 -19
- package/libusb/Xcode/config.h +25 -13
- package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +511 -109
- package/libusb/android/README +90 -54
- package/libusb/android/config.h +23 -43
- package/libusb/android/examples/unrooted_android.c +301 -0
- package/libusb/android/examples/unrooted_android.h +36 -0
- package/libusb/android/jni/Android.mk +1 -1
- package/libusb/android/jni/Application.mk +16 -0
- package/libusb/android/jni/examples.mk +63 -29
- package/libusb/android/jni/libusb.mk +14 -8
- package/libusb/android/jni/tests.mk +13 -24
- package/libusb/appveyor.yml +69 -30
- package/libusb/autogen.sh +5 -3
- package/libusb/bootstrap.sh +6 -2
- package/libusb/configure.ac +302 -228
- package/libusb/doc/Makefile.in +22 -0
- package/libusb/doc/doxygen.cfg.in +460 -223
- package/libusb/examples/Makefile.am +6 -13
- package/libusb/examples/dpfp.c +276 -73
- package/libusb/examples/ezusb.c +18 -8
- package/libusb/examples/ezusb.h +6 -17
- package/libusb/examples/fxload.c +4 -5
- package/libusb/examples/hotplugtest.c +1 -1
- package/libusb/examples/sam3u_benchmark.c +59 -24
- package/libusb/examples/testlibusb.c +138 -104
- package/libusb/examples/xusb.c +26 -22
- package/libusb/libusb/Makefile.am +57 -70
- package/libusb/libusb/Makefile.am.extra +26 -0
- package/libusb/libusb/core.c +420 -423
- package/libusb/libusb/descriptor.c +365 -419
- package/libusb/libusb/hotplug.c +197 -104
- package/libusb/libusb/io.c +491 -528
- package/libusb/libusb/libusb-1.0.def +7 -3
- package/libusb/libusb/libusb-1.0.rc +1 -9
- package/libusb/libusb/libusb.h +295 -226
- package/libusb/libusb/libusbi.h +587 -314
- package/libusb/libusb/os/darwin_usb.c +634 -317
- package/libusb/libusb/os/darwin_usb.h +39 -15
- package/libusb/libusb/os/events_posix.c +300 -0
- package/libusb/libusb/os/events_posix.h +59 -0
- package/libusb/libusb/os/events_windows.c +214 -0
- package/libusb/{msvc/missing.h → libusb/os/events_windows.h} +25 -11
- package/libusb/libusb/os/haiku_pollfs.cpp +14 -9
- package/libusb/libusb/os/haiku_usb.h +12 -12
- package/libusb/libusb/os/haiku_usb_backend.cpp +36 -37
- package/libusb/libusb/os/haiku_usb_raw.cpp +80 -116
- package/libusb/libusb/os/linux_netlink.c +55 -63
- package/libusb/libusb/os/linux_udev.c +61 -69
- package/libusb/libusb/os/linux_usbfs.c +926 -1015
- package/libusb/libusb/os/linux_usbfs.h +74 -57
- package/libusb/libusb/os/netbsd_usb.c +103 -168
- package/libusb/libusb/os/null_usb.c +111 -0
- package/libusb/libusb/os/openbsd_usb.c +71 -120
- package/libusb/libusb/os/sunos_usb.c +289 -375
- package/libusb/libusb/os/sunos_usb.h +0 -1
- package/libusb/libusb/os/threads_posix.c +81 -32
- package/libusb/libusb/os/threads_posix.h +19 -23
- package/libusb/libusb/os/threads_windows.c +9 -95
- package/libusb/libusb/os/threads_windows.h +33 -31
- package/libusb/libusb/os/windows_common.c +904 -0
- package/libusb/libusb/os/windows_common.h +329 -42
- package/libusb/libusb/os/windows_usbdk.c +161 -267
- package/libusb/libusb/os/windows_usbdk.h +5 -2
- package/libusb/libusb/os/windows_winusb.c +1326 -1190
- package/libusb/libusb/os/windows_winusb.h +167 -167
- package/libusb/libusb/strerror.c +20 -30
- package/libusb/libusb/sync.c +20 -21
- package/libusb/libusb/version.h +1 -1
- package/libusb/libusb/version_nano.h +1 -1
- package/libusb/msvc/.gitattributes +3 -0
- package/libusb/msvc/config.h +27 -20
- package/libusb/msvc/{hotplugtest_2012.vcxproj → dpfp_2013.vcxproj} +14 -10
- package/libusb/msvc/dpfp_2013.vcxproj.filters +26 -0
- package/libusb/msvc/{listdevs_2010.vcxproj → dpfp_2015.vcxproj} +14 -9
- package/libusb/msvc/dpfp_2015.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_2017.vcxproj +106 -0
- package/libusb/msvc/dpfp_2017.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_2019.vcxproj +106 -0
- package/libusb/msvc/dpfp_2019.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_threaded_2013.vcxproj +87 -0
- package/libusb/msvc/dpfp_threaded_2013.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_threaded_2015.vcxproj +87 -0
- package/libusb/msvc/dpfp_threaded_2015.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_threaded_2017.vcxproj +106 -0
- package/libusb/msvc/dpfp_threaded_2017.vcxproj.filters +26 -0
- package/libusb/msvc/{fxload_2012.vcxproj → dpfp_threaded_2019.vcxproj} +32 -17
- package/libusb/msvc/dpfp_threaded_2019.vcxproj.filters +26 -0
- package/libusb/msvc/fxload_2013.vcxproj +6 -3
- package/libusb/msvc/fxload_2013.vcxproj.filters +35 -0
- package/libusb/msvc/fxload_2015.vcxproj +6 -3
- package/libusb/msvc/fxload_2015.vcxproj.filters +35 -0
- package/libusb/msvc/fxload_2017.vcxproj +6 -7
- package/libusb/msvc/fxload_2017.vcxproj.filters +35 -0
- package/libusb/msvc/{fxload_2010.vcxproj → fxload_2019.vcxproj} +29 -6
- package/libusb/msvc/fxload_2019.vcxproj.filters +35 -0
- package/libusb/{examples → msvc}/getopt/getopt.c +0 -0
- package/libusb/{examples → msvc}/getopt/getopt.h +0 -0
- package/libusb/{examples → msvc}/getopt/getopt1.c +0 -0
- package/libusb/msvc/getopt_2013.vcxproj +4 -5
- package/libusb/msvc/getopt_2013.vcxproj.filters +26 -0
- package/libusb/msvc/getopt_2015.vcxproj +4 -4
- package/libusb/msvc/getopt_2015.vcxproj.filters +26 -0
- package/libusb/msvc/getopt_2017.vcxproj +4 -10
- package/libusb/msvc/getopt_2017.vcxproj.filters +26 -0
- package/libusb/msvc/{getopt_2012.vcxproj → getopt_2019.vcxproj} +25 -6
- package/libusb/msvc/getopt_2019.vcxproj.filters +26 -0
- package/libusb/msvc/hotplugtest_2013.vcxproj +6 -3
- package/libusb/msvc/hotplugtest_2013.vcxproj.filters +23 -0
- package/libusb/msvc/hotplugtest_2015.vcxproj +6 -3
- package/libusb/msvc/hotplugtest_2015.vcxproj.filters +23 -0
- package/libusb/msvc/hotplugtest_2017.vcxproj +6 -7
- package/libusb/msvc/hotplugtest_2017.vcxproj.filters +23 -0
- package/libusb/msvc/hotplugtest_2019.vcxproj +105 -0
- package/libusb/msvc/hotplugtest_2019.vcxproj.filters +23 -0
- package/libusb/msvc/libusb_2013.sln +50 -20
- package/libusb/msvc/libusb_2015.sln +51 -21
- package/libusb/msvc/libusb_2017.sln +90 -36
- package/libusb/msvc/libusb_2019.sln +240 -0
- package/libusb/msvc/libusb_dll_2013.vcxproj +6 -9
- package/libusb/msvc/libusb_dll_2013.vcxproj.filters +94 -0
- package/libusb/msvc/libusb_dll_2015.vcxproj +6 -8
- package/libusb/msvc/libusb_dll_2015.vcxproj.filters +94 -0
- package/libusb/msvc/libusb_dll_2017.vcxproj +6 -16
- package/libusb/msvc/libusb_dll_2017.vcxproj.filters +94 -0
- package/libusb/msvc/{libusb_dll_2010.vcxproj → libusb_dll_2019.vcxproj} +27 -9
- package/libusb/msvc/libusb_dll_2019.vcxproj.filters +94 -0
- package/libusb/msvc/libusb_static_2013.vcxproj +5 -9
- package/libusb/msvc/libusb_static_2013.vcxproj.filters +80 -0
- package/libusb/msvc/libusb_static_2015.vcxproj +5 -8
- package/libusb/msvc/libusb_static_2015.vcxproj.filters +80 -0
- package/libusb/msvc/libusb_static_2017.vcxproj +5 -8
- package/libusb/msvc/libusb_static_2017.vcxproj.filters +80 -0
- package/libusb/msvc/{libusb_static_2010.vcxproj → libusb_static_2019.vcxproj} +26 -9
- package/libusb/msvc/libusb_static_2019.vcxproj.filters +80 -0
- package/libusb/msvc/listdevs_2013.vcxproj +6 -3
- package/libusb/msvc/listdevs_2013.vcxproj.filters +23 -0
- package/libusb/msvc/listdevs_2015.vcxproj +6 -3
- package/libusb/msvc/listdevs_2015.vcxproj.filters +23 -0
- package/libusb/msvc/listdevs_2017.vcxproj +6 -7
- package/libusb/msvc/listdevs_2017.vcxproj.filters +23 -0
- package/libusb/msvc/listdevs_2019.vcxproj +105 -0
- package/libusb/msvc/listdevs_2019.vcxproj.filters +23 -0
- package/libusb/msvc/{listdevs_2012.vcxproj → sam3u_benchmark_2013.vcxproj} +13 -9
- package/libusb/msvc/sam3u_benchmark_2013.vcxproj.filters +26 -0
- package/libusb/msvc/{hotplugtest_2010.vcxproj → sam3u_benchmark_2015.vcxproj} +13 -8
- package/libusb/msvc/sam3u_benchmark_2015.vcxproj.filters +26 -0
- package/libusb/msvc/sam3u_benchmark_2017.vcxproj +106 -0
- package/libusb/msvc/sam3u_benchmark_2017.vcxproj.filters +26 -0
- package/libusb/msvc/sam3u_benchmark_2019.vcxproj +106 -0
- package/libusb/msvc/sam3u_benchmark_2019.vcxproj.filters +26 -0
- package/libusb/msvc/stress_2013.vcxproj +4 -2
- package/libusb/msvc/stress_2013.vcxproj.filters +32 -0
- package/libusb/msvc/stress_2015.vcxproj +4 -2
- package/libusb/msvc/stress_2015.vcxproj.filters +32 -0
- package/libusb/msvc/stress_2017.vcxproj +4 -6
- package/libusb/msvc/stress_2017.vcxproj.filters +32 -0
- package/libusb/msvc/{stress_2010.vcxproj → stress_2019.vcxproj} +26 -4
- package/libusb/msvc/stress_2019.vcxproj.filters +32 -0
- package/libusb/msvc/testlibusb_2013.vcxproj +6 -3
- package/libusb/msvc/testlibusb_2013.vcxproj.filters +23 -0
- package/libusb/msvc/testlibusb_2015.vcxproj +6 -3
- package/libusb/msvc/testlibusb_2015.vcxproj.filters +23 -0
- package/libusb/msvc/testlibusb_2017.vcxproj +6 -7
- package/libusb/msvc/testlibusb_2017.vcxproj.filters +23 -0
- package/libusb/msvc/{testlibusb_2010.vcxproj → testlibusb_2019.vcxproj} +28 -5
- package/libusb/msvc/testlibusb_2019.vcxproj.filters +23 -0
- package/libusb/msvc/xusb_2013.vcxproj +6 -3
- package/libusb/msvc/xusb_2013.vcxproj.filters +23 -0
- package/libusb/msvc/xusb_2015.vcxproj +6 -3
- package/libusb/msvc/xusb_2015.vcxproj.filters +23 -0
- package/libusb/msvc/xusb_2017.vcxproj +6 -7
- package/libusb/msvc/xusb_2017.vcxproj.filters +23 -0
- package/libusb/msvc/{xusb_2010.vcxproj → xusb_2019.vcxproj} +28 -5
- package/libusb/msvc/xusb_2019.vcxproj.filters +23 -0
- package/libusb/tests/Makefile.am +1 -0
- package/libusb/tests/libusb_testlib.h +12 -43
- package/libusb/tests/stress.c +59 -50
- package/libusb/tests/testlib.c +78 -171
- package/libusb.gypi +10 -11
- package/package.json +1 -1
- package/prebuilds/android-arm/node.napi.armv7.node +0 -0
- package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
- package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/linux-ia32/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
- package/prebuilds/linux-x64/node.napi.musl.node +0 -0
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/device.cc +12 -7
- package/src/node_usb.cc +10 -0
- package/test/usb.coffee +6 -0
- package/tsc/index.ts +2 -0
- package/tsc/usb/bindings.ts +5 -0
- package/tsc/usb/device.ts +6 -0
- package/libusb/.private/bd.cmd +0 -89
- package/libusb/.private/bwince.cmd +0 -57
- package/libusb/.private/wbs_wince.txt +0 -42
- package/libusb/Brewfile +0 -4
- package/libusb/appveyor_cygwin.bat +0 -11
- package/libusb/appveyor_minGW.bat +0 -19
- package/libusb/doc/Makefile.am +0 -9
- package/libusb/examples/dpfp_threaded.c +0 -557
- package/libusb/libusb/hotplug.h +0 -99
- package/libusb/libusb/os/poll_posix.c +0 -84
- package/libusb/libusb/os/poll_posix.h +0 -14
- package/libusb/libusb/os/poll_windows.c +0 -447
- package/libusb/libusb/os/poll_windows.h +0 -98
- package/libusb/libusb/os/wince_usb.c +0 -888
- package/libusb/libusb/os/wince_usb.h +0 -126
- package/libusb/libusb/os/windows_nt_common.c +0 -1010
- package/libusb/libusb/os/windows_nt_common.h +0 -110
- package/libusb/libusb/os/windows_nt_shared_types.h +0 -147
- package/libusb/msvc/appveyor.bat +0 -27
- package/libusb/msvc/ddk_build.cmd +0 -219
- package/libusb/msvc/errno.h +0 -102
- package/libusb/msvc/fxload_sources +0 -23
- package/libusb/msvc/getopt_2005.vcproj +0 -288
- package/libusb/msvc/getopt_2010.vcxproj +0 -72
- package/libusb/msvc/getopt_sources +0 -24
- package/libusb/msvc/hotplugtest_sources +0 -20
- package/libusb/msvc/inttypes.h +0 -295
- package/libusb/msvc/libusb.dsw +0 -71
- package/libusb/msvc/libusb_2005.sln +0 -95
- package/libusb/msvc/libusb_2010.sln +0 -105
- package/libusb/msvc/libusb_2012.sln +0 -105
- package/libusb/msvc/libusb_dll.dsp +0 -194
- package/libusb/msvc/libusb_dll_2005.vcproj +0 -464
- package/libusb/msvc/libusb_dll_2012.vcxproj +0 -107
- package/libusb/msvc/libusb_dll_wince.vcproj +0 -1251
- package/libusb/msvc/libusb_sources +0 -43
- package/libusb/msvc/libusb_static.dsp +0 -174
- package/libusb/msvc/libusb_static_2005.vcproj +0 -390
- package/libusb/msvc/libusb_static_2012.vcxproj +0 -98
- package/libusb/msvc/libusb_static_wince.vcproj +0 -1179
- package/libusb/msvc/libusb_wince.sln +0 -246
- package/libusb/msvc/listdevs.dsp +0 -103
- package/libusb/msvc/listdevs_2005.vcproj +0 -360
- package/libusb/msvc/listdevs_sources +0 -20
- package/libusb/msvc/listdevs_wince.vcproj +0 -1120
- package/libusb/msvc/missing.c +0 -80
- package/libusb/msvc/stdint.h +0 -256
- package/libusb/msvc/stress_2005.vcproj +0 -390
- package/libusb/msvc/stress_2012.vcxproj +0 -87
- package/libusb/msvc/stress_sources +0 -21
- package/libusb/msvc/stress_wince.vcproj +0 -1128
- package/libusb/msvc/testlibusb_2012.vcxproj +0 -83
- package/libusb/msvc/testlibusb_sources +0 -20
- package/libusb/msvc/xusb.dsp +0 -102
- package/libusb/msvc/xusb_2005.vcproj +0 -344
- package/libusb/msvc/xusb_2012.vcxproj +0 -83
- package/libusb/msvc/xusb_sources +0 -20
- package/libusb/msvc/xusb_wince.vcproj +0 -1120
- package/libusb/travis-autogen.sh +0 -39
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
AM_CPPFLAGS = -I$(top_srcdir)/libusb
|
|
2
2
|
LDADD = ../libusb/libusb-1.0.la
|
|
3
|
+
LIBS =
|
|
3
4
|
|
|
4
|
-
noinst_PROGRAMS =
|
|
5
|
+
noinst_PROGRAMS = dpfp dpfp_threaded fxload hotplugtest listdevs sam3u_benchmark testlibusb xusb
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
dpfp_threaded_CFLAGS = $(AM_CFLAGS)
|
|
11
|
-
noinst_PROGRAMS += dpfp_threaded
|
|
12
|
-
endif
|
|
13
|
-
|
|
14
|
-
sam3u_benchmark_SOURCES = sam3u_benchmark.c
|
|
15
|
-
noinst_PROGRAMS += sam3u_benchmark
|
|
16
|
-
endif
|
|
7
|
+
dpfp_threaded_CPPFLAGS = $(AM_CPPFLAGS) -DDPFP_THREADED
|
|
8
|
+
dpfp_threaded_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
|
|
9
|
+
dpfp_threaded_LDADD = $(LDADD) $(THREAD_LIBS)
|
|
10
|
+
dpfp_threaded_SOURCES = dpfp.c
|
|
17
11
|
|
|
18
12
|
fxload_SOURCES = ezusb.c ezusb.h fxload.c
|
|
19
|
-
fxload_CFLAGS = $(THREAD_CFLAGS) $(AM_CFLAGS)
|
package/libusb/examples/dpfp.c
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* libusb example program to manipulate U.are.U 4000B fingerprint scanner.
|
|
3
3
|
* Copyright © 2007 Daniel Drake <dsd@gentoo.org>
|
|
4
|
+
* Copyright © 2016 Nathan Hjelm <hjelmn@mac.com>
|
|
5
|
+
* Copyright © 2020 Chris Dickens <christopher.a.dickens@gmail.com>
|
|
4
6
|
*
|
|
5
7
|
* Basic image capture program only, does not consider the powerup quirks or
|
|
6
8
|
* the fact that image encryption may be enabled. Not expected to work
|
|
@@ -21,14 +23,121 @@
|
|
|
21
23
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
22
24
|
*/
|
|
23
25
|
|
|
26
|
+
#include <config.h>
|
|
27
|
+
|
|
24
28
|
#include <errno.h>
|
|
25
29
|
#include <signal.h>
|
|
26
|
-
#include <string.h>
|
|
27
30
|
#include <stdio.h>
|
|
28
31
|
#include <stdlib.h>
|
|
32
|
+
#include <string.h>
|
|
29
33
|
|
|
30
34
|
#include "libusb.h"
|
|
31
35
|
|
|
36
|
+
#if defined(_MSC_VER)
|
|
37
|
+
#define snprintf _snprintf
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
#if defined(DPFP_THREADED)
|
|
41
|
+
#if defined(PLATFORM_POSIX)
|
|
42
|
+
#include <fcntl.h>
|
|
43
|
+
#include <pthread.h>
|
|
44
|
+
#include <semaphore.h>
|
|
45
|
+
#include <unistd.h>
|
|
46
|
+
|
|
47
|
+
#define THREAD_RETURN_VALUE NULL
|
|
48
|
+
typedef sem_t * semaphore_t;
|
|
49
|
+
typedef pthread_t thread_t;
|
|
50
|
+
|
|
51
|
+
static inline semaphore_t semaphore_create(void)
|
|
52
|
+
{
|
|
53
|
+
sem_t *semaphore;
|
|
54
|
+
char name[50];
|
|
55
|
+
|
|
56
|
+
sprintf(name, "/org.libusb.example.dpfp_threaded:%d", (int)getpid());
|
|
57
|
+
semaphore = sem_open(name, O_CREAT | O_EXCL, 0, 0);
|
|
58
|
+
if (semaphore == SEM_FAILED)
|
|
59
|
+
return NULL;
|
|
60
|
+
/* Remove semaphore so that it does not persist after process exits */
|
|
61
|
+
(void)sem_unlink(name);
|
|
62
|
+
return semaphore;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static inline void semaphore_give(semaphore_t semaphore)
|
|
66
|
+
{
|
|
67
|
+
(void)sem_post(semaphore);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static inline void semaphore_take(semaphore_t semaphore)
|
|
71
|
+
{
|
|
72
|
+
(void)sem_wait(semaphore);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static inline void semaphore_destroy(semaphore_t semaphore)
|
|
76
|
+
{
|
|
77
|
+
(void)sem_close(semaphore);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static inline int thread_create(thread_t *thread,
|
|
81
|
+
void *(*thread_entry)(void *arg), void *arg)
|
|
82
|
+
{
|
|
83
|
+
return pthread_create(thread, NULL, thread_entry, arg) == 0 ? 0 : -1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static inline void thread_join(thread_t thread)
|
|
87
|
+
{
|
|
88
|
+
(void)pthread_join(thread, NULL);
|
|
89
|
+
}
|
|
90
|
+
#elif defined(PLATFORM_WINDOWS)
|
|
91
|
+
#define THREAD_RETURN_VALUE 0
|
|
92
|
+
typedef HANDLE semaphore_t;
|
|
93
|
+
typedef HANDLE thread_t;
|
|
94
|
+
|
|
95
|
+
#if defined(__CYGWIN__)
|
|
96
|
+
typedef DWORD thread_return_t;
|
|
97
|
+
#else
|
|
98
|
+
#include <process.h>
|
|
99
|
+
typedef unsigned thread_return_t;
|
|
100
|
+
#endif
|
|
101
|
+
|
|
102
|
+
static inline semaphore_t semaphore_create(void)
|
|
103
|
+
{
|
|
104
|
+
return CreateSemaphore(NULL, 0, 1, NULL);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static inline void semaphore_give(semaphore_t semaphore)
|
|
108
|
+
{
|
|
109
|
+
(void)ReleaseSemaphore(semaphore, 1, NULL);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static inline void semaphore_take(semaphore_t semaphore)
|
|
113
|
+
{
|
|
114
|
+
(void)WaitForSingleObject(semaphore, INFINITE);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static inline void semaphore_destroy(semaphore_t semaphore)
|
|
118
|
+
{
|
|
119
|
+
(void)CloseHandle(semaphore);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static inline int thread_create(thread_t *thread,
|
|
123
|
+
thread_return_t (__stdcall *thread_entry)(void *arg), void *arg)
|
|
124
|
+
{
|
|
125
|
+
#if defined(__CYGWIN__)
|
|
126
|
+
*thread = CreateThread(NULL, 0, thread_entry, arg, 0, NULL);
|
|
127
|
+
#else
|
|
128
|
+
*thread = (HANDLE)_beginthreadex(NULL, 0, thread_entry, arg, 0, NULL);
|
|
129
|
+
#endif
|
|
130
|
+
return *thread != NULL ? 0 : -1;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static inline void thread_join(thread_t thread)
|
|
134
|
+
{
|
|
135
|
+
(void)WaitForSingleObject(thread, INFINITE);
|
|
136
|
+
(void)CloseHandle(thread);
|
|
137
|
+
}
|
|
138
|
+
#endif
|
|
139
|
+
#endif
|
|
140
|
+
|
|
32
141
|
#define EP_INTR (1 | LIBUSB_ENDPOINT_IN)
|
|
33
142
|
#define EP_DATA (2 | LIBUSB_ENDPOINT_IN)
|
|
34
143
|
#define CTRL_IN (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN)
|
|
@@ -57,25 +166,69 @@ enum {
|
|
|
57
166
|
};
|
|
58
167
|
|
|
59
168
|
static int state = 0;
|
|
60
|
-
static
|
|
169
|
+
static libusb_device_handle *devh = NULL;
|
|
61
170
|
static unsigned char imgbuf[0x1b340];
|
|
62
171
|
static unsigned char irqbuf[INTR_LENGTH];
|
|
63
172
|
static struct libusb_transfer *img_transfer = NULL;
|
|
64
173
|
static struct libusb_transfer *irq_transfer = NULL;
|
|
65
174
|
static int img_idx = 0;
|
|
66
|
-
static
|
|
175
|
+
static volatile sig_atomic_t do_exit = 0;
|
|
176
|
+
|
|
177
|
+
#if defined(DPFP_THREADED)
|
|
178
|
+
static semaphore_t exit_semaphore;
|
|
179
|
+
static thread_t poll_thread;
|
|
180
|
+
#endif
|
|
181
|
+
|
|
182
|
+
static void request_exit(sig_atomic_t code)
|
|
183
|
+
{
|
|
184
|
+
do_exit = code;
|
|
185
|
+
#if defined(DPFP_THREADED)
|
|
186
|
+
semaphore_give(exit_semaphore);
|
|
187
|
+
#endif
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
#if defined(DPFP_THREADED)
|
|
191
|
+
#if defined(PLATFORM_POSIX)
|
|
192
|
+
static void *poll_thread_main(void *arg)
|
|
193
|
+
#elif defined(PLATFORM_WINDOWS)
|
|
194
|
+
static thread_return_t __stdcall poll_thread_main(void *arg)
|
|
195
|
+
#endif
|
|
196
|
+
{
|
|
197
|
+
(void)arg;
|
|
198
|
+
|
|
199
|
+
printf("poll thread running\n");
|
|
200
|
+
|
|
201
|
+
while (!do_exit) {
|
|
202
|
+
struct timeval tv = { 1, 0 };
|
|
203
|
+
int r;
|
|
204
|
+
|
|
205
|
+
r = libusb_handle_events_timeout(NULL, &tv);
|
|
206
|
+
if (r < 0) {
|
|
207
|
+
request_exit(2);
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
printf("poll thread shutting down\n");
|
|
213
|
+
return THREAD_RETURN_VALUE;
|
|
214
|
+
}
|
|
215
|
+
#endif
|
|
67
216
|
|
|
68
217
|
static int find_dpfp_device(void)
|
|
69
218
|
{
|
|
70
219
|
devh = libusb_open_device_with_vid_pid(NULL, 0x05ba, 0x000a);
|
|
71
|
-
|
|
220
|
+
if (!devh) {
|
|
221
|
+
errno = ENODEV;
|
|
222
|
+
return -1;
|
|
223
|
+
}
|
|
224
|
+
return 0;
|
|
72
225
|
}
|
|
73
226
|
|
|
74
227
|
static int print_f0_data(void)
|
|
75
228
|
{
|
|
76
229
|
unsigned char data[0x10];
|
|
230
|
+
size_t i;
|
|
77
231
|
int r;
|
|
78
|
-
unsigned int i;
|
|
79
232
|
|
|
80
233
|
r = libusb_control_transfer(devh, CTRL_IN, USB_RQ, 0xf0, 0, data,
|
|
81
234
|
sizeof(data), 0);
|
|
@@ -83,14 +236,14 @@ static int print_f0_data(void)
|
|
|
83
236
|
fprintf(stderr, "F0 error %d\n", r);
|
|
84
237
|
return r;
|
|
85
238
|
}
|
|
86
|
-
if (
|
|
239
|
+
if (r < (int)sizeof(data)) {
|
|
87
240
|
fprintf(stderr, "short read (%d)\n", r);
|
|
88
241
|
return -1;
|
|
89
242
|
}
|
|
90
243
|
|
|
91
244
|
printf("F0 data:");
|
|
92
245
|
for (i = 0; i < sizeof(data); i++)
|
|
93
|
-
printf("%02x
|
|
246
|
+
printf(" %02x", data[i]);
|
|
94
247
|
printf("\n");
|
|
95
248
|
return 0;
|
|
96
249
|
}
|
|
@@ -104,7 +257,7 @@ static int get_hwstat(unsigned char *status)
|
|
|
104
257
|
fprintf(stderr, "read hwstat error %d\n", r);
|
|
105
258
|
return r;
|
|
106
259
|
}
|
|
107
|
-
if (
|
|
260
|
+
if (r < 1) {
|
|
108
261
|
fprintf(stderr, "short read (%d)\n", r);
|
|
109
262
|
return -1;
|
|
110
263
|
}
|
|
@@ -123,8 +276,8 @@ static int set_hwstat(unsigned char data)
|
|
|
123
276
|
fprintf(stderr, "set hwstat error %d\n", r);
|
|
124
277
|
return r;
|
|
125
278
|
}
|
|
126
|
-
if (
|
|
127
|
-
fprintf(stderr, "short write (%d)", r);
|
|
279
|
+
if (r < 1) {
|
|
280
|
+
fprintf(stderr, "short write (%d)\n", r);
|
|
128
281
|
return -1;
|
|
129
282
|
}
|
|
130
283
|
|
|
@@ -134,15 +287,15 @@ static int set_hwstat(unsigned char data)
|
|
|
134
287
|
static int set_mode(unsigned char data)
|
|
135
288
|
{
|
|
136
289
|
int r;
|
|
137
|
-
printf("set mode %02x\n", data);
|
|
138
290
|
|
|
291
|
+
printf("set mode %02x\n", data);
|
|
139
292
|
r = libusb_control_transfer(devh, CTRL_OUT, USB_RQ, 0x4e, 0, &data, 1, 0);
|
|
140
293
|
if (r < 0) {
|
|
141
294
|
fprintf(stderr, "set mode error %d\n", r);
|
|
142
295
|
return r;
|
|
143
296
|
}
|
|
144
|
-
if (
|
|
145
|
-
fprintf(stderr, "short write (%d)", r);
|
|
297
|
+
if (r < 1) {
|
|
298
|
+
fprintf(stderr, "short write (%d)\n", r);
|
|
146
299
|
return -1;
|
|
147
300
|
}
|
|
148
301
|
|
|
@@ -153,27 +306,30 @@ static void LIBUSB_CALL cb_mode_changed(struct libusb_transfer *transfer)
|
|
|
153
306
|
{
|
|
154
307
|
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
|
155
308
|
fprintf(stderr, "mode change transfer not completed!\n");
|
|
156
|
-
|
|
309
|
+
request_exit(2);
|
|
157
310
|
}
|
|
158
311
|
|
|
159
312
|
printf("async cb_mode_changed length=%d actual_length=%d\n",
|
|
160
313
|
transfer->length, transfer->actual_length);
|
|
161
314
|
if (next_state() < 0)
|
|
162
|
-
|
|
315
|
+
request_exit(2);
|
|
163
316
|
}
|
|
164
317
|
|
|
165
318
|
static int set_mode_async(unsigned char data)
|
|
166
319
|
{
|
|
167
|
-
unsigned char *buf =
|
|
320
|
+
unsigned char *buf = malloc(LIBUSB_CONTROL_SETUP_SIZE + 1);
|
|
168
321
|
struct libusb_transfer *transfer;
|
|
169
322
|
|
|
170
|
-
if (!buf)
|
|
171
|
-
|
|
323
|
+
if (!buf) {
|
|
324
|
+
errno = ENOMEM;
|
|
325
|
+
return -1;
|
|
326
|
+
}
|
|
172
327
|
|
|
173
328
|
transfer = libusb_alloc_transfer(0);
|
|
174
329
|
if (!transfer) {
|
|
175
330
|
free(buf);
|
|
176
|
-
|
|
331
|
+
errno = ENOMEM;
|
|
332
|
+
return -1;
|
|
177
333
|
}
|
|
178
334
|
|
|
179
335
|
printf("async set mode %02x\n", data);
|
|
@@ -203,7 +359,7 @@ static int do_sync_intr(unsigned char *data)
|
|
|
203
359
|
return -1;
|
|
204
360
|
}
|
|
205
361
|
|
|
206
|
-
printf("recv interrupt %04x\n", *((uint16_t *)
|
|
362
|
+
printf("recv interrupt %04x\n", *((uint16_t *)data));
|
|
207
363
|
return 0;
|
|
208
364
|
}
|
|
209
365
|
|
|
@@ -223,17 +379,17 @@ static int sync_intr(unsigned char type)
|
|
|
223
379
|
|
|
224
380
|
static int save_to_file(unsigned char *data)
|
|
225
381
|
{
|
|
226
|
-
FILE *
|
|
382
|
+
FILE *f;
|
|
227
383
|
char filename[64];
|
|
228
384
|
|
|
229
385
|
snprintf(filename, sizeof(filename), "finger%d.pgm", img_idx++);
|
|
230
|
-
|
|
231
|
-
if (!
|
|
386
|
+
f = fopen(filename, "w");
|
|
387
|
+
if (!f)
|
|
232
388
|
return -1;
|
|
233
389
|
|
|
234
|
-
fputs("P5 384 289 255 ",
|
|
235
|
-
(void)
|
|
236
|
-
fclose(
|
|
390
|
+
fputs("P5 384 289 255 ", f);
|
|
391
|
+
(void)fwrite(data + 64, 1, 384*289, f);
|
|
392
|
+
fclose(f);
|
|
237
393
|
printf("saved image to %s\n", filename);
|
|
238
394
|
return 0;
|
|
239
395
|
}
|
|
@@ -241,6 +397,7 @@ static int save_to_file(unsigned char *data)
|
|
|
241
397
|
static int next_state(void)
|
|
242
398
|
{
|
|
243
399
|
int r = 0;
|
|
400
|
+
|
|
244
401
|
printf("old state: %d\n", state);
|
|
245
402
|
switch (state) {
|
|
246
403
|
case STATE_AWAIT_IRQ_FINGER_REMOVED:
|
|
@@ -282,57 +439,60 @@ static void LIBUSB_CALL cb_irq(struct libusb_transfer *transfer)
|
|
|
282
439
|
|
|
283
440
|
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
|
284
441
|
fprintf(stderr, "irq transfer status %d?\n", transfer->status);
|
|
285
|
-
|
|
286
|
-
libusb_free_transfer(transfer);
|
|
287
|
-
irq_transfer = NULL;
|
|
288
|
-
return;
|
|
442
|
+
goto err_free_transfer;
|
|
289
443
|
}
|
|
290
444
|
|
|
291
445
|
printf("IRQ callback %02x\n", irqtype);
|
|
292
446
|
switch (state) {
|
|
293
447
|
case STATE_AWAIT_IRQ_FINGER_DETECTED:
|
|
294
448
|
if (irqtype == 0x01) {
|
|
295
|
-
if (next_state() < 0)
|
|
296
|
-
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
449
|
+
if (next_state() < 0)
|
|
450
|
+
goto err_free_transfer;
|
|
299
451
|
} else {
|
|
300
452
|
printf("finger-on-sensor detected in wrong state!\n");
|
|
301
453
|
}
|
|
302
454
|
break;
|
|
303
455
|
case STATE_AWAIT_IRQ_FINGER_REMOVED:
|
|
304
456
|
if (irqtype == 0x02) {
|
|
305
|
-
if (next_state() < 0)
|
|
306
|
-
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
457
|
+
if (next_state() < 0)
|
|
458
|
+
goto err_free_transfer;
|
|
309
459
|
} else {
|
|
310
460
|
printf("finger-on-sensor detected in wrong state!\n");
|
|
311
461
|
}
|
|
312
462
|
break;
|
|
313
463
|
}
|
|
314
464
|
if (libusb_submit_transfer(irq_transfer) < 0)
|
|
315
|
-
|
|
465
|
+
goto err_free_transfer;
|
|
466
|
+
|
|
467
|
+
return;
|
|
468
|
+
|
|
469
|
+
err_free_transfer:
|
|
470
|
+
libusb_free_transfer(transfer);
|
|
471
|
+
irq_transfer = NULL;
|
|
472
|
+
request_exit(2);
|
|
316
473
|
}
|
|
317
474
|
|
|
318
475
|
static void LIBUSB_CALL cb_img(struct libusb_transfer *transfer)
|
|
319
476
|
{
|
|
320
477
|
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
|
321
478
|
fprintf(stderr, "img transfer status %d?\n", transfer->status);
|
|
322
|
-
|
|
323
|
-
libusb_free_transfer(transfer);
|
|
324
|
-
img_transfer = NULL;
|
|
325
|
-
return;
|
|
479
|
+
goto err_free_transfer;
|
|
326
480
|
}
|
|
327
481
|
|
|
328
482
|
printf("Image callback\n");
|
|
329
483
|
save_to_file(imgbuf);
|
|
330
|
-
if (next_state() < 0)
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
484
|
+
if (next_state() < 0)
|
|
485
|
+
goto err_free_transfer;
|
|
486
|
+
|
|
334
487
|
if (libusb_submit_transfer(img_transfer) < 0)
|
|
335
|
-
|
|
488
|
+
goto err_free_transfer;
|
|
489
|
+
|
|
490
|
+
return;
|
|
491
|
+
|
|
492
|
+
err_free_transfer:
|
|
493
|
+
libusb_free_transfer(transfer);
|
|
494
|
+
img_transfer = NULL;
|
|
495
|
+
request_exit(2);
|
|
336
496
|
}
|
|
337
497
|
|
|
338
498
|
static int init_capture(void)
|
|
@@ -394,12 +554,16 @@ static int do_init(void)
|
|
|
394
554
|
static int alloc_transfers(void)
|
|
395
555
|
{
|
|
396
556
|
img_transfer = libusb_alloc_transfer(0);
|
|
397
|
-
if (!img_transfer)
|
|
398
|
-
|
|
557
|
+
if (!img_transfer) {
|
|
558
|
+
errno = ENOMEM;
|
|
559
|
+
return -1;
|
|
560
|
+
}
|
|
399
561
|
|
|
400
562
|
irq_transfer = libusb_alloc_transfer(0);
|
|
401
|
-
if (!irq_transfer)
|
|
402
|
-
|
|
563
|
+
if (!irq_transfer) {
|
|
564
|
+
errno = ENOMEM;
|
|
565
|
+
return -1;
|
|
566
|
+
}
|
|
403
567
|
|
|
404
568
|
libusb_fill_bulk_transfer(img_transfer, devh, EP_DATA, imgbuf,
|
|
405
569
|
sizeof(imgbuf), cb_img, NULL, 0);
|
|
@@ -413,17 +577,33 @@ static void sighandler(int signum)
|
|
|
413
577
|
{
|
|
414
578
|
(void)signum;
|
|
415
579
|
|
|
416
|
-
|
|
580
|
+
request_exit(1);
|
|
417
581
|
}
|
|
418
582
|
|
|
419
|
-
|
|
583
|
+
static void setup_signals(void)
|
|
420
584
|
{
|
|
585
|
+
#if defined(PLATFORM_POSIX)
|
|
421
586
|
struct sigaction sigact;
|
|
587
|
+
|
|
588
|
+
sigact.sa_handler = sighandler;
|
|
589
|
+
sigemptyset(&sigact.sa_mask);
|
|
590
|
+
sigact.sa_flags = 0;
|
|
591
|
+
(void)sigaction(SIGINT, &sigact, NULL);
|
|
592
|
+
(void)sigaction(SIGTERM, &sigact, NULL);
|
|
593
|
+
(void)sigaction(SIGQUIT, &sigact, NULL);
|
|
594
|
+
#else
|
|
595
|
+
(void)signal(SIGINT, sighandler);
|
|
596
|
+
(void)signal(SIGTERM, sighandler);
|
|
597
|
+
#endif
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
int main(void)
|
|
601
|
+
{
|
|
422
602
|
int r;
|
|
423
603
|
|
|
424
604
|
r = libusb_init(NULL);
|
|
425
605
|
if (r < 0) {
|
|
426
|
-
fprintf(stderr, "failed to initialise libusb\n");
|
|
606
|
+
fprintf(stderr, "failed to initialise libusb %d - %s\n", r, libusb_strerror(r));
|
|
427
607
|
exit(1);
|
|
428
608
|
}
|
|
429
609
|
|
|
@@ -435,7 +615,7 @@ int main(void)
|
|
|
435
615
|
|
|
436
616
|
r = libusb_claim_interface(devh, 0);
|
|
437
617
|
if (r < 0) {
|
|
438
|
-
fprintf(stderr, "
|
|
618
|
+
fprintf(stderr, "claim interface error %d - %s\n", r, libusb_strerror(r));
|
|
439
619
|
goto out;
|
|
440
620
|
}
|
|
441
621
|
printf("claimed interface\n");
|
|
@@ -449,45 +629,66 @@ int main(void)
|
|
|
449
629
|
goto out_deinit;
|
|
450
630
|
|
|
451
631
|
/* async from here onwards */
|
|
632
|
+
setup_signals();
|
|
452
633
|
|
|
453
634
|
r = alloc_transfers();
|
|
454
635
|
if (r < 0)
|
|
455
636
|
goto out_deinit;
|
|
456
637
|
|
|
638
|
+
#if defined(DPFP_THREADED)
|
|
639
|
+
exit_semaphore = semaphore_create();
|
|
640
|
+
if (!exit_semaphore) {
|
|
641
|
+
fprintf(stderr, "failed to initialise semaphore\n");
|
|
642
|
+
goto out_deinit;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
r = thread_create(&poll_thread, poll_thread_main, NULL);
|
|
646
|
+
if (r) {
|
|
647
|
+
semaphore_destroy(exit_semaphore);
|
|
648
|
+
goto out_deinit;
|
|
649
|
+
}
|
|
650
|
+
|
|
457
651
|
r = init_capture();
|
|
458
652
|
if (r < 0)
|
|
459
|
-
|
|
653
|
+
request_exit(2);
|
|
460
654
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
655
|
+
while (!do_exit)
|
|
656
|
+
semaphore_take(exit_semaphore);
|
|
657
|
+
#else
|
|
658
|
+
r = init_capture();
|
|
659
|
+
if (r < 0)
|
|
660
|
+
goto out_deinit;
|
|
467
661
|
|
|
468
662
|
while (!do_exit) {
|
|
469
663
|
r = libusb_handle_events(NULL);
|
|
470
664
|
if (r < 0)
|
|
471
|
-
|
|
665
|
+
request_exit(2);
|
|
472
666
|
}
|
|
667
|
+
#endif
|
|
473
668
|
|
|
474
669
|
printf("shutting down...\n");
|
|
475
670
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
}
|
|
671
|
+
#if defined(DPFP_THREADED)
|
|
672
|
+
thread_join(poll_thread);
|
|
673
|
+
semaphore_destroy(exit_semaphore);
|
|
674
|
+
#endif
|
|
481
675
|
|
|
482
676
|
if (img_transfer) {
|
|
483
677
|
r = libusb_cancel_transfer(img_transfer);
|
|
484
678
|
if (r < 0)
|
|
485
|
-
|
|
679
|
+
fprintf(stderr, "failed to cancel transfer %d - %s\n", r, libusb_strerror(r));
|
|
486
680
|
}
|
|
487
681
|
|
|
488
|
-
|
|
682
|
+
if (irq_transfer) {
|
|
683
|
+
r = libusb_cancel_transfer(irq_transfer);
|
|
684
|
+
if (r < 0)
|
|
685
|
+
fprintf(stderr, "failed to cancel transfer %d - %s\n", r, libusb_strerror(r));
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
while (img_transfer || irq_transfer) {
|
|
489
689
|
if (libusb_handle_events(NULL) < 0)
|
|
490
690
|
break;
|
|
691
|
+
}
|
|
491
692
|
|
|
492
693
|
if (do_exit == 1)
|
|
493
694
|
r = 0;
|
|
@@ -495,8 +696,10 @@ int main(void)
|
|
|
495
696
|
r = 1;
|
|
496
697
|
|
|
497
698
|
out_deinit:
|
|
498
|
-
|
|
499
|
-
|
|
699
|
+
if (img_transfer)
|
|
700
|
+
libusb_free_transfer(img_transfer);
|
|
701
|
+
if (irq_transfer)
|
|
702
|
+
libusb_free_transfer(irq_transfer);
|
|
500
703
|
set_mode(0);
|
|
501
704
|
set_hwstat(0x80);
|
|
502
705
|
out_release:
|
package/libusb/examples/ezusb.c
CHANGED
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
* along with this program; if not, write to the Free Software
|
|
21
21
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
22
22
|
*/
|
|
23
|
+
|
|
24
|
+
#include <config.h>
|
|
25
|
+
|
|
23
26
|
#include <stdio.h>
|
|
24
27
|
#include <errno.h>
|
|
25
28
|
#include <stdlib.h>
|
|
@@ -29,9 +32,6 @@
|
|
|
29
32
|
#include "libusb.h"
|
|
30
33
|
#include "ezusb.h"
|
|
31
34
|
|
|
32
|
-
extern void logerror(const char *format, ...)
|
|
33
|
-
__attribute__ ((format(printf, 1, 2)));
|
|
34
|
-
|
|
35
35
|
/*
|
|
36
36
|
* This file contains functions for uploading firmware into Cypress
|
|
37
37
|
* EZ-USB microcontrollers. These chips use control endpoint 0 and vendor
|
|
@@ -139,7 +139,11 @@ static int ezusb_write(libusb_device_handle *device, const char *label,
|
|
|
139
139
|
else
|
|
140
140
|
logerror("%s ==> %d\n", label, status);
|
|
141
141
|
}
|
|
142
|
-
|
|
142
|
+
if (status < 0) {
|
|
143
|
+
errno = EIO;
|
|
144
|
+
return -1;
|
|
145
|
+
}
|
|
146
|
+
return 0;
|
|
143
147
|
}
|
|
144
148
|
|
|
145
149
|
/*
|
|
@@ -162,7 +166,11 @@ static int ezusb_read(libusb_device_handle *device, const char *label,
|
|
|
162
166
|
else
|
|
163
167
|
logerror("%s ==> %d\n", label, status);
|
|
164
168
|
}
|
|
165
|
-
|
|
169
|
+
if (status < 0) {
|
|
170
|
+
errno = EIO;
|
|
171
|
+
return -1;
|
|
172
|
+
}
|
|
173
|
+
return 0;
|
|
166
174
|
}
|
|
167
175
|
|
|
168
176
|
/*
|
|
@@ -195,7 +203,7 @@ static bool ezusb_cpucs(libusb_device_handle *device, uint32_t addr, bool doRun)
|
|
|
195
203
|
}
|
|
196
204
|
|
|
197
205
|
/*
|
|
198
|
-
* Send an FX3
|
|
206
|
+
* Send an FX3 jump to address command
|
|
199
207
|
* Returns false on error.
|
|
200
208
|
*/
|
|
201
209
|
static bool ezusb_fx3_jump(libusb_device_handle *device, uint32_t addr)
|
|
@@ -514,7 +522,8 @@ static int ram_poke(void *context, uint32_t addr, bool external,
|
|
|
514
522
|
if (external) {
|
|
515
523
|
logerror("can't write %u bytes external memory at 0x%08x\n",
|
|
516
524
|
(unsigned)len, addr);
|
|
517
|
-
|
|
525
|
+
errno = EINVAL;
|
|
526
|
+
return -1;
|
|
518
527
|
}
|
|
519
528
|
break;
|
|
520
529
|
case skip_internal: /* CPU must be running */
|
|
@@ -538,7 +547,8 @@ static int ram_poke(void *context, uint32_t addr, bool external,
|
|
|
538
547
|
case _undef:
|
|
539
548
|
default:
|
|
540
549
|
logerror("bug\n");
|
|
541
|
-
|
|
550
|
+
errno = EDOM;
|
|
551
|
+
return -1;
|
|
542
552
|
}
|
|
543
553
|
|
|
544
554
|
ctx->total += len;
|