Yet more on GPIO interrupts
-
@Boken-Lin No, I was never able to figure out how the edge file could be created and used via the sysfs interface. But since with the kernel patch and usage of kmod-gpio-irq I can now successfully deal with GPIO interrupts in C/C++ based on the code in gpio-test I am happy with what I can now achieve.
A relevant comment is that in playing with code based on gpio-test I have found:
-
There is only a single irq handler that can be installed using the existing code
-
BUT amongst the information passed to the irq handler is a structure that in one of its fields gives both the pin number for which the handler is called and the state of the pin - with this, it will be easy to write some code that:
- Calls on to an additional handler specific for an individual pin
- Can distinguish between rising and falling changes in the pin
I will be updating my new-gpio code to incorporate GPIO pin interrupt handling capabilities based on this.
Some interesting information about how the kmod-gpio-irq code works is:
- It works by detecting writes (in user mode code) information about the pin number and the process id to /sys/kernel/debug/gpio-irq to enable and disable interrupt handling for the pin
- When interrupt handling for a pin is added by writting to /sys/kernel/debug/gpio-irq the following line is created in /sys/kernel/debug/gpio (e.g.for pin 6):
- gpio-6 (GPIO IRQ handler ) in lo
- This line is removed when the interrupt handler for the pin is removed
As an aside, the default contents of /sys/kernel/debug/gpio are :
- gpio-8 (USB power ) out hi
gpio-11 (reset ) in lo
gpio-27 (onion:amber:system ) out lo
Of these:
a. I don't understand why gpio-8 is there (????)
b. gpio-11 makes sense since pin 11 is the reset pin
c. gpio-27 makes some sense since I understand that pin 27 is the Omega LED
-
-
@Boken-Lin A few days ago, you said: We will definitely add the patch into our buildroot so that the next update will have the irq support built-in.
This is NOT meant to be a complaint or hurry up, but do you have any rough idea when the updated with GPIO irq support as per the patch will be available?
The reason I ask is that I have now got some significant C/C++ code (as an extension to the new-gpio code I posted some time ago) that from my testing appears to work well in handling GPIO interrupts.
This includes a test program that in a very simple manner can be used to set a background program running that, on an interrupt (e.g. a button press), will run any shell command specified at the time the program was started. Thus allowing running of any command to be associated with a button push - multiple such instances can be set up - one for each GPIO pin if so desired.
However, this code is dependent upon:
- A kernel version with the above patch
- Installation of the kmod-gpio-irq package
I would like to post this code since I believe it would be of general use, but there is no point in doing so until the update is generally available.
-
@Kit-Bishop We will be putting out a new firmware today.
-
@Boken-Lin Great Thanks. Didn't mean to give you a hard time over this.
-
Hi @Kit-Bishop, if you do an
oupgrade
now, you should be able to upgrade to a firmware with the patches applied. Please let me know if it works.
-
@Boken-Lin Unfortunately, no it doesn't seem to work after a clean update to the latest release.
The first issue is that there is no kmod-gpio-irq that I require - it is not available via opkg even after doing an opkg update - so I tried installing the version I had built using the OpenWrt cross compile environment (and which worked with the patched system image I had built and installed).
I think i have tracked the problem down to the fact that there is no /sys/kernel/debug/gpio-irq file. The GPIO irq handling works by writing to this file.
I am trying to track down what I had installed in my separately compiled image that would have created this file.
If you have any info on this, I would be interested to hear. meanwhile, I will try to keep working to track down what is different between the latest Omega build (for which GPIO irq does not work) and the system build that I produced (for which GPIO irq works)
-
Hi @Kit-Bishop, It could have been that the patch did not get included in the build for whatever reason. I will work with @Lazar-Demin to sort it out tomorrow.
-
@Boken-Lin Thanks. Would be good if it was as simple as not having included the patch (it's this one: https://github.com/GBert/openwrt-misc/blob/master/gpio-test/src/patches-3.18/739-MIPS-ath79-add-gpio-irq-support.patch).
Though, it will be essential also that kmod-gpio-irq be available via opkg as well.I'm probably about to take a break (it's getting to be evening here) - if I don't here anything more from you on this, I will keep looking tomorrow.
-
hey @Kit-Bishop firmware b265 and later have kmod-gpio-irq and the gpio.c patch.
I installed and rangpio-test
locally, the edge based interrupts do in fact get triggered!Btw, I made the
gpio-test
package available in the Onion package repo.Happy hacking!
-
@Lazar-Demin Cool Thanks for quick feedback
I am currently on firmware b264 so will shortly upgrade and try again. Will report back when done
-
@Lazar-Demin Absolutely fantastic! Thank you very much
Have upgraded to b266 and everything works perfectly - including my GPIO IRQ and test program.
My IRQ code is basically an extension to the code I have previously posted for new GPIO access (https://community.onion.io/topic/143/alternative-c-code-for-gpio-access) with the addition of IRQ handling capabilities.
Because it may be of use to others, I will do the following:
- Send the test program and needed library with some basic documentation on its use in a separate post
- Later, update the package and details in https://community.onion.io/topic/143/alternative-c-code-for-gpio-access with the latest sources and full documentation