zhaolei / WiringOP

This is a GPIO access library for OrangePi. It is based on the original WiringPi for Raspberry Pi.
GNU Lesser General Public License v3.0
351 stars 134 forks source link

wiringPiISR and waitForInterrupt are changed. #5

Closed nopnop2002 closed 7 years ago

nopnop2002 commented 7 years ago

GPIO of OPI don't have interrupt function. poll function don't work. So read periodically /sys/class/gpio_sw/XXX/data.(/sys/class/gpio_sw/PA1/data) And change is judged.

sercxjo commented 7 years ago

GPIO has interrups in other driver enabled in Armbian. It works with the WereCatf's fork.

nopnop2002 commented 7 years ago

I tried this code using WereCatf's fork. But even if a button was pressed, an event didn't occur. Is an additional driver somewhat necessary?

`#include

include

include

define pin 0

void signal(void){ printf("Signal\n"); }

int main(void){ if(wiringPiSetup() == -1) { printf("wiringPiSetup Error\n"); } pinMode(pin,INPUT); wiringPiISR(pin, INT_EDGE_FALLING, signal ); // wiringPiISR(pin, INT_EDGE_RISING, signal ); while(1) { sleep(10000); } return 0; } `

sercxjo commented 7 years ago

WereCatf's fork based on old version, I have merged it with the current fork, better see it.

  1. Interrupts works only with PA... and PG... pins.
  2. I use Ubuntu with recompiled kernel. Check that directory /sys/class/gpio/ is presented.

My example with button between pin 37 (PA20) and pin 39 (Ground):

#define DBTN 37
wiringPiSetupPhys();
pinMode(DBTN, INPUT);
pullUpDnControl(DBTN, PUD_UP);
wiringPiISR(DBTN, INT_EDGE_BOTH, &btn_interrupt) ;
nopnop2002 commented 7 years ago

Hello sercxjo. Would your fork also work in Armbian? Is recompiled kernel needed?

sercxjo commented 7 years ago

I have not tried Armbian. Here is written that it works. I just ported kernel config-file from the last version of Armbian. Just add CONFIG_GPIO_SYSFS=y to the config.