From d351bcc03373d42abd07f6462fdb76964d61adee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20B=C3=A9rub=C3=A9?= Date: Fri, 31 May 2024 20:01:50 -0400 Subject: [PATCH] Preparing to support GPIOs on older kernels --- src/gpio.c | 9 +++++++-- src/gpio.h | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/gpio.c b/src/gpio.c index 7038647..9a2b278 100644 --- a/src/gpio.c +++ b/src/gpio.c @@ -1,7 +1,9 @@ #include "gpio.h" +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) const char *paths[] = {"/dev/gpiochip0", "/sys/class/gpio/gpiochip0"}; const char **path = paths; + int fd_gpio = 0; char gpio_count = 0; @@ -12,7 +14,6 @@ void gpio_deinit(void) { fd_gpio = 0; } -#ifdef __arm__ int gpio_init(void) { while (*path++) { if (access(*path, 0)) continue; @@ -81,6 +82,10 @@ int gpio_write(char pin, bool value) { return EXIT_SUCCESS; } #else +void gpio_deinit(void) { + +} + int gpio_init(void) { return EXIT_SUCCESS; } @@ -92,4 +97,4 @@ int gpio_read(char pin, bool *value) { int gpio_write(char pin, bool value) { return EXIT_SUCCESS; } -#endif +#endif \ No newline at end of file diff --git a/src/gpio.h b/src/gpio.h index 6489945..2ec53f1 100644 --- a/src/gpio.h +++ b/src/gpio.h @@ -1,13 +1,14 @@ #include +#include #include #include #include #include -#include #include -#ifdef __arm__ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) #include +#include #endif #define GPIO_ERROR(x, ...) fprintf(stderr, "%s \033[31m%s\033[0m\n", "[gpio] (x)", ##__VA_ARGS__) @@ -15,4 +16,4 @@ void gpio_deinit(void); int gpio_init(void); int gpio_read(char pin, bool *value); -int gpio_write(char pin, bool value); +int gpio_write(char pin, bool value); \ No newline at end of file