[SOLVED] GPIO interrupt of Edge trigger "both" on 4 pins

Post Reply
Tabularasa
Posts: 11
Joined: Wed Dec 07, 2016 6:50 am
languages_spoken: english, german
ODROIDs: C2
Has thanked: 0
Been thanked: 0
Contact:

[SOLVED] GPIO interrupt of Edge trigger "both" on 4 pins

Post by Tabularasa »

Hello,

Using https://github.com/hardkernel/wiringPi I can't setup more then 3 pins with edge detection "both" on my C2.
According to the documentation 4 pins should be possible in this mode but the 4th's pin edge mode is always "none".

Code: Select all

odroid@odroid64:~$ gpio edge 219 both
odroid@odroid64:~$ cat /sys/class/gpio/gpio219/edge 
both
odroid@odroid64:~$ gpio edge 236 both
odroid@odroid64:~$ cat /sys/class/gpio/gpio236/edge 
both
odroid@odroid64:~$ gpio edge 229 both
odroid@odroid64:~$ cat /sys/class/gpio/gpio229/edge 
both
odroid@odroid64:~$ gpio edge 224 both
odroid@odroid64:~$ cat /sys/class/gpio/gpio224/edge 
none
Does someone know a workaround? I need 4 pins since my project involves 2 encoders.
Last edited by Tabularasa on Wed Mar 08, 2017 2:53 am, edited 1 time in total.

User avatar
odroid
Site Admin
Posts: 36921
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1593 times
Been thanked: 1069 times
Contact:

Re: wiringPi - GPIO interrupt of Edge trigger "both" on 4 pi

Post by odroid »

Check the "lsmod" output.
One of modules(like a touchscreen driver) could use a GPIO IRQ.

mjbogusz
Posts: 1
Joined: Sun Feb 26, 2017 11:46 pm
languages_spoken: english, polish
ODROIDs: Odroid C2
Has thanked: 0
Been thanked: 0
Contact:

Re: wiringPi - GPIO interrupt of Edge trigger "both" on 4 pi

Post by mjbogusz »

First, check whether something is using the pin using

Code: Select all

sudo cat /sys/kernel/debug/gpio
For me it reported ts-pendown on 2 pins I've tried to use (via /sys/class/gpio/), and after some googling I've found it was caused by sx865x module (3.5" touchscreen driver). To block it from autoloading:

Code: Select all

sudo -i sh -c 'echo "blacklist sx865x" > /etc/modprobe.d/blacklist-sx865x.conf'

Tabularasa
Posts: 11
Joined: Wed Dec 07, 2016 6:50 am
languages_spoken: english, german
ODROIDs: C2
Has thanked: 0
Been thanked: 0
Contact:

Re: wiringPi - GPIO interrupt of Edge trigger "both" on 4 pi

Post by Tabularasa »

Thanks a lot guys. I'm using the 7 inch touch screen panel and think its driver uses 2 of the interrupts.

I found a workaround to use 2 encoders with 6 interrupts total.
The first pin stays on "both" while the second pin will trigger only on "rising" edge. A 100pF capacitor between the middle pin of the encoder and pin a does create additional triggers that are filtered with a state machine algorithm.
It works 100% clockwise and sometimes misses a step ccw. Not perfect but good enough for my project.

User avatar
odroid
Site Admin
Posts: 36921
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1593 times
Been thanked: 1069 times
Contact:

Re: wiringPi - GPIO interrupt of Edge trigger "both" on 4 pi

Post by odroid »

Can you tell me which display device do you use?
Does it have a resistive type touch screen?

Tabularasa
Posts: 11
Joined: Wed Dec 07, 2016 6:50 am
languages_spoken: english, german
ODROIDs: C2
Has thanked: 0
Been thanked: 0
Contact:

Re: wiringPi - GPIO interrupt of Edge trigger "both" on 4 pi

Post by Tabularasa »

I'm using a VU7PLUS capacitive touchscreen but the problem occurs even if it's not connected.
I blacklisted the sx865x module but it didn't make a difference.

I was able to see "both" on all 4 GPIO by using the "gpio edge xxx both" command

Unfortunately when I try in in C the last GPIO's edge is always "none".

Here is a simple porgram I used to set and check the GPIO status. The 4th pin is exported but always "none"
Does PITHREAD_CREATE take up an interrupt?

Code: Select all

#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

int rot1_pin_a = 10; // rotary 1 pin a
int rot1_pin_b = 26; // rotary 1 pin b
int rot2_pin_a = 22; // rotary 2 pin a
int rot2_pin_b =  4; // rotary 2 pin b


PI_THREAD(rotary_loop)
{
	void updateEncoders(void)
	{	
		int r1a = digitalRead(rot1_pin_a);
		int r1b = digitalRead(rot1_pin_b);
		int r2a = digitalRead(rot2_pin_a);
		int r2b = digitalRead(rot2_pin_b);

		printf("rot1_pin_a: %d\t", r1a);       
		printf("rot1_pin_b: %d\t", r1b);		
		printf("rot2_pin_a: %d\t", r2a);       
		printf("rot2_pin_b: %d\n\r", r2b);
	}
    
        wiringPiISR(rot1_pin_a,INT_EDGE_BOTH, updateEncoders);
        wiringPiISR(rot1_pin_b,INT_EDGE_BOTH, updateEncoders);
        wiringPiISR(rot2_pin_a,INT_EDGE_BOTH, updateEncoders);
        wiringPiISR(rot2_pin_b,INT_EDGE_BOTH, updateEncoders);
        delay(10000000);
	
}


int main(void)
{	
  	wiringPiSetup() ;	
	
        pinMode(rot1_pin_a, INPUT);
        pinMode(rot1_pin_b, INPUT);
        pinMode(rot2_pin_a, INPUT);
        pinMode(rot2_pin_b, INPUT);

       pullUpDnControl(rot1_pin_a, PUD_UP);
       pullUpDnControl(rot1_pin_b, PUD_UP);
       pullUpDnControl(rot2_pin_a, PUD_UP);
       pullUpDnControl(rot2_pin_b, PUD_UP);
	
	piThreadCreate (rotary_loop) ;
		
	while (1){
	delay(5);
	}
	
	return 0; 
}

User avatar
odroid
Site Admin
Posts: 36921
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1593 times
Been thanked: 1069 times
Contact:

Re: wiringPi - GPIO interrupt of Edge trigger "both" on 4 pi

Post by odroid »

Ahhh.. Sorry. I should check your issue earlier.
The SD card driver already uses two GPIO IRQs for the CARD-DETECT signal.

I've just updated the WiKi page.
http://odroid.com/dokuwiki/doku.php?id= ... rdware_irq

Tabularasa
Posts: 11
Joined: Wed Dec 07, 2016 6:50 am
languages_spoken: english, german
ODROIDs: C2
Has thanked: 0
Been thanked: 0
Contact:

Re: wiringPi - GPIO interrupt of Edge trigger "both" on 4 pi

Post by Tabularasa »

I use an eMMC. Is it possible to deactivate the SD card driver and gain the 2 additional interrupts or are both types (eMMC and SD cards) covered by one driver (I assume it's MMC_AML driver).

User avatar
odroid
Site Admin
Posts: 36921
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1593 times
Been thanked: 1069 times
Contact:

Re: wiringPi - GPIO interrupt of Edge trigger "both" on 4 pi

Post by odroid »

You can disable the SD function via modifying the DeviceTree.

Code: Select all

                compatible = "amlogic, aml_sd_emmc";
                dev_name = "aml_newsd.0";
                /*
                status = "okay";
                */
                status = "disabled";
We could use 8 GPIO IRQs after applying above chages.

Tabularasa
Posts: 11
Joined: Wed Dec 07, 2016 6:50 am
languages_spoken: english, german
ODROIDs: C2
Has thanked: 0
Been thanked: 0
Contact:

Re: wiringPi - GPIO interrupt of Edge trigger "both" on 4 pi

Post by Tabularasa »

You are awesome! Changed the device tree, recompiled the kernel and it just works.

Code: Select all

odroid@odroid64:/$ sudo cat /sys/kernel/debug/gpio
GPIOs 122-135, platform/c1109880.pinmux, ao-bank:
 gpio-127 (?                   ) in  lo    
 gpio-135 (blue:heartbeat      ) out hi    

GPIOs 136-255, platform/c1109880.pinmux, banks:
 gpio-150 (rst_pin             ) in  hi    
 gpio-165 (amlsd               ) out hi    
 gpio-219 (sysfs               ) in  hi IRQ
 gpio-224 (sysfs               ) in  hi IRQ
 gpio-229 (sysfs               ) in  hi IRQ
 gpio-236 (sysfs               ) in  hi IRQ
Thanks a lot guys.

User avatar
odroid
Site Admin
Posts: 36921
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1593 times
Been thanked: 1069 times
Contact:

Re: [SOLVED] GPIO interrupt of Edge trigger "both" on 4 pins

Post by odroid »

Thank you for the confirmation. :D

BTW, can you tell me what you are developing with two encoders?

Tabularasa
Posts: 11
Joined: Wed Dec 07, 2016 6:50 am
languages_spoken: english, german
ODROIDs: C2
Has thanked: 0
Been thanked: 0
Contact:

Re: [SOLVED] GPIO interrupt of Edge trigger "both" on 4 pins

Post by Tabularasa »

It's a boxed DVS system based on the project Ximae presetend here in the forums: http://forum.odroid.com/viewtopic.php?f=116&t=10837

In the beginning I thought 2 encoders are necessary for optimal user experience. It's still in progress and in the current iteration 1 encoder would have been sufficient. I think I will present the project here in the forum when the case is ready.

User avatar
odroid
Site Admin
Posts: 36921
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1593 times
Been thanked: 1069 times
Contact:

Re: [SOLVED] GPIO interrupt of Edge trigger "both" on 4 pins

Post by odroid »

I see that DVS controller need a rotary encoder for better user interface. :D
I hope you will have a nice case.

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 2 guests