Compare commits

..

18 Commits

Author SHA1 Message Date
Maxim
83959e3da8 доработка с двумя режимами 2026-06-09 15:45:31 +03:00
Maxim
79c711a486 wip 2026-06-09 13:44:52 +03:00
Maxim
bf23cf5ca4 версия без принтов 2026-06-09 13:37:59 +03:00
Maxim
c863f5bf20 доработка в кабинете 2026-05-06 12:52:14 +03:00
Maxim
655a8dd474 git changes 2026-05-04 09:33:30 +03:00
Maxim
eb364c8831 После отладки 2026-05-04 09:33:00 +03:00
Maxim
e1628a6c0a WIP. Для отладки 2026-04-29 13:57:54 +03:00
sasha80
9d8910af0a Доработка. Функция для чтения параллельного порта. Пример в котором данные с параллельной шины направляются в stdout 2026-04-20 08:20:42 +03:00
sasha80
ade3b26942 Добавлен пример для работы прерывания по gpio 2026-04-15 11:34:49 +03:00
mstroh
99f2780c1f Merge pull request #417 from WiringPi/develop
WiringPi 3.18
2026-02-08 21:32:04 +01:00
Manfred Wallner
c6bdf371d5 Merge pull request #414 from WiringPi/mstroh76-patch-1
Unit test: Adjust for Pi1/Zero test hardware
2026-02-08 21:28:11 +01:00
Manfred Wallner
056d3b5332 Merge pull request #415 from WiringPi/mstroh76-patch-2
Unit test: Supporting 5 SPI CS channels
2026-02-08 21:27:46 +01:00
Manfred Wallner
c88fb22b2d Merge pull request #416 from WiringPi/mstroh76-patch-3
Unit test: Adjust MaxPWMFreq for Raspberry Pi 1 models
2026-02-08 21:27:05 +01:00
mstroh
3025af515e Adjust MaxFreq for Raspberry Pi 1 models
Updated maximum frequency settings for Raspberry Pi models.
2026-01-18 11:10:55 +01:00
mstroh
111f4f36d1 Unit test supporting 5 SPI CS channels 2026-01-17 19:45:30 +01:00
mstroh
ece0ffe62a Change ANOTHER_LISTENER_PIN to BCM 12
old has conflict with SPI CE1
2026-01-17 16:27:49 +01:00
mstroh
960b112000 Adjust for Pi1/Zero test hardware 2026-01-17 15:00:49 +01:00
mstroh
b2af17eea9 Merge pull request #366 from WiringPi/develop
Release 3.16
2025-06-06 20:22:31 +02:00
234 changed files with 347 additions and 20 deletions

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

3
.gitignore vendored Normal file → Executable file
View File

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

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

5
examples/Makefile Normal file → Executable file
View File

@@ -27,7 +27,7 @@ Q ?= @
endif
#DEBUG = -g -O0
DEBUG = -O3
DEBUG = -O0 -g
CC ?= gcc
INCLUDE = -I/usr/local/include
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe $(EXTRA_CFLAGS)
@@ -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

281
examples/gpio-interrupt.c Normal file
View File

@@ -0,0 +1,281 @@
/*
Чтение данных с параллельной 8-битной шины Raspberry Pi 4
и вывод в stdout
Сборка (внутри WiringPi/examples):
make really-all
Требования:
Используется модифицированный WiringPi с функцией digitalReadPins()
Режимы:
fill - заполняет паузы последним байтом (высокий CPU, непрерывный поток)
sleep - спит при отсутствии данных (низкий CPU, только реальные данные)
*/
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stddef.h>
#include <stdbool.h>
#include <time.h>
#include <sys/time.h>
#include <getopt.h>
#include <wiringPi.h>
/*
Подключение физические контакты на Raspberry pi4:
29 - D0
7 - D1
22 - D2
18 - D3
37 - D4
35 - D5
33 - D6
31 - D7
36 - Запись
14 - GND
*/
unsigned int wr_pin = 27; // Пин сигнала записи (WR)
unsigned int pins[] = { 21, 7, 6, 5, 25, 24, 23, 22 }; // 8-битная шина данных (wPi)
const size_t out_buffer_len = 32U; // Размер логируемого пакета
const size_t fifo_buffer_len = 4096U; // Размер ПППУ в байтах
// Режимы работы
typedef enum {
MODE_FILL, // Заполнение пауз последним байтом (оригинальное поведение)
MODE_SLEEP // Сон при отсутствии данных (энергоэффективный)
} run_mode_t;
// Глобальные настройки
static run_mode_t run_mode = MODE_SLEEP; // По умолчанию энергоэффективный режим
static bool debug_mode = false;
struct fifo {
char *buffer;
size_t len;
size_t wri;
size_t rdi;
};
void fifo_reset(struct fifo* ff) {
ff->wri = 0;
ff->rdi = 0;
}
bool fifo_init(struct fifo* ff, size_t len) {
ff->buffer = malloc(len);
ff->len = len;
fifo_reset(ff);
return ff->buffer != NULL;
}
void fifo_uninit(struct fifo* ff) {
free(ff->buffer);
ff->buffer = NULL;
fifo_reset(ff);
}
size_t fifo_available(struct fifo *ff) {
if (ff->wri >= ff->rdi)
return ff->wri - ff->rdi;
else
return ff->wri + ff->len - ff->rdi;
}
bool fifo_can_write(struct fifo *ff, size_t len) {
return (ff->len - fifo_available(ff)) > len;
}
bool fifo_can_read(struct fifo *ff, size_t len) {
return fifo_available(ff) >= len;
}
bool fifo_try_read(struct fifo *ff, char* buffer, size_t len) {
if (!fifo_can_read(ff, len))
return false;
memcpy(buffer, &ff->buffer[ff->rdi], len);
ff->rdi = (ff->rdi + len) % ff->len;
return true;
}
bool fifo_try_write(struct fifo *ff, char* buffer, size_t len) {
if (!fifo_can_write(ff, len))
return false;
memcpy(&ff->buffer[ff->wri], buffer, len);
ff->wri = (ff->wri + len) % ff->len;
return true;
}
static struct fifo isr_ff;
// Антидребезг
static unsigned long long last_time_us = 0;
static const long debounce_us = 5000; // 5 мс
// Диагностика
static unsigned long total_bytes = 0;
static unsigned long interrupts_processed = 0;
static unsigned long loop_iterations = 0;
// Обработчик прерывания
void isr_handle(void) {
unsigned long long now_us;
struct timeval now;
gettimeofday(&now, NULL);
now_us = now.tv_sec * 1000000LL + now.tv_usec;
if (now_us - last_time_us < debounce_us) return;
last_time_us = now_us;
interrupts_processed++;
char byte_read = 0xff & digitalReadPins(pins, sizeof pins / sizeof pins[0]);
fifo_try_write(&isr_ff, &byte_read, 1);
}
// Режим 1: Заполнение пауз последним байтом
void run_mode_fill(void) {
char byte;
char byte_prev = 0;
while (true) {
if (fifo_try_read(&isr_ff, &byte, 1)) {
fwrite(&byte, 1, 1, stdout);
byte_prev = byte;
total_bytes++;
} else {
fwrite(&byte_prev, 1, 1, stdout);
}
fflush(stdout);
loop_iterations++;
if (debug_mode && (loop_iterations % 1000000 == 0)) {
fprintf(stderr, "[DEBUG] Mode=fill, iterations=%lu, bytes=%lu\n",
loop_iterations, total_bytes);
}
}
}
// Режим 2: Сон при отсутствии данных (с минимальной диагностикой)
void run_mode_sleep(void) {
char byte;
int first_bytes_shown = 0;
// Минимальная диагностика при запуске
fprintf(stderr, "GPIO Monitor: waiting for data on WR pin %d...\n", wr_pin);
fflush(stderr);
while (true) {
if (fifo_try_read(&isr_ff, &byte, 1)) {
fwrite(&byte, 1, 1, stdout);
fflush(stdout);
total_bytes++;
loop_iterations = 0;
// Показать первые 10 байт в stderr
if (first_bytes_shown < 10) {
if (first_bytes_shown == 0) {
fprintf(stderr, "First bytes: ");
}
fprintf(stderr, "0x%02x ", (unsigned char)byte);
first_bytes_shown++;
if (first_bytes_shown == 10) {
fprintf(stderr, "\n");
fflush(stderr);
}
}
} else {
usleep(1000);
loop_iterations++;
}
if (debug_mode && (loop_iterations > 0) && (loop_iterations % 10000 == 0)) {
fprintf(stderr, "[DEBUG] Mode=sleep, idle loops=%lu, bytes=%lu\n",
loop_iterations, total_bytes);
}
}
}
// Парсинг аргументов командной строки
void parse_arguments(int argc, char *argv[]) {
static struct option long_options[] = {
{"mode", required_argument, 0, 'm'},
{"debug", no_argument, 0, 'd'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
int opt;
int option_index = 0;
while ((opt = getopt_long(argc, argv, "m:dh", long_options, &option_index)) != -1) {
switch (opt) {
case 'm':
if (strcmp(optarg, "fill") == 0) {
run_mode = MODE_FILL;
} else if (strcmp(optarg, "sleep") == 0) {
run_mode = MODE_SLEEP;
} else {
fprintf(stderr, "Неизвестный режим: %s\n", optarg);
fprintf(stderr, "Доступные режимы: fill, sleep\n");
exit(EXIT_FAILURE);
}
break;
case 'd':
debug_mode = true;
break;
case 'h':
printf("Использование: %s [OPTIONS]\n\n", argv[0]);
printf("Опции:\n");
printf(" -m, --mode=MODE Режим работы: fill или sleep\n");
printf(" fill - заполнение пауз последним байтом\n");
printf(" sleep - сон при отсутствии данных (по умолчанию)\n");
printf(" -d, --debug Включить диагностику в stderr\n");
printf(" -h, --help Показать эту справку\n");
exit(EXIT_SUCCESS);
break;
default:
fprintf(stderr, "Используйте --help для справки\n");
exit(EXIT_FAILURE);
}
}
}
int main(int argc, char *argv[]) {
parse_arguments(argc, argv);
if (!fifo_init(&isr_ff, fifo_buffer_len)) {
perror("fifo_init()");
exit(EXIT_FAILURE);
}
if (wiringPiSetup() == -1) {
perror("wiringPiSetup()");
exit(EXIT_FAILURE);
}
pinMode(wr_pin, INPUT);
pullUpDnControl(wr_pin, PUD_UP);
for (unsigned int i = 0; i < (sizeof pins / sizeof pins[0]); i++) {
unsigned int pin = pins[i];
pullUpDnControl(pin, PUD_DOWN);
pinMode(pin, INPUT);
}
if (wiringPiISR(wr_pin, INT_EDGE_RISING, &isr_handle) != 0) {
perror("wiringPiISR()");
exit(EXIT_FAILURE);
}
if (run_mode == MODE_FILL) {
run_mode_fill();
} else {
run_mode_sleep();
}
fifo_uninit(&isr_ff);
return EXIT_SUCCESS;
}

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