Skip to content

Commit 55bdeec

Browse files
committed
Merge branch 'jdk21'
# Conflicts: # .github/workflows/continuous-integration.yaml # java-does-usb/.mvn/wrapper/maven-wrapper.properties
2 parents 2f8fcc0 + 8db72c7 commit 55bdeec

File tree

263 files changed

+7233
-5949
lines changed

Some content is hidden

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

263 files changed

+7233
-5949
lines changed

.github/workflows/continuous-integration.yaml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
name: Continuous Integration
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
paths-ignore:
6+
- "test-devices/**"
7+
- "reference/**"
8+
pull_request:
9+
paths-ignore:
10+
- "test-devices/**"
11+
- "reference/**"
12+
413

514
env:
615
MAVEN_ARGS: -B -V -ntp -e -Djansi.passthrough=true -Dstyle.color=always
@@ -20,29 +29,29 @@ jobs:
2029
uses: actions/setup-java@v3
2130
with:
2231
distribution: 'zulu'
23-
java-version: '20'
32+
java-version: '21'
2433
cache: 'maven'
25-
- name: Configure GPG Key
34+
- name: Configure GPG key
2635
run: |
2736
echo -n "$GPG_SIGNING_KEY" | base64 --decode | gpg --import
2837
env:
2938
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
3039
shell: bash
31-
- name: Library
40+
- name: Build java-does-usb
3241
run: ./mvnw $MAVEN_ARGS -DskipTests clean install javadoc:javadoc
3342
working-directory: ./java-does-usb
34-
- name: Example bulk_transfer
43+
- name: Example "bulk_transfer"
3544
run: ./mvnw $MAVEN_ARGS clean compile
3645
working-directory: ./examples/bulk_transfer
37-
- name: Example enumerate
46+
- name: Example "enumerate"
3847
run: ./mvnw $MAVEN_ARGS clean compile
3948
working-directory: ./examples/enumerate
40-
- name: Example monitor
49+
- name: Example "monitor"
4150
run: ./mvnw $MAVEN_ARGS clean compile
4251
working-directory: ./examples/monitor
43-
- name: Example stm_dfu
52+
- name: Example "stm_dfu"
4453
run: ./mvnw $MAVEN_ARGS clean compile
4554
working-directory: ./examples/stm_dfu
46-
- name: Example epaper_display
55+
- name: Example "epaper_display"
4756
run: ./mvnw $MAVEN_ARGS clean compile
4857
working-directory: ./examples/epaper_display

.github/workflows/test-devices.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Test Devices CI
2+
3+
on:
4+
push:
5+
paths:
6+
- "test-devices/**"
7+
- ".github/**"
8+
pull_request:
9+
paths:
10+
- "test-devices/**"
11+
- ".github/**"
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- uses: actions/cache@v3
20+
with:
21+
path: |
22+
~/.cache/pip
23+
~/.platformio/.cache
24+
key: ${{ runner.os }}-pio
25+
- uses: actions/setup-python@v4
26+
with:
27+
python-version: '3.9'
28+
- name: Install PlatformIO Core
29+
run: pip install --upgrade platformio
30+
31+
- name: Build loopback firmware
32+
run: pio run
33+
working-directory: ./test-devices/loopback-stm32
34+
35+
- name: Build composite firmware
36+
run: pio run
37+
working-directory: ./test-devices/composite-stm32

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
*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.)
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 only uses Java code and does not need JNI or any native third-party library. The *Foreign Function & Memory API* (aka as project Panama) is in preview and will be introduced in a future Java version. Currently, it can be used with Java 19 or Java 20 (with preview features enabled).
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).
88

9-
*Note: The main branch and published versions ≥ 0.5.0 work with JDK 20 only. For JDK 19, use version 0.4.x.*
9+
*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.
1010

1111

1212
## Features
@@ -41,14 +41,14 @@ If you are using Maven, add the below dependency to your pom.xml:
4141
<dependency>
4242
<groupId>net.codecrete.usb</groupId>
4343
<artifactId>java-does-usb</artifactId>
44-
<version>0.5.1</version>
44+
<version>0.6.0</version>
4545
</dependency>
4646
```
4747

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

5050
```groovy
51-
compile group: 'net.codecrete.usb', name: 'java-does-usb', version: '0.5.1'
51+
compile group: 'net.codecrete.usb', name: 'java-does-usb', version: '0.6.0'
5252
```
5353

5454
```java
@@ -78,31 +78,32 @@ public class EnumerateDevices {
7878
- [Enumeration](examples/enumerate/) lists all connected USB devices and displays information about interfaces and endpoints.
7979
- [Monitor](examples/monitor/) lists the connected USB devices and then monitors for USB devices being connected and disconnnected.
8080
- [Device Firmware Upload (DFU) for STM32](examples/stm_dfu) uploads firmware to STM32 microcontrollers supporting the built-in DFU mode.
81+
- [ePaper Display](examples/epaper_display) communicates with an IT8951 controller for e-Paper displays and shows an image on the display.
8182

8283

8384
## Prerequisite
8485

85-
- Java 20, preview features enabled (available at https://www.azul.com/downloads/?package=jdk)
86+
- Java 21, preview features enabled (available at https://www.azul.com/downloads/?package=jdk)
8687
- Windows (x86 64-bit), macOS (x86 64-bit, ARM 64-bit) or Linux 64 bit (x86 64-bit, ARM 64-bit)
8788

88-
For JDK 19, use the latest published version 0.4.x.
89+
For JDK 20, use the latest published version 0.5.x. For JDK 19, use the latest published version 0.4.x.
8990

9091

9192
## Platform-specific Considerations
9293

9394

9495
### macOS
9596

96-
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.
97+
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.
9798

9899

99100
### Linux
100101

101102
*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.
102103

103-
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.
104+
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).
104105

105-
Most Linux distributions by default set up user accounts without the permission 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:
106+
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:
106107

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

@@ -115,9 +116,9 @@ This adds the rule to assign permission mode 0666 to all USB devices with vendor
115116

116117
### Windows
117118

118-
The Windows driver model is more rigid than the ones of macOS or Linux. It's not possible to open any USB device by default. Instead, only devices using the *WinUSB* driver can be opened. This even applies to devices with no installed driver.
119+
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.
119120

120-
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 driver can also be manually installed or replaced using a software called [Zadig](https://zadig.akeo.ie/).
121+
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/).
121122

122123
The test devices implement the required control requests. So the driver is installed automatically.
123124

examples/bulk_transfer/pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66

77
<groupId>net.codecrete.usb.examples</groupId>
88
<artifactId>bulk-transfer</artifactId>
9-
<version>0.5.1</version>
9+
<version>0.6.0-SNAPSHOT</version>
1010

1111
<name>bulk-transfer</name>
1212
<url>https://github.com/manuelbl/JavaDoesUSB/examples/bulk_transfer</url>
1313

1414
<properties>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16-
<maven.compiler.source>20</maven.compiler.source>
17-
<maven.compiler.target>20</maven.compiler.target>
16+
<maven.compiler.source>21</maven.compiler.source>
17+
<maven.compiler.target>21</maven.compiler.target>
1818
</properties>
1919

2020
<dependencies>
2121
<dependency>
2222
<groupId>net.codecrete.usb</groupId>
2323
<artifactId>java-does-usb</artifactId>
24-
<version>0.5.1</version>
24+
<version>0.6.0-SNAPSHOT</version>
2525
</dependency>
2626
</dependencies>
2727

@@ -42,12 +42,12 @@
4242
<artifactId>maven-compiler-plugin</artifactId>
4343
<version>3.8.0</version>
4444
<configuration>
45-
<release>20</release>
45+
<release>21</release>
4646
<compilerArgs>
4747
<arg>--enable-preview</arg>
4848
</compilerArgs>
49-
<source>20</source>
50-
<target>20</target>
49+
<source>21</source>
50+
<target>21</target>
5151
</configuration>
5252
</plugin>
5353
<plugin>

examples/bulk_transfer/src/main/java/net/codecrete/usb/examples/BulkTransfer.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
* <p>
1515
* This example assumes that one of the interfaces has two bulk endpoints,
1616
* one for sending and one for receiving data. The test device fulfils
17-
* this requirement (see https://github.com/manuelbl/JavaDoesUSB/tree/main/test-devices/loopback-stm32)
17+
* this requirement (see
18+
* <a href="https://github.com/manuelbl/JavaDoesUSB/tree/main/test-devices/loopback-stm32">loopback-stm32</a>)
1819
* </p>
1920
*/
2021
public class BulkTransfer {
@@ -26,7 +27,13 @@ public class BulkTransfer {
2627
private static final int ENDPOINT_IN = 2;
2728

2829
public static void main(String[] args) {
29-
var device = USB.getDevice(new USBDeviceFilter(VID, PID));
30+
var optionalDevice = USB.getDevice(VID, PID);
31+
if (optionalDevice.isEmpty()) {
32+
System.out.printf("No USB device with VID=0x%04x and PID=0x%04x found.%n", VID, PID);
33+
return;
34+
}
35+
36+
var device = optionalDevice.get();
3037
device.open();
3138
device.claimInterface(INTERFACE_NO);
3239

examples/enumerate/pom.xml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,42 @@
66

77
<groupId>net.codecrete.usb.examples</groupId>
88
<artifactId>enumerate</artifactId>
9-
<version>0.5.1</version>
9+
<version>0.6.0-SNAPSHOT</version>
1010

1111
<name>enumerate</name>
1212
<url>https://github.com/manuelbl/JavaDoesUSB/examples/enumerate</url>
1313

1414
<properties>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16-
<maven.compiler.source>20</maven.compiler.source>
17-
<maven.compiler.target>20</maven.compiler.target>
16+
<maven.compiler.source>21</maven.compiler.source>
17+
<maven.compiler.target>21</maven.compiler.target>
1818
</properties>
1919

2020
<dependencies>
2121
<dependency>
2222
<groupId>net.codecrete.usb</groupId>
2323
<artifactId>java-does-usb</artifactId>
24-
<version>0.5.1</version>
24+
<version>0.6.0-SNAPSHOT</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.tinylog</groupId>
28+
<artifactId>tinylog-api</artifactId>
29+
<version>2.6.2</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.tinylog</groupId>
33+
<artifactId>tinylog-impl</artifactId>
34+
<version>2.6.2</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.tinylog</groupId>
38+
<artifactId>jsl-tinylog</artifactId>
39+
<version>2.6.2</version>
2540
</dependency>
2641
</dependencies>
2742

2843
<build>
29-
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
44+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (maybe moved to parent pom) -->
3045
<plugins>
3146
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
3247
<plugin>
@@ -42,12 +57,12 @@
4257
<artifactId>maven-compiler-plugin</artifactId>
4358
<version>3.8.0</version>
4459
<configuration>
45-
<release>20</release>
60+
<release>21</release>
4661
<compilerArgs>
4762
<arg>--enable-preview</arg>
4863
</compilerArgs>
49-
<source>20</source>
50-
<target>20</target>
64+
<source>21</source>
65+
<target>21</target>
5166
</configuration>
5267
</plugin>
5368
<plugin>

examples/enumerate/src/main/java/net/codecrete/usb/examples/Enumerate.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/**
1515
* Sample application enumerating connected USB devices.
1616
*/
17+
@SuppressWarnings("java:S106")
1718
public class Enumerate {
1819

1920
public static void main(String[] args) {
@@ -42,10 +43,14 @@ private static void printDevice(USBDevice device) {
4243
for (var intf: device.interfaces())
4344
printInterface(intf);
4445

46+
printRawDescriptor("Device descriptor", device.deviceDescriptor());
47+
printRawDescriptor("Configuration descriptor", device.configurationDescriptor());
48+
4549
System.out.println();
4650
System.out.println();
4751
}
4852

53+
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
4954
private static void printInParens(Optional<String> text) {
5055
if (text.isPresent()) {
5156
System.out.printf(" (%s)%n", text.get());
@@ -85,4 +90,17 @@ private static void printEndpoint(USBEndpoint endpoint) {
8590
System.out.printf(" Transfer type: %s%n", endpoint.transferType().name());
8691
System.out.printf(" Packet size: %d bytes%n", endpoint.packetSize());
8792
}
93+
94+
private static void printRawDescriptor(String title, byte[] descriptor) {
95+
System.out.println();
96+
System.out.println(title);
97+
98+
int len = descriptor.length;
99+
for (int i = 0; i < len; i += 16) {
100+
System.out.printf("%04x ", i);
101+
for (int j = i; j < Math.min(i + 16, len); j += 1)
102+
System.out.printf(" %02x", descriptor[j] & 255);
103+
System.out.println();
104+
}
105+
}
88106
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
writer = console
2+
writer.format = {date: HH:mm:ss.SSS} {level|size=5} [{class|size=40}] {message}
3+
writer.level = info

examples/epaper_display/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This sample shows how to communicate with an IT8951 controller for e-paper displ
44

55
## Prerequisites
66

7-
- Java 20
7+
- Java 21
88
- Apache Maven
99
- 64-bit operating system (macOS, Linux, Windows)
1010
- IT8951 controller
@@ -17,9 +17,9 @@ be temporarily detached.)
1717

1818
## How to run
1919

20-
### Install Java 20
20+
### Install Java 21
2121

22-
Check that *Java 20* is installed:
22+
Check that *Java 21* is installed:
2323

2424
```shell
2525
$ java -version

0 commit comments

Comments
 (0)