Re: To write Java binding for libgpiod - need help with looking for references

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jul 20, 2022 at 9:04 AM Meena M <scientistartist@xxxxxxxxx> wrote:

> I need to write Java binding for GPIO library.

That's interesting!

I would use the libgpiod2 branch for this because that is where active
development
is happening right now, with active language bindings for C++, Python and also
Rust in the works, so clone and work on top of this branch:
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/log/?h=next/libgpiod-2.0

> Decided to go with JNI for the purpose.

That's pretty much standard, right?

> All of the references have examples with using standard C libraries with functions
> such as printf or, from scientific library with method such as multiply. The library
> for which I need to write Java binding has macros, structs, with types such as
> __u32 which I am unable to see mapped to Java.

It seems like you are trying to use
/usr/include/linux/gpio.h, <linux/gpio.h> (the kernel header file) directly.

Don't do that, use libgpiod2 inbetween instead and it will be much
simpler. It has this friendly header instead:
https://github.com/brgl/libgpiod/blob/master/include/gpiod.h

> Until now have watched some
> youtube videos, looking at JNI programmers's guide which was
> recommended(but it is very old) and looking at an ibm documentation
> on JNI https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/types.html
> has not been very helpful.
> https://github.com/java-native-access/jna/blob/master/www/Mappings.md has
> mappings but in the library there are types such as __u32 for which there is
> no corresponding Java type
> https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/types.html,
> even the official documentation has no mappingfor __u32 or unsigned 32/64 bit

The __u32 etc are Linux kernel-to-userspace types. You certainly
*can* use them directly if you absolutely want, but libgpiod is going
to be so much better to use for this so please consider using that
instead.

> Is there any tools that can help me?

Yeah use libgpiod2. Create bindings on top of that instead.

> Where can I find a good reference for this?
> Or am I approaching this completely wrong?

libgpiod top README:
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/about/?h=next/libgpiod-2.0

Bartosz talking about libgpiod etc:
https://www.youtube.com/watch?v=0APvuY2eLkY

> Should I go for JNA or some other option?

Don't know much about Java since I haven't used it since I finished university
in 2004, so you tell me :D

Yours,
Linus Walleij



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux