-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6724899
commit 3770f0d
Showing
24 changed files
with
634 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,53 @@ | ||
[![](https://jitpack.io/v/DigitalSmile/gpio.svg)](https://jitpack.io/#DigitalSmile/gpio) | ||
# GPIO library with new java FFM API | ||
![](https://img.shields.io/badge/Java-21+-success) | ||
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/digitalsmile/gpio/gradle.yml) | ||
--- | ||
# Java GPIO library with new java FFM API | ||
With new FFM API that were released in a recent versions of Java you can work with any kind of hardware just within your app. No more JNI and JNA! | ||
|
||
Read more about FFM in here -> https://openjdk.org/jeps/442 | ||
|
||
Since Java 22 it will be the default option for usage the external C libraries. Be prepared now! | ||
|
||
## Features | ||
1) Zero dependencies (except SLF4J for logging) | ||
2) Modern Java 21+ with full language feature support | ||
3) Supports working with individual GPIO Pins | ||
4) Supports working with SPI | ||
5) Tested on Raspberry Pi 4. | ||
6) i2c and UART/TTL coming soon. | ||
|
||
## Usage | ||
1) Add a dependency. | ||
```groovy | ||
allprojects { | ||
repositories { | ||
... | ||
maven { url 'https://jitpack.io' } | ||
} | ||
} | ||
dependencies { | ||
implementation 'com.github.DigitalSmile:gpio:{version}' | ||
} | ||
``` | ||
2) <b>IMPORTANT:</b> add Java VM Option `--enable-preview` in your IDE and gradle -> https://stackoverflow.com/questions/72083752/enable-preview-features-in-an-early-access-version-of-java-in-intellij (that will go away when JAva will be upgraded to 22) | ||
3) Add to your code: | ||
|
||
```java | ||
var spiBus = GPIOBoard.ofSPI(0, SPIMode.MODE_0, 20_000_000); | ||
|
||
var rst = GPIOBoard.ofPin(17, Direction.OUTPUT); | ||
var busy = GPIOBoard.ofPin(24, Direction.INPUT); | ||
var dc = GPIOBoard.ofPin(25, Direction.OUTPUT); | ||
var pwr = GPIOBoard.ofPin(18, Direction.OUTPUT); | ||
|
||
pwr.write(State.HIGH); | ||
while (busy.read().equals(State.HIGH)) { | ||
Thread.sleep(10); | ||
} | ||
|
||
dc.write(State.LOW); | ||
spiBus.sendByteData(new byte[]{1}, false); | ||
``` | ||
4) Enjoy! :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
/** | ||
* Main GPIO module | ||
*/ | ||
module gpio.main { | ||
requires org.slf4j; | ||
|
||
exports org.digitalsmile.gpio.core; | ||
exports org.digitalsmile.gpio.pin; | ||
exports org.digitalsmile.gpio.pin.attributes; | ||
exports org.digitalsmile.gpio.spi; | ||
exports org.digitalsmile.gpio.pin.event; | ||
exports org.digitalsmile.gpio; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/org/digitalsmile/gpio/core/IntegerToHex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
...rg/digitalsmile/gpio/core/file/Flags.java → ...org/digitalsmile/gpio/core/file/Flag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.