Skip to content

Commit 9abda6c

Browse files
committed
Merge branch 'jdk22'
2 parents 688b26d + 0d912c3 commit 9abda6c

File tree

275 files changed

+23984
-15782
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

275 files changed

+23984
-15782
lines changed

.github/workflows/continuous-integration.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ jobs:
2626
steps:
2727
- uses: actions/checkout@v3
2828
- name: Setup Java
29-
uses: actions/setup-java@v3
29+
uses: oracle-actions/setup-java@v1
3030
with:
31-
distribution: 'zulu'
32-
java-version: '21'
33-
cache: 'maven'
31+
website: jdk.java.net
32+
release: 22
33+
version: latest
3434
- name: Configure GPG key
3535
run: |
3636
echo -n "$GPG_SIGNING_KEY" | base64 --decode | gpg --import

README.md

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@
22

33
[![javadoc](https://javadoc.io/badge2/net.codecrete.usb/java-does-usb/javadoc.svg)](https://javadoc.io/doc/net.codecrete.usb/java-does-usb)
44

5-
*Java Does USB* is a Java library for working with USB devices. It allows to query information about all conntected USB devices and to communicate with USB devices using custom / vendor specific protocols. (It is not intended for communication with standard types of USB devices such as mass storage devices, keyboards etc.)
5+
*Java Does USB* is a Java library for working with USB devices. It allows to query the conntected USB devices and to communicate with them using custom / vendor specific protocols. (It is not intended for communication with standard types of USB devices such as mass storage devices, keyboards etc.)
66

7-
The library uses the [Foreign Function & Memory API](https://github.com/openjdk/panama-foreign) to access native APIs of the underlying operating system. It is written entirely in Java and does not need JNI or any native third-party library. The *Foreign Function & Memory API* (aka as project Panama) is currently in preview and will leave preview with Java 22. Currently, it can be used with Java 19, Java 20 or Java 21 (with preview features enabled).
7+
The library uses the [Foreign Function and Memory API](https://docs.oracle.com/en/java/javase/21/core/foreign-function-and-memory-api.html#GUID-FBE990DA-C356-46E8-9109-C75567849BA8) to access native APIs of the underlying operating system. It is written entirely in Java and does not use JNI or any native third-party library. The *Foreign Function and Memory API* has been introduced with Java 22. Preview versions were available in several earlier releases.
88

9-
| Version | Main New Features | Compatibility |
10-
| - | - | - |
11-
| 0.7.x | New setter/getter names for improved Kotlin support; Kotlin examples | JDK 21 |
12-
| 0.6.x | Support for JDK 21; better handling of composite devices on Windows | JDK 21 |
13-
| 0.5.x | Support for JDK 20; high-throuput I/O streams | JDK 20 |
14-
| 0.4.x | Early release | JDK 19 |
15-
16-
*Note: The main branch and published versions ≥ 0.6.0 work with JDK 21 only. For JDK 20, use version 0.5.*. For JDK 19, use version 0.4.x.
179

1810

1911
## Features
@@ -25,17 +17,8 @@ The library uses the [Foreign Function & Memory API](https://github.com/openjdk/
2517
- Descriptive information about interfaces, settings and endpoints
2618
- High-throughput input/output streams
2719
- Support for alternate interface settings, composite devices and interface association
28-
- Published on Maven Central
29-
30-
### Planned
31-
32-
- Isochronous transfer
33-
34-
### Not planned
20+
- Published on Maven Central and licensed under the permissive MIT license
3521

36-
- Changing configuration: The library selects the first configuration. Changing configurations is rarely used and not supported on Windows (limitation of WinUSB).
37-
- USB 3.0 streams: Not supported on Windows (limitation of WinUSB).
38-
- Providing information about USB buses, controllers and hubs
3922

4023

4124
## Getting Started
@@ -48,14 +31,14 @@ If you are using Maven, add the below dependency to your pom.xml:
4831
<dependency>
4932
<groupId>net.codecrete.usb</groupId>
5033
<artifactId>java-does-usb</artifactId>
51-
<version>0.7.1</version>
34+
<version>1.0.0-SNAPSHOT</version>
5235
</dependency>
5336
```
5437

5538
If you are using Gradle, add the below dependency to your build.gradle file:
5639

5740
```groovy
58-
compile group: 'net.codecrete.usb', name: 'java-does-usb', version: '0.7.1'
41+
compile group: 'net.codecrete.usb', name: 'java-does-usb', version: '1.0.0-SNAPSHOT'
5942
```
6043

6144
```java
@@ -74,11 +57,14 @@ public class EnumerateDevices {
7457
```
7558

7659

60+
7761
## Documentation
7862

7963
- [Javadoc](https://javadoc.io/doc/net.codecrete.usb/java-does-usb)
8064

8165

66+
67+
8268
## Examples
8369

8470
- [Bulk Transfer](examples/bulk_transfer/) demonstrates how to find a USB device, open it and communicate using bulk transfer.
@@ -88,29 +74,29 @@ public class EnumerateDevices {
8874
- [ePaper Display](examples/epaper_display) communicates with an IT8951 controller for e-Paper displays and shows an image on the display.
8975

9076

77+
9178
## Prerequisite
9279

93-
- Java 21, preview features enabled (available at https://www.azul.com/downloads/?package=jdk)
80+
- Java 22 available at [jdk.java.net](https://jdk.java.net/21/), [Azul](https://www.azul.com/downloads/?package=jdk), [Adoptium](https://adoptium.net/temurin/releases/) or with your favorite package manager.
9481
- Windows (x86 64-bit), macOS (x86 64-bit, ARM 64-bit) or Linux 64 bit (x86 64-bit, ARM 64-bit)
9582

96-
For JDK 20, use the latest published version 0.5.x. For JDK 19, use the latest published version 0.4.x.
9783

9884

9985
## Platform-specific Considerations
10086

10187

10288
### macOS
10389

104-
No special considerations apply. Using this library, a Java application can connect to any USB device and claim any interfaces that isn't claimed by an operating system driver or another application. Standard operation-system drivers can be unloaded if the application is run with root privileges.
90+
No special considerations apply. Using this library, a Java application can connect to any USB device and claim any interfaces that isn't claimed by an operating system driver or another application. Standard operation system drivers can be unloaded if the application is run with root privileges. It runs both on Macs with Apple Silicon and Intel processors.
10591

10692

10793
### Linux
10894

109-
*libudev* is used to discover and monitor USB devices. It is closely tied to *systemd*. So the library only runs on Linux distributions with *systemd* and the related libraries. The majority of Linux distributions suitable for desktop computing (as opposed to distributions optimized for containers) fulfill this requirement.
95+
*libudev* is used to discover and monitor USB devices. It is closely tied to *systemd*. So the library only runs on Linux distributions with *systemd* and the related libraries. The majority of Linux distributions suitable for desktop computing (as opposed to distributions optimized for containers) fulfill this requirement. It runs on both Intel and ARM64 processors.
11096

11197
Similar to macOS, a Java application can connect to any USB device and claim any interfaces that isn't claimed by an operating system driver or another application. Standard operation system drivers can be unloaded (without the need for root privileges).
11298

113-
Most Linux distributions by default set up user accounts without permissions to access USB devices directly. The *udev* system daemon is responsible for assigning permissions to USB devices. It can be configured to assign specific permissions or ownership:
99+
Most Linux distributions set up user accounts without permissions to access USB devices. The *udev* system daemon is responsible for assigning permissions to USB devices. It can be configured to assign specific permissions or ownership:
114100

115101
Create a file called `/etc/udev/rules.d/80-javadoesusb-udev.rules` with the below content:
116102

@@ -120,35 +106,55 @@ SUBSYSTEM=="usb", ATTRS{idVendor}=="cafe", MODE="0666"
120106

121107
This adds the rule to assign permission mode 0666 to all USB devices with vendor ID `0xCAFE`. This unregistered vendor ID is used by the test devices.
122108

109+
Without the *udev* rule, it is still possible to enumerate and query all USB devices.
110+
123111

124112
### Windows
125113

126-
The Windows driver model is more rigid than the ones of macOS or Linux. It's not possible to open any USB device that is not claimed. Instead, only devices using the *WinUSB* driver can be opened. This even applies to devices with no installed driver.
114+
The Windows driver model is rather rigid. It's not possible to open any USB device unless it uses the *WinUSB* driver. This even applies to devices with no installed driver. Enumerating and querying USB devices is possible independent of the driver.
127115

128-
USB devices can implement certain control requests to instruct Windows to automatically install the WinUSB driver (search for *WCID* or *Microsoft OS Compatibility Descriptors*). The WinUSB driver can also be manually installed or replaced using a software called [Zadig](https://zadig.akeo.ie/).
116+
USB devices can implement special control requests to instruct Windows to automatically install the WinUSB driver (search for *WCID* or *Microsoft OS Compatibility Descriptors*). The WinUSB driver can also be manually installed or replaced using a software called [Zadig](https://zadig.akeo.ie/).
129117

130118
The test devices implement the required control requests. So the driver is installed automatically.
131119

132-
The library has not been tested on Windows for ARM64. It might or might not work.
120+
Windows for ARM64 is not yet supported. A port is probably easy, provided you have hardware to test it.
133121

134122

135-
### Troubleshooting
136123

137-
#### `ClassFormatError` (all platforms)
124+
## Troubleshooting
138125

139-
The error `java.lang.ClassFormatError: Illegal field name "" in class net/codecrete/usb/windows/WindowsUsbDeviceRegistry` is caused by a bug in JDK 21, which has been fixed in the mean-time. Please upgrade to the latest release of JDK 21 (at least 21.0.1).
126+
### 32-bit versions
140127

128+
The *Foreign Function And Memory API* has not been implemented for 32-bit operating systems / JDKs (and likely never will be).
141129

142130

143-
### 32-bit versions
144131

145-
The Foreign Function & Memory API has not been implemented for 32-bit operating systems / JDKs (and likely never will be).
132+
## Running on older JDK versions
146133

134+
The *Foreign Function And Memory API* has been available as a preview feature in JDKs before 22. However, incompatible changes were made from preview to preview to release. Earlier versions can be used with specific versions of this library:
147135

136+
| Version | Main New Features | Compatibility |
137+
| - | - | - |
138+
| 1.0.x | Release for final Java API | JDK 22 |
139+
| 0.7.x | New setter/getter names for improved Kotlin support; Kotlin examples | JDK 21 |
140+
| 0.6.x | Support for JDK 21; better handling of composite devices on Windows | JDK 21 |
141+
| 0.5.x | Support for JDK 20; high-throuput I/O streams | JDK 20 |
142+
| 0.4.x | Early release | JDK 19 |
148143

149-
## Code generation
144+
When using an older JDK, preview features must be enabled using the `--enable-preview` VM option.
150145

151-
Many bindings for the native APIs have been generated with *jextract*. See the [jextract](java-does-usb/jextract) subdirectory for more information. For functions that need to retain the error state (`errno` on Linux, `GetLastError()` on Windows), the bindings have been manually written as *jextract* does not support it.
146+
147+
148+
## Building from source
149+
150+
To build from source, run the following command:
151+
152+
```
153+
cd java-does-usb
154+
mvn clean install -DskipTests
155+
```
156+
157+
The tests are skipped as they require that a special test device is connected to the computer. See the next section for more information.
152158

153159

154160

@@ -164,17 +170,26 @@ The test device with the *loopback-stm32* code supports all tests. If the test d
164170
Tests can be run from the command line:
165171

166172
```
173+
cd java-does-usb
167174
mvn clean test
168175
```
169176

170-
If they are run from an IDE (such as IntelliJ IDEA), you must likely configure VM options to enable preview features and allow native access:
177+
If they are run from an IDE (such as IntelliJ IDEA), you must likely configure VM options to allow native access:
171178

172179
```
173-
--enable-preview --enable-native-access=net.codecrete.usb
180+
--enable-native-access=net.codecrete.usb
174181
```
175182

176183
Or (if modules are ignored):
177184

178185
```
179-
--enable-preview --enable-native-access=ALL-UNNAMED
186+
--enable-native-access=ALL-UNNAMED
180187
```
188+
189+
190+
191+
## Code generation
192+
193+
Many bindings for the native APIs have been generated with *jextract*. See the [jextract](java-does-usb/jextract) subdirectory for more information. For functions that need to retain the error state (`errno` on Linux, `GetLastError()` on Windows), the bindings have been manually written as *jextract* does not support it.
194+
195+
Since the code can only be generated for the current operating system, it must be generated on separate computers for Linux, Windows and macOS. Thus, the generated code is included in the repository. The generated code is compilable on all operating systems.

examples/bulk_transfer/.mvn/wrapper/maven-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.3/apache-maven-3.9.3-bin.zip
17+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
1818
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar

examples/bulk_transfer/README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ This sample shows how to find a device, open it and transfer data from and to bu
44

55
## Prerequisites
66

7-
- Java 21
7+
- Java 22
88
- Apache Maven
99
- 64-bit operating system (Windows, macOS, Linux)
1010
- A USB device with bulk IN and OUT endpoints (e.g. the test device, see https://github.com/manuelbl/JavaDoesUSB/tree/main/test-devices/loopback-stm32)
1111

1212
## How to run
1313

14-
### Install Java 21
14+
### Install Java 22
1515

16-
Check that *Java 21* is installed:
16+
Check that *Java 22* is installed:
1717

1818
```shell
1919
$ java -version
@@ -39,24 +39,22 @@ $ mvn compile exec:exec
3939
[INFO] Scanning for projects...
4040
[INFO]
4141
[INFO] --------------< net.codecrete.usb.examples:bulk-transfer >--------------
42-
[INFO] Building bulk-transfer 0.7.1
42+
[INFO] Building bulk-transfer 1.0.0-SNAPSHOT
4343
[INFO] --------------------------------[ jar ]---------------------------------
4444
[INFO]
45-
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ bulk-transfer ---
46-
[INFO] Using 'UTF-8' encoding to copy filtered resources.
47-
[INFO] skip non existing resourceDirectory /Users/me/Documents/JavaDoesUSB/examples/bulk_transfer/src/main/resources
45+
[INFO] --- maven-resources-plugin:3.3.1:resources (default-resources) @ bulk-transfer ---
46+
[INFO] skip non existing resourceDirectory /home/user/Documents/JavaDoesUSB/examples/bulk_transfer/src/main/resources
4847
[INFO]
49-
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ bulk-transfer ---
50-
[INFO] Changes detected - recompiling the module!
51-
[INFO] Compiling 1 source file to /Users/me/Documents/JavaDoesUSB/examples/bulk_transfer/target/classes
48+
[INFO] --- maven-compiler-plugin:3.12.1:compile (default-compile) @ bulk-transfer ---
49+
[INFO] Nothing to compile - all classes are up to date.
5250
[INFO]
53-
[INFO] --- exec-maven-plugin:3.1.0:exec (default-cli) @ bulk-transfer ---
51+
[INFO] --- exec-maven-plugin:3.1.1:exec (default-cli) @ bulk-transfer ---
5452
6 bytes sent.
5553
6 bytes received.
5654
[INFO] ------------------------------------------------------------------------
5755
[INFO] BUILD SUCCESS
5856
[INFO] ------------------------------------------------------------------------
59-
[INFO] Total time: 1.259 s
60-
[INFO] Finished at: 2023-03-23T14:10:17+01:00
57+
[INFO] Total time: 1.228 s
58+
[INFO] Finished at: 2024-02-18T16:23:29+01:00
6159
[INFO] ------------------------------------------------------------------------
6260
```

0 commit comments

Comments
 (0)