usb 2.17.0 → 3.0.0-alpha.2

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.
Files changed (207) hide show
  1. package/LICENSE +18 -4
  2. package/README.md +25 -516
  3. package/dist/index.d.ts +67 -13
  4. package/dist/index.js +333 -64
  5. package/index.d.ts +89 -0
  6. package/index.js +583 -0
  7. package/package.json +53 -33
  8. package/CHANGELOG.md +0 -294
  9. package/binding.gyp +0 -128
  10. package/dist/index.js.map +0 -1
  11. package/dist/usb/bindings.d.ts +0 -266
  12. package/dist/usb/bindings.js +0 -10
  13. package/dist/usb/bindings.js.map +0 -1
  14. package/dist/usb/capability.d.ts +0 -13
  15. package/dist/usb/capability.js +0 -17
  16. package/dist/usb/capability.js.map +0 -1
  17. package/dist/usb/descriptors.d.ts +0 -128
  18. package/dist/usb/descriptors.js +0 -3
  19. package/dist/usb/descriptors.js.map +0 -1
  20. package/dist/usb/device.d.ts +0 -100
  21. package/dist/usb/device.js +0 -297
  22. package/dist/usb/device.js.map +0 -1
  23. package/dist/usb/endpoint.d.ts +0 -94
  24. package/dist/usb/endpoint.js +0 -219
  25. package/dist/usb/endpoint.js.map +0 -1
  26. package/dist/usb/index.d.ts +0 -31
  27. package/dist/usb/index.js +0 -116
  28. package/dist/usb/index.js.map +0 -1
  29. package/dist/usb/interface.d.ts +0 -80
  30. package/dist/usb/interface.js +0 -133
  31. package/dist/usb/interface.js.map +0 -1
  32. package/dist/webusb/index.d.ts +0 -64
  33. package/dist/webusb/index.js +0 -295
  34. package/dist/webusb/index.js.map +0 -1
  35. package/dist/webusb/webusb-device.d.ts +0 -54
  36. package/dist/webusb/webusb-device.js +0 -434
  37. package/dist/webusb/webusb-device.js.map +0 -1
  38. package/libusb/.clang-tidy +0 -34
  39. package/libusb/.codespellrc +0 -3
  40. package/libusb/.private/README.txt +0 -5
  41. package/libusb/.private/appveyor_build.sh +0 -26
  42. package/libusb/.private/bm.sh +0 -54
  43. package/libusb/.private/ci-build.sh +0 -92
  44. package/libusb/.private/ci-container-build.sh +0 -67
  45. package/libusb/.private/post-rewrite.sh +0 -32
  46. package/libusb/.private/pre-commit.sh +0 -52
  47. package/libusb/.private/wbs.txt +0 -43
  48. package/libusb/.travis.yml +0 -58
  49. package/libusb/AUTHORS +0 -231
  50. package/libusb/COPYING +0 -504
  51. package/libusb/ChangeLog +0 -365
  52. package/libusb/HACKING +0 -25
  53. package/libusb/INSTALL_WIN.txt +0 -52
  54. package/libusb/KEYS +0 -123
  55. package/libusb/Makefile.am +0 -50
  56. package/libusb/NEWS +0 -2
  57. package/libusb/PORTING +0 -94
  58. package/libusb/README +0 -29
  59. package/libusb/README.git +0 -41
  60. package/libusb/TODO +0 -2
  61. package/libusb/Xcode/common.xcconfig +0 -92
  62. package/libusb/Xcode/config.h +0 -31
  63. package/libusb/Xcode/debug.xcconfig +0 -32
  64. package/libusb/Xcode/libusb.xcconfig +0 -21
  65. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +0 -1391
  66. package/libusb/Xcode/libusb_debug.xcconfig +0 -21
  67. package/libusb/Xcode/libusb_release.xcconfig +0 -21
  68. package/libusb/Xcode/release.xcconfig +0 -30
  69. package/libusb/android/README +0 -152
  70. package/libusb/android/config.h +0 -55
  71. package/libusb/android/examples/unrooted_android.c +0 -301
  72. package/libusb/android/examples/unrooted_android.h +0 -36
  73. package/libusb/android/jni/Android.mk +0 -23
  74. package/libusb/android/jni/Application.mk +0 -40
  75. package/libusb/android/jni/examples.mk +0 -168
  76. package/libusb/android/jni/libusb.mk +0 -60
  77. package/libusb/android/jni/tests.mk +0 -45
  78. package/libusb/appveyor.yml +0 -108
  79. package/libusb/autogen.sh +0 -10
  80. package/libusb/bootstrap.sh +0 -10
  81. package/libusb/configure.ac +0 -450
  82. package/libusb/doc/Makefile.in +0 -22
  83. package/libusb/doc/doxygen.cfg.in +0 -2571
  84. package/libusb/doc/libusb.png +0 -0
  85. package/libusb/examples/Makefile.am +0 -12
  86. package/libusb/examples/dpfp.c +0 -711
  87. package/libusb/examples/ezusb.c +0 -846
  88. package/libusb/examples/ezusb.h +0 -109
  89. package/libusb/examples/fxload.c +0 -310
  90. package/libusb/examples/hotplugtest.c +0 -147
  91. package/libusb/examples/listdevs.c +0 -73
  92. package/libusb/examples/sam3u_benchmark.c +0 -228
  93. package/libusb/examples/testlibusb.c +0 -312
  94. package/libusb/examples/xusb.c +0 -1254
  95. package/libusb/libusb/Makefile.am +0 -98
  96. package/libusb/libusb/Makefile.am.extra +0 -26
  97. package/libusb/libusb/core.c +0 -2925
  98. package/libusb/libusb/descriptor.c +0 -1558
  99. package/libusb/libusb/hotplug.c +0 -489
  100. package/libusb/libusb/io.c +0 -2865
  101. package/libusb/libusb/libusb-1.0.def +0 -199
  102. package/libusb/libusb/libusb-1.0.rc +0 -53
  103. package/libusb/libusb/libusb.h +0 -2421
  104. package/libusb/libusb/libusbi.h +0 -1535
  105. package/libusb/libusb/os/darwin_usb.c +0 -2977
  106. package/libusb/libusb/os/darwin_usb.h +0 -156
  107. package/libusb/libusb/os/emscripten_webusb.cpp +0 -875
  108. package/libusb/libusb/os/events_posix.c +0 -340
  109. package/libusb/libusb/os/events_posix.h +0 -62
  110. package/libusb/libusb/os/events_windows.c +0 -214
  111. package/libusb/libusb/os/events_windows.h +0 -46
  112. package/libusb/libusb/os/haiku_pollfs.cpp +0 -372
  113. package/libusb/libusb/os/haiku_usb.h +0 -113
  114. package/libusb/libusb/os/haiku_usb_backend.cpp +0 -532
  115. package/libusb/libusb/os/haiku_usb_raw.cpp +0 -231
  116. package/libusb/libusb/os/haiku_usb_raw.h +0 -188
  117. package/libusb/libusb/os/linux_netlink.c +0 -401
  118. package/libusb/libusb/os/linux_udev.c +0 -321
  119. package/libusb/libusb/os/linux_usbfs.c +0 -2829
  120. package/libusb/libusb/os/linux_usbfs.h +0 -221
  121. package/libusb/libusb/os/netbsd_usb.c +0 -617
  122. package/libusb/libusb/os/null_usb.c +0 -111
  123. package/libusb/libusb/os/openbsd_usb.c +0 -700
  124. package/libusb/libusb/os/sunos_usb.c +0 -1619
  125. package/libusb/libusb/os/sunos_usb.h +0 -79
  126. package/libusb/libusb/os/threads_posix.c +0 -126
  127. package/libusb/libusb/os/threads_posix.h +0 -98
  128. package/libusb/libusb/os/threads_windows.c +0 -40
  129. package/libusb/libusb/os/threads_windows.h +0 -113
  130. package/libusb/libusb/os/windows_common.c +0 -923
  131. package/libusb/libusb/os/windows_common.h +0 -424
  132. package/libusb/libusb/os/windows_usbdk.c +0 -724
  133. package/libusb/libusb/os/windows_usbdk.h +0 -106
  134. package/libusb/libusb/os/windows_winusb.c +0 -4766
  135. package/libusb/libusb/os/windows_winusb.h +0 -787
  136. package/libusb/libusb/strerror.c +0 -223
  137. package/libusb/libusb/sync.c +0 -342
  138. package/libusb/libusb/version.h +0 -18
  139. package/libusb/libusb/version_nano.h +0 -1
  140. package/libusb/libusb-1.0.pc.in +0 -11
  141. package/libusb/msvc/Base.props +0 -60
  142. package/libusb/msvc/Configuration.Application.props +0 -7
  143. package/libusb/msvc/Configuration.Base.props +0 -47
  144. package/libusb/msvc/Configuration.DynamicLibrary.props +0 -21
  145. package/libusb/msvc/Configuration.StaticLibrary.props +0 -7
  146. package/libusb/msvc/ProjectConfigurations.Base.props +0 -69
  147. package/libusb/msvc/build_all.ps1 +0 -17
  148. package/libusb/msvc/config.h +0 -58
  149. package/libusb/msvc/dpfp.vcxproj +0 -33
  150. package/libusb/msvc/dpfp_threaded.vcxproj +0 -38
  151. package/libusb/msvc/fxload.vcxproj +0 -46
  152. package/libusb/msvc/getopt/getopt.c +0 -1060
  153. package/libusb/msvc/getopt/getopt.h +0 -180
  154. package/libusb/msvc/getopt/getopt1.c +0 -188
  155. package/libusb/msvc/getopt.vcxproj +0 -33
  156. package/libusb/msvc/hotplugtest.vcxproj +0 -32
  157. package/libusb/msvc/init_context.vcxproj +0 -35
  158. package/libusb/msvc/libusb.sln +0 -542
  159. package/libusb/msvc/libusb_dll.vcxproj +0 -61
  160. package/libusb/msvc/libusb_static.vcxproj +0 -49
  161. package/libusb/msvc/listdevs.vcxproj +0 -32
  162. package/libusb/msvc/sam3u_benchmark.vcxproj +0 -33
  163. package/libusb/msvc/set_option.vcxproj +0 -35
  164. package/libusb/msvc/stress.vcxproj +0 -35
  165. package/libusb/msvc/stress_mt.vcxproj +0 -33
  166. package/libusb/msvc/testlibusb.vcxproj +0 -32
  167. package/libusb/msvc/xusb.vcxproj +0 -38
  168. package/libusb/tests/Makefile.am +0 -40
  169. package/libusb/tests/init_context.c +0 -153
  170. package/libusb/tests/libusb_testlib.h +0 -76
  171. package/libusb/tests/macos.c +0 -130
  172. package/libusb/tests/set_option.c +0 -253
  173. package/libusb/tests/stress.c +0 -172
  174. package/libusb/tests/stress_mt.c +0 -267
  175. package/libusb/tests/testlib.c +0 -184
  176. package/libusb/tests/umockdev.c +0 -1175
  177. package/libusb/tests/webusb-test-shim/index.js +0 -12
  178. package/libusb/tests/webusb-test-shim/package-lock.json +0 -50
  179. package/libusb/tests/webusb-test-shim/package.json +0 -10
  180. package/libusb.gypi +0 -154
  181. package/libusb_config/config.h +0 -1
  182. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  183. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  184. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  185. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  186. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  187. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  188. package/prebuilds/linux-ia32/node.napi.node +0 -0
  189. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  190. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  191. package/prebuilds/win32-arm64/node.napi.node +0 -0
  192. package/prebuilds/win32-ia32/node.napi.node +0 -0
  193. package/prebuilds/win32-x64/node.napi.node +0 -0
  194. package/src/device.cc +0 -439
  195. package/src/helpers.h +0 -64
  196. package/src/hotplug/hotplug.h +0 -22
  197. package/src/hotplug/libusb.cc +0 -90
  198. package/src/hotplug/windows.cc +0 -168
  199. package/src/node_usb.cc +0 -314
  200. package/src/node_usb.h +0 -131
  201. package/src/thread_name.cc +0 -79
  202. package/src/thread_name.h +0 -11
  203. package/src/transfer.cc +0 -143
  204. package/src/uv_async_queue.h +0 -41
  205. package/test/usb.coffee +0 -250
  206. package/test/webusb.coffee +0 -227
  207. package/test/worker.cjs +0 -13
@@ -1,109 +0,0 @@
1
- #ifndef ezusb_H
2
- #define ezusb_H
3
- /*
4
- * Copyright © 2001 Stephen Williams (steve@icarus.com)
5
- * Copyright © 2002 David Brownell (dbrownell@users.sourceforge.net)
6
- * Copyright © 2013 Federico Manzan (f.manzan@gmail.com)
7
- *
8
- * This source code is free software; you can redistribute it
9
- * and/or modify it in source code form under the terms of the GNU
10
- * General Public License as published by the Free Software
11
- * Foundation; either version 2 of the License, or (at your option)
12
- * any later version.
13
- *
14
- * This program is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- * GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License
20
- * along with this program; if not, write to the Free Software
21
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22
- */
23
-
24
- #include <config.h>
25
-
26
- #include <stdbool.h>
27
-
28
- #define FX_TYPE_UNDEFINED -1
29
- #define FX_TYPE_AN21 0 /* Original AnchorChips parts */
30
- #define FX_TYPE_FX1 1 /* Updated Cypress versions */
31
- #define FX_TYPE_FX2 2 /* USB 2.0 versions */
32
- #define FX_TYPE_FX2LP 3 /* Updated FX2 */
33
- #define FX_TYPE_FX3 4 /* USB 3.0 versions */
34
- #define FX_TYPE_MAX 5
35
- #define FX_TYPE_NAMES { "an21", "fx", "fx2", "fx2lp", "fx3" }
36
-
37
- #define IMG_TYPE_UNDEFINED -1
38
- #define IMG_TYPE_HEX 0 /* Intel HEX */
39
- #define IMG_TYPE_IIC 1 /* Cypress 8051 IIC */
40
- #define IMG_TYPE_BIX 2 /* Cypress 8051 BIX */
41
- #define IMG_TYPE_IMG 3 /* Cypress IMG format */
42
- #define IMG_TYPE_MAX 4
43
- #define IMG_TYPE_NAMES { "Intel HEX", "Cypress 8051 IIC", "Cypress 8051 BIX", "Cypress IMG format" }
44
-
45
- #ifdef __cplusplus
46
- extern "C" {
47
- #endif
48
-
49
- /*
50
- * Automatically identified devices (VID, PID, type, designation).
51
- * TODO: Could use some validation. Also where's the FX2?
52
- */
53
- typedef struct {
54
- uint16_t vid;
55
- uint16_t pid;
56
- int type;
57
- const char* designation;
58
- } fx_known_device;
59
-
60
- #define FX_KNOWN_DEVICES { \
61
- { 0x0547, 0x2122, FX_TYPE_AN21, "Cypress EZ-USB (2122S)" },\
62
- { 0x0547, 0x2125, FX_TYPE_AN21, "Cypress EZ-USB (2121S/2125S)" },\
63
- { 0x0547, 0x2126, FX_TYPE_AN21, "Cypress EZ-USB (2126S)" },\
64
- { 0x0547, 0x2131, FX_TYPE_AN21, "Cypress EZ-USB (2131Q/2131S/2135S)" },\
65
- { 0x0547, 0x2136, FX_TYPE_AN21, "Cypress EZ-USB (2136S)" },\
66
- { 0x0547, 0x2225, FX_TYPE_AN21, "Cypress EZ-USB (2225)" },\
67
- { 0x0547, 0x2226, FX_TYPE_AN21, "Cypress EZ-USB (2226)" },\
68
- { 0x0547, 0x2235, FX_TYPE_AN21, "Cypress EZ-USB (2235)" },\
69
- { 0x0547, 0x2236, FX_TYPE_AN21, "Cypress EZ-USB (2236)" },\
70
- { 0x04b4, 0x6473, FX_TYPE_FX1, "Cypress EZ-USB FX1" },\
71
- { 0x04b4, 0x8613, FX_TYPE_FX2LP, "Cypress EZ-USB FX2LP (68013A/68014A/68015A/68016A)" }, \
72
- { 0x04b4, 0x00f3, FX_TYPE_FX3, "Cypress FX3" },\
73
- }
74
-
75
- /*
76
- * This function uploads the firmware from the given file into RAM.
77
- * Stage == 0 means this is a single stage load (or the first of
78
- * two stages). Otherwise it's the second of two stages; the
79
- * caller having preloaded the second stage loader.
80
- *
81
- * The target processor is reset at the end of this upload.
82
- */
83
- extern int ezusb_load_ram(libusb_device_handle *device,
84
- const char *path, int fx_type, int img_type, int stage);
85
-
86
- /*
87
- * This function uploads the firmware from the given file into EEPROM.
88
- * This uses the right CPUCS address to terminate the EEPROM load with
89
- * a reset command where FX parts behave differently than FX2 ones.
90
- * The configuration byte is as provided here (zero for an21xx parts)
91
- * and the EEPROM type is set so that the microcontroller will boot
92
- * from it.
93
- *
94
- * The caller must have preloaded a second stage loader that knows
95
- * how to respond to the EEPROM write request.
96
- */
97
- extern int ezusb_load_eeprom(libusb_device_handle *device,
98
- const char *path, int fx_type, int img_type, int config);
99
-
100
- /* Verbosity level (default 1). Can be increased or decreased with options v/q */
101
- extern int verbose;
102
-
103
- extern void logerror(const char *format, ...) PRINTF_FORMAT(1, 2);
104
-
105
- #ifdef __cplusplus
106
- }
107
- #endif
108
-
109
- #endif
@@ -1,310 +0,0 @@
1
- /*
2
- * Copyright © 2001 Stephen Williams (steve@icarus.com)
3
- * Copyright © 2001-2002 David Brownell (dbrownell@users.sourceforge.net)
4
- * Copyright © 2008 Roger Williams (rawqux@users.sourceforge.net)
5
- * Copyright © 2012 Pete Batard (pete@akeo.ie)
6
- * Copyright © 2013 Federico Manzan (f.manzan@gmail.com)
7
- *
8
- * This source code is free software; you can redistribute it
9
- * and/or modify it in source code form under the terms of the GNU
10
- * General Public License as published by the Free Software
11
- * Foundation; either version 2 of the License, or (at your option)
12
- * any later version.
13
- *
14
- * This program is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- * GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License
20
- * along with this program; if not, write to the Free Software
21
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22
- */
23
-
24
- #include <config.h>
25
-
26
- #include <stdlib.h>
27
- #include <stdio.h>
28
- #include <string.h>
29
- #include <stdint.h>
30
- #include <stdarg.h>
31
- #include <sys/types.h>
32
- #include <getopt.h>
33
-
34
- #include "libusb.h"
35
- #include "ezusb.h"
36
-
37
- #if !defined(_WIN32) || defined(__CYGWIN__)
38
- #include <syslog.h>
39
- static bool dosyslog = false;
40
- #include <strings.h>
41
- #define libusb_strcasecmp strcasecmp
42
- #else
43
- #define libusb_strcasecmp _stricmp
44
- #endif
45
-
46
- #ifndef FXLOAD_VERSION
47
- #define FXLOAD_VERSION (__DATE__ " (libusb)")
48
- #endif
49
-
50
- #ifndef ARRAYSIZE
51
- #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
52
- #endif
53
-
54
- void logerror(const char *format, ...)
55
- {
56
- va_list ap;
57
- va_start(ap, format);
58
-
59
- #if !defined(_WIN32) || defined(__CYGWIN__)
60
- if (dosyslog)
61
- vsyslog(LOG_ERR, format, ap);
62
- else
63
- #endif
64
- vfprintf(stderr, format, ap);
65
- va_end(ap);
66
- }
67
-
68
- static int print_usage(int error_code) {
69
- fprintf(stderr, "\nUsage: fxload [-v] [-V] [-t type] [-d vid:pid] [-p bus,addr] [-s loader] -i firmware\n");
70
- fprintf(stderr, " -i <path> -- Firmware to upload\n");
71
- fprintf(stderr, " -s <path> -- Second stage loader\n");
72
- fprintf(stderr, " -t <type> -- Target type: an21, fx, fx2, fx2lp, fx3\n");
73
- fprintf(stderr, " -d <vid:pid> -- Target device, as an USB VID:PID\n");
74
- fprintf(stderr, " -p <bus,addr> -- Target device, as a libusb bus number and device address path\n");
75
- fprintf(stderr, " -v -- Increase verbosity\n");
76
- fprintf(stderr, " -q -- Decrease verbosity (silent mode)\n");
77
- fprintf(stderr, " -V -- Print program version\n");
78
- return error_code;
79
- }
80
-
81
- #define FIRMWARE 0
82
- #define LOADER 1
83
- int main(int argc, char*argv[])
84
- {
85
- fx_known_device known_device[] = FX_KNOWN_DEVICES;
86
- const char *path[] = { NULL, NULL };
87
- const char *device_id = NULL;
88
- const char *device_path = getenv("DEVICE");
89
- const char *type = NULL;
90
- const char *fx_name[FX_TYPE_MAX] = FX_TYPE_NAMES;
91
- const char *ext, *img_name[] = IMG_TYPE_NAMES;
92
- int fx_type = FX_TYPE_UNDEFINED, img_type[ARRAYSIZE(path)];
93
- int opt, status;
94
- unsigned int i, j;
95
- unsigned vid = 0, pid = 0;
96
- unsigned busnum = 0, devaddr = 0, _busnum, _devaddr;
97
- libusb_device *dev, **devs;
98
- libusb_device_handle *device = NULL;
99
- struct libusb_device_descriptor desc;
100
-
101
- while ((opt = getopt(argc, argv, "qvV?hd:p:i:I:s:S:t:")) != EOF)
102
- switch (opt) {
103
-
104
- case 'd':
105
- device_id = optarg;
106
- if (sscanf(device_id, "%x:%x" , &vid, &pid) != 2 ) {
107
- fputs ("please specify VID & PID as \"vid:pid\" in hexadecimal format\n", stderr);
108
- return -1;
109
- }
110
- break;
111
-
112
- case 'p':
113
- device_path = optarg;
114
- if (sscanf(device_path, "%u,%u", &busnum, &devaddr) != 2 ) {
115
- fputs ("please specify bus number & device number as \"bus,dev\" in decimal format\n", stderr);
116
- return -1;
117
- }
118
- break;
119
-
120
- case 'i':
121
- case 'I':
122
- path[FIRMWARE] = optarg;
123
- break;
124
-
125
- case 's':
126
- case 'S':
127
- path[LOADER] = optarg;
128
- break;
129
-
130
- case 'V':
131
- puts(FXLOAD_VERSION);
132
- return 0;
133
-
134
- case 't':
135
- type = optarg;
136
- break;
137
-
138
- case 'v':
139
- verbose++;
140
- break;
141
-
142
- case 'q':
143
- verbose--;
144
- break;
145
-
146
- case '?':
147
- case 'h':
148
- default:
149
- return print_usage(-1);
150
-
151
- }
152
-
153
- if (path[FIRMWARE] == NULL) {
154
- logerror("no firmware specified!\n");
155
- return print_usage(-1);
156
- }
157
- if ((device_id != NULL) && (device_path != NULL)) {
158
- logerror("only one of -d or -p can be specified\n");
159
- return print_usage(-1);
160
- }
161
-
162
- /* determine the target type */
163
- if (type != NULL) {
164
- for (i=0; i<FX_TYPE_MAX; i++) {
165
- if (strcmp(type, fx_name[i]) == 0) {
166
- fx_type = i;
167
- break;
168
- }
169
- }
170
- if (i >= FX_TYPE_MAX) {
171
- logerror("illegal microcontroller type: %s\n", type);
172
- return print_usage(-1);
173
- }
174
- }
175
-
176
- /* open the device using libusb */
177
- status = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0);
178
- if (status < 0) {
179
- logerror("libusb_init_context() failed: %s\n", libusb_error_name(status));
180
- return -1;
181
- }
182
- libusb_set_option(NULL, LIBUSB_OPTION_LOG_LEVEL, verbose);
183
-
184
- /* try to pick up missing parameters from known devices */
185
- if ((type == NULL) || (device_id == NULL) || (device_path != NULL)) {
186
- if (libusb_get_device_list(NULL, &devs) < 0) {
187
- logerror("libusb_get_device_list() failed: %s\n", libusb_error_name(status));
188
- goto err;
189
- }
190
- for (i=0; (dev=devs[i]) != NULL; i++) {
191
- _busnum = libusb_get_bus_number(dev);
192
- _devaddr = libusb_get_device_address(dev);
193
- if ((type != NULL) && (device_path != NULL)) {
194
- // if both a type and bus,addr were specified, we just need to find our match
195
- if ((libusb_get_bus_number(dev) == busnum) && (libusb_get_device_address(dev) == devaddr))
196
- break;
197
- } else {
198
- status = libusb_get_device_descriptor(dev, &desc);
199
- if (status >= 0) {
200
- if (verbose >= 3) {
201
- logerror("examining %04x:%04x (%d,%d)\n",
202
- desc.idVendor, desc.idProduct, _busnum, _devaddr);
203
- }
204
- for (j=0; j<ARRAYSIZE(known_device); j++) {
205
- if ((desc.idVendor == known_device[j].vid)
206
- && (desc.idProduct == known_device[j].pid)) {
207
- if (// nothing was specified
208
- ((type == NULL) && (device_id == NULL) && (device_path == NULL)) ||
209
- // vid:pid was specified and we have a match
210
- ((type == NULL) && (device_id != NULL) && (vid == desc.idVendor) && (pid == desc.idProduct)) ||
211
- // bus,addr was specified and we have a match
212
- ((type == NULL) && (device_path != NULL) && (busnum == _busnum) && (devaddr == _devaddr)) ||
213
- // type was specified and we have a match
214
- ((type != NULL) && (device_id == NULL) && (device_path == NULL) && (fx_type == known_device[j].type)) ) {
215
- fx_type = known_device[j].type;
216
- vid = desc.idVendor;
217
- pid = desc.idProduct;
218
- busnum = _busnum;
219
- devaddr = _devaddr;
220
- break;
221
- }
222
- }
223
- }
224
- if (j < ARRAYSIZE(known_device)) {
225
- if (verbose)
226
- logerror("found device '%s' [%04x:%04x] (%d,%d)\n",
227
- known_device[j].designation, vid, pid, busnum, devaddr);
228
- break;
229
- }
230
- }
231
- }
232
- }
233
- if (dev == NULL) {
234
- libusb_free_device_list(devs, 1);
235
- libusb_exit(NULL);
236
- logerror("could not find a known device - please specify type and/or vid:pid and/or bus,dev\n");
237
- return print_usage(-1);
238
- }
239
- status = libusb_open(dev, &device);
240
- libusb_free_device_list(devs, 1);
241
- if (status < 0) {
242
- logerror("libusb_open() failed: %s\n", libusb_error_name(status));
243
- goto err;
244
- }
245
- } else if (device_id != NULL) {
246
- device = libusb_open_device_with_vid_pid(NULL, (uint16_t)vid, (uint16_t)pid);
247
- if (device == NULL) {
248
- logerror("libusb_open() failed\n");
249
- goto err;
250
- }
251
- }
252
-
253
- /* We need to claim the first interface */
254
- libusb_set_auto_detach_kernel_driver(device, 1);
255
- status = libusb_claim_interface(device, 0);
256
- if (status != LIBUSB_SUCCESS) {
257
- libusb_close(device);
258
- logerror("libusb_claim_interface failed: %s\n", libusb_error_name(status));
259
- goto err;
260
- }
261
-
262
- if (verbose)
263
- logerror("microcontroller type: %s\n", fx_name[fx_type]);
264
-
265
- for (i=0; i<ARRAYSIZE(path); i++) {
266
- if (path[i] != NULL) {
267
- ext = path[i] + strlen(path[i]) - 4;
268
- if ((libusb_strcasecmp(ext, ".hex") == 0) || (libusb_strcasecmp(ext, ".ihx") == 0))
269
- img_type[i] = IMG_TYPE_HEX;
270
- else if (libusb_strcasecmp(ext, ".iic") == 0)
271
- img_type[i] = IMG_TYPE_IIC;
272
- else if (libusb_strcasecmp(ext, ".bix") == 0)
273
- img_type[i] = IMG_TYPE_BIX;
274
- else if (libusb_strcasecmp(ext, ".img") == 0)
275
- img_type[i] = IMG_TYPE_IMG;
276
- else {
277
- logerror("%s is not a recognized image type\n", path[i]);
278
- goto err;
279
- }
280
- }
281
- if (verbose && path[i] != NULL)
282
- logerror("%s: type %s\n", path[i], img_name[img_type[i]]);
283
- }
284
-
285
- if (path[LOADER] == NULL) {
286
- /* single stage, put into internal memory */
287
- if (verbose > 1)
288
- logerror("single stage: load on-chip memory\n");
289
- status = ezusb_load_ram(device, path[FIRMWARE], fx_type, img_type[FIRMWARE], 0);
290
- } else {
291
- /* two-stage, put loader into internal memory */
292
- if (verbose > 1)
293
- logerror("1st stage: load 2nd stage loader\n");
294
- status = ezusb_load_ram(device, path[LOADER], fx_type, img_type[LOADER], 0);
295
- if (status == 0) {
296
- /* two-stage, put firmware into internal memory */
297
- if (verbose > 1)
298
- logerror("2nd state: load on-chip memory\n");
299
- status = ezusb_load_ram(device, path[FIRMWARE], fx_type, img_type[FIRMWARE], 1);
300
- }
301
- }
302
-
303
- libusb_release_interface(device, 0);
304
- libusb_close(device);
305
- libusb_exit(NULL);
306
- return status;
307
- err:
308
- libusb_exit(NULL);
309
- return -1;
310
- }
@@ -1,147 +0,0 @@
1
- /* -*- Mode: C; indent-tabs-mode:t ; c-basic-offset:8 -*- */
2
- /*
3
- * libusb example program for hotplug API
4
- * Copyright © 2012-2013 Nathan Hjelm <hjelmn@mac.com>
5
- *
6
- * This library is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * This library is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with this library; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
- */
20
-
21
- #include <stdlib.h>
22
- #include <stdio.h>
23
-
24
- #include "libusb.h"
25
-
26
- int done = 0;
27
- libusb_device_handle *handle = NULL;
28
-
29
- static int LIBUSB_CALL hotplug_callback(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data)
30
- {
31
- struct libusb_device_descriptor desc;
32
- int rc;
33
-
34
- (void)ctx;
35
- (void)dev;
36
- (void)event;
37
- (void)user_data;
38
-
39
- rc = libusb_get_device_descriptor(dev, &desc);
40
- if (LIBUSB_SUCCESS == rc) {
41
- printf ("Device attached: %04x:%04x\n", desc.idVendor, desc.idProduct);
42
- } else {
43
- printf ("Device attached\n");
44
- fprintf (stderr, "Error getting device descriptor: %s\n",
45
- libusb_strerror((enum libusb_error)rc));
46
- }
47
-
48
- if (handle) {
49
- libusb_close (handle);
50
- handle = NULL;
51
- }
52
-
53
- rc = libusb_open (dev, &handle);
54
- if (LIBUSB_SUCCESS != rc) {
55
- fprintf (stderr, "No access to device: %s\n",
56
- libusb_strerror((enum libusb_error)rc));
57
- }
58
-
59
- done++;
60
-
61
- return 0;
62
- }
63
-
64
- static int LIBUSB_CALL hotplug_callback_detach(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data)
65
- {
66
- struct libusb_device_descriptor desc;
67
- int rc;
68
-
69
- (void)ctx;
70
- (void)dev;
71
- (void)event;
72
- (void)user_data;
73
-
74
- rc = libusb_get_device_descriptor(dev, &desc);
75
- if (LIBUSB_SUCCESS == rc) {
76
- printf ("Device detached: %04x:%04x\n", desc.idVendor, desc.idProduct);
77
- } else {
78
- printf ("Device detached\n");
79
- fprintf (stderr, "Error getting device descriptor: %s\n",
80
- libusb_strerror((enum libusb_error)rc));
81
- }
82
-
83
- if (handle) {
84
- libusb_close (handle);
85
- handle = NULL;
86
- }
87
-
88
- done++;
89
-
90
- return 0;
91
- }
92
-
93
- int main(int argc, char *argv[])
94
- {
95
- libusb_hotplug_callback_handle hp[2];
96
- int product_id, vendor_id, class_id;
97
- int rc;
98
-
99
- vendor_id = (argc > 1) ? (int)strtol (argv[1], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY;
100
- product_id = (argc > 2) ? (int)strtol (argv[2], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY;
101
- class_id = (argc > 3) ? (int)strtol (argv[3], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY;
102
-
103
- rc = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0);
104
- if (LIBUSB_SUCCESS != rc)
105
- {
106
- printf ("failed to initialise libusb: %s\n",
107
- libusb_strerror((enum libusb_error)rc));
108
- return EXIT_FAILURE;
109
- }
110
-
111
- if (!libusb_has_capability (LIBUSB_CAP_HAS_HOTPLUG)) {
112
- printf ("Hotplug capabilities are not supported on this platform\n");
113
- libusb_exit (NULL);
114
- return EXIT_FAILURE;
115
- }
116
-
117
- rc = libusb_hotplug_register_callback (NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED, 0, vendor_id,
118
- product_id, class_id, hotplug_callback, NULL, &hp[0]);
119
- if (LIBUSB_SUCCESS != rc) {
120
- fprintf (stderr, "Error registering callback 0\n");
121
- libusb_exit (NULL);
122
- return EXIT_FAILURE;
123
- }
124
-
125
- rc = libusb_hotplug_register_callback (NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, 0, vendor_id,
126
- product_id,class_id, hotplug_callback_detach, NULL, &hp[1]);
127
- if (LIBUSB_SUCCESS != rc) {
128
- fprintf (stderr, "Error registering callback 1\n");
129
- libusb_exit (NULL);
130
- return EXIT_FAILURE;
131
- }
132
-
133
- while (done < 2) {
134
- rc = libusb_handle_events (NULL);
135
- if (LIBUSB_SUCCESS != rc)
136
- printf ("libusb_handle_events() failed: %s\n",
137
- libusb_strerror((enum libusb_error)rc));
138
- }
139
-
140
- if (handle) {
141
- libusb_close (handle);
142
- }
143
-
144
- libusb_exit (NULL);
145
-
146
- return EXIT_SUCCESS;
147
- }
@@ -1,73 +0,0 @@
1
- /*
2
- * libusb example program to list devices on the bus
3
- * Copyright © 2007 Daniel Drake <dsd@gentoo.org>
4
- *
5
- * This library is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU Lesser General Public
7
- * License as published by the Free Software Foundation; either
8
- * version 2.1 of the License, or (at your option) any later version.
9
- *
10
- * This library is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- * Lesser General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU Lesser General Public
16
- * License along with this library; if not, write to the Free Software
17
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
- */
19
-
20
- #include <stdio.h>
21
-
22
- #include "libusb.h"
23
-
24
- static void print_devs(libusb_device **devs)
25
- {
26
- libusb_device *dev;
27
- int i = 0, j = 0;
28
- uint8_t path[8];
29
-
30
- while ((dev = devs[i++]) != NULL) {
31
- struct libusb_device_descriptor desc;
32
- int r = libusb_get_device_descriptor(dev, &desc);
33
- if (r < 0) {
34
- fprintf(stderr, "failed to get device descriptor");
35
- return;
36
- }
37
-
38
- printf("%04x:%04x (bus %d, device %d)",
39
- desc.idVendor, desc.idProduct,
40
- libusb_get_bus_number(dev), libusb_get_device_address(dev));
41
-
42
- r = libusb_get_port_numbers(dev, path, sizeof(path));
43
- if (r > 0) {
44
- printf(" path: %d", path[0]);
45
- for (j = 1; j < r; j++)
46
- printf(".%d", path[j]);
47
- }
48
- printf("\n");
49
- }
50
- }
51
-
52
- int main(void)
53
- {
54
- libusb_device **devs;
55
- int r;
56
- ssize_t cnt;
57
-
58
- r = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0);
59
- if (r < 0)
60
- return r;
61
-
62
- cnt = libusb_get_device_list(NULL, &devs);
63
- if (cnt < 0){
64
- libusb_exit(NULL);
65
- return (int) cnt;
66
- }
67
-
68
- print_devs(devs);
69
- libusb_free_device_list(devs, 1);
70
-
71
- libusb_exit(NULL);
72
- return 0;
73
- }