libusb 0.8.0-aarch64-mingw-ucrt

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 (53) hide show
  1. checksums.yaml +7 -0
  2. data/.appveyor.yml +33 -0
  3. data/.github/workflows/ci.yml +185 -0
  4. data/.gitignore +9 -0
  5. data/.travis.yml +26 -0
  6. data/.yardopts +6 -0
  7. data/COPYING +165 -0
  8. data/Gemfile +20 -0
  9. data/History.md +225 -0
  10. data/README.md +184 -0
  11. data/Rakefile +82 -0
  12. data/lib/libusb/bos.rb +501 -0
  13. data/lib/libusb/call.rb +707 -0
  14. data/lib/libusb/compat.rb +376 -0
  15. data/lib/libusb/configuration.rb +154 -0
  16. data/lib/libusb/constants.rb +181 -0
  17. data/lib/libusb/context.rb +577 -0
  18. data/lib/libusb/context_reference.rb +43 -0
  19. data/lib/libusb/dependencies.rb +7 -0
  20. data/lib/libusb/dev_handle.rb +571 -0
  21. data/lib/libusb/device.rb +456 -0
  22. data/lib/libusb/endpoint.rb +195 -0
  23. data/lib/libusb/eventmachine.rb +203 -0
  24. data/lib/libusb/gem_helper.rb +152 -0
  25. data/lib/libusb/interface.rb +60 -0
  26. data/lib/libusb/libusb_recipe.rb +29 -0
  27. data/lib/libusb/setting.rb +132 -0
  28. data/lib/libusb/ss_companion.rb +72 -0
  29. data/lib/libusb/stdio.rb +25 -0
  30. data/lib/libusb/transfer.rb +418 -0
  31. data/lib/libusb/version_gem.rb +19 -0
  32. data/lib/libusb/version_struct.rb +63 -0
  33. data/lib/libusb-1.0.dll +0 -0
  34. data/lib/libusb.rb +146 -0
  35. data/libusb.gemspec +28 -0
  36. data/test/test_libusb.rb +42 -0
  37. data/test/test_libusb_bos.rb +162 -0
  38. data/test/test_libusb_bulk_stream_transfer.rb +61 -0
  39. data/test/test_libusb_compat.rb +78 -0
  40. data/test/test_libusb_compat_mass_storage.rb +81 -0
  41. data/test/test_libusb_context.rb +88 -0
  42. data/test/test_libusb_descriptors.rb +258 -0
  43. data/test/test_libusb_event_machine.rb +118 -0
  44. data/test/test_libusb_event_machine_eintr.rb +81 -0
  45. data/test/test_libusb_gc.rb +52 -0
  46. data/test/test_libusb_hotplug.rb +129 -0
  47. data/test/test_libusb_iso_transfer.rb +56 -0
  48. data/test/test_libusb_mass_storage.rb +268 -0
  49. data/test/test_libusb_mass_storage2.rb +96 -0
  50. data/test/test_libusb_structs.rb +87 -0
  51. data/test/test_libusb_threads.rb +89 -0
  52. data/wireshark-usb-sniffer.png +0 -0
  53. metadata +110 -0
data/README.md ADDED
@@ -0,0 +1,184 @@
1
+ <!-- -*- coding: utf-8 -*- -->
2
+
3
+ [![Build Status](https://travis-ci.com/larskanis/libusb.svg?branch=master)](https://travis-ci.com/larskanis/libusb)
4
+ [![Build status](https://ci.appveyor.com/api/projects/status/mdfnfdwu4mil42o3/branch/master?svg=true)](https://ci.appveyor.com/project/larskanis/libusb/branch/master)
5
+
6
+ Access USB devices from Ruby
7
+ ============================
8
+
9
+ LIBUSB is a Ruby binding that gives Ruby programmers access to arbitrary USB devices.
10
+
11
+ * [libusb](http://libusb.info) is a library that gives full access to devices connected via the USB bus. No special kernel driver is thus necessary for accessing USB devices.
12
+ * This Ruby binding supports the API version 1.0 of [libusb](http://libusb.info). Note that the old "legacy" version 0.1.x of libusb uses a completely different API that is covered by the ruby extension [ruby-usb](http://www.a-k-r.org/ruby-usb/) .
13
+
14
+
15
+ LIBUSB for Ruby is covered by the GNU Lesser General Public License version 3.
16
+
17
+ Features
18
+ --------
19
+
20
+ * Access to descriptors of devices, configurations, interfaces, settings and endpoints
21
+ * Synchronous and asynchronous communication for bulk, control, interrupt and isochronous transfers
22
+ * Support for USB-3.0 descriptors and bulk streams
23
+ * Compatibility layer for [ruby-usb](http://www.a-k-r.org/ruby-usb/) (API based on libusb-0.1). See {::USB} for description.
24
+
25
+ Synopsis
26
+ --------
27
+ ```ruby
28
+ require "libusb"
29
+
30
+ usb = LIBUSB::Context.new
31
+ device = usb.devices(idVendor: 0x04b4, idProduct: 0x8613).first
32
+ device.open_interface(0) do |handle|
33
+ handle.control_transfer(bmRequestType: 0x40, bRequest: 0xa0, wValue: 0xe600, wIndex: 0x0000, dataOut: 1.chr)
34
+ end
35
+ ```
36
+ {LIBUSB::Context#devices} is used to get all or only particular devices.
37
+ After {LIBUSB::Device#open_interface opening and claiming} the {LIBUSB::Device} the resulting {LIBUSB::DevHandle} can be
38
+ used to communicate with the connected USB device
39
+ by {LIBUSB::DevHandle#control_transfer}, {LIBUSB::DevHandle#bulk_transfer},
40
+ {LIBUSB::DevHandle#interrupt_transfer} or by using the {LIBUSB::Transfer} classes.
41
+
42
+ A {LIBUSB::Device} can also be used to retrieve information about it,
43
+ by using the device descriptor attributes.
44
+ A {LIBUSB::Device} could have several configurations. You can then decide of which
45
+ configuration to enable. You can only enable one configuration at a time.
46
+
47
+ Each {LIBUSB::Configuration} has one or more interfaces. These can be seen as functional group
48
+ performing a single feature of the device.
49
+
50
+ Each {LIBUSB::Interface} has at least one {LIBUSB::Setting}. The first setting is always default.
51
+ An alternate setting can be used independent on each interface.
52
+
53
+ Each {LIBUSB::Setting} specifies it's own set of communication endpoints.
54
+ Each {LIBUSB::Endpoint} specifies the type of transfer, direction, polling interval and
55
+ maximum packet size.
56
+
57
+ See [the documentation](http://rubydoc.info/gems/libusb/frames) for a full API description.
58
+
59
+ Prerequisites
60
+ -------------
61
+
62
+ * Linux, MacOS or Windows system with Ruby MRI 2.x/3.x, JRuby or recent version of Rubinius
63
+ * Optionally: [libusb](http://libusb.info) C-library version 1.0.8 or any newer version.
64
+ The system libusb library can be installed like so:
65
+ * Debian or Ubuntu:
66
+
67
+ ```
68
+ $ sudo apt-get install libusb-1.0-0
69
+ ```
70
+ * MacOS: install with homebrew:
71
+
72
+ ```
73
+ $ brew install libusb
74
+ ```
75
+ or macports:
76
+
77
+ ```
78
+ $ port install libusb
79
+ ```
80
+ * Windows: libusb.gem already comes with a precompiled `libusb.dll`, but you need to install a device driver (see [below](#usage-on-windows))
81
+
82
+ Install
83
+ -------
84
+
85
+ $ gem install libusb
86
+
87
+ While ```gem install``` the system is checked for a usable libusb library installation.
88
+ If none could be found, a bundled libusb version is built and used, instead.
89
+
90
+ Latest code can be used in this way:
91
+
92
+ $ git clone git://github.com/larskanis/libusb.git
93
+ $ bundle
94
+ $ rake install_gem
95
+
96
+ Troubleshooting
97
+ ------------------------
98
+ In order to implement a driver for a USB device, it's essential to have a look at the packets that are send to and received back from the USB device. [Wireshark](https://www.wireshark.org) has builtin capabilities to sniff USB traffic. On Linux you possibly need to load the usbmon kernel module before start:
99
+ ```
100
+ sudo modprobe usbmon
101
+ ```
102
+ On Windows it's possible to sniff USB, if the USB kernel driver was installed by the Wireshark setup.
103
+
104
+ ![Wireshark](wireshark-usb-sniffer.png?raw=true "Wireshark sniffing USB packets")
105
+
106
+ Device hotplug support
107
+ ----------------------
108
+
109
+ Support for device hotplugging can be used, if ```LIBUSB.has_capability?(:CAP_HAS_HOTPLUG)``` returns ```true```.
110
+ This requires libusb-1.0.16 or newer on Linux or MacOS. Windows support is [still on the way](https://github.com/libusbx/libusbx/issues/9).
111
+
112
+ A hotplug event handler can be registered with {LIBUSB::Context#on_hotplug_event}.
113
+ You then need to call {LIBUSB::Context#handle_events} in order to receive any events.
114
+ This can be done as blocking calls (possibly in it's own thread) or by using {LIBUSB::Context#pollfds} to
115
+ detect any events to handle.
116
+
117
+
118
+ Usage on Windows
119
+ ----------------
120
+
121
+ In contrast to Linux, any access to an USB device by LIBUSB on Windows requires a proper driver
122
+ installed in the system. Fortunately creating such a driver is quite easy with
123
+ [Zadig](http://zadig.akeo.ie/). Select the interesting USB device,
124
+ choose WinUSB driver and press "Install Driver". That's it. You may take the generated output directory
125
+ with it's INI-file and use it for driver installations on other 32 or 64 bit Windows
126
+ systems.
127
+
128
+
129
+ Binary gems for Windows and Linux
130
+ ---------------------------
131
+
132
+ The Libusb gem is provided as source gem and as binary gems for Windows and Linux operating systems on [rubygems.org](https://rubygems.org/gems/libusb).
133
+ The binary version is usually preferred, but the source version of the gem can be enforced by:
134
+
135
+ $ gem install libusb --platform ruby
136
+
137
+ Libusb gem can be cross built for Windows and Linux, using the [rake-compiler-dock](https://github.com/larskanis/rake-compiler-dock) .
138
+ Just run:
139
+
140
+ $ rake gem:native
141
+
142
+ If everything works, there are several platform specific gem files (like `libusb-VERSION-x64-mingw32.gem`) in the pkg
143
+ directory.
144
+
145
+ EventMachine integration
146
+ ------------------------
147
+
148
+ Libusb for Ruby comes with an experimental integration to [EventMachine](http://rubyeventmachine.com/).
149
+ That API is currently proof of concept - see {LIBUSB::Context#eventmachine_register}.
150
+ If you're experienced with EventMachine, please leave a comment.
151
+
152
+
153
+ Testing LIBUSB gem
154
+ ------------------
155
+
156
+ Libusb for Ruby has a bundled test suite which verifies proper working of many functions of the library.
157
+ Only a small subset of these tests are executed on Github Actions due to the missing USB functions in the CI environments.
158
+ They just verify that the libusb library can be installed and called and that very basic functions are working.
159
+
160
+ To run the tests against real devices the following procedure should be done:
161
+
162
+ ```sh
163
+ $ # Connect a USB mass strorage device. It is used read-only.
164
+ $ sudo chown $USER /dev/bus/usb/*/*
165
+ $ rake test
166
+ ```
167
+
168
+ While the tests are running a second arbitrary USB device is requested to be connected and shortly after disconnected again.
169
+ There are only 5 seconds timeout for connecting and disconnecting, so that the device should have be ready.
170
+ Some USB mass storage devices are not compatible to the tests, so that it's best to try out different models to find some that doesn't fail.
171
+
172
+
173
+ Resources
174
+ ---------
175
+
176
+ * Project's home page: http://github.com/larskanis/libusb
177
+ * API documentation: http://rubydoc.info/gems/libusb/frames
178
+ * Mailinglist: http://rubyforge.org/mailman/listinfo/libusb-hackers
179
+ * Overall introduction to USB: http://www.usbmadesimple.co.uk
180
+
181
+ Todo
182
+ ----
183
+
184
+ * stabilize EventMachine interface
data/Rakefile ADDED
@@ -0,0 +1,82 @@
1
+ # -*- coding: utf-8 -*-
2
+ # -*- ruby -*-
3
+
4
+ require 'bundler/gem_helper'
5
+ require 'rubygems/package_task'
6
+ require 'pathname'
7
+ require 'uri'
8
+ require 'rake/clean'
9
+ require_relative 'lib/libusb/libusb_recipe'
10
+ require_relative 'lib/libusb/gem_helper'
11
+
12
+ CLOBBER.include 'pkg'
13
+ CLEAN.include 'ports'
14
+ CLEAN.include 'tmp'
15
+ CLEAN.include 'ext/tmp'
16
+ CLEAN.include 'lib/*.a'
17
+ CLEAN.include 'lib/*.so*'
18
+ CLEAN.include 'lib/*.dll*'
19
+
20
+ task :build do
21
+ require_relative 'lib/libusb/libusb_recipe'
22
+ recipe = LIBUSB::LibusbRecipe.new
23
+ recipe.download
24
+ end
25
+
26
+ task :gem => :build
27
+ task :compile do
28
+ sh "ruby -C ext extconf.rb --disable-system-libusb"
29
+ sh "make -C ext install RUBYARCHDIR=../lib"
30
+ end
31
+
32
+ task :gemfile_libusb_gem do
33
+ gf = File.read("Gemfile")
34
+ gf.gsub!(/^(gemspec)$/, "# \\1")
35
+ gf << "\ngem 'libusb'\n"
36
+ File.write("Gemfile_libusb_gem", gf)
37
+ puts "Gemfile_libusb_gem written"
38
+ end
39
+
40
+ task :test do
41
+ sh "ruby -w -W2 -I. -Ilib -e \"#{Dir["test/test_*.rb"].map{|f| "require '#{f}';"}.join}\" -- -v"
42
+ end
43
+ task :default => :test
44
+
45
+ ci_tests = %w[test_libusb.rb test_libusb_structs.rb]
46
+ task :ci do
47
+ sh "ruby -w -W2 -I. -e \"#{ci_tests.map{|f| "require 'test/#{f}';"}.join}\" -- -v"
48
+ end
49
+
50
+ CrossLibraries = [
51
+ ['aarch64-mingw-ucrt', 'aarch64-w64-mingw32', 'bin/libusb-1.0.dll'],
52
+ ['x86-mingw32', 'i686-w64-mingw32', 'bin/libusb-1.0.dll'],
53
+ ['x64-mingw32', 'x86_64-w64-mingw32', 'bin/libusb-1.0.dll'],
54
+ ['x64-mingw-ucrt', 'x86_64-w64-mingw32', 'bin/libusb-1.0.dll'],
55
+ # ['x86-linux', 'i686-linux-gnu', 'lib/libusb-1.0.so'],
56
+ # ['x86_64-linux', 'x86_64-linux-gnu', 'lib/libusb-1.0.so'],
57
+ ].map do |ruby_platform, host_platform, libusb_dll|
58
+ LIBUSB::CrossLibrary.new ruby_platform, host_platform, libusb_dll
59
+ end
60
+
61
+ LIBUSB::GemHelper.install_tasks
62
+ Bundler::GemHelper.instance.cross_platforms = CrossLibraries.map(&:ruby_platform)
63
+
64
+ CrossLibraries.map(&:ruby_platform).each do |platform|
65
+ desc "Build windows and linux fat binary gems"
66
+ multitask 'gem:native' => "gem:native:#{platform}"
67
+
68
+ task "gem:native:prepare" do
69
+ require 'rake_compiler_dock'
70
+ sh "bundle package"
71
+ end
72
+
73
+ task "gem:native:#{platform}" => "gem:native:prepare" do
74
+ RakeCompilerDock.sh <<-EOT, platform: platform
75
+ bundle --local &&
76
+ #{ "sudo yum install -y libudev-devel &&" if platform=~/linux/ }
77
+ bundle exec rake --trace cross:#{platform} gem "MAKE=make V=1 -j`nproc`" || cat tmp/*/ports/libusb/*/*.log
78
+ EOT
79
+ end
80
+ end
81
+
82
+ # vim: syntax=ruby