Jump to content

Getting started with GPIO, using "new" gpiod interface


TRS-80

Recommended Posts

My main desktop workstation is, in actuality, a server motherboard (KGPE-D16).  I have a need to turn it on remotely from time to time.  Apparently it is not capable of Wake on LAN, as that is a feature reserved for some add on server management card (which I don't have and am not going to purchase, as it requires some proprietary software).  So I realized I could simply hook up some relay to a microcontroller to pull the power switch low for 200 ms or whatever.  Well then I thought, I have a Cubietruck and an ODROID-XU4 (and a ROCKPro64 for that matter) right in the case which should have GPIO available and are already connected to Ethernet, why not use those instead...

 

I never played with GPIO before (on SBC), so I spent the better part of yesterday reading, but I'm still not quite sure how to proceed.  Here are the problems I ran into:

 

  • Cubietruck uses nonstandard size pin connectors (and I don't have any of those), so pretty quickly I started focusing on ODROID-XU4 instead.
  • Lots of resources I found seemed to be geared towards the older sysfs interface (instead of newer gpiod one).
  • Many resources geared towards WiringPi numbering scheme (and RPi tier nonsense in general), including the official ODROID-XU4 wiki info about pin numbering.  Which is absolutely Fing useless.  /facepalm
  • I am aware about the few tools that are available to abstract this away (WiringPi, pyGPIO, as well as ArmbianIO, and User Space IO) but I did not really want to have to write Python, C, or Java (I feel a simple shell script with gpiod commands, ex. gpioset should suffice for my very basic needs here).

 

So currently I am stuck at the mapping between physical pins and what they are called according to Linux's gpiod interface.  Here is output of gpioinfo on the ODROID-XU4 for instance:

 

Spoiler

$ sudo gpioinfo 

gpiochip0 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip1 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed  "power key"   input   active-low [used]
	line   4:      unnamed  "interrupt"   input  active-high [used]
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip10 - 8 lines:
	line   0:      unnamed      "reset"  output   active-low [used]
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip11 - 6 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
gpiochip12 - 4 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
gpiochip13 - 6 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
gpiochip14 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip15 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip16 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip17 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip18 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip19 - 2 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
gpiochip2 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip20 - 6 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
gpiochip21 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip22 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip23 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip24 - 2 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
gpiochip25 - 4 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
gpiochip26 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed "ads7846_pendown" input active-high [used]
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed        "sda"   input  active-high [used]
	line   7:      unnamed        "scl"   input  active-high [used]
gpiochip27 - 6 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
gpiochip28 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed     "spi1.0"  output  active-high [used]
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip29 - 5 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
gpiochip3 - 8 lines:
	line   0:      unnamed         "w1"   input  active-high [used]
	line   1:      unnamed     "spi1.1"  output  active-high [used]
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip30 - 5 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
gpiochip31 - 4 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
gpiochip32 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip33 - 2 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
gpiochip34 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip35 - 7 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
gpiochip4 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed        "hpd"   input  active-high [used]
gpiochip5 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip6 - 8 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
gpiochip7 - 7 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
gpiochip8 - 4 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
gpiochip9 - 2 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 

 

 

I even found this post from @sgjava detailing the line names: XU4 gpio device line names, but as you can see that does not match what I see above.

 

Then I thought maybe I need to enable some overlay or something, as these names should be into Armbian by now?  I was reading the Armbian Device Tree Overlay docs, which say to look in /boot/dtb/overlay, but I could not seem to find anything in there on my ODROID-XU4 other than already compiled .dtb files (no README or anything else, as it states in docs).  I tried to look through Armbian sources to find this information, but I guess I don't know where to look.  I was trying to find the name of the overlay to use for plain old on/off GPIO (as opposed to i2c or others).

 

Any tips will be appreciated.  I think the docs might need to be updated, which I will be happy to do once I can get this working.  I don't think I'm too far off (but could be wrong).

Link to comment
Share on other sites

Hi,

 

I had the same problem, when I started to write a driver for penta-sata HAT of rockpi4

Many docs with contrary informations, must of them absolutely useless :(

 

I don't know anything about odroid, but I can tell you, how I succeeded:

First you need so docs from manufacturer, that tells you the pin numbering. See the formula to calculate the gpio pin names for linux.

 

When you have the right number/name, you can test, whether gpio-handling of that pin works on your system. Here's a nice shellscript template for gpio usage. You'll see, that it uses sysfs.

You might consider sysfs as outdated, but if sysfs works, it works with any linux image (presupposed you have the right dtb-file). Higher level libraries don't work on every linux ...

Therefor I used sysfs in my driver.

Some systems like LE don't have a real bash, so I'd had to code some python ...

 

If the gpio for your pin does not work as expected, try different linux systems. I did so, to narrow the problems and find out, how to deal with hardware expectations. Finally I found out, that dtb from armbian was best to support all lowlevel modules I wanted to use.

I just had to replace the dtb from twisteros with the one from armbian and all things worked as expected :)

 

good luck!

Link to comment
Share on other sites

Thanks for the pointers @tony013, they are very helpful.

 

So, you are saying you did not need to enable any "overlays" as discussed in the Docs I linked above?  Just the stock .dtb that Armbian provided should be enough to already enable the pins from the Linux kernel perspective (in other words, they should be enabled already, in fact perhaps I proved this already with the output of gpioinfo, above)?

 

Also, the docs that manufacturer (ODROID) provide all only show the stupid and useless WiringPi numbers, instead of the actual ones.  Well, at least that I could find so far.  Maybe I need to look again (or look elsewhere, like somewhere in one of these libraries for instance, for the correct/real mappings).

Link to comment
Share on other sites

vor 50 Minuten schrieb TRS-80:

So, you are saying you did not need to enable any "overlays" as discussed in the Docs I linked above?

Right.

 

But - I don't know anything about dtb or gpio or kernel ...

Just succeeded by trial and error.

From all linux images I tested on rockpi4 - armbian multimedia legacy is the only linux, where gpio did not work ootb.

I used overlays, but only to enable pwm for fancontrol. Not for gpio.

Other linux work with config-file to enable specific overlays, but there I haven't to change a bit neither.

 

vor 54 Minuten schrieb TRS-80:

Also, the docs that manufacturer (ODROID) provide all only show the stupid and useless WiringPi numbers, instead of the actual ones. 

Yes, I found lot of docs with wrong pinnumbers too.

I can only recommend, try everything you can.

Well, in my case it was easier, as I wanted to find out the gpio-name of the provided button of the stata tower.

So I only had to enable the gpio pin and look, whether the value changes, when I press the button.

In your case, you want to use the gpiopin as output. That's bit harder.

... but may be, you could attach a button to see, whether you can see value changes at button press.

If so, then you can flip the direction and use it as output pin.

Link to comment
Share on other sites

At some point I had thought about connecting some LED pin by pin, but your way is better, and in retrospective, obvious.

 

In fact, if I am correctly understanding what gpiomon (part of gpiod package) does, it should be a snap just to go around with a properly[0] jumpered button hooked up pin by pin and map everything out.  That will have to wait until I am home again though (working a lot and traveling currently).

 

Then the only remaining question should be whether these are reliably mapped to the same pins all the time?  I really don't feel up to digging through gpiod sources to understand how the enumeration works.  But if it's consistent / reliable, I will post a table with my findings.  And if not, this method is still helpful for the individual who is just trying to hack something together for their own reasons.

 

[0] minding voltage, etc.

Link to comment
Share on other sites

vor 53 Minuten schrieb TRS-80:

In fact, if I am correctly understanding what gpiomon (part of gpiod package) does ...

You won't need external tools.

You can do all you need with tools provided by any system.

 

to enable a gpio pin with number 13:

echo 13 > /sys/class/gpio/export

 

to verify the pin direction:

cat /sys/class/gpio/gpio13/direction

Result should be "in" (the default)

 

to check the gpio pin state (value):

cat /sys/class/gpio/gpio13/value

 

 

vor 53 Minuten schrieb TRS-80:

... it should be a snap just to go around with a properly[0] jumpered button hooked up pin by pin and map everthing out. 

 

[0] minding voltage, etc.

From what I read so far, 3V should be a reasonable voltage for digital pins (1.8V for analog pins).

The button from tower works with a pullup resistor, so default value of unpressed button is "1"

Pressed button results in "0"

 

When your test pin has a default value of "0", check whether active_low is enabled

cat /sys/class/gpio/gpio13/active_low

active_low should have a value of "0"

 

A 10k resistor between gpio-pin and 3V will activate the pin and the switch should connect the pin with GND.

You could solder the resistor and the switch with a cable from connection between switch and resistor, so you have 3 cables. Connect resistor to 3V and switch to GND, then the intermediate cable is your pin-checker.

 

Last not least a little helper script, so you don't have to repeat the cat command:

#!/bin/bash
while grep -q 1 /sys/class/gpio/gpio13/value 
do
  echo -n .
  sleep 1
done
echo 'Ok, got it'

 

Link to comment
Share on other sites

1 hour ago, TRS-80 said:

if I am correctly understanding what gpiomon (part of gpiod package) does

 

I guess you start it once and it just publishes the events as they happen.  No need of shell script, it essentially does the same thing (apparently, as I have yet to try it).

 

Also, I was pretty sure I read that the /sys/class/... interface is (going to be? already is?) deprecated.  It's great to have multiple ways to do things, and maybe you prefer that way.  But it might go away at some point?

 

Being new to it all anyway, I figured I might as well learn the "new / supported" way.  But you wrote a lot of helpful info, so thanks for that.  I think we are hitting the goal / title of the thread from multiple viewpoints, so, good thread.  :)

Link to comment
Share on other sites

vor 1 Stunde schrieb TRS-80:

Also, I was pretty sure I read that the /sys/class/... interface is (going to be? already is?) deprecated. 

Thank you for insisting!

I didn't paid attention to this on your first posting :(

 

u r right - but if the pessimist would have been right, I could not have succeeded in my research.

As I wanted to have driver support for penta-sata on LibreElec, I had to do things, I never wanted to ...

LE does not have gpiod support. So I'm happy that sysfs stil works :)

 

vor 1 Stunde schrieb TRS-80:

I guess you start it once and it just publishes the events as they happen. 

No, I wrote that shellscript just for you as a sample, how to test gpio pins without any use of foreign library ...

If you're interested, my button-class to handle gpio buttons

Link to comment
Share on other sites

Some notes about why gpiod may not be the "right" tool for research and small user ideas ...

 

I was curious about gpiod, installed it on my armbian rockpi4 and did the usual tests. gpioinfo shows all gpio lines and which of them are used ...

 

Now I wanted to see, what gpio says about my penta-sata top-panel button.

According to docs from radxa the button is connected to GPIO4_C2 - and following the pin numbering scheme from radxa, it has number 146

 

libgpiod breaks the numbering scheme and uses line-numbering for each chip.

So I have to select chip4 - which reduces the pin-number from above by 4*32 and leads to 18

Looking at output from gpioinfo, line 18 is used by "sysfs" and gpiomon fails with

gpiomon: error waiting for events: Device or resource busy

My button class from last post works without issues.

If I want to achieve the same with gpiod, I probably have to modify kernel or at least some kernel modules - which is nothing I want to play with :(

Link to comment
Share on other sites

4 hours ago, TRS-80 said:

I figured I might as well learn the "new / supported" way.

From a user space point of view, there is no either or. It depends on which interface is supported by any existing software. If your kernel provides gpiochip and your software requires sysfs, enable "CONFIG_GPIO_SYSFS=y" and your software won't tell any difference between native sysfs. Gpiochip and sysfs interfaces can work simultaneously. New developments should use gpiochip, as it essentially offers more functionality.

But before any IO functionalities can be used, the pin configuration of the SOC must be carried out correct. Almost no SOC uses single pins exclusively for IO, most of the time pins are able to perform several different dedicated functions. Of course, if a pin is configured for a different functionality, it is no longer available for IO at the same time. Gpiochip provides access to all possible IOs of the SOC, but only those really configured by pinctrl for IO are usable. How the pins on your specific device are wired is shown by the schematic. In order for the kernel drivers to know how the device is wired, this must be described in a kernel readable form. This is the reason why devicetree exists as it makes no sense to hard code it for any device.

Link to comment
Share on other sites

vor 19 Minuten schrieb usual user:

You did your calculation wrong.

That may of cause be true.

 

... but I can't follow your calculation.

radxa writes:

Zitat

Rockchip RK3399 GPIO has 5 banks, GPIO0 to GPIO4, each bank has 32pins

 

GPIO4_D5 = 4*32 + 3*8 + 5 = 157 (A=0, B=1, C=2, D=3)

In my case GPIO4_C2 is 146 (you can find that number on the wiki-page from above)

... so I "only" need to take out the chip-calculation, which is 4*32 = 128

So 146 - 128 = 18

 

... and forward calculation leads to: C (2) * 8 + Pin 2 => 16 + 2 = 18

 

Link to comment
Share on other sites

50 minutes ago, tony013 said:

but I can't follow your calculation.

You are absolutely right, I am off by one.
A starts at 0 not 1
Sory for the noise.

 

2 hours ago, tony013 said:

line 18 is used by "sysfs" and gpiomon fails with


gpiomon: error waiting for events: Device or resource busy

Your IO is exported by sysfs interface at that time, which probably prevents the use of gpiod. Only one user allowed at a time. Can you retry without sysfs export?

Link to comment
Share on other sites

vor 24 Minuten schrieb usual user:

Your IO is exported by sysfs interface at that time, which probably prevents the use of gpiod. Only one user allowed at a time.

Interestingly the pwm, which I use for fan control is not recognized by gpioinfo.

Fan is attached to Pin 33, which is GPIO2_B4 or pin-num 76...

So I looked at line 12 from chip2, but that is noted as unused ...

 

vor 28 Minuten schrieb usual user:

Can you retry without sysfs export?

Of cause.

I did it - and the result is unbelievable ;)

command: gpiomon gpiochip4 18

Spoiler

event: FALLING EDGE offset: 18 timestamp: [     175.193702174]
event:  RISING EDGE offset: 18 timestamp: [     175.216348958]
event: FALLING EDGE offset: 18 timestamp: [     175.220979585]
event:  RISING EDGE offset: 18 timestamp: [     175.235161388]
event: FALLING EDGE offset: 18 timestamp: [     175.241295014]
event:  RISING EDGE offset: 18 timestamp: [     175.255088599]
event: FALLING EDGE offset: 18 timestamp: [     175.261979703]
event:  RISING EDGE offset: 18 timestamp: [     175.275359110]
event: FALLING EDGE offset: 18 timestamp: [     175.282158045]
event:  RISING EDGE offset: 18 timestamp: [     175.295347280]
event: FALLING EDGE offset: 18 timestamp: [     175.302631854]
event:  RISING EDGE offset: 18 timestamp: [     175.318293323]
event: FALLING EDGE offset: 18 timestamp: [     175.318306740]
event:  RISING EDGE offset: 18 timestamp: [     175.318320157]
event:  RISING EDGE offset: 18 timestamp: [     175.318332116]
event:  RISING EDGE offset: 18 timestamp: [     175.318343783]
event:  RISING EDGE offset: 18 timestamp: [     175.318360408]
event: FALLING EDGE offset: 18 timestamp: [     175.321495035]
event: FALLING EDGE offset: 18 timestamp: [     175.384892556]
event: FALLING EDGE offset: 18 timestamp: [     175.384940391]
event: FALLING EDGE offset: 18 timestamp: [     175.385011560]
event: FALLING EDGE offset: 18 timestamp: [     175.385022060]
event: FALLING EDGE offset: 18 timestamp: [     175.385033727]
event: FALLING EDGE offset: 18 timestamp: [     175.385045102]
event: FALLING EDGE offset: 18 timestamp: [     175.385056769]
event: FALLING EDGE offset: 18 timestamp: [     175.385073103]
event: FALLING EDGE offset: 18 timestamp: [     175.385111896]
event: FALLING EDGE offset: 18 timestamp: [     175.385122396]
event: FALLING EDGE offset: 18 timestamp: [     175.385133480]
event: FALLING EDGE offset: 18 timestamp: [     175.385144855]
event: FALLING EDGE offset: 18 timestamp: [     175.385156522]
event: FALLING EDGE offset: 18 timestamp: [     175.385170522]
event: FALLING EDGE offset: 18 timestamp: [     175.385181606]
event: FALLING EDGE offset: 18 timestamp: [     175.385193273]
event: FALLING EDGE offset: 18 timestamp: [     175.385223024]
event: FALLING EDGE offset: 18 timestamp: [     175.385234107]
event: FALLING EDGE offset: 18 timestamp: [     175.385247816]
event: FALLING EDGE offset: 18 timestamp: [     175.385259191]
event: FALLING EDGE offset: 18 timestamp: [     175.385298859]
event: FALLING EDGE offset: 18 timestamp: [     175.385349611]
event: FALLING EDGE offset: 18 timestamp: [     175.385403570]
event:  RISING EDGE offset: 18 timestamp: [     175.385473572]
event:  RISING EDGE offset: 18 timestamp: [     175.385522282]
event:  RISING EDGE offset: 18 timestamp: [     175.385697578]
event:  RISING EDGE offset: 18 timestamp: [     175.385750955]
event:  RISING EDGE offset: 18 timestamp: [     175.385839624]
event:  RISING EDGE offset: 18 timestamp: [     175.385869958]
event:  RISING EDGE offset: 18 timestamp: [     175.385923334]
event: FALLING EDGE offset: 18 timestamp: [     175.388275982]
event: FALLING EDGE offset: 18 timestamp: [     175.388291441]
event: FALLING EDGE offset: 18 timestamp: [     175.390268703]
event: FALLING EDGE offset: 18 timestamp: [     175.390295537]
event: FALLING EDGE offset: 18 timestamp: [     175.390307787]
event: FALLING EDGE offset: 18 timestamp: [     175.390320621]
event: FALLING EDGE offset: 18 timestamp: [     175.390332288]
event: FALLING EDGE offset: 18 timestamp: [     175.390343955]
event:  RISING EDGE offset: 18 timestamp: [     175.390384790]
event:  RISING EDGE offset: 18 timestamp: [     175.390395582]
event:  RISING EDGE offset: 18 timestamp: [     175.390411915]
event:  RISING EDGE offset: 18 timestamp: [     175.390427957]
event: FALLING EDGE offset: 18 timestamp: [     175.865613754]
event:  RISING EDGE offset: 18 timestamp: [     175.897626210]
event:  RISING EDGE offset: 18 timestamp: [     175.898679448]
event:  RISING EDGE offset: 18 timestamp: [     175.898699865]
event: FALLING EDGE offset: 18 timestamp: [     175.898711823]
event:  RISING EDGE offset: 18 timestamp: [     175.898721449]
event: FALLING EDGE offset: 18 timestamp: [     175.898731074]
event: FALLING EDGE offset: 18 timestamp: [     175.898740408]
event: FALLING EDGE offset: 18 timestamp: [     175.898749741]
event: FALLING EDGE offset: 18 timestamp: [     175.898760241]
event: FALLING EDGE offset: 18 timestamp: [     175.898769575]
event: FALLING EDGE offset: 18 timestamp: [     175.898780367]
event: FALLING EDGE offset: 18 timestamp: [     175.898789701]
event: FALLING EDGE offset: 18 timestamp: [     175.898808368]
event: FALLING EDGE offset: 18 timestamp: [     175.898873120]
event:  RISING EDGE offset: 18 timestamp: [     175.915135730]
event: FALLING EDGE offset: 18 timestamp: [     175.921932624]
event:  RISING EDGE offset: 18 timestamp: [     175.934194625]
event: FALLING EDGE offset: 18 timestamp: [     175.942493934]
event:  RISING EDGE offset: 18 timestamp: [     175.953832494]
event: FALLING EDGE offset: 18 timestamp: [     175.962845240]
event:  RISING EDGE offset: 18 timestamp: [     175.973407361]
event:  RISING EDGE offset: 18 timestamp: [     175.973412028]
event: FALLING EDGE offset: 18 timestamp: [     175.983014832]
event:  RISING EDGE offset: 18 timestamp: [     175.993152275]
event: FALLING EDGE offset: 18 timestamp: [     176.003214174]
event:  RISING EDGE offset: 18 timestamp: [     176.013069276]
event: FALLING EDGE offset: 18 timestamp: [     176.023134676]
event:  RISING EDGE offset: 18 timestamp: [     176.032895276]
event: FALLING EDGE offset: 18 timestamp: [     176.043109429]
event:  RISING EDGE offset: 18 timestamp: [     176.052728567]
event: FALLING EDGE offset: 18 timestamp: [     176.063099641]
event:  RISING EDGE offset: 18 timestamp: [     176.072556899]
event: FALLING EDGE offset: 18 timestamp: [     176.083043769]
event:  RISING EDGE offset: 18 timestamp: [     176.092405649]
event: FALLING EDGE offset: 18 timestamp: [     176.103067815]
event:  RISING EDGE offset: 18 timestamp: [     176.112301942]
event:  RISING EDGE offset: 18 timestamp: [     176.112314192]
event: FALLING EDGE offset: 18 timestamp: [     176.123070569]
event:  RISING EDGE offset: 18 timestamp: [     176.332251734]
event: FALLING EDGE offset: 18 timestamp: [     176.342851773]
event:  RISING EDGE offset: 18 timestamp: [     176.352522245]
event: FALLING EDGE offset: 18 timestamp: [     176.364046893]
event:  RISING EDGE offset: 18 timestamp: [     176.374721309]
event: FALLING EDGE offset: 18 timestamp: [     177.504150203]
event:  RISING EDGE offset: 18 timestamp: [     177.515901482]
event: FALLING EDGE offset: 18 timestamp: [     177.523356977]
event: FALLING EDGE offset: 18 timestamp: [     177.579378631]
event: FALLING EDGE offset: 18 timestamp: [     177.579392631]
event: FALLING EDGE offset: 18 timestamp: [     177.579419757]
event: FALLING EDGE offset: 18 timestamp: [     177.579425299]
event: FALLING EDGE offset: 18 timestamp: [     177.579446007]
event: FALLING EDGE offset: 18 timestamp: [     177.579449508]
event: FALLING EDGE offset: 18 timestamp: [     177.579453008]
event: FALLING EDGE offset: 18 timestamp: [     177.579457091]
event: FALLING EDGE offset: 18 timestamp: [     177.579464383]
event:  RISING EDGE offset: 18 timestamp: [     177.579471675]
event: FALLING EDGE offset: 18 timestamp: [     177.579485092]
event:  RISING EDGE offset: 18 timestamp: [     177.579490050]
event: FALLING EDGE offset: 18 timestamp: [     177.579493550]
event: FALLING EDGE offset: 18 timestamp: [     177.579497342]
event: FALLING EDGE offset: 18 timestamp: [     177.579508717]
event: FALLING EDGE offset: 18 timestamp: [     177.579512218]
event:  RISING EDGE offset: 18 timestamp: [     177.579515718]
event: FALLING EDGE offset: 18 timestamp: [     177.579519218]
event: FALLING EDGE offset: 18 timestamp: [     177.579523010]
event: FALLING EDGE offset: 18 timestamp: [     177.579526801]
event:  RISING EDGE offset: 18 timestamp: [     177.579530301]
event: FALLING EDGE offset: 18 timestamp: [     177.579534093]
event: FALLING EDGE offset: 18 timestamp: [     177.579537593]
event: FALLING EDGE offset: 18 timestamp: [     177.579546344]
event:  RISING EDGE offset: 18 timestamp: [     177.579549552]
event: FALLING EDGE offset: 18 timestamp: [     177.579554219]
event:  RISING EDGE offset: 18 timestamp: [     177.579565302]
event:  RISING EDGE offset: 18 timestamp: [     177.579574344]
event:  RISING EDGE offset: 18 timestamp: [     177.579593595]
event:  RISING EDGE offset: 18 timestamp: [     177.579610220]
event:  RISING EDGE offset: 18 timestamp: [     177.579630346]
event:  RISING EDGE offset: 18 timestamp: [     177.579637638]
event:  RISING EDGE offset: 18 timestamp: [     177.579668555]
event:  RISING EDGE offset: 18 timestamp: [     177.579684014]
event:  RISING EDGE offset: 18 timestamp: [     177.579707056]
event:  RISING EDGE offset: 18 timestamp: [     177.579743516]
event:  RISING EDGE offset: 18 timestamp: [     177.579814976]
event:  RISING EDGE offset: 18 timestamp: [     177.579834226]
event:  RISING EDGE offset: 18 timestamp: [     177.579853477]
event:  RISING EDGE offset: 18 timestamp: [     177.579875936]
event:  RISING EDGE offset: 18 timestamp: [     177.579925229]
event:  RISING EDGE offset: 18 timestamp: [     177.579945938]
event:  RISING EDGE offset: 18 timestamp: [     177.579963438]
event:  RISING EDGE offset: 18 timestamp: [     177.579981814]
event:  RISING EDGE offset: 18 timestamp: [     177.580000773]
event:  RISING EDGE offset: 18 timestamp: [     177.580038690]
event:  RISING EDGE offset: 18 timestamp: [     177.580046274]
event:  RISING EDGE offset: 18 timestamp: [     177.580050649]
event:  RISING EDGE offset: 18 timestamp: [     177.580055024]
event:  RISING EDGE offset: 18 timestamp: [     177.580072233]
event:  RISING EDGE offset: 18 timestamp: [     177.580092358]
event:  RISING EDGE offset: 18 timestamp: [     177.580104900]
event:  RISING EDGE offset: 18 timestamp: [     177.580131151]
event:  RISING EDGE offset: 18 timestamp: [     177.580145152]
event:  RISING EDGE offset: 18 timestamp: [     177.580166735]
event:  RISING EDGE offset: 18 timestamp: [     177.580179277]
event: FALLING EDGE offset: 18 timestamp: [     177.580199986]
event: FALLING EDGE offset: 18 timestamp: [     177.580252779]
event: FALLING EDGE offset: 18 timestamp: [     177.580268530]
event: FALLING EDGE offset: 18 timestamp: [     177.580291281]
event: FALLING EDGE offset: 18 timestamp: [     177.580305573]
event: FALLING EDGE offset: 18 timestamp: [     177.580328032]
event: FALLING EDGE offset: 18 timestamp: [     177.580347574]
event: FALLING EDGE offset: 18 timestamp: [     177.580371783]
event: FALLING EDGE offset: 18 timestamp: [     177.590954613]
event: FALLING EDGE offset: 18 timestamp: [     177.590989614]
event:  RISING EDGE offset: 18 timestamp: [     177.591000114]
event:  RISING EDGE offset: 18 timestamp: [     177.591004198]
event: FALLING EDGE offset: 18 timestamp: [     177.591013240]
event:  RISING EDGE offset: 18 timestamp: [     177.591017323]
event: FALLING EDGE offset: 18 timestamp: [     177.591026657]
event:  RISING EDGE offset: 18 timestamp: [     177.591030740]
event:  RISING EDGE offset: 18 timestamp: [     177.591040657]
event:  RISING EDGE offset: 18 timestamp: [     177.591055532]
event:  RISING EDGE offset: 18 timestamp: [     177.591059616]
event: FALLING EDGE offset: 18 timestamp: [     178.244940454]
event:  RISING EDGE offset: 18 timestamp: [     178.256360974]
event: FALLING EDGE offset: 18 timestamp: [     178.261726037]
event:  RISING EDGE offset: 18 timestamp: [     178.274053373]
event: FALLING EDGE offset: 18 timestamp: [     178.282787278]
event:  RISING EDGE offset: 18 timestamp: [     178.293781078]
event: FALLING EDGE offset: 18 timestamp: [     178.303274212]
event:  RISING EDGE offset: 18 timestamp: [     178.313289444]
event: FALLING EDGE offset: 18 timestamp: [     178.323016501]
event:  RISING EDGE offset: 18 timestamp: [     178.332588678]
event: FALLING EDGE offset: 18 timestamp: [     178.342973170]
event:  RISING EDGE offset: 18 timestamp: [     178.352253673]
event: FALLING EDGE offset: 18 timestamp: [     178.363029009]
event:  RISING EDGE offset: 18 timestamp: [     178.372270719]
event: FALLING EDGE offset: 18 timestamp: [     178.383310020]
event:  RISING EDGE offset: 18 timestamp: [     178.392885990]
event: FALLING EDGE offset: 18 timestamp: [     178.403400568]
event:  RISING EDGE offset: 18 timestamp: [     178.413429800]
event: FALLING EDGE offset: 18 timestamp: [     178.423533409]
event:  RISING EDGE offset: 18 timestamp: [     178.435154601]
event: FALLING EDGE offset: 18 timestamp: [     178.443933132]
event:  RISING EDGE offset: 18 timestamp: [     178.454466670]
event: FALLING EDGE offset: 18 timestamp: [     178.464773576]
event: FALLING EDGE offset: 18 timestamp: [     178.475766501]
event:  RISING EDGE offset: 18 timestamp: [     178.475788960]
event: FALLING EDGE offset: 18 timestamp: [     178.475799752]
event: FALLING EDGE offset: 18 timestamp: [     178.475811419]
event:  RISING EDGE offset: 18 timestamp: [     178.475853128]
event:  RISING EDGE offset: 18 timestamp: [     178.475868587]
event:  RISING EDGE offset: 18 timestamp: [     178.482451975]
event:  RISING EDGE offset: 18 timestamp: [     178.482474142]
event:  RISING EDGE offset: 18 timestamp: [     178.482484642]
event: FALLING EDGE offset: 18 timestamp: [     178.482528977]
event: FALLING EDGE offset: 18 timestamp: [     178.482539477]
event: FALLING EDGE offset: 18 timestamp: [     178.482551144]
event: FALLING EDGE offset: 18 timestamp: [     178.482562520]
event: FALLING EDGE offset: 18 timestamp: [     178.482574187]
event: FALLING EDGE offset: 18 timestamp: [     178.482590812]
event: FALLING EDGE offset: 18 timestamp: [     178.488400679]
event: FALLING EDGE offset: 18 timestamp: [     178.488427805]
event: FALLING EDGE offset: 18 timestamp: [     178.488438597]
event:  RISING EDGE offset: 18 timestamp: [     178.488451430]
event:  RISING EDGE offset: 18 timestamp: [     178.488467472]
event: FALLING EDGE offset: 18 timestamp: [     178.488479139]
event:  RISING EDGE offset: 18 timestamp: [     178.488491390]
event:  RISING EDGE offset: 18 timestamp: [     178.488503057]
event:  RISING EDGE offset: 18 timestamp: [     178.488557308]
event:  RISING EDGE offset: 18 timestamp: [     178.488603393]
event:  RISING EDGE offset: 18 timestamp: [     178.488613893]
event: FALLING EDGE offset: 18 timestamp: [     178.546438971]
event:  RISING EDGE offset: 18 timestamp: [     178.555031705]
event: FALLING EDGE offset: 18 timestamp: [     178.563127426]
event:  RISING EDGE offset: 18 timestamp: [     178.575401969]
event: FALLING EDGE offset: 18 timestamp: [     178.582575706]
event:  RISING EDGE offset: 18 timestamp: [     178.594806207]
event: FALLING EDGE offset: 18 timestamp: [     178.602583127]
event:  RISING EDGE offset: 18 timestamp: [     178.613862768]
event: FALLING EDGE offset: 18 timestamp: [     178.622871722]
event:  RISING EDGE offset: 18 timestamp: [     178.634120738]
event: FALLING EDGE offset: 18 timestamp: [     178.643045981]
event:  RISING EDGE offset: 18 timestamp: [     178.653734398]
event: FALLING EDGE offset: 18 timestamp: [     178.662930898]
event:  RISING EDGE offset: 18 timestamp: [     178.673980700]
event: FALLING EDGE offset: 18 timestamp: [     178.683213952]
event:  RISING EDGE offset: 18 timestamp: [     178.693526691]
event: FALLING EDGE offset: 18 timestamp: [     178.703090411]
event:  RISING EDGE offset: 18 timestamp: [     178.713112934]
event: FALLING EDGE offset: 18 timestamp: [     178.723060497]
event:  RISING EDGE offset: 18 timestamp: [     178.733035186]
event: FALLING EDGE offset: 18 timestamp: [     178.743070835]
event:  RISING EDGE offset: 18 timestamp: [     178.752972896]
event: FALLING EDGE offset: 18 timestamp: [     178.763054338]
event:  RISING EDGE offset: 18 timestamp: [     178.773044194]
event: FALLING EDGE offset: 18 timestamp: [     178.783031716]
event:  RISING EDGE offset: 18 timestamp: [     178.793224578]
event: FALLING EDGE offset: 18 timestamp: [     178.802973510]
event:  RISING EDGE offset: 18 timestamp: [     178.813009451]
event: FALLING EDGE offset: 18 timestamp: [     178.822944764]
event:  RISING EDGE offset: 18 timestamp: [     178.832877743]
event: FALLING EDGE offset: 18 timestamp: [     178.843065063]
event:  RISING EDGE offset: 18 timestamp: [     178.852684783]
event: FALLING EDGE offset: 18 timestamp: [     178.863014732]
event:  RISING EDGE offset: 18 timestamp: [     178.872625994]
event: FALLING EDGE offset: 18 timestamp: [     178.883010777]
event:  RISING EDGE offset: 18 timestamp: [     178.892592872]
event: FALLING EDGE offset: 18 timestamp: [     178.902925154]
event:  RISING EDGE offset: 18 timestamp: [     178.912567625]
event: FALLING EDGE offset: 18 timestamp: [     178.922956200]
event:  RISING EDGE offset: 18 timestamp: [     178.932694341]
event: FALLING EDGE offset: 18 timestamp: [     178.943003872]
event:  RISING EDGE offset: 18 timestamp: [     178.952710220]
event: FALLING EDGE offset: 18 timestamp: [     178.963138171]
event:  RISING EDGE offset: 18 timestamp: [     178.972762851]
event: FALLING EDGE offset: 18 timestamp: [     178.982992463]
event:  RISING EDGE offset: 18 timestamp: [     178.992889566]
event: FALLING EDGE offset: 18 timestamp: [     179.003206681]
event:  RISING EDGE offset: 18 timestamp: [     179.012799276]
event: FALLING EDGE offset: 18 timestamp: [     179.023012847]
event:  RISING EDGE offset: 18 timestamp: [     179.032705778]
event: FALLING EDGE offset: 18 timestamp: [     179.042992850]
event:  RISING EDGE offset: 18 timestamp: [     179.052674114]
event: FALLING EDGE offset: 18 timestamp: [     179.063025063]
event: FALLING EDGE offset: 18 timestamp: [     179.063066189]
event:  RISING EDGE offset: 18 timestamp: [     179.072745120]
event: FALLING EDGE offset: 18 timestamp: [     179.082797102]
event:  RISING EDGE offset: 18 timestamp: [     179.092881753]
event: FALLING EDGE offset: 18 timestamp: [     179.102879192]
event:  RISING EDGE offset: 18 timestamp: [     179.112685293]
event: FALLING EDGE offset: 18 timestamp: [     179.122904697]
event:  RISING EDGE offset: 18 timestamp: [     179.132617170]
event: FALLING EDGE offset: 18 timestamp: [     179.142897534]
event:  RISING EDGE offset: 18 timestamp: [     179.152558381]
event: FALLING EDGE offset: 18 timestamp: [     179.162896204]
event:  RISING EDGE offset: 18 timestamp: [     179.172538676]
event: FALLING EDGE offset: 18 timestamp: [     179.182917042]
event:  RISING EDGE offset: 18 timestamp: [     179.192517512]
event: FALLING EDGE offset: 18 timestamp: [     179.202914838]
event:  RISING EDGE offset: 18 timestamp: [     179.212492849]
event: FALLING EDGE offset: 18 timestamp: [     179.222934509]
event:  RISING EDGE offset: 18 timestamp: [     179.232448935]
event: FALLING EDGE offset: 18 timestamp: [     179.242978972]
event:  RISING EDGE offset: 18 timestamp: [     179.252436814]
event: FALLING EDGE offset: 18 timestamp: [     179.263145356]
event:  RISING EDGE offset: 18 timestamp: [     179.273024084]
event: FALLING EDGE offset: 18 timestamp: [     179.283637540]
event:  RISING EDGE offset: 18 timestamp: [     179.293549810]

I counted the lines: 308 events for ONE single button press.

Well the button is not of good quality and some kind of flaky, but that many events? Puh

Now I understand, why I had so many problems in detecting the right button states ... :D

Link to comment
Share on other sites

1 hour ago, tony013 said:

Interestingly the pwm, which I use for fan control is not recognized by gpioinfo.

Of course not, it's probably pinmuxed on special pwm functionality and therefore no longer available for GPIO.

 

1 hour ago, tony013 said:

Well the button is not of good quality and some kind of flaky, but that many events? Puh

Now I understand, why I had so many problems in detecting the right button states ... :D

For this there is the gpio-keys driver in the kernel. I would add something along this lines to the devicetree and leave anything else to the input event system:

#include <dt-bindings/input/linux-event-codes.h>

gpio-keys {
        compatible = "gpio-keys";
        autorepeat;

        power {
                debounce-interval = <100>;
                gpios = <&gpio4 RK_PC2 GPIO_ACTIVE_LOW>;
                label = "Power-key";
                linux,code = <KEY_POWER>;
                wakeup-source;
        };
};

I left out the pinmux settings as your GPIO already seems to be set up properly.

Link to comment
Share on other sites

vor 38 Minuten schrieb usual user:

Of course not, it's probably pinmuxed on special pwm functionality and therefore no longer available for GPIO.

Sorry, but I don't understand your reply.

You write that the pin should not be available for GPIO.

I completely agree with you.

But not with the output of gpioinfo! - gpioinfo states the pin as unused (and for so as available)

 

Of cause - the pin is muxed - according radxa docs, the fan pwm line is the clock signal of a spi-channel

 

vor 41 Minuten schrieb usual user:

I would add something along this lines to the devicetree and leave anything else to the input event system:

Hm, that looks of cause very interesting.

Is that an overlay or what is it? Who processes that file?

 

I would not have that key labeled "Power-key".

... anyway: does that "wakeup-source" mean, that the rockpi4 is able to wakeup on keypress after issuing a "poweroff"?

 

and last not least - how can I act on key-events in userspace?

Actually I recognize 3 different button states in my driver: single key press, double press and long hold press. Together with the config file, it is possible to call a python function, or a system process

So I can execute 3 different things with a single button.

Is that possible with gpio-keys too?

Link to comment
Share on other sites

3 hours ago, tony013 said:

gpioinfo states the pin as unused

As "not used for GPIO", but not automatically available if the SOC has configured it for another function. This situation can change at runtime if, for example, one driver is unloaded and another is loaded. It is only available for GPIO if the pinctrl is set up for GPIO functinality for that pin. And this requires suitable properties in devicetree. Be it native in the base dtb or applied as overlay.

 

3 hours ago, tony013 said:

Is that an overlay or what is it? Who processes that file?

It is a devicetree source code snippet, how you apply it is up to you. You can add it to your source or write it as an overlay and then apply it dynamically or statically.

 

3 hours ago, tony013 said:

I would not have that key labeled "Power-key".

It's the label showing up in the listing:

Spoiler


        line   0:      unnamed        unused   input  active-high
        line   1:      unnamed   "vcc3v0-sd"  output  active-high [used]
        line   2:      unnamed        unused   input  active-high
        line   3:      unnamed        unused   input  active-high
        line   4:      unnamed "host-wakeup"   input  active-high [used]
        line   5:      unnamed   "Power-key"   input  active-low  [used]
        line   6:      unnamed "ir-receiver"   input  active-low  [used]
        line   7:      unnamed          "cd"   input  active-low  [used]
        line   8:      unnamed        unused   input  active-high
        line   9:      unnamed    "shutdown"  output  active-high [used]
        line  10:      unnamed       "reset"  output  active-low  [used]
        line  11:      unnamed        unused   input  active-high
        line  12:      unnamed        unused   input  active-high
        line  13:      unnamed  "status_led"  output  active-high [used]
        line  14:      unnamed        unused   input  active-high
        line  15:      unnamed        unused   input  active-high
        line  16:      unnamed        unused   input  active-high

 

 

3 hours ago, tony013 said:

... anyway: does that "wakeup-source" mean, that the rockpi4 is able to wakeup on keypress after issuing a "poweroff"?

Only if this line is also wired up to the pmic. When the power is cut off, no code is executed any longer that could initiate actions.

Spoiler

screenshot.png.04c3a9d6eba73f0397257d46b530ccd8.png

 

3 hours ago, tony013 said:

and last not least - how can I act on key-events in userspace?

As with any other keycode that the input event system outputs. If you had configured "linux,code = <KEY_A>;", you would not be able to tell if you have pressed the button or the "A" key on your keyboard.

Link to comment
Share on other sites

On 6/1/2021 at 2:34 PM, TRS-80 said:

(I feel a simple shell script with gpiod commands, ex. gpioset should suffice for my very basic needs here)

Whereas Python is an interpreter language too, right?

 

 

Apart from that, I read on below Github:

On 6/1/2021 at 2:34 PM, TRS-80 said:

including the official ODROID-XU4 wiki info about pin numbering

  • Cross platform MMIO GPIO that doesn't require one off code for each board. Only a simple property file is required to map registers.

Sounds to me like do it once for me and the armbian community (sending in your findings), but I may be totally wrong.

https://github.com/sgjava/java-periphery

Link to comment
Share on other sites

I have written an overlay for my device to assign names to the GPIO lines wich are wired up to the extention connector. This facilitates the identification of the GPIOs to be selected.

Spoiler

gpiochip0 - 32 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed  "vcc3v0-sd"  output  active-high [used]
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed "host-wakeup" input active-high [used]
	line   5:      unnamed "GPIO Key Power" input active-low [used]
	line   6:      unnamed "ir-receiver" input active-low [used]
	line   7:      unnamed         "cd"   input   active-low [used]
	line   8:      unnamed       unused   input  active-high 
	line   9:      unnamed   "shutdown"  output  active-high [used]
	line  10:      unnamed      "reset"  output   active-low [used]
	line  11:      unnamed       unused   input  active-high 
	line  12:      unnamed       unused   input  active-high 
	line  13:      unnamed "status_led"  output  active-high [used]
	line  14:      unnamed       unused   input  active-high 
	line  15:      unnamed       unused   input  active-high 
	line  16:      unnamed       unused   input  active-high 
	line  17:      unnamed       unused   input  active-high 
	line  18:      unnamed       unused   input  active-high 
	line  19:      unnamed       unused   input  active-high 
	line  20:      unnamed       unused   input  active-high 
	line  21:      unnamed       unused   input  active-high 
	line  22:      unnamed       unused   input  active-high 
	line  23:      unnamed       unused   input  active-high 
	line  24:      unnamed       unused   input  active-high 
	line  25:      unnamed       unused   input  active-high 
	line  26:      unnamed       unused   input  active-high 
	line  27:      unnamed       unused   input  active-high 
	line  28:      unnamed       unused   input  active-high 
	line  29:      unnamed       unused   input  active-high 
	line  30:      unnamed       unused   input  active-high 
	line  31:      unnamed       unused   input  active-high 
gpiochip1 - 32 lines:
	line   0:    "con1-07"       unused   input  active-high 
	line   1:    "con1-11"       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:    "con1-13"       unused   input  active-high 
	line   4:    "con1-15"       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
	line   8:      unnamed       unused   input  active-high 
	line   9:      unnamed       unused   input  active-high 
	line  10:      unnamed       unused   input  active-high 
	line  11:      unnamed       unused   input  active-high 
	line  12:      unnamed       unused   input  active-high 
	line  13:      unnamed       unused   input  active-high 
	line  14:      unnamed       unused   input  active-high 
	line  15:      unnamed       unused   input  active-high 
	line  16:      unnamed       unused   input  active-high 
	line  17:      unnamed       unused   input  active-high 
	line  18:    "con1-12"       unused   input  active-high 
	line  19:      unnamed       unused   input  active-high 
	line  20:      unnamed       unused   input  active-high 
	line  21:      unnamed       unused   input  active-high 
	line  22:    "con1-16"       unused   input  active-high 
	line  23:    "con1-18"       unused   input  active-high 
	line  24:    "con1-22"       unused   input  active-high 
	line  25:      unnamed       unused   input  active-high 
	line  26:      unnamed       unused   input  active-high 
	line  27:      unnamed       unused   input  active-high 
	line  28:      unnamed       unused   input  active-high 
	line  29:      unnamed       unused   input  active-high 
	line  30:      unnamed       unused   input  active-high 
	line  31:      unnamed       unused   input  active-high 
gpiochip2 - 32 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused  output  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
	line   8:      unnamed       unused   input  active-high 
	line   9:      unnamed       unused   input  active-high 
	line  10:      unnamed       unused   input  active-high 
	line  11:      unnamed       unused   input  active-high 
	line  12:      unnamed       unused   input  active-high 
	line  13:      unnamed       unused   input  active-high 
	line  14:      unnamed       unused   input  active-high 
	line  15:      unnamed       unused   input  active-high 
	line  16:      unnamed       unused   input  active-high 
	line  17:      unnamed       unused   input  active-high 
	line  18:      unnamed       unused   input  active-high 
	line  19:      unnamed       unused   input  active-high 
	line  20:      unnamed       unused   input  active-high 
	line  21:      unnamed       unused   input  active-high 
	line  22:      unnamed       unused   input  active-high 
	line  23:      unnamed       unused   input  active-high 
	line  24:      unnamed       unused   input  active-high 
	line  25:      unnamed       unused   input  active-high 
	line  26:      unnamed "device-wakeup" output active-high [used]
	line  27:      unnamed       unused   input  active-high 
	line  28:      unnamed       unused   input  active-high 
	line  29:      unnamed       unused   input  active-high 
	line  30:      unnamed       unused   input  active-high 
	line  31:      unnamed       unused   input  active-high 
gpiochip3 - 32 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
	line   8:      unnamed       unused   input  active-high 
	line   9:      unnamed       unused   input  active-high 
	line  10:      unnamed       unused   input  active-high 
	line  11:      unnamed       unused   input  active-high 
	line  12:      unnamed       unused   input  active-high 
	line  13:      unnamed       unused   input  active-high 
	line  14:      unnamed       unused   input  active-high 
	line  15:      unnamed  "PHY reset"  output   active-low [used]
	line  16:      unnamed       unused   input  active-high 
	line  17:      unnamed       unused   input  active-high 
	line  18:      unnamed       unused   input  active-high 
	line  19:      unnamed       unused   input  active-high 
	line  20:      unnamed       unused   input  active-high 
	line  21:      unnamed       unused   input  active-high 
	line  22:      unnamed       unused   input  active-high 
	line  23:      unnamed       unused   input  active-high 
	line  24:      unnamed       unused   input  active-high 
	line  25:      unnamed       unused   input  active-high 
	line  26:      unnamed       unused   input  active-high 
	line  27:      unnamed       unused   input  active-high 
	line  28:    "con1-37"       unused   input  active-high 
	line  29:    "con1-38"       unused   input  active-high 
	line  30:    "con1-40"       unused   input  active-high 
	line  31:      unnamed       unused   input  active-high 
gpiochip4 - 32 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
	line   8:      unnamed       unused   input  active-high 
	line   9:      unnamed       unused   input  active-high 
	line  10:      unnamed       unused   input  active-high 
	line  11:      unnamed       unused   input  active-high 
	line  12:      unnamed       unused   input  active-high 
	line  13:      unnamed       unused   input  active-high 
	line  14:      unnamed       unused   input  active-high 
	line  15:      unnamed       unused   input  active-high 
	line  16:    "con1-10"       unused   input  active-high 
	line  17:    "con1-08"       unused   input  active-high 
	line  18:      unnamed       unused   input  active-high 
	line  19:      unnamed       unused   input  active-high 
	line  20:      unnamed       unused   input  active-high 
	line  21:    "con1-26"       unused   input  active-high 
	line  22:      unnamed       unused   input  active-high 
	line  23:      unnamed       unused   input  active-high 
	line  24:      unnamed       unused   input  active-high 
	line  25:      unnamed       unused   input  active-high 
	line  26:      unnamed "vbus-typec"  output  active-high [used]
	line  27:      unnamed       unused  output  active-high 
	line  28:      unnamed "Headphone detection" input active-high [used]
	line  29:      unnamed       unused   input  active-high 
	line  30:      unnamed       unused   input  active-high 
	line  31:      unnamed       unused   input  active-high 

 

I have also written a rk3399-rock-pi-4 one. It can be staticly applied to the base dtb like this:

[root]# mv rk3399-rock-pi-4a.dtb rk3399-rock-pi-4a.dtb.orig
[root]# fdtoverlay --input rk3399-rock-pi-4a.dtb.orig --output rk3399-rock-pi-4a.dtb rk3399-rock-pi-4-con1.dtbo

The wiring of the GPIOs differs substantially between my device and the rock-pi, but because of the chosen name format (con1-## with ## = connector pin number) this is not relevant for user space any longer. E. g.: "gpioget $(gpiofind con1-11)" always finds the correct line to request the state of pin 11 of the connector. Of course only GPIO supported pins can be used, e. g. my device has way less pins capable of GPIO than the rock-pi. Therefore, con1-03 may be for rock-pi, but never available for my device.
The only remaining task is now to create one-time corresponding overlays for all devices to be supported and to apply them accordingly.

rk3399-rock-pi-4-con1.dtbo

Link to comment
Share on other sites

vor 13 Stunden schrieb lanefu:

In case its help i made a helper script for managing relays

Thank you for showing your script.

Beautiful work! I love verbose coding :)

 

vor 3 Stunden schrieb usual user:

I have also written a rk3399-rock-pi-4 one. It can be staticly applied to the base dtb like this

Thanks for that command!

Haven't read about fdtoverlay before.

That's a very nice way (with little additional scripting) to enable overlays for cases where dynamically overloading is not supported.

 

vor 3 Stunden schrieb usual user:

because of the chosen name format (con1-## with ## = connector pin number) this is not relevant for user space any longer. E. g.: "gpioget $(gpiofind con1-11)" always finds the correct line

Good job!

This is by far the first reason for using "new" gpiod layer.

Your key sample didn't convince me. I prefer "my" way of button handling. But finding pins by pin-name is sexy :)

 

Do you mind to publish the source of your overlay?

I asked dtc for the source, and it looks terrible. Can't believe, that you had to write such ugly stuff.

 

Do you know about a way to find conflicts between muxed modules, which share the same pin?

A developer told me, that pwm-pin for the fan control of penta-sata-hat conflicts with hdmi sound (I2S ?).

I'd like to verify that. But I can't

I use both - the fancontrol on the same rockpi4 which generates the sound for my AVR (over HDMI) and I can't confirm any conflicts as I don't hear any problems.

Link to comment
Share on other sites

7 hours ago, tony013 said:

Do you mind to publish the source of your overlay?

Sure thing, the attached overlays are written in absolut path notation. That is, they apply to any target base dtb regardless of whether they are built with the "@" switch or not. They can serve as a basis to collect overlays for all types of devices.                                                               
Gpiochip is configured in rk3399.dtsi, i.e. the overlays can be used as a template for all dtbs which include this file. Therefore, the compatible must be adjusted, and the con1-## names must be inserted in the right place.                                                                                         
Because libgpiod provides python bindings, it should be easy to make use of the con1-## names. Now you can forget about WiringPi. All you need is a devicetree overlay that assigns the con1-## names, and you can make any device with gpiochip support usable without changing the user space software.

 

7 hours ago, tony013 said:

Do you know about a way to find conflicts between muxed modules, which share the same pin?

The first step would be to look at the schematic to see if it's really wired that way. If so, you need to decide which feature you prefer and configure devicetree in the appropriate way. Maybe is this a solution to use a spare GPIO. If the wireing is ok, there is still the possibility it is misconfigured in the devicetree but only looking at the source will tell.

rk3399-nanopc-t4-con1.dts rk3399-rock-pi-4-con1.dts

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines