Добавлен пример для работы прерывания по gpio

This commit is contained in:
sasha80
2026-04-15 11:34:36 +03:00
parent 99f2780c1f
commit ade3b26942
235 changed files with 366 additions and 2 deletions

0
.github/workflows/build.yml vendored Normal file → Executable file
View File

1
.gitignore vendored Normal file → Executable file
View File

@@ -5,3 +5,4 @@ lib*.so.*
debian-template/wiringPi
debian-template/wiringpi-*.deb
gpio/gpio
.idea/

0
COPYING.LESSER Normal file → Executable file
View File

0
INSTALL Normal file → Executable file
View File

0
People Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

0
VERSION Normal file → Executable file
View File

0
debian-template/wiringPi/control_template Normal file → Executable file
View File

0
debian/.gitignore vendored Normal file → Executable file
View File

0
debian/changelog vendored Normal file → Executable file
View File

0
debian/compat vendored Normal file → Executable file
View File

0
debian/control vendored Normal file → Executable file
View File

0
debian/copyright vendored Normal file → Executable file
View File

0
debian/libwiringpi-dev.dirs vendored Normal file → Executable file
View File

0
debian/libwiringpi-dev.install vendored Normal file → Executable file
View File

0
debian/libwiringpi2.install vendored Normal file → Executable file
View File

0
debian/libwiringpi2.shlibs vendored Normal file → Executable file
View File

0
debian/rules vendored Normal file → Executable file
View File

0
debian/wiringpi.dirs vendored Normal file → Executable file
View File

0
debian/wiringpi.install vendored Normal file → Executable file
View File

0
devLib/Makefile Normal file → Executable file
View File

0
devLib/ds1302.c Normal file → Executable file
View File

0
devLib/ds1302.h Normal file → Executable file
View File

0
devLib/font.h Normal file → Executable file
View File

0
devLib/gertboard.c Normal file → Executable file
View File

0
devLib/gertboard.h Normal file → Executable file
View File

0
devLib/lcd.c Normal file → Executable file
View File

0
devLib/lcd.h Normal file → Executable file
View File

0
devLib/lcd128x64.c Normal file → Executable file
View File

0
devLib/lcd128x64.h Normal file → Executable file
View File

0
devLib/maxdetect.c Normal file → Executable file
View File

0
devLib/maxdetect.h Normal file → Executable file
View File

0
devLib/piFace.c Normal file → Executable file
View File

0
devLib/piFace.h Normal file → Executable file
View File

0
devLib/piFaceOld.c Normal file → Executable file
View File

0
devLib/piGlow.c Normal file → Executable file
View File

0
devLib/piGlow.h Normal file → Executable file
View File

0
devLib/piNes.c Normal file → Executable file
View File

0
devLib/piNes.h Normal file → Executable file
View File

0
devLib/scrollPhat.c Normal file → Executable file
View File

0
devLib/scrollPhat.h Normal file → Executable file
View File

0
devLib/scrollPhatFont.h Normal file → Executable file
View File

0
documentation/deutsch/functions.md Normal file → Executable file
View File

0
documentation/english/functions.md Normal file → Executable file
View File

0
examples/COPYING.LESSER Normal file → Executable file
View File

0
examples/Gertboard/7segments.c Normal file → Executable file
View File

0
examples/Gertboard/Makefile Normal file → Executable file
View File

0
examples/Gertboard/buttons.c Normal file → Executable file
View File

0
examples/Gertboard/gertboard.c Normal file → Executable file
View File

0
examples/Gertboard/record.c Normal file → Executable file
View File

0
examples/Gertboard/temperature.c Normal file → Executable file
View File

0
examples/Gertboard/voltmeter.c Normal file → Executable file
View File

0
examples/Gertboard/vumeter.c Normal file → Executable file
View File

3
examples/Makefile Normal file → Executable file
View File

@@ -48,7 +48,8 @@ SRC = blink.c blink8.c blink12.c \
delayTest.c serialRead.c serialTest.c okLed.c ds1302.c \
lowPower.c \
max31855.c \
rht03.c
rht03.c \
gpio-interrupt.c
OBJ = $(SRC:.c=.o)

0
examples/PiFace/Makefile Normal file → Executable file
View File

0
examples/PiFace/blink.c Normal file → Executable file
View File

0
examples/PiFace/buttons.c Normal file → Executable file
View File

0
examples/PiFace/ladder.c Normal file → Executable file
View File

0
examples/PiFace/metro.c Normal file → Executable file
View File

0
examples/PiFace/motor.c Normal file → Executable file
View File

0
examples/PiFace/reaction.c Normal file → Executable file
View File

0
examples/PiGlow/Makefile Normal file → Executable file
View File

0
examples/PiGlow/piGlow0.c Normal file → Executable file
View File

0
examples/PiGlow/piGlow1.c Normal file → Executable file
View File

0
examples/PiGlow/piglow.c Normal file → Executable file
View File

0
examples/README.TXT Normal file → Executable file
View File

0
examples/blink-thread.c Normal file → Executable file
View File

0
examples/blink.c Normal file → Executable file
View File

0
examples/blink.rtb Normal file → Executable file
View File

0
examples/blink.sh Normal file → Executable file
View File

0
examples/blink12.c Normal file → Executable file
View File

0
examples/blink12drcs.c Normal file → Executable file
View File

0
examples/blink6drcs.c Normal file → Executable file
View File

0
examples/blink8-drcn.c Normal file → Executable file
View File

0
examples/blink8.c Normal file → Executable file
View File

0
examples/clock.c Normal file → Executable file
View File

0
examples/delayTest.c Normal file → Executable file
View File

0
examples/ds1302.c Normal file → Executable file
View File

113
examples/gpio-interrupt.c Executable file
View File

@@ -0,0 +1,113 @@
/* Demonstration C GPIO interrupt handling routine for Raspberry Pi
This is a modified code found at https://github.com/phil-lavin/raspberry-pi-gpio-interrupt
The program displays a notice whenever you:
-turn on the Raspberry Pi's pin 11 (apply 3.3V),
-turn the pin off.
This routine uses wiringPi library (follow the installation instructions at wiringpi.com),
and should be compiled with a command:
gcc source_filename -o executable_filename -lwiringPi
You must have root privileges to run it - I don't know any workaround yet:
sudo ./executable_filename
Then the program displays a notice whenever you turn the GPIO pin 11 on and off.
It runs as an infinite loop and you can cancel it by pressing ctrl-C.
*/
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/time.h>
#include <wiringPi.h>
// Which GPIO pin we're using. For this program we'll use physical pin numbers.
#define PIN 27
// How much time a change must be since the last in order to count as a change
// (in microseconds); allows to avoid generating interrupts on contact bouncing etc.
#define IGNORE_CHANGE_BELOW_USEC 10000
// Current state of the pin
static volatile int state;
// Time of last change
struct timeval last_change;
// Handler for interrupt
void handle(void) {
struct timeval now;
static __uint64_t cnt;
unsigned long diff;
//gettimeofday(&now, NULL);
state = digitalRead(PIN);
printf("-->%d %d\n", ++cnt, state);
return;
// Time difference in microseconds
diff = (now.tv_sec * 1000000 + now.tv_usec) - (last_change.tv_sec * 1000000 + last_change.tv_usec);
// Filter any changes in intervals shorter than diff (like contact bouncing etc.):
/*
if (diff > IGNORE_CHANGE_BELOW_USEC) {
// Check whether the last state was on or off:
if (state) {
// Print info to console:
printf("Input goes off\n");
// You can add some code to do when input goes off here...
}
else {
// Print info to console:
printf("Input goes on\n");
// Add code to do when input goes on here...
}
// Change the "state" variable value:
state = !state;
}
*/
// Store the time for last state change:
last_change = now;
}
int main(void) {
// Init -- use the physical pin number on RPi P1 connector
if (wiringPiSetup() == -1)
{
printf("ошибка wiringPiSetup()\n");
exit(1);
}
// Set pin to input in case it's not
pinMode(PIN, INPUT);
pullUpDnControl(PIN, PUD_UP);
// Time now
gettimeofday(&last_change, NULL);
// Bind to interrupt
wiringPiISR(PIN, INT_EDGE_RISING, &handle);
// Get initial state of pin
state = digitalRead(PIN);
// Feedback for user that the program has started, depending on input state:
if (state) {
printf("Started! Initial state is on\n");
}
else {
printf("Started! Initial state is off\n");
}
// Waste time but not CPU
for (;;) {
sleep(1);
state = digitalRead(PIN);
}
}

0
examples/header.h Normal file → Executable file
View File

0
examples/isr-osc.c Normal file → Executable file
View File

0
examples/isr.c Normal file → Executable file
View File

0
examples/isr3.c Normal file → Executable file
View File

0
examples/isr_debounce.c Normal file → Executable file
View File

0
examples/lcd-adafruit.c Normal file → Executable file
View File

0
examples/lcd.c Normal file → Executable file
View File

0
examples/lowPower.c Normal file → Executable file
View File

0
examples/max31855.c Normal file → Executable file
View File

0
examples/nes.c Normal file → Executable file
View File

0
examples/okLed.c Normal file → Executable file
View File

0
examples/pwm.c Normal file → Executable file
View File

0
examples/q2w/Makefile Normal file → Executable file
View File

0
examples/q2w/binary.c Normal file → Executable file
View File

0
examples/q2w/blink-io.c Normal file → Executable file
View File

0
examples/q2w/blink.c Normal file → Executable file
View File

0
examples/q2w/blink.sh Normal file → Executable file
View File

0
examples/q2w/bright.c Normal file → Executable file
View File

0
examples/q2w/button.c Normal file → Executable file
View File

0
examples/q2w/volts.c Normal file → Executable file
View File

0
examples/rht03.c Normal file → Executable file
View File

Some files were not shown because too many files have changed in this diff Show More